1

The goal of the opl model below is to choose the freights with total minimum cost to fulfill all orders, I have a soft optimization objective objective1 where it's to try to put all orders with CategoryPriority on one freight or as small number of freight as possible. But how to encode that objective? (in the example below, order 2 and 3 is optimal to be on the same truck)

current .mod file (model file)

tuple TFreightTypes {
  key string Destination;
  key string VehicleType;
  int TotalWeight;
  key string Company;
  int Cost;
};

tuple TOrders {
  key int OrderNumber;
  float Weight;
  string ClientId;
  string Destination;
  string MaterialCategory;
  int CategoryPriority;
};

{TFreightTypes}    FreightTypes = ...;
{TOrders}    Orders = ...;


dvar boolean Assignment[Orders][FreightTypes];

//choose freight with total minimum cost
dexpr float objective = 
  sum(o in Orders, f in FreightTypes)
     Assignment[o][f] * f.Cost;

//try to put all orders with CategoryPriority=1 on one truck 
//dexpr float objective1 = 
  //how to do that?

minimize 0.95*objective+0.05*objective1;


subject to{

  //c1: all order must be fulfilled
  forall(o in Orders)
    sum(f in FreightTypes) Assignment[o][f]==1;       
   
}

.dat file (data file)

FreightTypes = {
    <"LONDON","Type1",20000,"SP TRANSPORTS",40000>,
    <"LONDON","Type2",20000,"SP TRANSPORTS",40000>,
    <"DURHAM","Type3",10000,"SP TRANSPORTS",30000>,

};
Orders = {
    <1,5000,"Client1","LONDON","A",0>,
    <2,1000,"Client2","DURHAM","B",1>,
    <3,2000,"Client3","LONDON","C",1>,      

};
william007
  • 17,375
  • 25
  • 118
  • 194

1 Answers1

1

instead of weighted sum

minimize 0.95objective+0.05objective1;

you can use lexicographic :

minimize staticLex(objective,objective1);

Full example https://github.com/AlexFleischerParis/zooopl/blob/master/zoomultiobjective.mod

int nbKids=200;
float costBus40=500;
float costBus30=400;
float costBus50=625;
     
dvar int+ nbBus40;
dvar int+ nbBus30;
dvar int+ nbBus50;

dvar float cost;
dvar float co2emission;
     
minimize
  staticLex(cost,co2emission);
     
subject to
{
 cost==costBus40*nbBus40  +nbBus30*costBus30+nbBus50*costBus50;
 co2emission==nbBus50+nbBus40*1.1+nbBus30*1.2;

  40*nbBus40+nbBus30*30+nbBus50*50>=nbKids;
}

execute DISPLAY_After_SOLVE
{
  writeln("The minimum cost is ",cost);
  writeln("CO2 emission is ",co2emission);
  writeln("We will use ",nbBus40," 40 seats buses ",nbBus30,
  " 30 seats buses and ", nbBus50," buses 50 seats");
}

which could look like the following with your model

tuple TFreightTypes {
  key string Destination;
  key string VehicleType;
  int TotalWeight;
  key string Company;
  int Cost;
};

tuple TOrders {
  key int OrderNumber;
  float Weight;
  string ClientId;
  string Destination;
  string MaterialCategory;
  int CategoryPriority;
};

{TFreightTypes}    FreightTypes = ...;
{TOrders}    Orders = ...;


dvar boolean Assignment[Orders][FreightTypes];

//choose freight with total minimum cost
dexpr float objective = 
  sum(o in Orders, f in FreightTypes)
     Assignment[o][f] * f.Cost;

//try to put all orders with CategoryPriority=1 on one truck 
//dexpr float objective1 = 
  //how to do that?
  
{int} priorities={o.CategoryPriority | o in Orders};
  
dvar int nbFreightPerPriority[priorities]; 
dvar float+ objective1;

minimize staticLex(objective,objective1);


subject to{
  
  forall(p in priorities) 
  nbFreightPerPriority[p]==
  sum(f in FreightTypes) (1<=sum (o in Orders:o.CategoryPriority==p) Assignment[o][f]);
  
  objective1==sum(p in priorities) nbFreightPerPriority[p];

  //c1: all order must be fulfilled
  forall(o in Orders)
    sum(f in FreightTypes) Assignment[o][f]==1;       
   
}
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thanks, What about the part of grouping high priority stock, actually that’s the key part of the question where I did not know how to achieve – william007 Jun 24 '22 at 10:13