Download Contents
Transcript
124 CHAPTER 3. GENERAL MODELING EXAMPLES AND TRICKS programs with absolute values into LP’s. You must have a convex program to begin with. E.g., using Tom Rutherford’s example, the weights w(i,j) must be nonnegative (which I’m sure they are in his case). If you had a negative w and you tried the trick, the LP would terminate unbounded. The trick falls apart in that case because the solver sees an objective function incentive to making both the positive and negative deviation variables positive at the same time. Similarly, it is easy to convert math programs that have constraints with absolute value terms to LP’s, when the absolute value term has a positive coeficient and appears in a less-than-or-equal constraint. If you change the sign of the coefficient or sense of the inequality, the problem is nonconvex and unsolvable by LP. I am not sure that these warnings are as widely published as the tricks are. 3.11 Writing to Files Named by Set Text Labels Answer from rutherford@colorado.edu: Example -- GAMS Code Illustrating How to Produce Files with Names Indexed by the Text Labels of a Set. The following is from a GAMS program which runs under Windows 95/NT or DOS. It generates a bunch of files to be mailed to different students and a Unix script to mail the files. *---------------------------------------------------------------------------------* Set S identifies students by 9-digit student number: SET S STUDENTS / 585986377 Norman 446686312 Patrick 219068570 John ... * Set address(s) is used to associate an email address with * each student: SET ADDRESS(S) Student Email addresses / 585986377 Joe@mars.edu 446686312 Pat@themoon.EDU, 219068570 Bryant@earth.EDU, ... *---------------------------------------------------------------------------------*... I omit all the grading stuff -- because of the syntax for *... exceptions, I find GAMS much easier to use than a spreadsheet *.. for computing marks. *---------------------------------------------------------------------------------* Define the temporary file to spool messages: file kout / tomail.txt/; kout.lw = 0; * Define a temporary batch file which is executed on the fly * to copy the temporary file to a file with a name defined by * the text elements for set s: file kbat / copym.bat/; * This is the mail command file to be appended with variable-width * set identifiers: file kmail / mail\3070mail.cmd /;