AMPL An Introduction. Outline AMPL - What is it (good for)? Basics Starting a Problem Running the Problem Example.

Slides:



Advertisements
Similar presentations
IENG313 Operation Research I
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Introducing JavaScript
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Html: getting started HTML is hyper text markup language. It is what web browsers look at on the Internet. HTML documents should be created in a simple.
What is GAMS?. While they are not NLP solvers, per se, attention should be given to modeling languages like: GAMS- AIMMS-
Linear Programming Models & Case Studies
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Tutorial 10: Performing What-If Analyses
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Computational Methods for Management and Economics Carla Gomes
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Computer Science 1620 Programming & Problem Solving.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
AMPL Presentation 1 By Raymond Kleinberg Outline AMPL - Ugh! - What is it good for? Basics Starting a Problem Running the Problem Example.
Nonlinear Pricing Models
 Explore the principles of cost-volume-profit relationships  Perform a basic what-if analysis  Use Goal Seek to calculate a solution  Create a one-variable.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
EXAMPLE: 3.1 ASSEMBLING AND TESTING COMPUTERS
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
Advanced Excel for Finance Professionals A self study material from South Asian Management Technologies Foundation.
Network Models II Shortest Path Cross Docking Enhance Modeling Skills Modeling with AMPL Spring 03 Vande Vate.
A GAMS TUTORIAL. WHAT IS GAMS ? General Algebraic Modeling System Modeling linear, nonlinear and mixed integer optimization problems Useful with large,
SqlReports Dean Dahlvang PSUG-MO March About Dean Dean Dahlvang Director of Administrative Technology for the Proctor.
Spreadsheet Modeling of Linear Programming (LP). Spreadsheet Modeling There is no exact one way to develop an LP spreadsheet model. We will work through.
Spreadsheet-Based Decision Support Systems Chapter 22:
Introduction to Python
Optimization Models Mathematical optimization models usually contain an objective (what to do) constraints (the rules that must be followed). Also referred.
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Linear Programming: Basic Concepts
GAMS Anwendung Nutzeroberfläche eigene Programme Modellierungs- System GAMS AMPL ILOG Studio … Solver CPLEX, CONOPT, MINOS, COIN, BARON,...
Spreadsheet Modeling and Decision Analysis, 3e, by Cliff Ragsdale. © 2001 South-Western/Thomson Learning. 6-1 Integer Linear Programming Chapter 6.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
1 ILOG CPLEX CPLEX is a product developed by ILOG to solve  LPs  MIPs  QPs  MIQPs  Network Flow problems CPLEX technologies  CPLEX callable library.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Chapter 19: The Solver Re-Visited Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
1 3.1 Basic Control Flow and Operators in the OPTMODEL Procedure 3.2 Model Updates in the OPTMODEL Procedure 3.3 Sensitivity Analysis and Parametric Programming.
M1G Introduction to Database Development 5. Doing more with queries.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
15.053Tuesday, April 9 Branch and Bound Handouts: Lecture Notes.
Lab 3 Solver Add-In In Excel ► Lab 2 Review ► Solver Add-in Introduction ► Practice Solver following Instructor » Saferly Inc.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
RESEARCH ASSISTANTS Mazyar Ghadirinejad & Farhood Rismanchian.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Intermediate 2 Computing Unit 2 - Software Development.
Introduction to LISP Atoms, Lists Math. LISP n LISt Processing n Function model –Program = function definition –Give arguments –Returns values n Mathematical.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
 Labs next week:  Both labs will be posted on Monday  Both will be due the following Monday  Your decision on which to do first ▪ Web App Design Lab.
