Originally posted by: HB0D_欣炜_沈
Hi all,
I used CPLEX Python API to realize benders decomposition with annotatons, the codes are as below:
import cplex
def set_annotations(prob,var_idx,Sub_j,var_name):
"""set annotations of var, so that vars are put into SubProblem.
prob Cplex object
var_idx index of var, where var are continuous variables that will
be put into SubProblem Sub_j
Sub_j index num of SubProblem, which should be a integer >= 1
var_name str of variable's name
"""
anno = prob.long_annotations
idx = anno.add(name='{0}_to_Subprob'.format(var_name), # var to Subproblem
defval=anno.benders_mastervalue)
objtype = anno.object_type.variable
var_idx_start=var_idx.tolist()[0][0]-1
var_idx_end=var_idx.tolist()[0][-1]-1
prob.long_annotations.set_values(idx, objtype,
[(i,Sub_j)
for i in range(var_idx_start,var_idx_end)])
prob = cplex.Cplex()
…………………………
………………………… (model formulation and getting index of variables)
prob.parameters.benders.strategy.set(prob.parameters.benders.strategy.values.user)
set_annotations(prob,wc_idx,1,'wc')
set_annotations(prob,np_idx,2,'np')
set_annotations(prob,ng_idx,3,'ng')
set_annotations(prob,y_idx,4,'y')
prob.solve()
However, "CPLEX Error 2000: No Benders decomposition available." appeared afterwards, thus I think the set_annotations() didn't work, it's also noteworthy that the variables "y" in my model are actually binary variables, which CANNOT be put into any Subproblem for sure.
So, what's wrong with my code?
I also put my_annotations attached, according to which this annotations should have been right.
#CPLEXOptimizers#DecisionOptimization