how to generate lp file without solving it Topic is solved

Problems with modeling
yanzhiping
User
User
Posts: 84
Joined: 6 months ago

how to generate lp file without solving it

Postby yanzhiping » 6 months ago

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.

User avatar
bussieck
Moderator
Moderator
Posts: 48
Joined: 11 months ago

Re: how to generate lp file without solving it  Topic is solved

Postby bussieck » 6 months ago

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,new-york) - 0.153*x(seattle,chicago) - 0.162*x(seattle,topeka) - 0.225*x(san-diego,new-york) - 0.162*x(san-diego,chicago) - 0.126*x(san-diego,topeka) + z =E= 0 ; (LHS = 0)

---- supply =L= observe supply limit at plant i

supply(seattle).. x(seattle,new-york) + x(seattle,chicago) + x(seattle,topeka) =L= 350 ; (LHS = 0)

supply(san-diego).. x(san-diego,new-york) + x(san-diego,chicago) + x(san-diego, topeka) =L= 600 ; (LHS = 0)


---- demand =G= satisfy demand at market j

demand(new-york).. x(seattle,new-york) + x(san-diego,new-york) =G= 325 ; (LHS = 0, INFES = 325 ****)

demand(chicago).. x(seattle,chicago) + x(san-diego,chicago) =G= 300 ; (LHS = 0, INFES = 300 ****)

demand(topeka).. x(seattle,topeka) + x(san-diego,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][0-9]*\) \(.*\):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][0-9]*\) \(.*\):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[0-9]* or e[0-9]*:

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

yanzhiping
User
User
Posts: 84
Joined: 6 months ago

Re: how to generate lp file without solving it

Postby yanzhiping » 6 months ago

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, ...

yanzhiping
User
User
Posts: 84
Joined: 6 months ago

Re: how to generate lp file without solving it

Postby yanzhiping » 3 weeks ago

where should I run those sed commands? in GAMS IDE or convert.opt?


Return to “Modeling”

Who is online

Users browsing this forum: No registered users and 1 guest