linear-programmingcplexibm-ilog-opl

How to code this linear program in IBM CPLEX?


How can I code the linear program using IBM CPLEX?

In this picture u,v represent the edge of the graph.


Solution

  • 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];
    }
    }