@@ -67,6 +67,12 @@ def pricerredcost(self):
67
67
self .data ['patterns' ].append (newPattern )
68
68
self .data ['var' ].append (newVar )
69
69
70
+ if self .data ["deactivate" ]:
71
+ # Testing deactivatePricer
72
+ self .model .deactivatePricer (self )
73
+ for c in self .model .getConss ():
74
+ self .model .setModifiable (c , False )
75
+
70
76
return {'result' :SCIP_RESULT .SUCCESS }
71
77
72
78
# The initialisation function for the variable pricer to retrieve the transformed constraints of the problem
@@ -124,6 +130,7 @@ def test_cuttingstock():
124
130
pricer .data ['rollLength' ] = rollLength
125
131
pricer .data ['patterns' ] = patterns
126
132
pricer .data ['redcosts' ] = []
133
+ pricer .data ["deactivate" ] = False
127
134
128
135
# solve problem
129
136
s .optimize ()
@@ -174,4 +181,67 @@ class IncompletePricer(Pricer):
174
181
model .includePricer (pricer , "" , "" )
175
182
176
183
with pytest .raises (Exception ):
177
- model .optimize ()
184
+ model .optimize ()
185
+
186
+ def test_deactivate_pricer ():
187
+ # create solver instance
188
+ s = Model ("CuttingStock" )
189
+
190
+ s .setPresolve (0 )
191
+ s .data = {}
192
+ s .data ["nSols" ] = 0
193
+
194
+ # creating a pricer
195
+ pricer = CutPricer ()
196
+ s .includePricer (pricer , "CuttingStockPricer" , "Pricer to identify new cutting stock patterns" )
197
+
198
+ # item widths
199
+ widths = [14 , 31 , 36 , 45 ]
200
+ # width demand
201
+ demand = [211 , 395 , 610 , 97 ]
202
+ # roll length
203
+ rollLength = 100
204
+ assert len (widths ) == len (demand )
205
+
206
+ # adding the initial variables
207
+ cutPatternVars = []
208
+ varNames = []
209
+ varBaseName = "Pattern"
210
+ patterns = []
211
+
212
+ for i in range (len (widths )):
213
+ varNames .append (varBaseName + "_" + str (i ))
214
+ cutPatternVars .append (s .addVar (varNames [i ], obj = 1.0 ))
215
+
216
+ # adding a linear constraint for the knapsack constraint
217
+ demandCons = []
218
+ for i in range (len (widths )):
219
+ numWidthsPerRoll = float (int (rollLength / widths [i ]))
220
+ demandCons .append (s .addCons (numWidthsPerRoll * cutPatternVars [i ] >= demand [i ],
221
+ separate = False , modifiable = True ))
222
+ newPattern = [0 ]* len (widths )
223
+ newPattern [i ] = numWidthsPerRoll
224
+ patterns .append (newPattern )
225
+
226
+ # Setting the pricer_data for use in the init and redcost functions
227
+ pricer .data = {}
228
+ pricer .data ['var' ] = cutPatternVars
229
+ pricer .data ['cons' ] = demandCons
230
+ pricer .data ['widths' ] = widths
231
+ pricer .data ['demand' ] = demand
232
+ pricer .data ['rollLength' ] = rollLength
233
+ pricer .data ['patterns' ] = patterns
234
+ pricer .data ['redcosts' ] = []
235
+ pricer .data ["deactivate" ] = True
236
+
237
+ for c in s .getConss ():
238
+ c .isModifiable ()
239
+
240
+ # solve problem
241
+ s .optimize ()
242
+
243
+ for c in s .getConss ():
244
+ assert not c .isModifiable ()
245
+
246
+ # the optimal solution with normal pricing
247
+ assert s .isGT (s .getObjVal (), 452.25 )
0 commit comments