How can I code the linear program using IBM CPLEX?
Asked
Active
Viewed 188 times
-2
-
Welcome to stackoverflow. In the future, please do not just link to images. Instead, please spend the time to describe the problem textually, so that others can help you more easily. See [how do I ask a good question](https://stackoverflow.com/help/how-to-ask). – rkersh Jun 27 '19 at 16:12
1 Answers
1
I would use the ternary operator.
Let me give you a starting point:
{int} E=asSet(1..10);
int V[u in E,v in E]=u+v;
int nbK=2;
int nbN=4;
range N=1..nbN;
range K=1..nbK;
int U[k in K]=2*k;
int C0=1;
dvar boolean y[E][E];
dvar boolean x[E][E][K];
minimize sum(u,v in E) y[u][v]*V[u][v];
subject to
{
forall(u,v in E,k in K)
{
forall(k in K) sum(w in N) x[u][w][k]-sum(v in N) x[v][u][k]==
( (u==C0)?1:(u==U[k]?-1:0) );
forall(u,v in E,k in K) x[u][v][k]<=y[u][v];
}
}

halfer
- 19,824
- 17
- 99
- 186

Alex Fleischer
- 9,276
- 2
- 12
- 15