Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
limbo::solvers::LinearModel< T, V > Class Template Reference

model to describe an optimization problem More...

#include <Solvers.h>

Inheritance diagram for limbo::solvers::LinearModel< T, V >:
LpParser::LpDataBase

Public Types

typedef T coefficient_value_type
 T coefficient.
 
typedef V variable_value_type
 V variable.
 
typedef LpParser::LpDataBase base_type
 base class
 
typedef Variable
< coefficient_value_type
variable_type
 variable type
 
typedef LinearTerm
< coefficient_value_type
term_type
 term type
 
typedef LinearExpression
< coefficient_value_type
expression_type
 expression type
 
typedef LinearConstraint
< coefficient_value_type
constraint_type
 constraint type
 
typedef VariableProperty
< variable_value_type
property_type
 variable property type
 

Public Member Functions

 LinearModel ()
 constructor
 
 LinearModel (LinearModel const &rhs)
 copy constructor More...
 
LinearModeloperator= (LinearModel const &rhs)
 assignment More...
 
 ~LinearModel ()
 destructor
 
std::vector< constraint_type >
const & 
constraints () const
 
std::vector< constraint_type > & constraints ()
 
bool addConstraint (constraint_type const &constr, std::string name="")
 add a constraint More...
 
bool emplaceConstraint (expression_type &expr, char sense, coefficient_value_type rhs, std::string name="")
 emplace a constraint More...
 
std::string const & constraintName (constraint_type const &constr) const
 
std::vector< std::string > const & constraintNames () const
 
std::vector< std::string > & constraintNames ()
 
expression_type const & objective () const
 
void setObjective (expression_type const &expr)
 set objective More...
 
void emplaceObjective (expression_type &expr)
 set objective by swaping with the expression More...
 
SolverProperty optimizeType () const
 
void setOptimizeType (SolverProperty optType)
 
std::vector< property_type >
const & 
variableProperties () const
 
std::vector< property_type > & variableProperties ()
 
unsigned int numVariables () const
 
variable_type variable (unsigned int id) const
 
std::string variableName (variable_type const &var) const
 
void setVariableName (variable_type const &var, std::string const &name)
 set variable name More...
 
variable_value_type variableLowerBound (variable_type const &var)
 
void setVariableLowerBound (variable_type const &var, variable_value_type lb)
 set variable lower bound More...
 
void updateVariableLowerBound (variable_type const &var, variable_value_type lb)
 update variable lower bound More...
 
variable_value_type variableUpperBound (variable_type const &var)
 
void setVariableUpperBound (variable_type const &var, variable_value_type ub)
 set variable upper bound More...
 
void updateVariableUpperBound (variable_type const &var, variable_value_type ub)
 update variable upper bound More...
 
SolverProperty variableNumericType (variable_type const &var)
 
void setVariableNumericType (variable_type const &var, SolverProperty type)
 set numeric type of variable More...
 
variable_type addVariable (variable_value_type lb, variable_value_type ub, SolverProperty nt, std::string name="")
 add one variable More...
 
std::vector
< variable_value_type > const & 
variableSolutions () const
 
std::vector
< variable_value_type > & 
variableSolutions ()
 
variable_value_type variableSolution (variable_type const &var) const
 
void setVariableSolution (variable_type const &var, variable_value_type v)
 
void reserveVariables (unsigned int n)
 reserve space for variables More...
 
void reserveConstraints (unsigned int n)
 reserve space for constraints More...
 
void resizeConstraints (unsigned int n)
 resize constraints More...
 
void scaleObjective (coefficient_value_type factor)
 scale objective More...
 
void scaleConstraint (unsigned int id, coefficient_value_type factor)
 scaling a constraint More...
 
coefficient_value_type evaluateExpression (expression_type const &expr, std::vector< variable_value_type > const &vVariableSol) const
 evaluate expression given solutions of variables More...
 
coefficient_value_type evaluateObjective (std::vector< variable_value_type > const &vVariableSol) const
 evaluate objective More...
 
coefficient_value_type evaluateObjective () const
 evaluate objective More...
 
coefficient_value_type evaluateConstraint (constraint_type const &constr, std::vector< variable_value_type > const &vVariableSol) const
 evaluate slackness of a constraint given solutions of variables More...
 
coefficient_value_type evaluateConstraint (constraint_type const &constr) const
 evaluate slackness of a constraint given solutions of variables More...
 
void evaluateConstraint () const
 evaluate slackness of all constraints given solutions of variables and print to screen
 
void read (std::string const &filename)
 read lp format More...
 
bool print (std::string const &filename) const
 print problem in lp format to file More...
 
std::ostream & print (std::ostream &os=std::cout) const
 print problem in lp format More...
 
std::ostream & print (std::ostream &os, term_type const &term) const
 print expression More...
 
