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>,
};