1

So just one quick question - I'm trying to implement a SOS type 1 probelm in CPLEX.

When I look at the documentation I see the add function

add(self, type='1', SOS=SparsePair(ind = [0], val = [0.0]), name='')
Adds a special ordered set constraint to the problem.

found here https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.7.0/ilog.odms.cplex.help/refpythoncplex/html/cplex._internal._subinterfaces.SOSInterface-class.html#add

When I look at the documentation I understand everything except val. My idea of this SOS1 problem is really you are adding the constraint (assuming that all the variables are binary {0,1} that the sum of all the variables at less then or equal to 1. That is to say that either all variables are 0 or there is at most one 1. So since its a sum the val weights are all 1? How would it be anything else? I mention this because I have found a peice of source code that makes these weights 25,18 as seen below

def setproblemdata(p):
    p.objective.set_sense(p.objective.sense.maximize)

    p.linear_constraints.add(rhs=[20.0, 30.0, 0.0], senses="LLE")

    obj = [1.0, 2.0, 3.0, 1.0]
    lb = [0.0, 0.0, 0.0, 2.0]
    ub = [40.0, cplex.infinity, cplex.infinity, 3.0]
    cols = [[[0, 1], [-1.0, 1.0]],
            [[0, 1, 2], [1.0, -3.0, 1.0]],
            [[0, 1], [1.0, 1.0]],
            [[0, 2], [10.0, -3.5]]]

    p.variables.add(obj=obj, lb=lb, ub=ub, columns=cols,
                    types="CIII", names=["0", "1", "2", "3"])
    p.SOS.add(type="1", SOS=[["2", "3"], [25.0, 18.0]])

    p.order.set([(1, 8, p.order.branch_direction.up),
                 ("3", 7, p.order.branch_direction.down)])
    p.order.write("mipex3.ord")

    return
Eigenvalue
  • 1,093
  • 1
  • 14
  • 35

1 Answers1

0

Let me quote CPLEX documentation

Members of an SOS should be given unique weights that in turn define the order of the variables in the set. (These unique weights are also called reference row values.) Each of those ways of declaring SOS members allows you to specify weights.

halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15