Download presentation
Presentation is loading. Please wait.
2
AMPL Presentation 1 By Raymond Kleinberg
3
Outline AMPL - Ugh! - What is it good for? Basics Starting a Problem Running the Problem Example
4
AMPL Ugh! - What is it good for?
5
AMPL does: Solves simple LP’s (Slightly older than CDs) Solves not-so-simple LP’s Solves hard LP’s Solves IP’s Solves MIP’s (that does not include Will Smith!) You’ll see how much it can do!!
6
Basics Files you will need How to write them How to save them
7
Writing the.mod file Open up OxEdit and type the file - we’ll learn how to do that later.
8
Saving the file Save the file as a mod file e.g. helloworld.mod
9
Syntax of File As with any computer language, AMPL requires the file it reads to be a certain way. The first set of problems we will do will only require one file and the format is very simple and natural. Here’s how it goes.
10
Order of entry Enter the variables first: var x1 >=0; var Sally >=4.5; var smileyface <=-1; var happy integer >=0;
11
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;
12
Order of Entry - Cont. Next enter the constraints: subject to WOOD: 2*x1 - 40*happy<=27; subject to WORK: x3 + 2.5*Sally<=34; subject to MACHINE: happy - Sally<=14;
13
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: x3 + 2.5*Sally<=34; subject to MACHINE: happy - 3*smileyface<=14;
14
Running the File Once you have the file written and saved, we need to run it to get our solution.
15
How to Run AMPL Open up AMPL Tell AMPL what you want solved by: “model data\project1.mod;” If you want to use a different solver: “option solver ;” Tell AMPL to solve it: “solve;”
16
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.
17
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 = 22.33333 happy = 11 smileyface = 0
18
That’s it. You’ve seen that AMPL can solve many types of programming problems with lots of variables and constraints. Later you will see more of its power when it comes to streamlining the problem and running it more efficiently.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.