CPLEX OPL软目标,将高优先股分组

发布于 2025-02-10 13:20:50 字数 1436 浏览 4 评论 0 原文

OPL模型的目标是选择以最低成本的总成本来履行所有订单,我有一个软优化目标 Objective1 尝试将所有订单与 categoryPriority 在一个货运或尽可能少的货物上。但是如何编码该目标呢? (在下面的示例中,订单2和3是在同一卡车上的最佳选择)

当前.mod文件(型号文件)

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文件(数据文件)

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

};

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

};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神妖 2025-02-17 13:20:50

而不是加权总和

最小化0.95 目标+0.05 Objective1;

您可以使用词典学:

最小化静态(objective,objective1);

完整示例

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");
}

在您的模型中看起来像以下内容

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

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;       
   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文