170 likes | 185 Views
AMPL. Presentation 1. By Raymond Kleinberg. Outline. AMPL - Ugh! - What is it good for? Basics Starting a Problem Running the Problem Example. AMPL. Ugh! - What is it good for?. AMPL does:. Solves simple LP’s (Slightly older than CDs) Solves not-so-simple LP’s Solves hard LP’s
E N D
AMPL Presentation 1 By Raymond Kleinberg
Outline • AMPL - Ugh! - What is it good for? • Basics • Starting a Problem • Running the Problem • Example
AMPL Ugh! - What is it good for?
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!!
Basics • Files you will need • How to write them • How to save them
Writing the .mod file Open up OxEdit and type the file - we’ll learn how to do that later.
Saving the file Save the file as a mod file e.g. helloworld.mod
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.
Order of entry Enter the variables first: var x1 >=0; var Sally >=4.5; var smileyface <=-1; var happy integer >=0;
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;
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;
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;
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 data\project1.mod;” • If you want to use a different solver: • “option solver <solver name>;” • Tell AMPL to solve it: • “solve;”
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 nodesdisplay x1,x3,Sally,smileyface,happy;x1 = 0x3 = -1Sally = 22.33333happy = 11smileyface = 0
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.