Introduction to Integer Programming Integer programming models Thursday, April 4 Handouts: Lecture Notes.
ALLOY: A Formal Methods Tool Glenn Gordon Indiana University of Pennsylvania COSC 481- Formal Methods Dr. W. Oblitey 26 April 2005.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
9/21/04 James Gallagher Server Installation and Testing: Hands-on ● Install the CGI server with the HDF and FreeForm handlers ● Link data so the server.
Development Environment
Completing the Problem-Solving Process
Matlab Training Session 4: Control, Flow and Functions
Excel Solver IE 469 Spring 2017.
Intro to PHP & Variables
MATLAB: Structures and File I/O
EMIS 8373: Integer Programming
T. Jumana Abu Shmais – AOU - Riyadh
A Mathematical Programming Language
Excel Solver IE 469 Fall 2018.
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
Matlab Basics Tutorial
Presentation transcript:

AMPL An Introduction

Outline AMPL - What is it (good for)? Basics Starting a Problem Running the Problem Example

Outline (Continued) Two File Format Why Use a Data File? All About Sets Example (single file) Example with data file Logical Operators

Outline (A little More) Set Operations Set Indexing Syntax Where to get AMPL

AMPL What is it (good for)?

AMPL is: A Mathematical Programming Language Supports over 30 solvers Only need to know syntax for AMPL to use many different solvers

AMPL does: Solves LP’s Solves IP’s Solves MIP’s, and non-linear programs

Basics Files you will need How to write them How to save them

Writing the.mod file Open up a non-contextual text editor (e.g. GNU Emacs, OxEdit, or textedit), type the model, save with file extension “.mod”

Syntax of File AMPL is a computer language, so it doesn’t understand what you mean Because of this, there is a particular format that AMPL files must have to run properly The format is fairly straightforward Here’s how it goes:

Order of entry Enter the variables first, e.g.: var x1 >=0; var Sally >=4.5; var smileyface <=-1; var happy integer >=0; Everything has to be identified before you use it, so AMPL knows it is there to use

Order of Entry- Cont. Next enter the objective: maximize OBJ: 3*x1 - happy + 2*Sally; minimize COST: 3*x3 + 2*x1 - Sally; maximize WHOCARES: 0;

A Quick Note: AMPL is case sensitive, so “SALLY”, “Sally”, and “sally” are three different names for variables. If something isn’t working correctly, a case error is an easy thing to identify and fix.

Order of Entry - Cont. Next enter the constraints: subject to WOOD: 2*x1 - 40*happy<=27; subject to WORK: x *Sally<=34; subject to MACHINE: happy - Sally<=14;

Put it all together: var x1 >=0; var Sally >=4.5; var smileyface <=-1; var happy integer >=0; maximize OBJ: 3*x1 - happy + 2*Sally + 4.5*smileyface; subject to WOOD: 2*x1 - 40*happy<=27; subject to WORK: x *Sally<=34; subject to MACHINE: happy - 3*smileyface<=14;

Running the File Once you have the file written and saved, we need to run it to get our solution.

How to Run AMPL Open up AMPL Tell AMPL what you want solved by: “model \project1.mod;” If the file is in AMPL’s search path, you may be able to just enter “model FILENAME.mod;” If you want to use a different solver: “option solver ;” Tell AMPL to solve it: “solve;”

Subject to Semicolons You may have noticed all the semicolons running around the file we put together, and in the commands to run the model. These tell AMPL where to separate lines, and things will not work properly without them. For instance, if you typed “solve” rather than “solve;”, AMPL would return a prompt that looks like this “ampl?”

Getting the variables This will only give you the optimal value, if it exists. How do you know the variable values that give this objective? Tell AMPL to give them to you: “display x1,x3,Sally,happy,smileyface;” This will display the variable values Remember, AMPL is case sensitive.

Put it all together ampl: model data\ampl1.mod; ampl: option solver cplex; ampl: solve; CPLEX 8.0.0, optimal integral solution found, objective value 712.2, 0 MIP iterations, 0 branch and bound nodes display x1,x3,Sally,smileyface,happy; x1 = 0 x3 = -1 Sally = happy = 11 smileyface = 0

