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

泄露秘密 提交于 2019-12-11 12:18:10

问题


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

In which cases is one of them better to use than the other one?


回答1:


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

Example

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



来源:https://stackoverflow.com/questions/52802131/in-gams-what-is-the-difference-between-variables-and-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!