0

I am trying to iterate through a MIP model with my own branching algorithm. So at each iterations, I am assigning all the binaries a value (0 or 1). Based on the results, I change how I assign the values. As an efficiency step, I have defined all the binaries as continuous and then fix their values. Due to how docplex works in the background, having no binaries defined has significant speed up in performance.

I have a conditional constraint (v=0 ==> S = 0). I could use either BigM formulations(not suitable in my case) or the inbuilt indicator function in a vanilla Branch and Bound MIP algo. However, since I have converted all my binaries, the indicator method doesnt work any more.

Is there a way around this? Or alternatively, I could define all the S=0 constraints(and deactivate them). Then at each iteration, I can manually check if v=0 and then activate the corresponding s=0 constraints (i.e. doing what the indicator constraint does but manually).

Other alternatives would be welcome too.

Abilash
  • 95
  • 10

1 Answers1

0

Let me use the zoo example to show how to disactivate a constraint through rhs:

from docplex.mp.model import Model

# original model

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)

mdl.solve()

for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)

#now deactivate the "kids" cosntraints

print()
   
    
mdl.get_constraint_by_name("kids").rhs=0;
mdl.solve()

for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)

gives

nbBus40  =  6.0
nbBus30  =  2.0

nbBus40  =  0
nbBus30  =  0
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15