The.dat File AMPL supports using a separate file for the particular data The.dat file holds the values for the parameters, and the names of the variables

Why Use 2 Files? You may want to do similar problems You may need to modify the data, but not the model It makes finding and changing parameters easy It makes adding or removing variables easy

All About Sets AMPL lets you define sets in the model by declaring them: set SETNAME Once a set is declared, you can index parameters over it: param PARAMETER {i in SETNAME} Alternatively: param PARAMETER {SETNAME} You can even index variables over sets: var VARIABLE {i in SETNAME} Also, you can use summation notation: sum {i in SETNAME} VARIABLE[i]*PARAMETER[i]

A (Relatively) Simple Example Suppose there is a steel mill that can process raw steel into two products, bands and coils. The manager of the mill wants to maximize his profit, given the restrictions on processing time available, and the limitations on how much he can realistically sell of each Bands can be processed at 200 tons per hour, at a profit of $25 per ton, and at most 6000 tons can be sold Coils are processed at 140 tons per hour, at a profit of $30 per ton, with a market cap of 4000 tons There are 40 hours available per week to process the steel

The old way Without using sets or a.dat file, the model would look something like this: var Bands; var Coils; maximize Profit: 25 * Bands + 30 * Coils; subject to Time: (1/200)*Bands + (1/140)*Coils <= 40; subject to B_Limit: 0 <= Bands <= 6000; subject to C_Limit: 0 <= Coils <= 4000;

The New Way Alternatively, we could split this into a.mod file and a.dat file:

steel.mod set Products; param rate {i in Products}; param profit {i in Products}; param market {i in Products}; param hours; var X {i in Products}; maximize Total_Profit: sum {i in Products} X[i] * profit[i]; subject to Time: sum {i in Products} X[i]/rate[i]<=hours; subject to Market {i in Products}: 0<= X[i] <= market[i];

steel.dat set Products := bands coils; param: ratemarketprofit := bands coils ; param hours := 40;

WHY???? Right now, it looks like the old way is easier, right? What if we want to add a new product, rods? In the old way, we would need to find every place that something might change and alter it individually In the new way, we just have to change the.dat file

The Old Way, Updated var Bands; var Coils; var Rods; maximize Profit: 25 * Bands + 30 * Coils + 28 * Rods; subject to Time: (1/200)*Bands + (1/140)*Coils + (1/160)*Rods <= 40; subject to B_Limit: 0 <= Bands <= 6000; subject to C_Limit: 0 <= Coils <= 4000; subject to R_Limit: 0<= Rods <= 5000;

Or, just change steel.dat set Products := bands coils rods; param: ratemarketprofit := bands coils rods ; param hours := 40;

Also… If you are dealing with large models, the.mod file can get REALLY big without a.dat file Changing the problem becomes very easy with a.dat file

Logical Operators AMPL supports some logical operators Boolean variables (true/false) If-then If-then-else

How to Use if-then-else Suppose all variables, except one, have the same upper bound, and the other has an upper bound that is twice that of the rest A constraint like this will take care of all the the upper bounds: subject to UB {i in SETNAME }: variable[i] <= 10*(if i=1 then 2 else 1);

Set Operations Basic set operations: –Union: U = A union B –Intersection: U = A inter B –Cartesian Product: U = {A,B}

Advantage of Set Operations Suppose we have 3 sets of products, –CANDY –TOYS –GAMES In our model we may need to declare the following parameters for each: –Price –Supply –Demand

Naïve Setup –Param Price_C {CANDY}; –Param Price_T {TOYS}; –Param Price_G {GAMES}; –Param Supply_C {CANDY}; –Param Supply_T {TOYS}; –Param Supply_G {GAMES}; –Param Demand_C {CANDY}; –Param Demand_T {TOYS}; –Param Demand_G {GAMES};

