Decision Optimization

Decision Optimization

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

 View Only
  • 1.  error in cplex.addSOSs (type, ind, wt)

    Posted Thu October 10, 2013 04:04 PM

    Originally posted by: Liebe


    Hi,

    I use "Special Ordered Sets of type 1" (SOS1) in a mixed-integer program. I have written cplex.addSOSs (type, ind, wt), e.g. cplex.addSOSs ('111 ', {[1 2 3]' [4 5 6] '[7 8 9]'}, {[1 2 3] '[1 2 3]' [1 2 3] '}).

    I do not know exactly what is the weights (wt) of SOS1 and how can I write the matrix as SOS weights. The type of x1 x2 x3 is 'B' as binary. When I start my program, the result is sometimes not correct, e.g.  "1" occurs twice in variables x1, x2 and x3. I have already so defined that only one of the three variables can be equal to 1.

    I think, I don't understand the "wt" of SOS1. Can anybody tell me what is the weights of SOS1 and how can I write the matrix as SOS weights.

    Thank you


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: error in cplex.addSOSs (type, ind, wt)

    Posted Thu October 10, 2013 05:31 PM

    The weights in SOSs are used to select branching variables. They define an order of the variables in the special ordered set. You can find more details in the respective chapter of the user manual here. The weights should not affect correctness. So if you get invalid results then something else is wrong.

    You cannot specify the weights as a matrix (see the documentation of addSOSs here). You can only give a cell array of columns.

    As far as I can tell, your code looks correct. Could you add this statement before cplex.solve():

    cplex.writeModel('model.lp');

    Then look at the created file model.lp (maybe post it here). This file should contain a section called SOS with this content:

    SOS
     s1: S1 ::  x1 : 1  x2 : 2  x3 : 3
     s2: S1 ::  x4 : 1  x5 : 2  x6 : 3
     s3: S1 ::  x7 : 1  x8 : 2  x9 : 3

    Do you see this in the file? If yes then the SOSs are correctly defined and the issue must be somewhere else.

    If you observe that two of x1, x2, x3 are 1, are they really 1 or are they just not equal to 0? What are the exact floating point values of those variables in an incorrect solution?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  回复:Re: error in cplex.addSOSs (type, ind, wt)

    Posted Fri October 11, 2013 05:09 AM

    Originally posted by: Liebe


    Thank you for your answer.

    Sorry, I said something wrong. I used a cell array of columns rather than a matrix.

    I have added this statement before cplex.solve(): cplex.writeModel('model.lp'); and  I have seen the file contains a section called SOS as you write.

    And two of x1, x2, x3 are really 1.

    I define 9 binary variables from x1 to x9.

     I write the constraint as cplex.addSOSs ('111 ', {[1 2 3]' [4 5 6] '[7 8 9]'}, {[1 2 3] '[1 2 3]' [1 2 3] '}), then sometimes two of x1, x2, x3 are 1 and sometimes all the variables are 0. But the 3 constraints are written normal without SOS1 as x1+x2+x3-1=0; x4+x5+x6-1=0; x7+x8+x9-1=0. Then the result is right.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  回复:Re: error in cplex.addSOSs (type, ind, wt)

    Posted Fri October 11, 2013 09:39 AM

    x1=x2=x3=0 is fine. An SOS {x1,x2,x3} does not require any of them to be non-zero. It only forbids two of them to be non-zero simultaneously. If you want one of them to be 1 you have to add x1+x2+x3=1.

    x1=x2=1 violates the SOS constraint, so that should not happen. Could you attach the model.lp here and show us the solution vector you get in matlab?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  回复:Re: error in cplex.addSOSs (type, ind, wt)

    Posted Fri October 11, 2013 06:02 PM

    Originally posted by: Liebe


    Thank you so much.

    My program is used to solve mixed-integer quadratic problem. It also has other restrictions, SOS1 is just one of them, and there are a lot of SOS1. The most important thing is my program input values ​​are randomly selected. I now run my program a few times, the case of two '1' occurs no more. When I get the wrong result, I'll attach the model.lp and the solution.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  回复:Re: error in cplex.addSOSs (type, ind, wt)

    Posted Sun October 13, 2013 07:05 PM

    Originally posted by: Liebe


    Hi Daniel,

    I have a question.

    Can I the weights of SOS1 selected randomly? Will different weights (because random select) affect the optimal results?

    Thank you!


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  回复:Re: error in cplex.addSOSs (type, ind, wt)

    Posted Mon October 14, 2013 05:02 AM

    The weights in the special ordered set specifications affect (only) the branching decisions that CPLEX takes and therefore (only) the path that CPLEX takes through the search tree.

    That means that the weights do not affect correctness. The objective function value reported as optimal solution will be the same. However, if there is more than one optimal solution to your problem (several different x vectors with same objective function value) then different weights may result in different optimal x vectors being reported.

    So different weights will not affect the optimal objective function value reported but may affect the optimal x vector returned (but all results will still be correct).


    #CPLEXOptimizers
    #DecisionOptimization