2
$\begingroup$

How to write the following constraint in cplex?

  1. the cost for full truck load is $700

  2. and the cost of fractional truck load is \$800 *fraction up to $700

$\endgroup$
  • $\begingroup$ If you were asking for an OPL solution, then accept @Alex Fleischer's answer [pretty please]. -- Otherwise, also: please, specify the modeling/programming language you are looking for. $\endgroup$ – fbahr Apr 18 at 19:26
5
$\begingroup$
//the cost for full truck load is $700
    // the cost of fractional truck load is $800 *fraction up to 700

float truckCost=700;
float truckPartialCost=800;

range r=1..3;

float values[r]=[5,6.5,6.9];
dvar float nbTruck[r];
dvar float cost[r];

// computation
dvar int intNbTruck[r];
dvar float floatNbTruck[r] in 0..0.99;

subject to
{
  forall(i in r) 
  {
    nbTruck[i]==values[i];
    nbTruck[i]==intNbTruck[i]+floatNbTruck[i];
    cost[i]==intNbTruck[i]*truckCost+minl(truckCost,floatNbTruck[i]*truckPartialCost);
  }
}

execute
{
  writeln(cost);
}

gives

[3500 4600 4900]

Nb: Some more info here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.