在 GAMS 中,变量和参数有什么区别?

In GAMS, what is the difference between variables and parameters?

在GAMS中,变量和参数有什么区别?

在哪些情况下,其中一种比另一种更好用?

Short explanation

Parameters are used for introducing data into the model. This data can be used in equations and will not be affected by the optimisation. Mathematically, you may think of a constant. (Decision) Variables are 'variable' during the optimisation. The value of a variable in the optimum is reported after the optimisation has finished.

Mnemonic

Should the model decide on the value of the data (e.g. production quantity, allocation etc.):
Yes -> Variable
No -> Parameter

例子

Take the Tansport Problem Example from the GAMS website, where the objective is to minimize the cost of shipping goods from 2 plants to 3 markets.

As the distance between the two plants is known (and nothing we could change or want to decide on), this data is entered into the model as a Parameter (in this case a table)

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  ;

Also, in this type of model, the freight costs are known. As this data (dollars per shipping case per thousand miles) is one dimensional, it can be entered as a scalar (which is also a Parameter)

Scalar f  freight in dollars per case per thousand miles  /90/ ; 

With this information, you can calculate the shipping costs by multiplying the freight cost with the distance between the different plants.

Parameter
c(i,j)  transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;

As you can see, we assigned a value to the parameter c(i,j) by specifying a function of freight costs and distance between the canning plants. Independant on the model type (LP, MIP, NLP etc.), we can use non-linear functions when calculating parameter values as long as there are no decision variables involved.

Now the only thing the model may decide on is the shipping quantity between the different plants (i) and markets (j), in our model labeled as x(i,j)

cost ..        z  =e=  sum((i,j), c(i,j)*x(i,j)) ;

I hope this little example points out what a parameter and a decision variable (at least in the context of GAMS) is.

It may also be interesting to know that Parameter values are computed at compile time, while variables will be computed during solve (or execution time).