My Project
Classes | Public Types | Public Member Functions | List of all members
Milp_Model Class Reference

#include <MILP_Model.h>

Public Types

enum  VarType { REAL, INTEGER, BOOLEAN }
 
enum  RowType { LEQ, GEQ, EQ }
 Types of variables.
 
enum  Status {
  OPTIMAL, NONOPTIMAL, UNFEASIBLE, UNBOUNDED,
  UNKNOWN, ERROR
}
 Type of constraints.
 
using Term = pair< double, int >
 Type of solution.
 
using vecTerms = vector< Term >
 Type to represent a term (coefficient, var index)
 
using vecVars = vector< int >
 Vector of terms.
 

Public Member Functions

 Milp_Model (const string &solver="")
 Vector of variables. More...
 
const string & getError () const
 
void setError (const string &err="")
 Defines the error message of the object (no error by default). More...
 
void setMinimize ()
 Defines a model to minimize the cost function.
 
void setMaximize ()
 Defines a model to maximize the cost function.
 
void setEpsilon (double eps)
 Defines the min epsilon value to distinguish from zero. More...
 
int numVariables () const
 
int numConstraints () const
 
int newRealVar (string name="", double lower_bound=0.0, double upper_bound=-1.0)
 Creates a new real variable. More...
 
int newIntegerVar (string name="", double lower_bound=0, double upper_bound=-1)
 Creates a new integer variable. More...
 
int newBooleanVar (string name="")
 Creates a new Boolean variable. More...
 
Status getStatus () const
 
double getObj () const
 
double operator[] (int i) const
 Returns the value of a variable. More...
 
double operator[] (const string &name) const
 Returns the value of a variable. More...
 
bool isTrue (int i) const
 Checks whether the value of a boolean variable is true. More...
 
bool isFalse (int i) const
 Checks whether the value of a boolean variable is false. More...
 
int newRow (char type='<', double rhs=0.0, const string &name="")
 Creates a new row in the constraint matrix. More...
 
int newRow (const vecTerms &terms, char type='<', double rhs=0.0, const string &name="")
 Creates a new row in the constraint matrix from a vector of terms. More...
 
void newTerm (int rowIndex, double coeff, int varIndex)
 Adds a new term to a constraint. More...
 
void setRHS (int rowIndex, double rhs)
 Defines the RHS of a constraint. More...
 
int atMostOne (const vecVars &vars, const string &name="")
 Creates an at-most-one constraint (v1+...+vn <= 1). More...
 
int atLeastOne (const vecVars &vars, const string &name="")
 Creates an at-least-one constraint (v1+...+vn >= 1). More...
 
int exactlyOne (const vecVars &vars, const string &name="")
 Creates an exactly-one constraint (v1+...+vn = 1). More...
 
int equalSum (const vecVars &x, const vecVars &y, const string &name="")
 Creates a constraint indicating that the sum of a set of variables must be equal to the sum of another set, i.e., x1 + ... + xn = y1 + ... + ym. More...
 
int allEqual (const vecVars &v)
 Creates a set of constraints that enforces a set of variables to have the same value. More...
 
int implies (int x, const vecVars &y)
 Creates a constraint representing the Boolean implication x => y1 + ... + ym. More...
 
int implies (const vecVars &x, int y)
 Creates a set of constraints representing the Boolean implication x1 + ... + xn => y. More...
 
void newCostTerm (double coeff, int varIndex)
 Adds a new term to the cost function. More...
 
bool writeLP (const string &filename)
 Write the LP model into a file in CPLEX LP format. More...
 
bool solve (int timelimit=-1)
 Calls the MILP solver. More...
 
bool init (const string &solver="")
 Initializes the MILP model. More...
 
void writeOutDelays (const string &file_name)
 Writes a output file to save output pin timing to retrieve critical path. More...
 
string getVarName (int id)
 Get variables names. More...
 

Detailed Description

Author
Jordi Cortadella
Date
16/04/18

Constructor & Destructor Documentation

◆ Milp_Model()

Milp_Model::Milp_Model ( const string &  solver = "")
inline

Vector of variables.

Default constructor.

Member Function Documentation

◆ allEqual()

int Milp_Model::allEqual ( const vecVars v)
inline

Creates a set of constraints that enforces a set of variables to have the same value.

Parameters
vThe vector of variables.
Returns
The index of the first row of the constraints.
Note
The vector is assumed to contain two variables at least.

◆ atLeastOne()

int Milp_Model::atLeastOne ( const vecVars vars,
const string &  name = "" 
)
inline

Creates an at-least-one constraint (v1+...+vn >= 1).

Parameters
varsThe variables of the constraint.
nameThe name of the constraint.
Returns
The index of the row.

◆ atMostOne()

int Milp_Model::atMostOne ( const vecVars vars,
const string &  name = "" 
)
inline

Creates an at-most-one constraint (v1+...+vn <= 1).

Parameters
varsThe variables of the constraint.
nameThe name of the constraint.
Returns
The index of the row.

◆ equalSum()

int Milp_Model::equalSum ( const vecVars x,
const vecVars y,
const string &  name = "" 
)
inline

Creates a constraint indicating that the sum of a set of variables must be equal to the sum of another set, i.e., x1 + ... + xn = y1 + ... + ym.

Parameters
xThe first set of variables.
yThe second set of variables.
nameThe name of the constraint.
Returns
The index of the row.

◆ exactlyOne()

int Milp_Model::exactlyOne ( const vecVars vars,
const string &  name = "" 
)
inline

Creates an exactly-one constraint (v1+...+vn = 1).

