7.2.7. MdoVar

class mindopt::MdoVar

Object to define an optimization variable.

This object implements the data structure to hold an optimization variable. An empty variable object can be created by calling MdoModel::addVar(). Once created, users may modify the its lower bound, upper bound, or objective coefficient by calling MdoVar::setRealAttr() with a proper real-valued model attribute.

Note

Do not use constructor (MdoVar::MdoVar()) to create an empty variable object.

Examples

/* Create an empty model. */
MdoModel model;

MdoI32 itmp = 0;
MdoReal dtmp = 0.0;
std::string ctmp;

/* Add variables. */
std::vector<std::reference_wrapper<MdoVar> > x;
x.push_back(model.addVar(0.0, 10.0,         1.0, col[0], "x0", MDO_NO));
x.push_back(model.addVar(0.0, MDO_INFINITY, 1.0, col[1], "x1", MDO_NO));
x.push_back(model.addVar(0.0, MDO_INFINITY, 1.0, col[2], "x2", MDO_NO));
x.push_back(model.addVar(0.0, MDO_INFINITY, 1.0, col[3], "x3", MDO_NO));

/* Check variable object */
MdoVar x0 = model.getVar(0);
itmp = x[0].get().sameAs(x0);
std::string x0_name = x0.getStrAttr("ColName");
MdoVar x0_copy = model.getVar(x0_name);
itmp = x[0].get().sameAs(x0_copy);
itmp = x0.getIndex();

/* Set/get attribute */
x[1].get().setIntAttr("IsInteger", 0);
itmp = x[1].get().getIntAttr("IsInteger");
x[1].get().setStrAttr("ColName", col_name);
ctmp = x[1].get().getStrAttr("ColName");
x[2].get().setRealAttr("Obj", +100);
dtmp = x[2].get().getRealAttr("Obj");

Constructor / destructor.

MdoVar(void)

Default constructor.

MdoVar(MdoMdlPtr model, MdoI32 index)

Constructor with argument.

Parameters
  • model – Pointer to the optimization model.

  • index – Variable index.

virtual ~MdoVar(void)

Destructor.

MdoVar(const MdoVar &rhs)

Copy constructor.

Parameters

rhs – Object to copy.

Basic operators.

MdoVar &operator=(const MdoVar &rhs)

Assignment operator.

Parameters

rhs – Object to copy.

Return

Updated object.

Functions to access the internal data.

MdoI32 getIndex(void) const

This function retrieves the current index of the variable in the optimization model.

Return

The current index of the variable in the optimization model.

MdoBool sameAs(const MdoVar &rhs) const

This function checks whether two variable objects refer to the same variable.

Parameters

rhs – Another variable object.

Return

A boolean flag indicates if two variable objects refer to the same variable.

void setStrAttr(std::string att, std::string val)

This function changes the value of a string-valued column attribute.

Parameters
  • att – A string-valued column attribute to access.

  • val – A new value for the string-valued column attribute.

std::string getStrAttr(std::string att) const

This function retrieves the value of a string-valued column attribute.

Parameters

att – A string-valued column attribute to access.

Return

The value of a string-valued column attribute.

void setIntAttr(std::string att, MdoI32 val)

This function changes the value of an integer-valued column attribute.

Parameters
  • att – An integer-valued column attribute to access.

  • val – A new value.

MdoI32 getIntAttr(std::string att) const

This function retrieves the value of an integer-valued column attribute.

Parameters

att – An integer-valued column attribute to access.

Return

The value of an integer-valued column attribute.

void setRealAttr(std::string att, MdoReal val)

This function changes the value of a real-valued column attribute.

Parameters
  • att – A real-valued column attribute to access.

  • val – A new value.

MdoReal getRealAttr(std::string att) const

This function retrieves the value of a real-valued column attribute.

Parameters

att – A real-valued column attribute to access.

Return

The value of a real-valued column attribute.