Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  About annotations for Benders Decompostition in CPLEX Python API

    Posted Wed September 04, 2019 09:31 AM

    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


  • 2.  Re: About annotations for Benders Decompostition in CPLEX Python API

    Posted Wed September 04, 2019 10:03 AM

    If you want to create an annotation that CPLEX can use for automated Benders, then this annotation has to have the name given by Cplex.long_annotations.benders_annotation.

    Take a look at the benders.py example that ships with CPLEX.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: About annotations for Benders Decompostition in CPLEX Python API

    Posted Wed September 04, 2019 10:27 AM

    Originally posted by: HB0D_欣炜_沈


    Thank you! It worked now!

    In fact I read "benders.py" and copy some of the codes to the set_annotations but I didn't fully understand the meaning of "name"...

    A following question is that:

    Can I use prob.long_annotations.set_values(idx, objtype, seq) several times to give different variables different annotations?

    As you may have noticed, I use 

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

    to do so, however, now an error "CPLEX Error  1222: Duplicate entry or entries." was reported after that.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: About annotations for Benders Decompostition in CPLEX Python API

    Posted Wed September 04, 2019 11:21 AM

    Originally posted by: HB0D_欣炜_沈


    Problem solved.

    change the set_annotations() to:

    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=prob.long_annotations.get_names(prob.long_annotations.benders_annotation)
        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)])
    

    benders_annotations cannot be added, but its name can be called and its value can be set repeatedly.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: About annotations for Benders Decompostition in CPLEX Python API

    Posted Wed September 04, 2019 12:12 PM

    Originally posted by: HB0D_欣炜_沈


    Dear Daniel, 

    Now I found a very interesting fact: CPLEX has been spending too much time in adding benders cut in the problem, and conventional dynamic search process didn't start even after a long time. Is there a way I can limit the time comsuned in benders cut generation?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: About annotations for Benders Decompostition in CPLEX Python API

    Posted Tue September 10, 2019 12:22 PM

    Originally posted by: AndreaTramontani


    Hello,

    about your question on time spent for separating Benders cuts, there is unfortunately no explicit way to limit the time consumed in Benders' cut separation.
    Can you please provide more information about this issue?
    The initial Benders cut loop (applied before branch-and-cut/dynamic search) could be slow due to a mixture of several factors:
    .. the solve of a single worker LP (to generate one cut) is too slow
    .. too many cuts are generated in a single pass of the Benders cut loop
    .. too many passes of the initial cut loop are executed before CPLEX starts the regular branch-and-cut.

    Do you know where the issue is in your case?
    Can you share the CPLEX log?


    Also, from the previous comments, I understand that in your decomposition you have 4 workers.
    Am I correct?


    Best,
    Andrea


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: About annotations for Benders Decompostition in CPLEX Python API

    Posted Wed September 04, 2019 12:18 PM

    Originally posted by: HB0D_欣炜_沈


    Just btw, according to the log file, there's no "Best Integer" showed up in the benders decomposition process. and the "Objective" just improved very slowly.

    However, to the best of my knowledge, it would be better if a (globally--in both master and sub prob) feasible solution has been produced by the Master Problem and passed to the Sub Problem, the the iteration would be more effective.


    #CPLEXOptimizers
    #DecisionOptimization