Variables annotations in CPLEX for Automatic Benders decomposition Java API

Viewed 37

I am trying to implement the automatic benders decomposition to my problem using CPLEX version 20.10. I want to use USER strategy where CPLEX attempts to decompose the model according to my annotations.

So first I initialize the strategy of benders algorithm and cplex.newLongAnnotation to specify cpxBendersPartition of variables.

cplex.setParam(IloCplex.Param.Benders.Strategy, IloCplex.BendersStrategy.User);     
IloCplex.LongAnnotation benders = cplex.newLongAnnotation("cpxBendersPartition");

Then after initializing the integer variable $x \in X$

IloIntVar [] x  = new IloIntVar[NumofX]; //integer 

I tried to annotate it as following and add it to the master problem (value = 0)

for(int k=0; k < x.length; k++) {       
    x[k] = cplex.intVar(0,UB,"x_"+k);
    cplex.setAnnotation(benders, x[k], 0);  
}

However at this point I got this following error:

ilog.cplex.IloCplex$UnknownObjectException: CPLEX Error: object is unknown to IloCplex
at ilog.cplex.IloCplex.getIndexOrException(IloCplex.java:11470)
at ilog.cplex.IloCplex.access$7400(IloCplex.java:453)
at ilog.cplex.IloCplex$AnnotationList.getIndexAndType(IloCplex.java:22273)
at ilog.cplex.IloCplex$AnnotationList.setAnnotation(IloCplex.java:22302)
at ilog.cplex.IloCplex.setAnnotation(IloCplex.java:22851)

So my questions are why am I getting this error ? and how to annotate the variables to use in an annotated decomposition for Benders algorithm?

Is there a way to export the .LP files of the master and the sub-problem(s) ?

Thank you so much in advance.

1 Answers

For manual annotation, you have an example in CPLEX_Studio221\cplex\examples\src\java : Facility.java

where we can see

cplex.newLongAnnotation(IloCplex.CPX_BENDERS_ANNOTATION,
                                       IloCplex.CPX_BENDERS_MASTERVALUE + 1);
            for (int j = 0; j < nbLocations; ++j)
               cplex.setAnnotation(decomp, open[j], IloCplex.CPX_BENDERS_MASTERVALUE);

I do not think you can directly get the submodel but you can get the annotation:

cpx.writeBendersAnnotation("benders.ann");

Nb : Same question at

https://community.ibm.com/community/user/datascience/discussion/variables-annotations-in-cplex-for-automatic-benders-decomposition-java-api#bm337e8cc3-0332-4ddd-98ee-9bf8aba83801

Related