std::ostream & print (std::ostream &os, expression_type const &expr) const
 print expression More...
 
std::ostream & print (std::ostream &os, constraint_type const &constr) const
 print constraint More...
 
bool printSolution (std::string const &filename) const
 print solutions to file
 
std::ostream & printSolution (std::ostream &os=std::cout) const
 print solutions More...
 
required callback from @ref LpParser::LpDataBase

add variable that l <= vname <= r.

Parameters
vnamevariable name
llower bound
rupper bound
void add_variable (std::string const &vname, double l=limbo::lowest< double >(), double r=std::numeric_limits< double >::max())
 
void add_constraint (std::string const &cname, LpParser::TermArray const &terms, char compare, double constant)
 add constraint that terms compare constant. More...
 
void add_objective (bool minimize, LpParser::TermArray const &terms)
 add object terms More...
 
void set_integer (std::string const &vname, bool binary)
 set integer variables More...
 
- Public Member Functions inherited from LpParser::LpDataBase
virtual void add_variable (string const &vname, double l=limbo::lowest< double >(), double r=std::numeric_limits< double >::max())=0
 add variable that l <= vname <= r. More...
 
virtual void add_constraint (string const &cname, TermArray const &terms, char compare, double constant)=0
 add constraint that terms compare constant. More...
 
virtual void set_integer (string const &vname, bool binary)=0
 set integer variables More...
 

Protected Member Functions

void copy (LinearModel const &rhs)
 copy object
 

Protected Attributes

std::vector< constraint_typem_vConstraint
 constraints
 
expression_type m_objective
 objective
 
std::vector< property_typem_vVariableProperty
 variable properties
 
SolverProperty m_optType
 optimization objective
 
std::vector< std::string > m_vConstraintName
 constraint names
 
std::vector< variable_value_typem_vVariableSol
 variable solutions, it can be either initial solution or final solution
 
std::map< std::string,
variable_type
m_mName2Variable
 mapping from variable name to variable, only used when reading from files
 

Detailed Description

template<typename T, typename V>
class limbo::solvers::LinearModel< T, V >

model to describe an optimization problem

Template Parameters
Tcoefficient type
Vvariable type

Definition at line 80 of file Solvers.h.

Constructor & Destructor Documentation

template<typename T , typename V >
limbo::solvers::LinearModel< T, V >::LinearModel ( LinearModel< T, V > const &  rhs)
inline

copy constructor

Parameters
rhsright hand side

Definition at line 1188 of file Solvers.h.

Member Function Documentation

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::add_constraint ( std::string const &  cname,
LpParser::TermArray const &  terms,
char  compare,
double  constant 
)
inline

add constraint that terms compare constant.

Parameters
cnameconstraint name
termsarray of terms in left hand side
compareoperator '<', '>', '='
constantconstant in the right hand side

Definition at line 1507 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::add_objective ( bool  minimize,
LpParser::TermArray const &  terms 
)
inlinevirtual

add object terms

Parameters
minimizetrue denotes minimizing object, false denotes maximizing object
termsarray of terms

Implements LpParser::LpDataBase.

Definition at line 1521 of file Solvers.h.

template<typename T , typename V >
bool limbo::solvers::LinearModel< T, V >::addConstraint ( constraint_type const &  constr,
std::string  name = "" 
)
inline

add a constraint

Parameters
constrconstraint
nameconstraint name
Returns
true if added

Definition at line 1217 of file Solvers.h.

template<typename T , typename V >
variable_type limbo::solvers::LinearModel< T, V >::addVariable ( variable_value_type  lb,
variable_value_type  ub,
SolverProperty  nt,
std::string  name = "" 
)
inline

add one variable

Parameters
lblower bound
ubupper bound
ntnumeric type
namevariable name
Returns
variable

Definition at line 1365 of file Solvers.h.

template<typename T , typename V >
std::string const& limbo::solvers::LinearModel< T, V >::constraintName ( constraint_type const &  constr) const
inline
Parameters
constrconstraint
Returns
constraint name

Definition at line 1286 of file Solvers.h.

template<typename T , typename V >
std::vector<std::string> const& limbo::solvers::LinearModel< T, V >::constraintNames ( ) const
inline
Returns
array of constraint names

Definition at line 1288 of file Solvers.h.

template<typename T , typename V >
std::vector<std::string>& limbo::solvers::LinearModel< T, V >::constraintNames ( )
inline
Returns
array of constraint names

Definition at line 1290 of file Solvers.h.

template<typename T , typename V >
std::vector<constraint_type> const& limbo::solvers::LinearModel< T, V >::constraints ( ) const
inline
Returns
array of constraints

Definition at line 1210 of file Solvers.h.

template<typename T , typename V >
std::vector<constraint_type>& limbo::solvers::LinearModel< T, V >::constraints ( )
inline
Returns
array of constraints

