8.2.2. MdoCons¶
-
class mindopt::MdoCons¶
Constraint object.
This object implements the data structure to hold an optimization constraint. An empty constraint object by calling
MdoModel::addCons()
. Once created, users may modify its left-hand-side value or right-hand-side value by callingMdoCons::setRealAttr()
with a proper real-valued model attribute.Note
Do not use constructor (
MdoVar::MdoCons()
) to create an empty constraint object.Examples
/* Create an empty model. */ MdoModel model; MdoI32 itmp = 0; MdoReal dtmp = 0.0; std::string ctmp; /* Add empty constraints. */ std::vector<std::reference_wrapper<MdoCons> > cons; cons.push_back(model.addCons(1.0, 1.0, "c0")); cons.push_back(model.addCons(1.0, MDO_INFINITY, "c1")); /* Input columns. */ std::vector<MdoCol> col(4); col[0].addTerm(cons[0], 1.0); col[0].addTerm(cons[1], 1.0); col[1].addTerm(cons[0], 1.0); col[2].addTerm(cons[0], 2.0); col[2].addTerm(cons[1], -1.0); col[3].addTerm(cons[0], 3.0); col[3].addTerm(cons[1], 6.0); /* Check constraint object */ MdoCons c0 = model.getCons(0); itmp = cons[0].get().sameAs(c0); std::string c0_name = c0.getStrAttr("RowName"); MdoCons c0_2 = model.getCons(c0_name); itmp = cons[0].get().sameAs(c0_2); itmp = c0.getIndex(); /* Set/get attribute */ cons[1].setIntAttr("RowBasis", 1); itmp = cons[1].get().getIntAttr("RowBasis"); cons[1].get().setRealAttr("LHS", -5.0); dtmp = cons[1].get().getRealAttr("LHS"); cons[1].get().setStrAttr("RowName", row_name); ctmp = cons[1].get().getStrAttr("RowName");
Constructor / destructor.
-
MdoCons(void)¶
Default constructor.
-
MdoCons(MdoMdlPtr model, MdoI32 index)¶
Constructor with argument.
- Parameters
model – Pointer to the optimization model.
index – Constraint index.
-
virtual ~MdoCons(void)¶
Destructor.
Basic operators.
-
MdoCons &operator=(const MdoCons &rhs)¶
Assignment operator.
- Parameters
rhs – Object to copy.
- Return
Updated object.
Functions to access the internal data.
-
MdoI32 getIndex(void) const¶
This function returns the current index of the constraint in the optimization model.
- Return
The current index of the constraint in the optimization model.
-
MdoBool sameAs(const MdoCons &rhs) const¶
This function checks whether two constraint objects refer to the same constraint.
- Parameters
rhs – Another constraint object.
- Return
A boolean flag indicates if two constraint objects refer to the same constraint.
-
void setStrAttr(std::string att, std::string val)¶
This function changes the value of a string-valued row attribute.
- Parameters
att – A string-valued row attribute to access.
val – A new value for the string-valued row attribute.
-
std::string getStrAttr(std::string att) const¶
This function returns the value of a string-valued row attribute.
- Parameters
att – A string-valued row attribute to access.
- Return
The value of a string-valued row attribute.
-
void setIntAttr(std::string att, MdoI32 val)¶
This function changes the value of an integer-valued row attribute.
- Parameters
att – An integer-valued row attribute to access.
val – A new value.
-
MdoI32 getIntAttr(std::string att) const¶
This function returns the value of an integer-valued row attribute.
- Parameters
att – An integer-valued row attribute to access.
- Return
The value of an integer-valued row attribute.
-
MdoCons(void)¶