在主要使用 OPL 以数组形式制定 MILP 之后,我正在尝试将一些问题转换为元组制定以从稀疏数据中获益!
由于我不是来自编程背景,所以我花了一些时间来理解数据结构以及它们是如何工作的。我想我现在了解了基础知识,但在尝试制定我的约束时遇到了困难。我阅读了示例,观看了 youtube 教程,并尝试了不同的代码,但我还没有想出解决方案。
问题:问题本身是多周期(逆向供应链)位置分配问题的一部分。
我目前正在尝试制定的约束条件: 在一个区域(a in A)供应的所有产品(p in P)和尺寸(s in S)在每个时期(t n T)需要被提取并运输到一个位置(l in L)
因为其他约束也存在同样的问题,我将非常感谢一个答案,告诉我我的错误(思考)在哪里。
提前谢谢大家!
Part of my array formulation (works fine)
int supply[A][P][S][T] =...; (data is read from on excel file)
dvar int+ transport[A][L][P][S][T] in 0...100;
我跳过了目标函数的公式(最小化:对所有时期、产品、尺寸、面积和位置运输*成本求和)
(第一个)约束
forall (p in P, s in S, a in A, t in T)
supply [a,p,s,t]==sum (l in L) transport[a,l,p,s,t];
我的元组公式(声明):
tuple Treturns{
int A;
int P;
int S;
int T;
}
{Treturns} returnsT=...; (read from excel, could also be generated in mod file)
//Return including supply Value
tuple Tsupply{
Treturns ret;
int supplyvalue;
}
{Tsupply} supplyT with ret in returnsT =...; (read frrom excel)
//Transport --> use tuple in dvar fomulation
tuple Ttransport{
Treturns ret; //area, product, size and period
int L; //location
}
{int} L=...; (data file connection)
{Ttransport} transT with ret in returnsT, L in L ={<c,l> |c in returnsT, l in L};
dvar int+ transport[transT] in 0..100;
minimize sum(c in transT)transport[c]
这里是约束的尝试:
subject to {
forall (d in supplyT:d.supplyvalue>0, c in transT:c.ret==d.ret)
d.supplyvalue ==sum (l in L)transport[c];
}
模型不能用这个约束求解。如果我将“==”更改为“<=" the model is solved, and I can see that the constraint does not do what I want. ;)
在当前的公式中(使用 <= instead of =), I get different values for each period, product, size, and area. But the value is always the same for both locations. Thus, if, for instance, 3 units of product p, size s are returned in period 1 and area 1 --> transport[c] 为每个位置 (l)(以及 p、s、a 和 t 的组合)给出“2”)。
如果约束正常工作,它必须是总共三个运输单元而不是四个(并且两个位置的值必须不同(0/3、1/2、2/1、3/0)) .