as you know, convert can generate lp file but without names.
in cplex.opt, we can define writelp to output lp file which will come with names.
when I use cplex.opt insolve statement, it will generate lp and solve it also.
For a big problem, I would like to check the problem first without solving it. How can I use cplex.opt to do that? I know convert can do that but it cannot generate a lp file with variable names which is not good for debugging.
how to generate lp file without solving it
Re: how to generate lp file without solving it
Hi,
I don't know what kind of debugging you want to do but usually the equation listing in the listing file is a pretty good debugging tool if you visually need to inspect your constraints:
A Transportation Problem (TRNSPORT,SEQ=1)
Equation Listing SOLVE transport Using LP From line 66
 cost =E= define objective function
cost..  0.225*x(seattle,newyork)  0.153*x(seattle,chicago)  0.162*x(seattle,topeka)  0.225*x(sandiego,newyork)  0.162*x(sandiego,chicago)  0.126*x(sandiego,topeka) + z =E= 0 ; (LHS = 0)
 supply =L= observe supply limit at plant i
supply(seattle).. x(seattle,newyork) + x(seattle,chicago) + x(seattle,topeka) =L= 350 ; (LHS = 0)
supply(sandiego).. x(sandiego,newyork) + x(sandiego,chicago) + x(sandiego, topeka) =L= 600 ; (LHS = 0)
 demand =G= satisfy demand at market j
demand(newyork).. x(seattle,newyork) + x(sandiego,newyork) =G= 325 ; (LHS = 0, INFES = 325 ****)
demand(chicago).. x(seattle,chicago) + x(sandiego,chicago) =G= 300 ; (LHS = 0, INFES = 300 ****)
demand(topeka).. x(seattle,topeka) + x(sandiego,topeka) =G= 275 ; (LHS = 0, INFES = 275 ****)
You can try to stop Cplex with a time limit or an iteration limit, but it still will take some time before Cplex checks the very first time for this limit.
Convert produces a scalar GAMS model with generic names x1,x2, ... and e1, e2, ... and a dict.txt that helps mapping back to original GAMS names. What we have done before is to replaces the generic names with the ones in dict.txt:
sed n e "s:^ \([ex][09]*\) \(.*\):s/\1/\2/g:gp" dict.txt  sed n "1!G;h;$p" > r.sed
sed f r.sed gams.gms > names.gms
The file names.gms does not compile but is good to look at. If you need the resulting file to run, do
sed n e "y/(),/____/" e "s:^ \([ex][09]*\) \(.*\):s/\1/\2/g:gp" dict.txt  sed n '1!G;h;$p' > r.sed
sed f r.sed gams.gms > namesThatDoesCompile.gms
This works well as long as you don't have original variable or equation names that match x[09]* or e[09]*:
Thanks to my colleague Stefan Vigerske who came up with the sed commands. BTW, GAMS ships the sed tool with its Windows distribution: c:\GAMS\win64\24.8\gbin\sed.exe
Hope this helps,
Michael
I don't know what kind of debugging you want to do but usually the equation listing in the listing file is a pretty good debugging tool if you visually need to inspect your constraints:
A Transportation Problem (TRNSPORT,SEQ=1)
Equation Listing SOLVE transport Using LP From line 66
 cost =E= define objective function
cost..  0.225*x(seattle,newyork)  0.153*x(seattle,chicago)  0.162*x(seattle,topeka)  0.225*x(sandiego,newyork)  0.162*x(sandiego,chicago)  0.126*x(sandiego,topeka) + z =E= 0 ; (LHS = 0)
 supply =L= observe supply limit at plant i
supply(seattle).. x(seattle,newyork) + x(seattle,chicago) + x(seattle,topeka) =L= 350 ; (LHS = 0)
supply(sandiego).. x(sandiego,newyork) + x(sandiego,chicago) + x(sandiego, topeka) =L= 600 ; (LHS = 0)
 demand =G= satisfy demand at market j
demand(newyork).. x(seattle,newyork) + x(sandiego,newyork) =G= 325 ; (LHS = 0, INFES = 325 ****)
demand(chicago).. x(seattle,chicago) + x(sandiego,chicago) =G= 300 ; (LHS = 0, INFES = 300 ****)
demand(topeka).. x(seattle,topeka) + x(sandiego,topeka) =G= 275 ; (LHS = 0, INFES = 275 ****)
You can try to stop Cplex with a time limit or an iteration limit, but it still will take some time before Cplex checks the very first time for this limit.
Convert produces a scalar GAMS model with generic names x1,x2, ... and e1, e2, ... and a dict.txt that helps mapping back to original GAMS names. What we have done before is to replaces the generic names with the ones in dict.txt:
sed n e "s:^ \([ex][09]*\) \(.*\):s/\1/\2/g:gp" dict.txt  sed n "1!G;h;$p" > r.sed
sed f r.sed gams.gms > names.gms
The file names.gms does not compile but is good to look at. If you need the resulting file to run, do
sed n e "y/(),/____/" e "s:^ \([ex][09]*\) \(.*\):s/\1/\2/g:gp" dict.txt  sed n '1!G;h;$p' > r.sed
sed f r.sed gams.gms > namesThatDoesCompile.gms
This works well as long as you don't have original variable or equation names that match x[09]* or e[09]*:
Thanks to my colleague Stefan Vigerske who came up with the sed commands. BTW, GAMS ships the sed tool with its Windows distribution: c:\GAMS\win64\24.8\gbin\sed.exe
Hope this helps,
Michael

 User
 Posts: 85
 Joined: 8 months ago
Re: how to generate lp file without solving it
thanks for the reply. I think the running time and number of iterations could be an option.
what you have done by replacing the generic names with the ones in dict.txt is exactly the one I want. For a large problem, it is hard to check the equations with just generic names x1,x2, ... and e1, e2, ...
what you have done by replacing the generic names with the ones in dict.txt is exactly the one I want. For a large problem, it is hard to check the equations with just generic names x1,x2, ... and e1, e2, ...

 User
 Posts: 85
 Joined: 8 months ago
Re: how to generate lp file without solving it
where should I run those sed commands? in GAMS IDE or convert.opt?
Who is online
Users browsing this forum: No registered users and 1 guest