Search code examples
linear-programmingcplexnonlinear-optimizationmixed-integer-programming

LP / MILP (CPLEX) difficulties


I'm trying to solve an optimization problem with CPLEX.

//Variables 

int n = ...;
range time =1..n; //n definido em data

dvar float+ c[time] in 0..0.9;
dvar float+ d[time] in 0..0.9;
dvar float+ x[time];

int beta[time]=...;
float pc[time]=...;
float pd[time]=...;

//Expressions

dexpr float objective = sum(t in time) (d[t]*pd[t]-c[t]*pc[t]); 

//Model

maximize objective;

subject to {

    x[1] == 0.5;
    c[1] == 0;
    d[1] == 0;

    forall(t in time)
        const1:
            x[t] <= 1;          

    forall(t in time: t!=1)
        const2:
            (x[t] == x[t-1] + c[t] - beta[t]*d[t]);             
 }

Can anyone tell me how I can prevent d[t] and c[t] to be bigger than 0 at the same time?

Basically I want to write this:

if( d[t] > 0) c[t] = 0; 

Thank you,


Solution

  • you could use a logical constraint:

    ( d[t] <= 0) || (c[t] <= 0);