10

When using DOCplex to implement column generation, is it possible to add columns as an object, as opposed to creating a variable and then modifying the coefficients in the constraints?

Edit: In gurobi one can add a column creating the object Column and passing that object as the last argument of the function that creates variables

LarrySnyder610
  • 13,141
  • 3
  • 41
  • 105
Daniel Duque
  • 1,355
  • 6
  • 20

1 Answers1

4

let me a tiny example out of my zoo and buses story:

from docplex.mp.model import Model

# original model

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
ctKids=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)

print()
print("Same number of 40 and 30 seats buses")

mdl.add_constraint(nbbus40==nbbus30, 'samenumberofbuses')

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


print()
print("Now with buses with 50 seats")




# And now we add 50 seats buses

nbbus50 = mdl.integer_var(name='nbBus50')

ctKids.left_expr.add_term(nbbus50, 50)
mdl.minimize(nbbus40*500 + nbbus30*400 + nbbus50*700)

mdl.solve()

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

gives

nbBus40  =  6.0
nbBus30  =  2.0

Same number of 40 and 30 seats buses
nbBus40  =  6.0
nbBus30  =  2.0

Now with buses with 50 seats
nbBus40  =  3.0
nbBus30  =  3.0
nbBus50  =  2.0
Alex Fleischer
  • 4,000
  • 5
  • 11
  • This approach does the job, but I'm looking for something like the Column object in gurobi-python api. This is just for speed in implementation. See the last argument on this: https://www.gurobi.com/documentation/8.1/refman/py_model_addvar.html – Daniel Duque Sep 04 '19 at 13:00