AMPL-CPLEX Setup Guide for Windows∗ Applied Mathematics 121 Spring 2011 Contents 1 Getting AMPL and CPLEX 2 2 Running AMPL 2 ∗ These instructions have been tested on Windows XP and not on Vista. Chances are the set up shouldn’t be much different. 1 1 Getting AMPL and CPLEX Download the full version of AMPL and CPLEX by entering the following link into your browser: http://fas.harvard.edu/~apm121/ampl201101.cplex122.zip If asked whether you want to open or save the file, choose save, and select a location (e.g., the Desktop). Locate the file using My Computer (or if it’s on the Desktop, you can find it there). Right click on it and select Extract All. Follow the Extraction Wizard to extract all files to the directory C:\. Wait the extraction to finish. Now you should have a folder C:\ampl201101.cplex122.win . Next, we need to tell your computer where to find AMPL, CPLEX, and the license file. Go to Start → Control Panel → Systems. Click on the Advanced tab, and then click Environment Variables. In the upper window (User variables), check whether you already have a PATH variable. If there is not PATH variable, click New. In the window that pops up, enter PATH for variable name, and C:\ampl201101.cplex122.win for the variable value. If you already have a PATH variable in the user variable window, click Edit. In the window that pops up, add ;C:\ampl201101.cplex122.win to the end of the variable value. Click OK. To allow your computer to locate the license file, click New for user variables. In the window that pops up, create an environment variable named ILOG_LICENSE_FILE. Enter C:\ampl201101.cplex122.win\access.ilm for the variable value. Click OK, and OK to save all your changes to the environment variables. To keep organized, we can create a new directory in the C:\ampl201101.cplex122.win folder for all the model and data files you will create (e.g., call this directory AM121). To set it up so that AMPL can easily locate the model and data files you create without having to type in the name of the directory every time, we can create a file modinc in the C:\ampl201101.cplex122.win directory. Open notepad and type in the following: This tells AMPL-CPLEX to look in the listed directories. Specifically, given you had created a subdirectory called AM121, this will allow you to open files from there. Directories listed above others are searched first (this handles cases when two files in different directories happen to have the same name). Once entered, click File, Save, navigate to C:\ampl201101.cplex122.win, enter the filename "modinc" (with the double quotes!), and press save. 2 Running AMPL You need Internet connection to run AMPL because AMPL needs to communicate with a networked license server. While you can just double-click on ampl to run it in the command prompt, you probably don’t want to do this. First, you are probably better off with the scrolling window program, sw.exe, that comes with AMPL. In C:\ampl201101.cplex122.win, double-click on sw.exe to bring up the “scrolling window” with the prompt sw: in the top line. 2 Type “ampl modinc -” (don’t miss the dash) at this prompt to start up AMPL; at this point the contents of the window should be sw: ampl modinc netlicchk: Trying to start license manager ampl_lic. netlicchk: Invoking "C:\ampl201101.cplex122.win\alic_run.exe" "C:\ampl201101.cplex122.win\ampl_lic.exe". ampl: If a Windows Security Alert window pops up and ask whether you would like to keep blocking the program ampl_lic, click Unblock. You can proceed to enter commands at the “ampl:” prompts. The scroll bar at the right lets you scroll back to earlier output (if the output is longer than the window height), and the menus provide facilities for cut-and-paste and font selection. The arrow keys recall previous commands for editing and resubmission. See the sw readme file1 for details. We have typed ampl modinc - instead of just ampl so that when AMPL opens, it loads the modinc file you had edited, which allows the program to know where to look for files you create. If you just typed ampl, no worries. At the ampl: prompt, type include modinc or commands modinc. This will do the exact same thing. Okay, let’s see if you did everything correctly. Get into ampl, making sure modinc is loaded (either way you do it is fine). You can use ampl commands to load the model and data files from here. To absolutely make sure you did every step correct. Let’s try to load the production model, it’s data file, and solve it. Here, at the ampl: prompt, type: model prod.mod; If you did it correctly, it shouldn’t say anything. If it says: Can’t find file "prod.mod" context: model >>> prod.mod; <<< 1 http://www.netlib.org/ampl/student/mswin/readme.sw or in the folder you installed. 3 Then you probably didn’t set up the modinc thing correctly. Again, if it says nothing and just gives you another line of the prompt, it’s working - and by working we mean it loaded the ”prod.mod” file from whichever directory came up in the modinc file. Beware of name conflicts if such issues should arise! Now load the data file. Execute: data prod.dat; Okay, again, if it doesn’t complain, so far so good. Now, to tell AMPL to use CPLEX as the server, type: Now, type: option solver cplexamp; Finally, type: solve; and you should see something like this: ampl: solve; CPLEX 12.2.0.0: optimal solution; objective 192000 1 dual simplex iterations (0 in phase I) ampl: Okay, now if you want to quit the program, type quit or exit;. And that’s all there is to it! 4