Hi,Sorry for the delayed response.
new_pattern_id = max(pt.id for pt in master_model.patterns) + 1
new_pattern = TPattern(new_pattern_id, 1)
master_model.patterns.append(new_pattern)
for used, item in zip(item_usages, master_model.items):
master_model.pattern_item_filled[new_pattern, item] = used
# --- add one decision variable, linked to the new pattern.
new_pattern_cut_var = master_model.continuous_var(lb=0, ub=master_model.MAX_CUT,
name='cut_{0}'.format(new_pattern_id))
master_model.cut_vars[new_pattern] = new_pattern_cut_var
# update constraints
for item, ct in zip(master_model.items, master_model.item_fill_cts):
# update fill constraint by changing lhs
ctlhs = ct.lhs
filled = master_model.pattern_item_filled[new_pattern, item]
if filled:
ctlhs += new_pattern_cut_var * filled
I think the above code snippet, is where a new variable is initialized corresponding to the new pattern. And then, all the corresponding constraints are retrieved.
Finally, you add the variable to each constraint using : ctlhs += new_pattern_cut_var * filled
I think the above is a good way. I will try using this and inform of the performance improvement.
Thanks!
------------------------------
HARIHARAN SUBRAMANIAN
------------------------------
Original Message:
Sent: Sun June 16, 2024 11:37 AM
From: ALEX FLEISCHER
Subject: How to add column in CPLEX + DOCplex + Python for Column Generation process?
Hi,
have you had a look at the cutstock.py example ?
Column generation is a solution process that begins with a small, manageable part of a problem (specifically, a few of the variables), solves that part, analyzes the partial solution to determine the next part of the problem (specifically, one or more variables) to add to the model, and then solves the new, enlarged model. Column generation repeats the process until a satisfactory solution to the whole problem is achieved.
------------------------------
[Alex] [Fleischer]
[Data and AI Technical Sales]
[IBM]
Original Message:
Sent: Sat June 15, 2024 12:08 AM
From: HARIHARAN SUBRAMANIAN
Subject: How to add column in CPLEX + DOCplex + Python for Column Generation process?
Hello,
-- For CG process, how to add a variable in each iteration ?
Assuming I formulate this model, solve it, and get a reduced cost column from the SubProblem, how do I add this variable without reformulating the model entirely? Is there a function like AddCols(that is available in C) available in Python ? Do let me know, since in every iteration this would again save more time.
Thanks
------------------------------
HARIHARAN SUBRAMANIAN
------------------------------