10
$\begingroup$

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

$\endgroup$
  • 2
    $\begingroup$ Since you tagged your question with column_generation, maybe this link has something to help. $\endgroup$ – EhsanK Sep 4 '19 at 0:43
  • $\begingroup$ 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? $\endgroup$ – LarrySnyder610 Sep 4 '19 at 2:44
  • 1
    $\begingroup$ @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. $\endgroup$ – Daniel Duque Sep 4 '19 at 12:57
  • 1
    $\begingroup$ @EhsanK that was my first attempt. That example implements the approach I described (create a variable and then modify the coefficients in the constraints). $\endgroup$ – Daniel Duque Sep 4 '19 at 13:02
  • $\begingroup$ @DanielDuque OK, please check my edits to make sure they are OK. $\endgroup$ – LarrySnyder610 Sep 4 '19 at 13:32
4
$\begingroup$

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
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.