Lab 1 - University of Toronto Department of Mechanical and...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: University of Toronto Department of Mechanical and Industrial Engineering MIE376: Mathematical Programming Winter 2011 Lab 1 – Introduction to AMPL AMPL, A Mathematical Programming Language, is an algebraic modeling language for mathematical programming that has been designed and implemented since 1985. The AMPL syntax is highly similar to arithmetic expressions of the algebraic expressions in written mathematical models. AMPL does not solve the models, but instead calls on external solvers (such as CPLEX and Gurobi) to get the optimal solutions. This lab introduces the students to the basics of AMPL to solve simple Linear Programs. 1. Location of AMPL Server Remotely login to the AppServer to access AMPL and Gurobi licences: i. Go to the website https://ssl.ecf.utoronto.ca/ecf/services/rd ii. Click on the AppServer Server Icon to download the remote desktop connection file iii. Open the AppServer.rdp connection file iv. Login to the server with your ECF username/password v. Once you are on the Remote Server, open AMPL from the Start Menu vi. AMPL starts in a DOS format 2. Writing AMPL Model Files With the general form of a Linear Program following: Objective Function: max ∑ subject to Constraints: ∑ ,∀ where xi are the decision variables, ci, bi, aij are parameters, we can use to following code to express the different parts of the Linear Program in AMPL Declarations o param: parameters of known data o var: decision variables Objective: Describe the linear program expression to optimize o maximize o minimize Constraints: Define the constraints the objective function is subjected to o subject to Example: Given the Linear Program: max subject to: 3 , 16 7 0 2 University of Toronto Department of Mechanical and Industrial Engineering MIE376: Mathematical Programming Winter 2011 Type the following into a normal text file and save it as Lab01Ex.mod in the local H:\ drive: var x1; var x2; maximize Profit: x1 + 2*x2; subject to Lathe: x1 + 3*x2 <= 16; subject to Drill: x1 + x2 <= 7; subject to NonNegX1: x1 >= 0; subject to NonNegX2: x2 >= 0; Description of Code var x1; ‐ Defines the decision variable x1 (number of P1 products to produce) var x2; ‐ Defines the decision variable x2 (number of P1 products to produce) maximize Profit: x1 + 2*x2; ‐ Defines the objective function to optimize named “Profit” subject to Lathe: X1 + 3*x2 <= 16; ‐ Defines the constraint for number of Lathe hours available named “Lathe” subject to Drill: x1 + x2 <= 7; ‐ Defines the constraint for number of Drill hours available named “Drill” subject to NonNegX1: x1 >= 0; ‐ Defines the non‐negativity constraints o Alternative, we can define non‐negativity in the definition of the decision variables with the syntax (in this case with an upper bound M): var x1 >= 0, <= M; 3. Running Model Files and Solving with Gurobi Example To Solve the Example above: 1. Open AMPL and type the bold text below: 2. Select the Gurobi solver package: ampl: option solver gurobi_ampl; <Press Enter> 3. Load AMPL Model file: ampl: model H:\Lab01Ex.mod; <Press Enter> 4. Solve the model: ampl: solve; <Press Enter> 5. Obtain the Solution: ampl: display x1, x2; <Press Enter> 6. Read the Result from the solver: (Objective: 11.5, Decision Variables: x1 = 2.5, x2 = 4.5) University of Toronto Department of Mechanical and Industrial Engineering MIE376: Mathematical Programming Winter 2011 Figure 1: Output on AMPL from Example To Do Solve Question 2 in the LP Formulation Problems posted online 4. To Do Formulate, Code and Solve in AMPL Question 2 in the LP Formulation Problems posted online 5. Useful Information .mod file Code Code # set P := 1..4; var X{P}; X[1] subject to C1{i in P}: X[i]>=0; sum{i in P} X[i] Description Comments in .mod file Defines a set P which indices 1, 2, 3, 4 Defines an array of decision variables X indexed by P X1 Defines a constraint for all elements of i in the set P ∑ AMPL Code option solver [name]; solve; reset; display [name]; expand [name]; data [name]; quit Description Specifies solver to be used Solves the model Clear all model declarations and data Displays [name] parameter or decision variable Expands the [name] term (usually a constraint) in the model file Defines the data file for the model file Exits AMPL ...
View Full Document

This note was uploaded on 04/20/2011 for the course MIE 376 taught by Professor Daniel during the Spring '11 term at University of Toronto.

Ask a homework question - tutors are online