.. Equation specifications

Top  Previous  Next

While the equation section names the equations it contains nothing about their algebraic structure.  That structure is defined in the specification or .. relationships within GAMS.  In particular, each equation defined must be matched by a .. command which contains it's exact algebraic structure.  The syntax for an equation specification is

equation name(setdependency)$optional logical condition . .

   lhs_equation_terms   equation_type   rhs_equation_terms;

where

equation name(setdependency) must have already been named in an equation declaration.
The set dependency specification must either match the sets used in the declaration, or use sets which are subsets thereof or elements thereof.
The $optional logical condition is optional and is discussed in the Conditionals chapter.
The definition always contains two dots '..' .

Examples:

(model.gms)

tcosteq..

tcost =e=

sum(warehouse,dataw(warehouse,"cost")/dataw(warehouse,"life")

              *build(warehouse))

+sum((supplyl,market)   ,shipsm(supplyl,market)

                        *costsm(supplyl,market))

+sum((supplyl,warehouse),shipsw(supplyl,warehouse)

                        *costsw(supplyl,warehouse))

+sum((warehouse,market) ,shipwm(warehouse,market)

                        *costwm(warehouse,market));

supplyeq(supplyl)..    sum(market, shipsm(supplyl, market))

                     + sum(warehouse,shipsw(supplyl,warehouse))

                      =l= supply(supplyl);

demandeq(market)$ demand(market)..  

           sum(supplyl, shipsm(supplyl, market))

                   +  sum(warehouse, shipwm(warehouse, market))

                      =g= demand(market);

balance(warehouse)..     sum(market, shipwm(warehouse, market))

                                    - sum(supplyl,shipsw(supplyl,warehouse))

                      =l= 0;

capacity(warehouse)..  sum(market, shipwm(warehouse, market))

                             -build(warehouse)*dataw(warehouse,"capacity")

                      =l= 0 ;

configure..           sum(warehouse,build(warehouse)) =l= 1;

 

Here GAMS will operate over all the elements in the sets in each term.  For example, in the tcosteq equation GAMS will add up the term shipsm(supplyl,market)*costsm(supplyl,market) for all pairs of the set elements in supplyl and market.  Similarly the equation capacity(warehouse) will define a separate equation case for each element of warehouse and within the equation for each paricular case of warehouse only the elements of shipwm(warehouse, market) associated with that warehouse will be included in the term sum(market, shipwm(warehouse, market)).

Notes:

The algebraic terms of the equation (lhs equation terms, rhs equation terms) can be constants or algebraic expressions at least one of which contains variables.
Terms containing variables can appear on either or both of the right or left hand side of the algebraic part of the equation specification.
The equation type specifies the type of equation restriction with the following types allowed:

 

Symbol Used

Equation Type

Nature of restriction

=e=

Equality

eq.term 1 = eq.term 2

=g=

Greater than or equal to

eq.term 1 ≥ eq.term 2

=l=

Less than or equal to

eq.term 1 ≤ eq.term 2

=n=

No specification

Rarely used but can occur in MCP models.

=x=

External defined

Equation defined by external program as discussed in Links to Other Programs Including Spreadsheets chapter.

=c=

Conic

See the Mosek solver manual or the GAMS notes on conic models a http://www.gams.com/conic/.

 

Equation specification .. statements can carry over as many lines of input as needed.
Blanks can be inserted to improve readability.
An equation, once defined, cannot be altered or re-defined.  If one needs to change the logic, a new equation with a new name will have to be defined.
Parameter data or calculated sets incorporated in the equations may be changed by using assignment statements (see the Calculating Items chapter).
Equation specifications end with a ;
The equations and variables in a model are defined by the evaluation of the .. equation specifications.  If conditionals or subsets used so that the entire domain of the defining sets is not covered the variables and equations will not be present for all elements of the domain.  This given a constraint resource(j) and a subset i(j) where there are elements in j that are not in i and a .. command for resource(i).. means that resource equations will only be defined for the cases of j that also exist in i, not all that are in j.
The only variables that will be defined for a model are those that appear with nonzero coefficient somewhere in at least one of the equations defined by the .. equations.