问题
I am using CPLEX and declaring the dvar with the following:
dvar int+ Y[i in a][j in a][m in b] in 0..1
I do not want to create a variable when i = j.
回答1:
variable indexer are not allowed but you have 3 workarounds:
https://github.com/AlexFleischerParis/zooopl/blob/master/zooarrayvariableindexertupleset.mod https://github.com/AlexFleischerParis/zooopl/blob/master/zooarrayvariableindexerdexpr.mod https://github.com/AlexFleischerParis/zooopl/blob/master/zooarrayvariableindexerunion.mod
The first one is the most used and for your case this gives:
{int} a={1,2};
{int} b={4,5};
tuple t
{
int i;
int j;
}
{t} ijs={<i,j> | i,j in a:i!=j};
//dvar int+ Y[i in a][j in a][m in b] in 0..1
dvar int+ Y[ij in ijs][m in b] in 0..1;
subject to
{
Y[<1,2>][4]==1;
}
来源:https://stackoverflow.com/questions/65477497/cplex-dvar-declaration-with-conditions