CPLEX OPL约束,计算唯一字符串
OPL模型的目标是选择以最低成本的总成本来履行所有订单,我对货运上的订单限制必须交付给< = 2 ClientId。当前,最佳解决方案是将第三货运用于所有订单(因为它是最便宜的),但是有了新的约束,第三货运最多可以携带两个订单(因为每个订单均适用于不同的客户端ID)。但是如何编码该约束呢?
当前.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];
dexpr float objective =
sum(o in Orders, f in FreightTypes)
Assignment[o][f] * f.Cost;
//choose freight with total minimum cost
minimize objective;
subject to{
//c1: all order must be fulfilled
forall(o in Orders)
sum(f in FreightTypes) Assignment[o][f]==1;
//c2: the order on a freight must be less than 2 destination
}
.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 constraint of the order on a freight must be delivered to <= 2 clientId. Currently the optimal solution is to use the third freight for all orders (since it's the cheapest), but with the new constraint, the 3rd freight can carry at most two orders (since each order is for different clientId). but how to encode that constraint?
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];
dexpr float objective =
sum(o in Orders, f in FreightTypes)
Assignment[o][f] * f.Cost;
//choose freight with total minimum cost
minimize objective;
subject to{
//c1: all order must be fulfilled
forall(o in Orders)
sum(f in FreightTypes) Assignment[o][f]==1;
//c2: the order on a freight must be less than 2 destination
}
.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以写作
,2符合两个目的地,完整的模型看起来像
You can write
and 2 comply with the 2 destinations, the complete model could look like