XPRBsos
- java.lang.Object
-
- com.dashoptimization.XPRBsos
-
public class XPRBsos extends java.lang.Object
This class represents a Special Ordered Set (SOS) definition in BCL. All members in SOS must belong to the same problem as the SOS itself.
-
-
Method Summary
Modifier and Type Method and Description void
add(XPRBexpr l)
Add a linear expression to a SOS.void
addElement(double val, XPRBvar var)
void
addElement(XPRBvar var, double val)
Add an element to a SOS.void
assign(XPRBexpr l)
Assign a linear expression to a SOS.void
delElement(XPRBvar var)
Delete an element from a SOS.java.lang.String
getName()
Get the name of a SOS.int
getType()
Get the type of a SOS.boolean
isValid()
Test whether a SOS is correctly defined.void
print()
Print out a Special Ordered Set.void
setDir(int type)
void
setDir(int type, double val)
Set a branching directive for a SOS.java.lang.String
toString()
-
-
-
Method Detail
-
isValid
public boolean isValid()
Test whether a SOS is correctly defined.XPRBsos set1; if(set1.isValid() == false) System.out.println("Error in SOS definition.");
-
assign
public void assign(XPRBexpr l) throws java.lang.ArithmeticException
Assign a linear expression to a SOS.XPRBprob expl2; XPRBvar[] x; int i; XPRBexpr l; XPRBsos set3; expl2 = new XPRBprob("example2"); for(i=0;i<5;i++) x[i] = expl2.newVar("x"); l = new XPRBexpr(); for(i=1;i<4;i++) l.add(x[i].mul(i)); set3.assign(l);
- Parameters:
-
l
- linear expression - Throws:
-
java.lang.ArithmeticException
-
getName
public java.lang.String getName()
Get the name of a SOS. If the user has not defined a name the default name generated by BCL is returned.XPRBprob expl2; XPRBsos set1; expl2 = new XPRBprob("example2"); set1 = expl2.newSos("sos1", XPRB.S1); System.out.println("SOS name:" + set1.getName());
- Returns:
-
Name of the SOS if method executed successfully,
null
otherwise
-
getType
public int getType()
Get the type of a SOS.XPRBprob expl2; XPRBsos set1; int stype; expl2 = new XPRBprob("example2"); set1 = expl2.newSos("sos1", XPRB.S1); stype = set1.getType();
- Returns:
-
Type of the SOS. Possible values:
XPRB.S1
Special Ordered Set of type 1XPRB.S2
Special Ordered Set of type 2-1
an error has occurred
-
setDir
public void setDir(int type, double val)
Set a branching directive for a SOS. This method sets any type of branching directive available in Xpress. This may be a priority for branching on a SOS (typeXPRB.PR
), the preferred branching direction (typesXPRB.UP, XPRB.DN
) or the estimated cost incurred when branching on a SOS (typesXPRB.PU, XPRB.PU
). Several directives of different types may be set for a single set. MethodXPRBvar.setDir(int, double)
may be used to set a branching directive for a variable.XPRBprob expl2; XPRBsos set1; expl2 = new XPRBprob("example2"); set1 = expl2.newSos("sos1", XPRB.S1); set1.setDir(XPRB.PR, 5); set1.setDir(XPRB.DN);
- Parameters:
-
type
- directive type. Possible values:XPRB.PR
priorityXPRB.UP
first branch upwardsXPRB.DN
first branch downwardsXPRB.PU
pseudocost on branching upwardsXPRB.PD
pseudocost on branching downwards
-
val
- the value of this argument depends on the type of directive to be defined. Possible values:XPRB.PR
: priority value, integer between 1 (highest) and 1000 (least priority, default value)XPRB.UP,XPRB.DN
: no input required, choose any dummy value (e.g. 0)XPRB.PU,XPRB.PD
: value of pseudocost for the corresponding branch
-
setDir
public void setDir(int type)
- See Also:
-
setDir(type, 0)
-
addElement
public void addElement(XPRBvar var, double val)
Add an element to a SOS. This method adds a variable and its weight coefficient to a Special Ordered Set. If the variable is already contained in the set, the indicated value is added to its weight. Note that weight coefficients must be different from 0.XPRBprob expl2; XPRBsos set1; XPRBvar x2; expl2 = new XPRBprob("example2"); x2 = expl2.newvar("abc1", XPRB.PL, 0, INFINITY); set1 = expl2.newSos("sos1", XPRB.S1); set1.addElement(x2, 9);
- Parameters:
-
var
- a variable of typeXPRBvar
-
val
- the corresponding weight or reference value
-
addElement
public void addElement(double val, XPRBvar var)
- See Also:
-
addElement(type, 0)
-
delElement
public void delElement(XPRBvar var)
Delete an element from a SOS.XPRBprob expl2; XPRBsos set1; XPRBvar x2; expl2 = new XPRBprob("example2"); x2 = expl2.newvar("abc1", XPRB.PL, 0, INFINITY); set1 = expl2.newSos("sos1", XPRB.S1); set1.addElement(x2, 9); set1.delElement(x2);
- Parameters:
-
var
- a variable of typeXPRBvar
-
add
public void add(XPRBexpr l) throws java.lang.ArithmeticException
Add a linear expression to a SOS. If a variable in the linear expression is already contained in the set, the indicated value is added to its weight. Constant terms in the linear expression are ignored.XPRBprob expl2; XPRBvar[] x; int i; XPRBexpr l; XPRBsos set3; expl2 = new XPRBprob("example2"); for(i=0;i<5;i++) x[i] = expl2.newVar("x"); l = new XPRBexpr(); for(i=1;i<4;i++) l.add(x[i].mul(i)); set3 = expl2.newSos("sos2", XPRB.S2); set3.add(l);
- Parameters:
-
l
- linear expression - Throws:
-
java.lang.ArithmeticException
-
print
public void print()
Print out a Special Ordered Set. This method is not available in the Student Edition.XPRBprob expl2; XPRBsos set1; expl2 = new XPRBprob("example2"); set1 = expl2.newSos("sos1", XPRB.S1); set1.print();
-
toString
public java.lang.String toString()
- Overrides:
-
toString
in classjava.lang.Object
- See Also:
-
getName()
-
-