{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ampldoc

# ampldoc - Introduction to AMPL A Tutorial AMPL is a...

This preview shows pages 1–3. Sign up to view the full content.

Introduction to AMPL A Tutorial * January 22, 2003 AMPL is a powerful language designed specifically for mathematical programming. AMPL has many features and options; however this tutorial covers a small subset of these 1 . Sections 1 through 5 provide an in- troduction to modeling Linear Programming (LP) problems with AMPL. Sections 6 and 7 introduce AMPL’s modeling capabilities for Integer Programming (IP) and Nonlinear Programming (NLP), respectively. 1 A Simple LP Model Consider the following example. Berkeley Paint Company makes two colors of paint, blue and gold. The blue paint sells for \$10 per gallon, while the gold paint sells for \$15 per gallon. The company has one factory, and can make only one color of paint at a time. However, blue paint is easier to make so the factory can make 40 gallons per hour of blue paint, but only 30 gallons per hour of gold paint. In addition, the marketing department tells manufacturing that they can sell at most 860 gallons of gold paint and 1000 gallons of blue paint. If a week is 40 hours and paint can’t be stored until next week, we need to determine how many gallons of blue and gold paint to make; so that the total revenue is maximized. Let PaintB represent the gallons of blue paint we will make, and PaintG represent the gallons of gold paint we will make. Then the problem is formulated as the following LP: max 10 PaintB + 15 PaintG s.t. : (1 / 40) PaintB + (1 / 30) PaintG 40 0 PaintB 1000 0 PaintG 860 . AMPL is designed to allow mathematical programs to be entered in a syntax very close to the algebraic notation you see above. To use AMPL, we need to create a text file with the mathematical program code. To create a text file, you can use any text editor you feel comfortable with. For example, you can use Notepad , which is found on every Windows 95 and Windows NT system. To create the following program file, start Notepad , and enter the following text. * This tutorial was originally prepared by P. Kaminsky. The original version is later modified and expanded by D. Rajan. 1 For more information, see the book AMPL: A Modeling Language for Mathematical Programming by R. Fourer, D. M. Gay, and B. W. Kernighan (1993: Boyd & Fraser) 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
## Example One var PaintB; # amount of blue var PaintG; # amount of gold maximize profit: 10*PaintB + 15*PaintG; subject to time: (1/40)*PaintB + (1/30)*PaintG <= 40; subject to blue_limit: 0 <= PaintB <= 1000; subject to gold_limit: 0 <= PaintG <= 860; Note the following things about the AMPL language: The # symbol indicates the start of a comment. Everything after that symbol is ignored. Variables must be declared using the var keyword. All lines of code must end with a semi-colon. The objective starts with maximize or minimize , a name, and a semi-colon (:). After that, the objective statement appears. Each constraint starts with subject to , a name, and a semi-colon. After that, the equation or inequality appears.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern