Search code examples
cplexnegative-number

Solution gives a negative value for dvar float+ in CPLEX


The solution of my variable returns a negative value, while I defined it as a dvar flaot+, how is this possible? Here is my code:

int fixed_cost = 75;
dvar int+ x[truck, order] in 0..1;
dvar int+ savings[truck];
...
forall(h in truck) sum(n in order) (x_[h,n])*fixed_cost- fixed_cost == savings[h];

The solution shows this:

savings = [-75, 75];

While I need the following:

savings = [0, 75];

I also tried the following, but then my OPL won't run:

forall(h in truck) savings[h] >= 0;

Can someone please help me? Thank you in advance!


Solution

  • In OPL CPLEX when a model is not feasible, you will get a relaxation.

    For instance:

    dvar int+ x;
    dvar int+ y;
    
    subject to
    {
      x==5;
      x+y==0;
    }
    

    will give y==-5 in the IDE.

    The constraint that y should be positive is relaxed.

    See IDE and OPL > CPLEX Studio IDE > IDE Tutorials > Relaxing infeasible models > How relaxation and conflict search works in CPLEX documentation.