试图在Gurobi中查找违反的约束-线性编程

时间:2019-05-08 07:06:47

标签: optimization constraints linear-programming gurobi

我正在尝试实现一种机制,以列出是否违反了特定约束。我正在使用Gurobi,请在这里帮助我

1)最小化约束

2)合法性​​约束(ShiftCodelegality_A_Constraint,ShiftCodelegality_B_Constraint)

3)阈值约束(ShiftCodelegality_A__Threshold_Constraint,ShiftCodelegality_B__Threshold_Constraint)

我需要通过添加其他变量(例如Extra_A,Extra_B,Extra_A_Legality,Extra_B_Legality)来找出问题。 这样我就可以使用这些变量值来了解约束是否违反。

未修改的LP文件可能是错误的,需要实现一些想法

\ Model Shift Processing
\ LP format - for model browsing. Use MPS format to capture full model detail.
Minimize
  0.4 Person_593800_ShiftA + 0.2 Person_593800_ShiftB
Subject To
 Person_593800_Constraint: Person_593800_ShiftA + Person_593800_ShiftB + UNCOV_593800 = 1
 Person_862998_Constraint: Person_862998_ShiftA + Person_862998_ShiftB + UNCOV_862998 = 1
 ShiftCodelegality_A_Constraint: Person_593800_ShiftA + Person_862998_ShiftA
   <= 2
 ShiftCodelegality_B_Constraint: Person_593800_ShiftB + Person_862998_ShiftB
   <= 2
 ShiftCodelegality_A__Threshold_Constraint: Person_593800_ShiftA + Person_862998_ShiftA + UNCOV_ShiftAPOS_0
   = 1
 ShiftCodelegality_B__Threshold_Constraint: Person_593800_ShiftB + Person_862998_ShiftB + UNCOV_ShiftBPOS_0
   = 0
 MinimizedUncoverageConstraint: UNCOV_ShiftAPOS_0
   = 0
 PersonWiseAllocationConstraint: = 0
Bounds
Binaries
 Person_593800_ShiftA Person_593800_ShiftB Person_862998_ShiftA Person_862998_ShiftB UNCOV_593800
 UNCOV_862998 UNCOV_ShiftAPOS_0 UNCOV_ShiftBPOS_0
End

下面是修改后的LP文件

\ Model Shift Processing
\ LP format - for model browsing. Use MPS format to capture full model detail.
Minimize
  0.4 Person_593800_ShiftA + 0.2 Person_593800_ShiftB + 50 Extra_A
Subject To
 Person_593800_Constraint: Person_593800_ShiftA + Person_593800_ShiftB + UNCOV_593800 = 1
 Person_862998_Constraint: Person_862998_ShiftA + Person_862998_ShiftB + UNCOV_862998 = 1
 ShiftCodelegality_A_Constraint: Person_593800_ShiftA + Person_862998_ShiftA + Extra_A
   <= 2
 ShiftCodelegality_B_Constraint: Person_593800_ShiftB + Person_862998_ShiftB + Extra_B
   <= 2
 ShiftCodelegality_A__Threshold_Constraint: Person_593800_ShiftA + Person_862998_ShiftA + UNCOV_ShiftAPOS_0 
   - Extra_A_Legality = 1
 ShiftCodelegality_B__Threshold_Constraint: Person_593800_ShiftB + Person_862998_ShiftB + UNCOV_ShiftBPOS_0
   - Extra_B_Legality = 0
 MinimizedUncoverageConstraint: UNCOV_ShiftAPOS_0 + UNCOV_ShiftBPOS_0
   = 0
 PersonWiseAllocationConstraint: = 0
Bounds
Binaries
 Person_593800_ShiftA Person_593800_ShiftB Person_862998_ShiftA Person_862998_ShiftB UNCOV_593800
 UNCOV_862998 UNCOV_ShiftAPOS_0 UNCOV_ShiftBPOS_0
End

0 个答案:

没有答案