【问题标题】:ILOG CPLEX: Constraint assigning a decision variable in specific orderILOG CPLEX:约束以特定顺序分配决策变量
【发布时间】:2019-03-07 16:56:29
【问题描述】:

在 CPLEX 中,我构建了我想用于将产品定位到位置的附加模型。尝试按升序排列产品分配到位置的约束 Stackingorder[s] 并没有给我想要的结果。

如果一个产品被分配在位置 xi 它应该有一个更小的 stackingorder+1 然后所有位于位置 xi 之后的产品。

CPLEX 似乎在满足所有其他约束时忽略了约束。

我应该如何更改约束或模型以使其正常工作?

    forall(w in Locations: w+1 in Locations, s in Products) 
 ctStackingorder:
    {(Slot[s][w+1] * Stackingorder[s]) <= Slot[s][w] * (Stackingorder[s]+1);}



int Fixed = ...;
int NbLocations = ...;
range Locations = 0..NbLocations-1;
int NbProducts = ...;
range Products = 0..NbProducts-1;
int Capacity[Locations] = ...;
int LocationCosts[Products][Locations] = ...;
int RequiredLoc[Products] = ...;
int Stackingorder[Products] = ...;

dvar boolean Use[Locations];
dvar boolean Slot[Products][Locations];
dvar int SError[Products][Locations];

minimize
  sum( w in Locations ) 
    Fixed * Use[w] +
  sum( w in Locations , s in Products ) 
LocationCosts[s][w] * Slot[s][w] +
  sum( w in Locations , s in Products )
    SError[s][w] *1000 * RequiredLoc[s];

subject to{

  forall(s in Products )
    ctProductHasEnoughLocations:
      sum( w in Locations)
        Slot[s][w] * Capacity[w] ==  RequiredLoc[s];    

  forall(s in Products, w in Locations: w+1 in Locations)
    ctFacings:
        if(RequiredLoc[s] >1){ Slot[s][w+1]==Slot[s][w];}

  forall( w in Locations, s in Products )
    ctUseSlotProduct:
      Slot[s][w] <= Use[w];

  forall( w in Locations )
    ctMaxUseOfLocation:         
      sum( s in Products ) 
        Slot[s][w] <= Capacity[w];

      forall(w in Locations: w+1 in Locations, s in Products) 
 ctStackingorder:
    {(Slot[s][w+1] * Stackingorder[s]) <= Slot[s][w] * (Stackingorder[s]+1);}
} 

{int} Productsof[w in Locations] = { s | s in Products : Slot[s][w] == 1 };

execute
{
  writeln("Open=",Use);
  writeln("Storesof=",Productsof);
}

.dat

Fixed = 30;
NbLocations = 6;
NbProducts = 5;
RequiredLoc = [1,1,1,1,1];
Capacity = [1,1,1,1,1,1];
LocationCosts = [ 
   [ 1, 1, 1, 1, 1, 1 ], 
   [ 1, 1, 1, 1, 1, 1 ],
   [ 1, 1, 1, 1, 1, 1 ],
   [ 1, 1, 1, 1, 1, 1 ],
   [ 1, 1, 1, 1, 1, 1 ] ];

Stackingorder = [328,326,228,226,226];   

【问题讨论】:

  • 您好,您可以分享.dat 以便其他用户尝试吗?问候
  • @AlexFleischer 使用 .dat 内容编辑了原始帖子

标签: constraints linear-programming cplex ilog


【解决方案1】:

您的模型不可行,CPLEX 放宽了它。在放松选项卡中,您可能会看到:

如果您希望该约束成为硬约束,则应将其更改为:

forall(s in Products )
    //ctProductHasEnoughLocations:
      sum( w in Locations)
        Slot[s][w] * Capacity[w] ==  RequiredLoc[s]; 

(无标签)

然后其他的约束就会放松。

见:

https://www.ibm.com/support/knowledgecenter/SSSA5P_12.8.0/ilog.odms.ide.help/OPL_Studio/usroplexamples/topics/opl_mp_examples_relaxation.html

【讨论】:

  • 感谢更改了约束以最大程度地减少不满足约束的错误。现在工作正常。结果 Slot[s][w] 是可行的并且满足所有约束。但是现在我尝试将分配最低的 stackingorder 排序为最高。那么 slot[s][w] * stackingorder[s] >= sum(s in products where x
  • 嗨@JLo,如果这个或任何答案解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。如果您有后续(不同)问题,建议创建一个新(单独)问题,而不是使用 cmets。谢谢!
猜你喜欢
  • 2021-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多