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

• Since you tagged your question with column_generation, maybe this link has something to help.
– EhsanK
Sep 4 '19 at 0:43
• Is this really a question about column generation (which is an algorithmic technique) or just about whether the model itself can be built column-wise instead of row-wise? Sep 4 '19 at 2:44
• @LarrySnyder610 is about implementing column generation in docplex. The issue is that adding one variable at a time and changing the coefficients is very slow. Sep 4 '19 at 12:57
• @EhsanK that was my first attempt. That example implements the approach I described (create a variable and then modify the coefficients in the constraints). Sep 4 '19 at 13:02
• @DanielDuque OK, please check my edits to make sure they are OK. Sep 4 '19 at 13:32

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")

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')

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