Home > Mobile >  Hello, I should use floor function in cplex , but it does not work. I is a decision variable and J i
Hello, I should use floor function in cplex , but it does not work. I is a decision variable and J i

Time:05-29

sum(f in Nuflow) floor (sum(v in Nuvnf, n in Nunode, j in Nusfc) I[v] [n] [f] [j]/J)

CodePudding user response:

you should linearize floor.

See floor example in How to with OPL CPLEX ?

    range r=1..4;

    float x[r]=[1.5,4.0,2.0001,5.9999];

    dvar int y[r];
    dvar float f[r] in 0..0.99999;

    subject to
    {
    forall(i in r) x[i]==y[i] f[i];


    }

    execute
    {
    writeln(x," ==> ",y);
    }

    assert forall(i in r) y[i]==floor(x[i]);

//which gives

// [1.5 4 2.0001 5.9999] ==> [1 4 2 5]

CodePudding user response:

//ranges
int N=11;
range Nunode=0..N;
int V=5;
range Nuvnf=1..V;
int J=5;
range Nusfc=1..J;
int F=50;
range Nuflow =1..F;

//decision variable
dvar boolean I[Nuvnf][Nunode][Nuflow][Nusfc];
dexpr float x[f in Nuflow]=sum(v in Nuvnf, n in Nunode, j in Nusfc) I [v][n][f][j] / J;
float y[f in Nuflow];

maximize sum(f in Nuflow) y[f];

subject to {forall(f in Nuflow, j in Nusfc) cons:sum(n in Nunode, v in Nuvnf) I[v][n][f][j] <= 1;}

execute {writeln(x, "x==>y", y);}

assert forall(f in Nuflow) y[f]==floor(x[f]); 
  • Related