ILOG CPLEX:约束按特定顺序分配决策变量

时间:2019-03-07 16:56:30

标签: constraints linear-programming cplex ilog

在CPLEX中,我构建了一个附件模型,该模型用于将产品定位到位置。试图按升序对产品分配到位置的约束Stackingorder [s]没有给我想要的结果。

如果将产品分配到位置xi,则其堆叠顺序+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];   

1 个答案:

答案 0 :(得分:0)

您的模型不可行,CPLEX放松了它。

在放松标签中,您可能会看到 relaxation

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

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

最诚挚的问候