Parameters
varsThe variables of the constraint.
nameThe name of the constraint.
Returns
The index of the row.

◆ getError()

const string& Milp_Model::getError ( ) const
inline
Returns
The error message associated to the object.

◆ getObj()

double Milp_Model::getObj ( ) const
inline
Returns
The value of the objective function.

◆ getStatus()

Status Milp_Model::getStatus ( ) const
inline
Returns
The status of the solution.

◆ getVarName()

string Milp_Model::getVarName ( int  id)
inline

Get variables names.

Parameters
idvariable id

◆ implies() [1/2]

int Milp_Model::implies ( int  x,
const vecVars y 
)
inline

Creates a constraint representing the Boolean implication x => y1 + ... + ym.

Parameters
xThe variable in the antecedent.
yThe set of variables in the consequent.
Returns
The index of the row.

◆ implies() [2/2]

int Milp_Model::implies ( const vecVars x,
int  y 
)
inline

Creates a set of constraints representing the Boolean implication x1 + ... + xn => y.

Parameters
xThe set of variables in the antecedent.
yThe variable in the consequent.
Returns
The index of the first row.

◆ init()

bool Milp_Model::init ( const string &  solver = "")
inline

Initializes the MILP model.

Parameters
solverName of the MILP solver.
Returns
True if the initialization was correct, and false otherwise.

◆ isFalse()

bool Milp_Model::isFalse ( int  i) const
inline

Checks whether the value of a boolean variable is false.

Parameters
iIndex of the variable.
Returns
True if the variable is not asserted, and false otherwise.

◆ isTrue()

bool Milp_Model::isTrue ( int  i) const
inline

Checks whether the value of a boolean variable is true.

Parameters
iIndex of the variable.
Returns
True if the variable is asserted, and false otherwise.

◆ newBooleanVar()

int Milp_Model::newBooleanVar ( string  name = "")
inline

Creates a new Boolean variable.

Parameters
nameName of the variable.
Returns
The index of the variable.

◆ newCostTerm()

void Milp_Model::newCostTerm ( double  coeff,
int  varIndex 
)
inline

Adds a new term to the cost function.

Parameters
coeffCoefficient of the term.
varIndexIndex of the variable.

◆ newIntegerVar()

int Milp_Model::newIntegerVar ( string  name = "",
double  lower_bound = 0,
double  upper_bound = -1 
)
inline

Creates a new integer variable.

Parameters
nameName of the variable.
lower_boundLower bound.
upper_boundUpper bound (unbounded if upper_bound < lower_bound).
Returns
The index of the variable.

◆ newRealVar()

int Milp_Model::newRealVar ( string  name = "",
double  lower_bound = 0.0,
double  upper_bound = -1.0 
)
inline

Creates a new real variable.

Parameters
nameName of the variable.
lower_boundLower bound
upper_boundUpper bound (unbounded if upper_bound < lower_bound).
Returns
The index of the variable.

◆ newRow() [1/2]

int Milp_Model::newRow ( char  type = '<',
double  rhs = 0.0,
const string &  name = "" 
)
inline

Creates a new row in the constraint matrix.

Parameters
typeType of row ('<', '>', '=').
rhsRHS of the constraint.
nameName of the row.
Returns
The index of the row.

◆ newRow() [2/2]

int Milp_Model::newRow ( const vecTerms terms,
char  type = '<',
double  rhs = 0.0,
const string &  name = "" 
)
inline

Creates a new row in the constraint matrix from a vector of terms.

Parameters
termsVector of terms (pairs of {coeff, var index}).
typeType of row ('<', '>', '=').
rhsRHS of the constraint.
nameName of the constraint.
Returns
The index of the row.

◆ newTerm()

void Milp_Model::newTerm ( int  rowIndex,
double  coeff,
int  varIndex 
)
inline

Adds a new term to a constraint.

Parameters
rowIndexIndex of the constraint.
coeffCoefficient of the term.
varIndexIndex of the variable.

◆ numVariables()

int Milp_Model::numVariables ( ) const
inline
Returns
The number of variables of the model.

◆ operator[]() [1/2]

double Milp_Model::operator[] ( int  i) const
inline

Returns the value of a variable.

Parameters
iIndex of the variable.
Returns
The value of variable i.

◆ operator[]() [2/2]

double Milp_Model::operator[] ( const string &  name) const
inline

Returns the value of a variable.

Parameters
nameName of the variable.
Returns
The value of variable.

◆ setEpsilon()

void Milp_Model::setEpsilon ( double  eps)
inline

Defines the min epsilon value to distinguish from zero.

Parameters
epsEpsilon value.

◆ setError()

void Milp_Model::setError ( const string &  err = "")
inline

Defines the error message of the object (no error by default).

Parameters
errError message.

◆ setRHS()

void Milp_Model::setRHS ( int  rowIndex,
double  rhs 
)
inline

Defines the RHS of a constraint.

Parameters
rowIndexIndex of the constraint.
rhsRHS value.

◆ solve()

bool Milp_Model::solve ( int  timelimit = -1)
inline

Calls the MILP solver.

Parameters
timelimitTime limit in seconds. No limit if <= 0.
Returns
True if successful, and false otherwise.

◆ writeLP()

bool Milp_Model::writeLP ( const string &  filename)
inline

Write the LP model into a file in CPLEX LP format.

Parameters
filenameName of the file.
Returns
True if successful, and false otherwise.

◆ writeOutDelays()

void Milp_Model::writeOutDelays ( const string &  file_name)
inline

Writes a output file to save output pin timing to retrieve critical path.

Parameters
file_namename of the file where to save the output

The documentation for this class was generated from the following file: