gams:split_up_my_model_in_a_definition_and_into_a_data_part

Consider the transport example. Please find below two part of the transport model. The first one (`first.gms`

with the equations and (empty) set/parameter definition) must be run first and saved in a restart file.

It may contain data assignments (line 16 in `first.gms`

`) and therefore we cannot execute the GAMS code (impossible without data). Hence we have to run `

`gams first a=c s=sfirst`

The `a=c`

says 'compile only'. Another specialty is that we have to provide the compiler with the dimension of the sets (we don't have to do that if we fill the sets with data, but without data we have to do that). Hence the basic set definition (`i`

and `j`

) have to have the `'*`

' as an index.

In the second model (`second.gms`

) we do the set and parameter definitions again. Usually, GAMS doesn't allow that so we have to do the `$on/offmulti`

. Run `gams second r=sfirst`

GAMS takes the restart file, populates the sets and parameters according to the data definition in `second.gms`

, knows that the code in the restart file hasn't be executed and does the execution now. Then it executes the code in `second.gms`

, which triggers the solve.

$onempty Sets i(*) canning plants / / j(*) markets / / ; Parameters a(i) capacity of plant i in cases / / b(j) demand at market j in cases / / d(i,j) distance in thousands of miles / /; $offempty Scalar f freight in dollars per case per thousand miles /90/; Parameter c(i,j) transport cost in thousands of dollars per case ; c(i,j) = f * d(i,j) / 1000 ; Variables x(i,j) shipment quantities in cases z total transportation costs in thousands of dollars ; Positive Variable x ; Equations cost define objective function supply(i) observe supply limit at plant i demand(j) satisfy demand at market j ; cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; supply(i) .. sum(j, x(i,j)) =l= a(i) ; demand(j) .. sum(i, x(i,j)) =g= b(j) ; Model transport /all/ ;

$onmulti Sets i canning plants / seattle, san-diego / j markets / new-york, chicago, topeka / ; Parameters a(i) capacity of plant i in cases / seattle 350 san-diego 600 / b(j) demand at market j in cases / new-york 325 chicago 300 topeka 275 / ; Table d(i,j) distance in thousands of miles new-york chicago topeka seattle 2.5 1.7 1.8 san-diego 2.5 1.8 1.4 ; Scalar f freight in dollars per case per thousand miles /90/ ; $offmulti Solve transport using lp minimizing z ; Display x.l, x.m ;

IMPRESSUM / LEGAL NOTICE
PRIVACY POLICY
gams/split_up_my_model_in_a_definition_and_into_a_data_part.txt · Last modified: 2008/10/24 14:43 by support