Definition at line 1212 of file Solvers.h.

template<typename T , typename V >
bool limbo::solvers::LinearModel< T, V >::emplaceConstraint ( expression_type expr,
char  sense,
coefficient_value_type  rhs,
std::string  name = "" 
)
inline

emplace a constraint

Parameters
exprexpression
sensesense
rhsright hand side
nameconstraint name
Returns
true if added

Definition at line 1228 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::emplaceObjective ( expression_type expr)
inline

set objective by swaping with the expression

Parameters
exprobjective

Definition at line 1302 of file Solvers.h.

template<typename T , typename V >
coefficient_value_type limbo::solvers::LinearModel< T, V >::evaluateConstraint ( constraint_type const &  constr,
std::vector< variable_value_type > const &  vVariableSol 
) const
inline

evaluate slackness of a constraint given solutions of variables

Parameters
constrconstraint
vVariableSolvariable solutions
Returns
slackness is computed as right hand side minum left hand side assuming sense is '<' or '='

Definition at line 1439 of file Solvers.h.

template<typename T , typename V >
coefficient_value_type limbo::solvers::LinearModel< T, V >::evaluateConstraint ( constraint_type const &  constr) const
inline

evaluate slackness of a constraint given solutions of variables

Parameters
constrconstraint
Returns
slackness is computed as right hand side minum left hand side assuming sense is '<' or '='

Definition at line 1450 of file Solvers.h.

template<typename T , typename V >
coefficient_value_type limbo::solvers::LinearModel< T, V >::evaluateExpression ( expression_type const &  expr,
std::vector< variable_value_type > const &  vVariableSol 
) const
inline

evaluate expression given solutions of variables

Parameters
exprexpression
vVariableSolvariable solutions
Returns
result of the expression after applying the solutions

Definition at line 1414 of file Solvers.h.

template<typename T , typename V >
coefficient_value_type limbo::solvers::LinearModel< T, V >::evaluateObjective ( std::vector< variable_value_type > const &  vVariableSol) const
inline

evaluate objective

Parameters
vVariableSolvariable solutions
Returns
objective after applying the solution

Definition at line 1425 of file Solvers.h.

template<typename T , typename V >
coefficient_value_type limbo::solvers::LinearModel< T, V >::evaluateObjective ( ) const
inline

evaluate objective

Returns
objective after applying the solution

Definition at line 1431 of file Solvers.h.

template<typename T , typename V >
unsigned int limbo::solvers::LinearModel< T, V >::numVariables ( ) const
inline
Returns
number of variables

Definition at line 1316 of file Solvers.h.

template<typename T , typename V >
expression_type const& limbo::solvers::LinearModel< T, V >::objective ( ) const
inline
Returns
objective

Definition at line 1292 of file Solvers.h.

template<typename T , typename V >
LinearModel& limbo::solvers::LinearModel< T, V >::operator= ( LinearModel< T, V > const &  rhs)
inline

assignment

Parameters
rhsright hand side

Definition at line 1195 of file Solvers.h.

template<typename T , typename V >
SolverProperty limbo::solvers::LinearModel< T, V >::optimizeType ( ) const
inline
Returns
optimization objective, whether maximize or minimize the objective

Definition at line 1308 of file Solvers.h.

template<typename T , typename V >
bool limbo::solvers::LinearModel< T, V >::print ( std::string const &  filename) const
inline

print problem in lp format to file

Parameters
filenameoutput file name
Returns
true if succeed; otherwise false

Definition at line 1552 of file Solvers.h.

template<typename T , typename V >
std::ostream& limbo::solvers::LinearModel< T, V >::print ( std::ostream &  os = std::cout) const
inline

print problem in lp format

Parameters
osoutput stream
Returns
output stream

Definition at line 1564 of file Solvers.h.

template<typename T , typename V >
std::ostream& limbo::solvers::LinearModel< T, V >::print ( std::ostream &  os,
term_type const &  term 
) const
inline

print expression

Parameters
osoutput stream
termterm
Returns
output stream

Definition at line 1629 of file Solvers.h.

template<typename T , typename V >
std::ostream& limbo::solvers::LinearModel< T, V >::print ( std::ostream &  os,
expression_type const &  expr 
) const
inline

print expression

Parameters
osoutput stream
exprexpression
Returns
output stream

Definition at line 1638 of file Solvers.h.

template<typename T , typename V >
std::ostream& limbo::solvers::LinearModel< T, V >::print ( std::ostream &  os,
constraint_type const &  constr 
) const
inline

print constraint

Parameters
osoutput stream
constrconstraint
Returns
output stream

Definition at line 1655 of file Solvers.h.

template<typename T , typename V >
std::ostream& limbo::solvers::LinearModel< T, V >::printSolution ( std::ostream &  os = std::cout) const
inline

print solutions

Parameters
osoutput stream
Returns
output stream

