AIMMS Tutorial Beginners
AIMMS Tutorial Beginners
AIMMS Tutorial Beginners
Copyright c 19932010 by Paragon Decision Technology B.V. All rights reserved. Paragon Decision Technology B.V. Schipholweg 1 2034 LS Haarlem The Netherlands Tel.: +31 23 5511512 Fax: +31 23 5511517 Paragon Decision Technology Inc. 500 108th Avenue NE Ste. # 1085 Bellevue, WA 98004 USA Tel.: +1 425 458 4024 Fax: +1 425 458 4025 Paragon Decision Technology Pte. Ltd. 80 Raes Place UOB Plaza 1, Level 36-01 Singapore 048624 Tel.: +65 9640 4182
Aimms is a registered trademark of Paragon Decision Technology B.V. IBM ILOG CPLEX and sc CPLEX is a registered trademark of IBM Corporation. GUROBI is a registered trademark of Gurobi Optimization, Inc. KNITRO is a registered trademark of Ziena Optimization, Inc. XPRESS-MP is a registered trademark of FICO Fair Isaac Corporation. Mosek is a registered trademark of Mosek ApS. Windows and Excel are A registered trademarks of Microsoft Corporation. TEX, LTEX, and A S-LTEX are trademarks of the American M A Mathematical Society. Lucida is a registered trademark of Bigelow & Holmes Inc. Acrobat is a registered trademark of Adobe Systems Inc. Other brands and their products are trademarks of their respective holders. Information in this document is subject to change without notice and does not represent a commitment on the part of Paragon Decision Technology B.V. The software described in this document is furnished under a license agreement and may only be used and copied in accordance with the terms of the agreement. The documentation may not, in whole or in part, be copied, photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form without prior consent, in writing, from Paragon Decision Technology B.V. Paragon Decision Technology B.V. makes no representation or warranty with respect to the adequacy of this documentation or the programs which it describes for any particular purpose or with respect to its adequacy to produce any particular result. In no event shall Paragon Decision Technology B.V., its employees, its contractors or the authors of this documentation be liable for special, direct, indirect or consequential damages, losses, costs, charges, claims, demands, or claims for lost prots, fees or expenses of any nature or kind. In addition to the foregoing, users should recognize that all complex software systems and their documentation contain errors and omissions. The authors, Paragon Decision Technology B.V. and its employees, and its contractors shall not be responsible under any circumstances for providing information or corrections to errors and omissions discovered at any time in this book or the software it describes, whether or not they are aware of the errors or omissions. The authors, Paragon Decision Technology B.V. and its employees, and its contractors do not recommend the use of the software described in this book for applications in which errors or omissions could threaten life, injury or signicant loss.
A This documentation was typeset by Paragon Decision Technology B.V. using L TEX and the Lucida font family.
Contents
Contents Common Aimms Shortcut Keys 1 2 Introduction What 2.1 2.2 2.3 to Expect Scope of one-hour tutorial . . . . . . . . . . . . . . . . . . . . . . Problem description and model statement . . . . . . . . . . . . A preview of your output . . . . . . . . . . . . . . . . . . . . . .
iii iv 1 3 3 3 6 7 7 8 9 10 13 15 21 21 22 24 27 27 30 30 30 33 35 40 40 42
Building the Model 3.1 Starting a new project . . . . . . . . . . . . . . . . . . . 3.2 The Model Explorer . . . . . . . . . . . . . . . . . . . . . 3.3 Entering sets and indices . . . . . . . . . . . . . . . . . . 3.4 Entering parameters and variables . . . . . . . . . . . . 3.5 Entering constraints and the mathematical program 3.6 Viewing the identiers . . . . . . . . . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Entering and Saving the Data 4.1 Entering set data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Entering parameter data . . . . . . . . . . . . . . . . . . . . . . . 4.3 Saving your data . . . . . . . . . . . . . . . . . . . . . . . . . . . . Solving the Model 5.1 Computing the solution . . . . . . . . . . . . . . . . . . . . . . . Building a Page 6.1 Creating a new page . . . . . 6.2 Presenting the input data . 6.3 Presenting the output data 6.4 Finishing the page . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Performing a What-If Run 7.1 Modifying input data . . . . . . . . . . . . . . . . . . . . . . . . . Common Aimms Shortcut Keys
Key F1 F2 F3 F4 F5 F6 Alt+F6 F7 F8 Ctrl+F8 F9 Alt+ F9 Ctrl+ F9 F10 Ctrl+ F10 F11 Ctrl+ B Ctrl+ D Ctrl+ F Ctrl+ M Ctrl+ P Ctrl+ T Ctrl+Shift + T Ctrl+ W Ctrl+ Space Ctrl+ Shift+Space Ctrl+ Enter Insert
Function Open Aimms Help Rename the selected identier Find and repeat nd Switch between edit mode and end-user mode (for the active page) Compile all Run MainExecution Switch to debugger mode Save the active page Open Model Explorer Open Identifer Selector Open Page Manager Open Template Manager Open Menu Builder Open Data Manager Open Data Management Setup Open Identifer Info dialog Insert a break point in debugger mode Open Data Page Open Find dialog Open Message Window Open Progress Window View Text Representation of selected part(s) View Text Representation of whole model Open Wizard Name completion Name completion including Aimms Predeclared Identifers Check, commit, and close Insert a node (when single insert choice) or Open Select Node Type dialog (when multiple insert choices)
Chapter 1 Introduction
There are several ways in which you can learn the Aimms language and get a basic understanding of its underlying development environment. The following opportunities are immediately available, and are part of the Aimms installation. There are two tutorials on Aimms to provide you with some initial working knowledge of the system and its language. One tutorial is intended for beginners, while the other is aimed at professional users of Aimms. There is a model library with a variety of examples to illustrate simple and advanced applications together with particular aspects of both the language and the graphical user interface. There are three reference books on Aimms, which are available in PDF format and in hard copy form. They are The Users Guide to introduce you to Aimms and its development environment, The Language Reference to describe the modeling language in detail, and Optimization Modeling to enable you to become familiar with building models. As a beginner into optimization modeling languages, you may not have much time for learning yet another tool in order to nish some project or homework requirements. In this case, concentrate your eorts on this tutorial. After completing this tutorial, you should be able to use the system to build your own simple models, and to enter your own small data sets for subsequent viewing. The book on Optimization Modeling may teach you some useful tricks, and will show you dierent (mostly non-trivial) examples of optimization models. Besides English, the tutorial for beginners is also available in Spanish, Hungarian, German and French, which can be found on our web site:
http://www.aimms.com/downloads/tutorials/tutorial-for-beginners.
. . . for beginners
As a professional in the eld of optimization modeling you are looking for a tool that simplies your work and minimizes the time needed for model construction and model maintenance. In this situation, you cannot get around the fact that you will need to initially make a substantial time investment to get to know several of the advanced features that will subsequently support you in your role as a professional application builder. Depending on your skills, experience, and learning habits you should determine your own individual learning path. Along this path you are advised to work through the extensive tutorial
. . . for professionals
Chapter 1. Introduction
especially designed for professionals. This tutorial for professionals provides a good start, and should create excitement about the possibilities of Aimms. Individual examples in the library, plus selected portions of the three books, will subsequently oer you additional ideas on how to use Aimms eectively while building your own advanced applications. The one-hour tutorial for beginners is designed as the bare minimum needed to build simple models using the Aimms Model Explorer. Data values are entered by hand using data pages, and the student can build a page with objects to view and modify the data. The extensive tutorial for professionals is an elaborate tour of Aimms covering a range of advanced language features plus an introduction to all the building tools. Especially of interest will be the modeling of time using the concepts of horizon and calendar, the use of quantities and units, the link to a database, the connection to an external DLL, and advanced reporting facilities. Even then, some topics such as eciency considerations (execution eciency, matrix manipulation routines) and the Aimms API will remain untouched. Tutorials are dierent in scope
In this chapter you will nd a brief overview of the tasks to be performed, a compact statement of the underlying model to be built, and a glimpse of the output you will produce.
This chapter
The following table provides the data for the problem described in the previous paragraph.
Data overview
Customers Unit Transport Cost Plants Amsterdam Breda Gouda Amersfoort Den Bosch Supply Haarlem 131 405 188 396 485 47 Eindhoven 554 351 479 366 155 63 Demand 28 16 22 31 12
The following declarations list the identiers that are part of the mathematical program to be built. Indices: p c Parameters: Sp Dc Upc Variables: xpc z
Identier declarations
plants customers supply at plant p demand by customer c unit transport cost from p to c transport from p to c total transport cost
The mathematical model summary below captures the least-cost plan to transport beer such that the demand is met and shipments do not exceed available supply. Minimize: z=
pc
Model summary
Upc xpc
p c (p, c)
xpc Dc
p
xpc 0
Haarlem Amsterdam
Even though the above notation with one-letter symbols is typical of small mathematical optimization models, it will not be used to represent the model in Aimms. Instead, explicit names will be used throughout to avoid any unnecessary translation symbols. The number of symbols needed to describe practical applications is generally large, and a clear naming convention supports the understanding and maintenance of large models.
Next, the Aimms Model Explorer and the Aimms Page Manager will be automatically opened. We will look at the Aimms Model Explorer rst.
To declare the index p as an attribute of the set Plants, execute the following sequence of actions: move the mouse cursor to the Index attribute eld, and click in the (empty) edit eld, enter the letter p, and complete the attribute form by pressing the Check, Commit and Close button .
10
Next, create the set Customers with associated index c in exactly the same way as you created the set Plants with index domain p. Figure 3.4 contains the resulting model tree.
The asterisk on the left of the project name indicates that additions to your project have not yet been saved to disk. To save your work, please press the on the toolbar. Save Project button
11
The last model parameter UnitTransportCost is a two-dimensional parameter with index domain (p, c). After entering UnitTransportCost(p,c), the resulting model tree should be the same as in Figure 3.5.
Declaring a variable is similar to declaring a parameter. on the toolbar to create a new variable in press the variable button the model tree, specify Transport(p,c) as the name of the variable, and press the Enter key to register the variable. After opening the attribute form of the variable by double-clicking on the node Transport in the model tree, press the wizard button in front of the Range attribute eld. The resulting dialog box provides the opportunity to specify the range of values that the variable Transport is allowed to take. In this case, select the Standard Range, then select nonnegative, and nally press the OK button (see Figure 3.6).
12
It should be clear by now how to create the variable TotalTransportCost. This variable will be used to specify the objective function. After entering its name, open the attribute form. There is no need to specify the range attribute, since the default range free will suce. You are now ready to enter the following denition of this particular variable:
sum[ (p,c), UnitTransportCost(p,c) * Transport(p,c) ]
Simply enter the above denition in the Denition attribute eld. You could type the entire sentence yourself, but you can also let Aimms do some of the typing for you. Considering the parameter UnitTransportCost(p,c), the following two support features are quite useful. Type the letter u or U, and press the Ctrl-Spacebar combination for automatic name completion. Another option available to you is to drag the name UnitTransportCost(p,c) from the model tree to the edit eld of the Denition attribute. The attribute form should now have the same content as shown in Figure 3.7. , you can verify whether By pressing the Check, Commit and Close button Aimms will accept the denition you entered.
13
Figure 3.7: The completed attribute form for the variable TotalTransportCost
Figure 3.8: The completed attribute form for the constraint SupplyRestriction
14
Figure 3.9: The completed attribute form for the constraint DemandRequirement
A mathematical program, unlike sets, parameters, variables and constraints, does not have a special button on the toolbar. By using the identier button , you obtain access to all the other types of Aimms identiers. After pressing icon, this button, select the Mathematical Program entry alongside the press the OK button, and enter LeastCostTransportPlan as the name of the mathematical program. The complete the attribute form of the mathematical program as illustrated in Figure 3.10. Among the attributes, AIMMS has automatically lled Direction, Constraints, Variables and Type attributes with default values and there is no need to change them for this project. You only need to ll the Objective attribute.
The Objective attribute wizard requires you to select a scalar variable. In the identier selection wizard (see Figure 3.11), simply select the scalar variable TotalTransportCost, and press the Finish button.
15
16
Even though the Model Explorer is a convenient medium with which to build and inspect your model, AIMMS provides two other ways to view your model. If you would like to see a text(ASCII) representation of the model, you can do the following: select node(s) in Aimms Model Explorer, go to the View - Text Representation menu and execute the Selected Part(s) command(see Figure 3.13). View text model
17
The text model provides a simple overview of selected identiers. For instance, Figure 3.14 shows the text model when the root node Main Beer Transport is selected.
18
Another way to inspect the model is by Aimms Identier Selector. This allows you to view several identiers with similar properties at the same time. In this tutorial you will encounter one such example of a predened view, namely all identiers with a denition (see Figure 3.15). Aimms allows you to make your own views as you desire.
Identier overviews
19
You can create a view window by executing the following steps: press the Identier Selector button on the toolbar, select the Identiers with Denition node, and use the right mouse and select the Open With. . . command from the popup menu (see Figure 3.16).
Creating a view
For the selected identiers the view can be constructed as follows: select the Domain - Denition entry from the View Manager window (see Figure 3.17), and press the Open button to obtain the overall view.
20
22
To change the name of an element, just, select the element, press the delete button and enter the modied name in the same way as described above. The elements of the set Customers are entered in exactly the same way as for the set Plants. The ve elements are listed in Figure 4.2. Note that the last element Den Bosch contains a blank character.
Supply data
23
The data values for the parameter Demand are entered in exactly the same way as for the parameter Supply. The ve data values are listed in Figure 4.4.
Demand data
The parameter UnitTransportCost is two-dimensional, and requires you to complete a table. The completed data page for this parameter is shown in Figure 4.5.
Cost data
24
If a project in Aimms is closed and subsequently reopened, you may want to reload your data. You may even want Aimms to load a specic case automatically each time your project is started. This can be accomplished (without programming) using the Aimms Options dialog box illustrated in Figure 4.7. go to the Settings menu and execute the Project Options command, select the Project - Startup & Authorization folder in the option tree, click on the Option Startup Case in the right-most window, press the wizard button, select the case Initial Beer Transport Data, press the OK button on the Select Case dialog box, press the Apply button on the Aimms Options dialog box, and nish by pressing the OK button.
25
It is a good habit to save your work regularly. The option settings above are also saved when you save the entire project. You can save the project by pressing the Save Project button . Note that saving a project does not mean that the data is also saved. Saving data requires you to save a case.
26
At any time during an Aimms session you can load a case manually as follows: go to the Data menu, select the Load Case submenu and execute the As Active. . . command, select the desired case name in the Load Case dialog box (see Figure 4.8), and press the Load button.
The procedure MainExecution can be completed as follows: press the F8 key to open the Model Explorer, select the MainExecution procedure and open it by double-clicking , enter the two statements in the body attribute as illustrated in Figure 5.1, and press the Check, Commit and Close button to register the changes. Should Aimms report errors, simply check your input and make the necessary corrections.
Building a procedure
28
To obtain information about specic Aimms keywords, you can use the rightmouse popup menu to open the Aimms documentation on the appropriate page with a single click. For instance, you can obtain help on the ProgramStatus keyword as follows: position the cursor over the ProgramStatus keyword, right-click the mouse and select the ProgramStatus entry in the Help submenu (see Figure 5.2).
The procedure MainExecution is special in that there is a dedicated key, F6, to execute this procedure. For all other procedures you can use the right mouse button to select the Run Procedure command. By pressing the Ctrl and p keys simultaneously, Aimms displays a progress window with selected information on the progress it has made (or is making) during an execution phase. Figure 5.3 shows the progress window you should expect to see.
29
You have already encountered data pages while entering the elements of sets and the numeric values of parameters. Once Aimms has computed the values of the variable Transport, these values become immediately available on the corresponding data page. Just go to this variable in the model tree, and click on it. Then use the right mouse to select the Data. . . command to open the data page. This will open a pivot table with Transport data and its corresponding suces. If you drag the column sux header out of the pivot table and set this to level you should see the gure below. Upon closing the data page select Yes, this will save the lay out changes you just made.
Figure 5.4: Data page displaying the solution for the variable Transport
Even though Aimms provides standard pages for each identier, such pages are not set up to look at groups of related identiers. That is why model builders and end-users of an application usually prefer to interact with an application through one or more custom pages.
Figure 6.1: A Page Manager with a single page Note that changes made in the previous chapter to the lay out of the Transport data table are also saved in the Page Manager.
31
To open the new page in Edit mode: double click on the page name in the Page Manager, and button on the toolbar to open the selected page in Edit mode. press the To create a new table, perform the following actions: on the toolbar, press the new-table button position the mouse cursor at where the upper left corner of the new table should be, depress the left mouse button and drag the mouse cursor to where the lower right corner of the new table should be, and release the mouse button. You can now complete the identier selection dialog box as follows: select the parameter UnitTransportCost(p,c) in the identier selection wizard as illustrated in Figure 6.2, press the Next button, press the Finish button, and if necessary adjust the position and size of the table object such that all information is neatly displayed.
32
To add another identier to the UnitTransportCost table, execute the following actions in Edit mode: select the table by clicking on it, button on the toolbar (or alternatively, use the right mouse) press the to access the properties dialog box, select the contents tab (see Figure 6.3), press the Add button, select the identier Supply(p), press the Next button, and then press the Finish button, and back on the contents tab, press the OK button.
You can add demand data to the table in the same way as you added the supply data. The resulting table is shown in Figure 6.4.
33
Creating a bar chart is essentially the same process as creating a table. The following steps summarize the process for the parameter Supply: on the toolbar, press the new-bar-chart button position the mouse cursor, and drag to form the new bar chart, select the parameter Supply(p) in the identier selection wizard, press the Next button, and then the Finish button. You can then create a bar chart for the demand data in the same way as you created the bar chart for the supply data. Your intermediate page should now look like the one in Figure 6.5.
34
press the Next button, and then the Finish button. Yet another way to display the solution is by means of a stacked bar chart: create a standard bar chart displaying the variable Transport(p,c). select the bar chart tab in the properties dialog box as illustrated in Figure 6.6), instead of the default Overlapping option, select the Stacked Bar option, and press the OK button. Creating a stacked bar chart
The scalar object is designed to display scalar values. To display the optimal solution value in a scalar object you should do the following: button on the toolbar to create a scalar object, press the draw the scalar object using the mouse, select the scalar variable TotalTransportCost in the identier selection wizard, and press the Finish button.
35
Creating a button
36
Figure 6.7: The action tab of the button properties dialog box
37
Figure 6.9: The text tab of the text properties dialog box
You can now specify and name the appropriate font, and thereby complete the text object. select Bold as the Font Style, and 20 as the Font Size, press the OK button, specify Title as the name of the new font, press the OK button to return to the Text Properties tab, again, press the OK button to leave the Text properties dialog box, The other two text objects displaying the text Input Data and Output Data are created in the same way. Instead of using the newly constructed Title font, you should create a second custom font, named Header font, of size 14. The font tab of the Text Properties dialog box is displayed in Figure 6.10.
38
Figure 6.10: The font tab of the text properties dialog box
The page is completed by adding two rectangles to emphasize that there are two groups of objects representing input data and output data. Assuming that you have rearranged and resized the objects to t neatly together, you can draw the rectangles as follows: select the Rectangle command from the Object menu, and draw the rectangle using the mouse. Your page should now look like the one in Figure 6.11.
39
Chapter
What-if analysis
41
Alternatively, you can click on the corresponding bar, and enter the new supply value of 57 in the edit eld on the lower left part of the bar chart. You are now ready to re-solve the model. To do so, simply press the Solve Beer Transport button at the top of your page. You will see an improvement (i.e. decrease) in optimal cost from 27499 to 26626. Note that a cost decrease could have been expected, because the entire capacity of Haarlem had been used initially. By increasing the supply at Haarlem, Gouda no longer needs Eindhoven as a second supplier (see Figure 7.2). Re-solving the mathematical program Improvement explained
Key F1 F2 F3 F4 F5 F6 Alt+F6 F7 F8 Ctrl+F8 F9 Alt+ F9 Ctrl+ F9 F10 Ctrl+ F10 F11 Ctrl+ B Ctrl+ D Ctrl+ F Ctrl+ M Ctrl+ P Ctrl+ T Ctrl+Shift + T Ctrl+ W Ctrl+ Space Ctrl+ Shift+Space Ctrl+ Enter Insert
Function Open Aimms Help Rename the selected identier Find and repeat nd Switch between edit mode and end-user mode (for the active page) Compile all Run MainExecution Switch to debugger mode Save the active page Open Model Explorer Open Identifer Selector Open Page Manager Open Template Manager Open Menu Builder Open Data Manager Open Data Management Setup Open Identifer Info dialog Insert a break point in debugger mode Open Data Page Open Find dialog Open Message Window Open Progress Window View Text Representation of selected part(s) View Text Representation of whole model Open Wizard Name completion Name completion including Aimms Predeclared Identifers Check, commit, and close Insert a node (when single insert choice) or Open Select Node Type dialog (when multiple insert choices)