Search code examples
gams-math

A way to restrict the domain of a variable?


I have a code snippet for a transport problem like:

set i /1*50/
    d /1*10/

Alias(i,j,k)

parameter  
         edge(i,j)
         distance(i,j)
         possible(i,d)  'a collection of possible nodes for d'
         possible_edge(i,j,d)  'a collection of possible edge for d';

binary variable x(i,j,d);

I import all the edges from an excel file. But to reduce the number of variables, I'd like to create another parameter like possible node and possible edge. suppose we run a shortest path algorithm form a source node i and we define possible(i,d) to be all i where distance(i,j) is smaller than a predefined threshold.

In other words, when the network node become larger and larger, I want to find out if there's any possibility to not define x(i,j,d) for every (i,j) combination? Like forcing to only have x(i,j,d)$possible_edge(i,j,d)?? Is there anything like this??


Solution

  • Yes, you can limit the domain of variables in the model statement, like this

    Model m / all, x(possible_edge) /;
    

    So, here, the variable x would be limited by the set possible_edge wherever it occurs in model m. Note, that possible_edge must be a set here, not a parameter.

    You can find more info about this concept here: https://www.gams.com/latest/docs/UG_ModelSolve.html#UG_ModelSolve_LimitedDomain