Definition at line 1677 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::read ( std::string const &  filename)
inline

read lp format

Parameters
filenameinput file in lp format initializing graph

Definition at line 1464 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::reserveConstraints ( unsigned int  n)
inline

reserve space for constraints

Parameters
nnumber of constraints to reserve

Definition at line 1389 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::reserveVariables ( unsigned int  n)
inline

reserve space for variables

Parameters
nnumber of variables to reserve

Definition at line 1382 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::resizeConstraints ( unsigned int  n)
inline

resize constraints

Parameters
nnumber of constraints

Definition at line 1396 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::scaleConstraint ( unsigned int  id,
coefficient_value_type  factor 
)
inline

scaling a constraint

Parameters
idconstraint index
factorscaling factor

Definition at line 1409 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::scaleObjective ( coefficient_value_type  factor)
inline

scale objective

Parameters
factorscaling factor

Definition at line 1405 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::set_integer ( std::string const &  vname,
bool  binary 
)
inline

set integer variables

Parameters
vnameinteger variables
binarydenotes whether they are binary variables

Definition at line 1537 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::setObjective ( expression_type const &  expr)
inline

set objective

Parameters
exprobjective

Definition at line 1295 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::setOptimizeType ( SolverProperty  optType)
inline
Parameters
optTypeoptimization objective

Definition at line 1310 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::setVariableLowerBound ( variable_type const &  var,
variable_value_type  lb 
)
inline

set variable lower bound

Parameters
varvariable
lblower bound

Definition at line 1338 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::setVariableName ( variable_type const &  var,
std::string const &  name 
)
inline

set variable name

Parameters
varvariable
namename

Definition at line 1332 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::setVariableNumericType ( variable_type const &  var,
SolverProperty  type 
)
inline

set numeric type of variable

Parameters
varvariable
typenumeric type

Definition at line 1358 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::setVariableSolution ( variable_type const &  var,
variable_value_type  v 
)
inline
Parameters
varvariable
vinitial solution

Definition at line 1379 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::setVariableUpperBound ( variable_type const &  var,
variable_value_type  ub 
)
inline

set variable upper bound

Parameters
varvariable
ubupper bound

Definition at line 1348 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::updateVariableLowerBound ( variable_type const &  var,
variable_value_type  lb 
)
inline

update variable lower bound

Parameters
varvariable
lblower bound

Definition at line 1342 of file Solvers.h.

template<typename T , typename V >
void limbo::solvers::LinearModel< T, V >::updateVariableUpperBound ( variable_type const &  var,
variable_value_type  ub 
)
inline

update variable upper bound

Parameters
varvariable
ubupper bound

Definition at line 1352 of file Solvers.h.

template<typename T , typename V >
variable_type limbo::solvers::LinearModel< T, V >::variable ( unsigned int  id) const
inline
Returns
variable

Definition at line 1318 of file Solvers.h.

template<typename T , typename V >
variable_value_type limbo::solvers::LinearModel< T, V >::variableLowerBound ( variable_type const &  var)
inline
Returns
lower bound of variables

Definition at line 1334 of file Solvers.h.

template<typename T , typename V >
std::string limbo::solvers::LinearModel< T, V >::variableName ( variable_type const &  var) const
inline
Returns
name of variables

Definition at line 1320 of file Solvers.h.

template<typename T , typename V >
SolverProperty limbo::solvers::LinearModel< T, V >::variableNumericType ( variable_type const &  var)
inline
Returns
numeric type of variable

Definition at line 1354 of file Solvers.h.

template<typename T , typename V >
std::vector<property_type> const& limbo::solvers::LinearModel< T, V >::variableProperties ( ) const
inline
Returns
array of variable properties

Definition at line 1312 of file Solvers.h.

template<typename T , typename V >
std::vector<property_type>& limbo::solvers::LinearModel< T, V >::variableProperties ( )
inline
Returns
array of variable properties

Definition at line 1314 of file Solvers.h.

template<typename T , typename V >
variable_value_type limbo::solvers::LinearModel< T, V >::variableSolution ( variable_type const &  var) const
inline
Returns
solution of a variable

Definition at line 1376 of file Solvers.h.

template<typename T , typename V >
std::vector<variable_value_type> const& limbo::solvers::LinearModel< T, V >::variableSolutions ( ) const
inline
Returns
array of solution

Definition at line 1372 of file Solvers.h.

template<typename T , typename V >
std::vector<variable_value_type>& limbo::solvers::LinearModel< T, V >::variableSolutions ( )
inline
Returns
array of solution

Definition at line 1374 of file Solvers.h.

template<typename T , typename V >
variable_value_type limbo::solvers::LinearModel< T, V >::variableUpperBound ( variable_type const &  var)
inline
Returns
upper bound of variables

Definition at line 1344 of file Solvers.h.


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