Using Set Operation Union Param Price {CANDY union TOYS union GAMES}; Param Supply {CANDY union TOYS union GAMES}; Param Demand {CANDY union TOYS union GAMES};

Even Better… Set PRODUCTS = CANDY union TOYS union GAMES; Param Price {PRODUCTS}; Param Supply {PRODUCTS}; Param Demand {PRODUCTS};

Compound Sets Suppose you have a set called PRODUCTS of products to sell at a store Consider that instead of one store you have three stores in different parts of the country Each store has a different level of each paramater

One Solution Instead of using the set PRODUCTS, make three different sets: –PRODUCTS_1 –PRODUCTS_2 –PRODUCTS_3 Let each of the three numbers represent one of your store locations

One Solution (cont…) Next, define each parameter for each set of products: –Param Price {PRODUCTS_1}; –Param Supply {PRODUCTS_1}; –Param Demand {PRODUCTS_1}; –Param Price {PRODUCTS_2}; –Param Supply {PRODUCTS_2}; –…

Easier Solution For a better solution use compound sets: –Param Price {PRODUCTS, STORES}; –Param Supply {PRODUCTS, STORES}; –Param Demand {PRODUCTS, STORES};

Structure of {PRODUCTS, STORES} Suppose –PRODUCTS := oreos jenga lazertag ; –STORES:= ; Then {PRODUCTS, STORES} is the set of all combinations of products with stores: (oreos,1)(oreos,2)(oreos,3) (jenga,1) (jenga,2) (jenga,3) (lazertag,1) (lazertag,2) (lazertag,3)

Specifying Data In your.dat file, your declaration of Demand could look like this: param Demand:123:= oreos jenga lazertag403022;

Set Indexing

Indexing of Sets Indexing of a one dimensional set sum {i in PRODUCTS} cost[i]*make[i]; Indexing is similar in compound sets One can say sum { (i,j) in {PRODUCTS, STORES}} cost[i]*make[i,j]; or sum { i in PRODUCTS, j in STORES} cost[i]*make[i,j];

When do we need indexing? We may declare a parameter with or without giving index values: param Demand { PRODUCTS, STORES }; or param Demand { i in PRODUCTS, j in STORES };

With PRODUCTS and STORES: “The sales at each store will not exceed the demand for any given product at that store.” Could be expressed as the following constraint: subject to DEMAND {(i,j) in {PRODUCTS, STORES}}: Demand [i,j] >= Sell [i,j];

With PRODUCTS and STORES: Suppose we have another parameter: Param Capacity {STORES}; Let the capacity of a store be the total number of items it can sell all together

With PRODUCTS and STORES: “The total sales at any given store can not exceed the sales capacity of that store.” Could be expressed as follows Subject to CAPACITY {j in STORES}: Sum {i in PRODUCTS} Sell [i, j] <= Capacity [j];

Advanced Syntax Tips and Shortcuts

Transposition

How to Transpose Recall an earlier example: Param Demand:123:= oreos jenga lazertag403022;

How to Transpose Data in Transposed form Param Demand (tr): oreos jenga lazertag:= ;

Why Transpose Not Necessary, but can help with data management What if we had 30 stores? Param Demand (tr): oreos jenga lazertag:= ;

Omitted Data

Omitted Data Entry Example: Consider the following data Param:Cost Supply Demand := oreos jenga lazertag403022;

Omitted Data Entry Suppose in addition to the data specified in the previous table, you have an additional parameter such as: Param Calories {FOOD}; This parameter would apply to oreos, but not to jenga or lazertag.

Example Param:Cost Supply Demand := oreos jenga lazertag403022; Param: Calories := oreos 100 ;

Example Param:Cost Supply Demand Calories:= oreos jenga lazertag ; We can use “.” to represent omitted data

Where to get AMPL –Link to the web interface –Download the student edition For Windows, it is an easy installation For Mac OS, use unix install. You may need to install additional components Walkthrough available at: – b3/amplInstallingUsing.pdf