ROC++  v1.2
Automatic Robust Optimization in C++
ProductTerm Class Reference

Product term. More...

#include <ConstraintTerm.hpp>

Inheritance diagram for ProductTerm:
Collaboration diagram for ProductTerm:

Public Types

typedef multimap< string, ROCPPVarIF_PtrvarMapType
 Multimap from string to decision variable. More...
 
typedef multimap< string, ROCPPUnc_PtruncMapType
 Multimap from string to uncertain parameter. More...
 
typedef multimap< string, ROCPPVarIF_Ptr >::const_iterator varsIterator
 Constant iterator for decision variable map (m_DVMap) More...
 
typedef multimap< string, ROCPPUnc_Ptr >::const_iterator uncIterator
 Constant iterator for uncertain parameter map (m_UncMap) More...
 
- Public Types inherited from ConstraintTermIF
typedef dvMapType::const_iterator dvIterator
 Constant iterator for product term decision variable map. More...
 
typedef uncMapType::const_iterator uncIterator
 Constant iterator for product term uncertain parameter map. More...
 

Public Member Functions

 ProductTerm (double c)
 Constructor of the ProductTerm class. More...
 
 ProductTerm (double c, ROCPPVarIF_Ptr pVariable)
 Constructor of the ProductTerm class. More...
 
 ProductTerm (double c, ROCPPUnc_Ptr pUncertainty, ROCPPVarIF_Ptr pVariable)
 Constructor of the ProductTerm class. More...
 
 ProductTerm (double c, ROCPPUnc_Ptr pUncertainty)
 Constructor of the ProductTerm class. More...
 
 ProductTerm (double c, ROCPPVarIF_Ptr pVariable1, ROCPPVarIF_Ptr pVariable2)
 Constructor of the ProductTerm class. More...
 
 ProductTerm (double c, ROCPPUnc_Ptr pUncertainty, ROCPPVarIF_Ptr pVariable1, ROCPPVarIF_Ptr pVariable2)
 Constructor of the ProductTerm class. More...
 
 ProductTerm (double c, const vector< ROCPPUnc_Ptr > &uncVec, const vector< ROCPPVarIF_Ptr > &varVec)
 Constructor of the ProductTerm class. More...
 
 ~ProductTerm ()
 Destructor of the ProductTerm class. More...
 
bool operator== (const ProductTerm &other) const
 Check it two terms are equal. More...
 
void operator*= (ROCPPconstCstrTermIF_Ptr term)
 Multiply this object with the given term. More...
 
void operator*= (ROCPPVarIF_Ptr var)
 Multiply this object with the given decision variable. More...
 
void operator*= (ROCPPUnc_Ptr unc)
 Multiply this object with the given uncertainty. More...
 
void operator*= (double a)
 Multiply this object with the given coefficient␐␐␐. More...
 
varsIterator varsBegin () const
 Return a pointer to the begining of the decision variable map (m_DVMap) More...
 
varsIterator varsEnd () const
 Return a pointer to the end of the decision variable map (m_DVMap) More...
 
uncIterator uncBegin () const
 Return a pointer to the begining of the uncertain parameter map (m_UncMap) More...
 
uncIterator uncEnd () const
 Return a pointer to the end of the uncertain parameter map (m_UncMap) More...
 
pair< bool, ROCPPCstrTermIF_PtrfactorOut (ROCPPUnc_Ptr unc) const
 Calculate the coeffiecient of the given uncertainty. More...
 
ROCPPCstrTermIF_Ptr mapTermVars (const map< string, ROCPPVarIF_Ptr > &mapFromOldToNewVars) const
 Map the old decision variables in this term to new variables. More...
 
ROCPPCstrTermIF_Ptr mapTermUnc (const map< string, ROCPPUnc_Ptr > &mapFromOldToNewUnc) const
 Map the old uncertain parameters in this term to new uncertainties. More...
 
ROCPPExpr_Ptr mapVars (const map< string, ROCPPExpr_Ptr > &mapFromVarToExpression) const
 Map the old variables in this term to expressions. More...
 
ROCPPExpr_Ptr mapUncs (const map< string, ROCPPExpr_Ptr > &mapFromUncToExpression) const
 Map the old uncertainties in this term to expressions. More...
 
ROCPPCstrTermIF_Ptr replaceTermWithVar (const multimap< string, ROCPPVarIF_Ptr > &term, ROCPPVarIF_Ptr var) const
 Replace the given term in this term with the given decision variable. More...
 
void add (ROCPPconstCstrTermIF_Ptr other)
 Add a given constraint term to this term. More...
 
void add_vars_involved_in_prod (dvContainer &dvs) const
 Add the decisions variables involved in a product in this term to the given container dvs. More...
 
double evaluate (const map< string, double > &valuesMap) const
 Calculate the value of this term. More...
 
constraintTermType getType () const
 Return the type of the term. More...
 
bool isProductTerm () const
 Return true if and only if the term is of type prodTerm. More...
 
bool hasNonlinearities () const
 Return true if and only if there is a product between two decision variables in this term. More...
 
bool hasProdsUncertainties () const
 Return true if and only if there is a product between two uncertainties in this term. More...
 
bool hasProdsContVars () const
 Return true if and only if there is a product between two continuous variables in this term. More...
 
bool isConstant () const
 Return true if and only if the term is just a constant. More...
 
bool isDeterministic () const
 Return true if and only if the term is deterministic. More...
 
bool isLinear () const
 Return true if and only if the term is linear. More...
 
bool isQuadratic () const
 Return true if and only if the term is quadratic. More...
 
double getCoeff () const
 Return the coefficient (a double type) of this object. More...
 
bool isWellDefined () const
 Return true if and only if this object is not empty. More...
 
bool is_same (ROCPPconstCstrTermIF_Ptr other) const
 Return true if and only if the given constraint term is the same as this object. More...
 
uint getNumTimesTermAppears (const multimap< string, ROCPPVarIF_Ptr > &term) const
 Get the number of times the given term appears in this object. More...
 
void getAllProductsOf2Variables (map< pair< string, string >, uint > &freqMap, map< pair< string, string >, multimap< string, ROCPPVarIF_Ptr > > &termMap) const
 Get the products of any two variables in this term. More...
 
ROCPPCstrTermIF_Ptr Clone () const
 Clone this term and return a pointer to the clone. More...
 
void WriteToStream (ofstream &ofs) const
 Print this term to the stream ofs. More...
 
- Public Member Functions inherited from ConstraintTermIF
 ConstraintTermIF ()
 Constructor of the ConstraintTermIF class. More...
 
virtual ~ConstraintTermIF ()
 Destructor of the ConstraintTermIF class. More...
 
dvIterator varsBegin () const
 Return a constant iterator pointing to the beginning of the decision variable map (m_pDVContainer) More...
 
dvIterator varsEnd () const
 Return a constant iterator pointing to the end of the decision variable map (m_pDVContainer) More...
 
uncIterator uncBegin () const
 Return a constant iterator pointing to the beginning of the uncertain parameter map (m_pUncContainer) More...
 
uncIterator uncEnd () const
 Return a constant iterator pointing to the end of the uncertain parameter map (m_pUncContainer) More...
 
void add_int_vars (dvContainer &dvs) const
 Add the integer variables in this term to the given container. More...
 
virtual bool isNonlinearProdTerm () const
 Return true if and only if the term is a product term and is nonlinear, i.e., if it involves products of decision variables. More...
 
virtual bool isNormTerm () const
 Return true if and only if the term is of type normTerm. More...
 
ROCPPconstdvContainer_Ptr getDVContainer () const
 Return the decision variable container (m_dvContainer) of this object. More...
 
ROCPPconstuncContainer_Ptr getUncContainer () const
 Return the uncertainty container (m_uncContainer) in this object. More...
 
uint getNumContVars () const
 Return the number of real-valued decision variables in this term. More...
 
uint getNumIntVars () const
 Return the number of integer decision variables in this term. More...
 
uint getNumBoolVars () const
 Return the number of boolen decision variables in this term. More...
 
uint getNumAdaptiveContVars () const
 Return the number of adaptive real-valued decision variables in this term. More...
 
uint getNumAdaptiveVars () const
 Return the number of adaptive decision variables in this term. More...
 
size_t getNumUncertainties () const
 Return the number of uncertain parameters in this term. More...
 
size_t getNumVars () const
 Return the number of decision variables in this term. More...
 
bool allIntVarsBounded () const
 Return true if and only if all integer decision variables in this term are bounded. More...
 

Private Member Functions

void addVariable (ROCPPVarIF_Ptr pVariable)
 Multiply the term by pVariable. More...
 
void addUncertainty (ROCPPUnc_Ptr pUncertainty)
 Multiply the term by pUncertainty. More...
 

Private Attributes

double m_coeff
 Coefficient of this term. More...
 
multimap< string, ROCPPVarIF_Ptrm_DVMap
 Multimap from decision variable name to decision variable. The variable appears in the map as many times as it is present in the term. More...
 
multimap< string, ROCPPUnc_Ptrm_UncMap
 Multimap from uncertain parameter name to the uncertain parameter. The uncertain parameter appears in the map as many times as it is present in the term. More...
 

Additional Inherited Members

- Protected Attributes inherited from ConstraintTermIF
ROCPPdvContainer_Ptr m_pDVContainer
 Decision variable container. More...
 
ROCPPuncContainer_Ptr m_pUncContainer
 Uncertain parameter container. More...
 

Detailed Description

Product term.

Term for product of coefficient, decision variables, and uncertainties (monomial)

Member Typedef Documentation

◆ uncIterator

typedef multimap<string, ROCPPUnc_Ptr>::const_iterator ProductTerm::uncIterator

Constant iterator for uncertain parameter map (m_UncMap)

◆ uncMapType

typedef multimap<string, ROCPPUnc_Ptr> ProductTerm::uncMapType

Multimap from string to uncertain parameter.

◆ varMapType

typedef multimap<string, ROCPPVarIF_Ptr> ProductTerm::varMapType

Multimap from string to decision variable.

◆ varsIterator

typedef multimap<string, ROCPPVarIF_Ptr>::const_iterator ProductTerm::varsIterator

Constant iterator for decision variable map (m_DVMap)

Constructor & Destructor Documentation

◆ ProductTerm() [1/7]

ProductTerm::ProductTerm ( double  c)

Constructor of the ProductTerm class.

Parameters
ccoefficient

◆ ProductTerm() [2/7]

ProductTerm::ProductTerm ( double  c,
ROCPPVarIF_Ptr  pVariable 
)

Constructor of the ProductTerm class.

Parameters
ccoefficient
pVariabledecision variable involved in the product term

◆ ProductTerm() [3/7]

ProductTerm::ProductTerm ( double  c,
ROCPPUnc_Ptr  pUncertainty,
ROCPPVarIF_Ptr  pVariable 
)

Constructor of the ProductTerm class.

Parameters
ccoefficient
pUncertaintyuncertain parameter involved in the product term
pVariabledecision variable involved in the product term

◆ ProductTerm() [4/7]

ProductTerm::ProductTerm ( double  c,
ROCPPUnc_Ptr  pUncertainty 
)

Constructor of the ProductTerm class.

Parameters
ccoefficient
pUncertaintyuncertain parameter involved in the product term

◆ ProductTerm() [5/7]

ProductTerm::ProductTerm ( double  c,
ROCPPVarIF_Ptr  pVariable1,
ROCPPVarIF_Ptr  pVariable2 
)

Constructor of the ProductTerm class.

Parameters
ccoefficient
pVariable1first decision variable involved in the product term
pVariable2second decision variable involved in the product term

◆ ProductTerm() [6/7]

ProductTerm::ProductTerm ( double  c,
ROCPPUnc_Ptr  pUncertainty,
ROCPPVarIF_Ptr  pVariable1,
ROCPPVarIF_Ptr  pVariable2 
)

Constructor of the ProductTerm class.

Parameters
ccoefficient
pUncertaintyuncertain parameter involved in the product term
pVariable1first decision variable involved in the product term
pVariable2second decision variable involved in the product term

◆ ProductTerm() [7/7]

ProductTerm::ProductTerm ( double  c,
const vector< ROCPPUnc_Ptr > &  uncVec,
const vector< ROCPPVarIF_Ptr > &  varVec 
)

Constructor of the ProductTerm class.

Parameters
ccoefficient
uncVecvector of uncetainties involved in the product term
varVecvector of decision variables involved in the product term

◆ ~ProductTerm()

ProductTerm::~ProductTerm ( )
inline

Destructor of the ProductTerm class.

Member Function Documentation

◆ add()

void ProductTerm::add ( ROCPPconstCstrTermIF_Ptr  other)
virtual

Add a given constraint term to this term.

Note
Only valid in class ProductTerm. Throws an exception if the two terms are not identical

Reimplemented from ConstraintTermIF.

◆ add_vars_involved_in_prod()

void ProductTerm::add_vars_involved_in_prod ( dvContainer dvs) const
virtual

Add the decisions variables involved in a product in this term to the given container dvs.

Implements ConstraintTermIF.

◆ addUncertainty()

void ProductTerm::addUncertainty ( ROCPPUnc_Ptr  pUncertainty)
private

Multiply the term by pUncertainty.

Parameters
pUncertaintyuncertain parameter that will multiply this term

◆ addVariable()

void ProductTerm::addVariable ( ROCPPVarIF_Ptr  pVariable)
private

Multiply the term by pVariable.

Parameters
pVariabledecision variable that will multiply this term

◆ Clone()

ROCPPCstrTermIF_Ptr ProductTerm::Clone ( ) const
virtual

Clone this term and return a pointer to the clone.

Implements ConstraintTermIF.

◆ evaluate()

double ProductTerm::evaluate ( const map< string, double > &  valuesMap) const
virtual

Calculate the value of this term.

Parameters
valuesMapa map from name of the variable to its value

Implements ConstraintTermIF.

◆ factorOut()

pair< bool, ROCPPCstrTermIF_Ptr > ProductTerm::factorOut ( ROCPPUnc_Ptr  unc) const
virtual

Calculate the coeffiecient of the given uncertainty.

Returns
The first element of the pair indicates whether the given uncertainty exists in this object, the second element stores the coefficient if the uncertianty exist

Reimplemented from ConstraintTermIF.

◆ getAllProductsOf2Variables()

void ProductTerm::getAllProductsOf2Variables ( map< pair< string, string >, uint > &  freqMap,
map< pair< string, string >, multimap< string, ROCPPVarIF_Ptr > > &  termMap 
) const
virtual

Get the products of any two variables in this term.

Parameters
freqMapmap from the pair of the variable names in each product to the frequency of this product
termMapmap from the pair of the variable names in each product to the map of the name to the variable involved in the product
Note
The calculated results are stored in the two inputs of this method

Implements ConstraintTermIF.

◆ getCoeff()

double ProductTerm::getCoeff ( ) const
inlinevirtual

Return the coefficient (a double type) of this object.

Note
Only valid in class ProductTerm

Reimplemented from ConstraintTermIF.

◆ getNumTimesTermAppears()

uint ProductTerm::getNumTimesTermAppears ( const multimap< string, ROCPPVarIF_Ptr > &  term) const
virtual

Get the number of times the given term appears in this object.

Parameters
termmap from name of the variable to the pointer of the variable involved in the term

Implements ConstraintTermIF.

◆ getType()

constraintTermType ProductTerm::getType ( ) const
virtual

Return the type of the term.

Returns
enumerated type, term's type

Implements ConstraintTermIF.

◆ hasNonlinearities()

bool ProductTerm::hasNonlinearities ( ) const
virtual

Return true if and only if there is a product between two decision variables in this term.

Implements ConstraintTermIF.

◆ hasProdsContVars()

bool ProductTerm::hasProdsContVars ( ) const
virtual

Return true if and only if there is a product between two continuous variables in this term.

Implements ConstraintTermIF.

◆ hasProdsUncertainties()

bool ProductTerm::hasProdsUncertainties ( ) const
virtual

Return true if and only if there is a product between two uncertainties in this term.

Implements ConstraintTermIF.

◆ is_same()

bool ProductTerm::is_same ( ROCPPconstCstrTermIF_Ptr  other) const
virtual

Return true if and only if the given constraint term is the same as this object.

Implements ConstraintTermIF.

◆ isConstant()

bool ProductTerm::isConstant ( ) const
inlinevirtual

Return true if and only if the term is just a constant.

Note
Only valid in class ProductTerm

Reimplemented from ConstraintTermIF.

◆ isDeterministic()

bool ProductTerm::isDeterministic ( ) const
inlinevirtual

Return true if and only if the term is deterministic.

Note
Only valid in class ProductTerm

Reimplemented from ConstraintTermIF.

◆ isLinear()

bool ProductTerm::isLinear ( ) const
inlinevirtual

Return true if and only if the term is linear.

Note
Only valid in class ProductTerm

Reimplemented from ConstraintTermIF.

◆ isProductTerm()

bool ProductTerm::isProductTerm ( ) const
inlinevirtual

Return true if and only if the term is of type prodTerm.

Reimplemented from ConstraintTermIF.

◆ isQuadratic()

bool ProductTerm::isQuadratic ( ) const
inlinevirtual

Return true if and only if the term is quadratic.

Note
Only valid in class ProductTerm

Reimplemented from ConstraintTermIF.

◆ isWellDefined()

bool ProductTerm::isWellDefined ( ) const
inlinevirtual

Return true if and only if this object is not empty.

Implements ConstraintTermIF.

◆ mapTermUnc()

ROCPPCstrTermIF_Ptr ProductTerm::mapTermUnc ( const map< string, ROCPPUnc_Ptr > &  mapFromOldToNewUnc) const
virtual

Map the old uncertain parameters in this term to new uncertainties.

Parameters
mapFromOldToNewUncmap from old uncertainty name to new uncertainty pointer

Implements ConstraintTermIF.

◆ mapTermVars()

ROCPPCstrTermIF_Ptr ProductTerm::mapTermVars ( const map< string, ROCPPVarIF_Ptr > &  mapFromOldToNewVars) const
virtual

Map the old decision variables in this term to new variables.

Parameters
mapFromOldToNewVarsmap from old variable name to new variable pointer

Implements ConstraintTermIF.

◆ mapUncs()

ROCPPExpr_Ptr ProductTerm::mapUncs ( const map< string, ROCPPExpr_Ptr > &  mapFromUncToExpression) const
virtual

Map the old uncertainties in this term to expressions.

Parameters
mapFromUncToExpressionmap from uncertain parameter names to pointers to expressions

Implements ConstraintTermIF.

◆ mapVars()

ROCPPExpr_Ptr ProductTerm::mapVars ( const map< string, ROCPPExpr_Ptr > &  mapFromVarToExpression) const
virtual

Map the old variables in this term to expressions.

Parameters
mapFromVarToExpressionmap from old variables names to pointers to expressions

Implements ConstraintTermIF.

◆ operator*=() [1/4]

void ProductTerm::operator*= ( double  a)
inlinevirtual

Multiply this object with the given coefficient␐␐␐.

Note
only valid in ProductTerm

Reimplemented from ConstraintTermIF.

◆ operator*=() [2/4]

void ProductTerm::operator*= ( ROCPPconstCstrTermIF_Ptr  term)
virtual

Multiply this object with the given term.

Note
only valid in ProductTerm

Reimplemented from ConstraintTermIF.

◆ operator*=() [3/4]

void ProductTerm::operator*= ( ROCPPUnc_Ptr  unc)
inlinevirtual

Multiply this object with the given uncertainty.

Note
only valid in ProductTerm

Reimplemented from ConstraintTermIF.

◆ operator*=() [4/4]

void ProductTerm::operator*= ( ROCPPVarIF_Ptr  var)
inlinevirtual

Multiply this object with the given decision variable.

Note
only valid in ProductTerm

Reimplemented from ConstraintTermIF.

◆ operator==()

bool ProductTerm::operator== ( const ProductTerm other) const
virtual

Check it two terms are equal.

Note
only valid in ProductTerm

Reimplemented from ConstraintTermIF.

◆ replaceTermWithVar()

ROCPPCstrTermIF_Ptr ProductTerm::replaceTermWithVar ( const multimap< string, ROCPPVarIF_Ptr > &  term,
ROCPPVarIF_Ptr  var 
) const
virtual

Replace the given term in this term with the given decision variable.

Parameters
termmap including the decision variables in the term to be replaced
varvariable used to replace the term
Note
Only replace the nonlinear term with variable

Implements ConstraintTermIF.

◆ uncBegin()

uncIterator ProductTerm::uncBegin ( ) const
inline

Return a pointer to the begining of the uncertain parameter map (m_UncMap)

◆ uncEnd()

uncIterator ProductTerm::uncEnd ( ) const
inline

Return a pointer to the end of the uncertain parameter map (m_UncMap)

◆ varsBegin()

varsIterator ProductTerm::varsBegin ( ) const
inline

Return a pointer to the begining of the decision variable map (m_DVMap)

◆ varsEnd()

varsIterator ProductTerm::varsEnd ( ) const
inline

Return a pointer to the end of the decision variable map (m_DVMap)

◆ WriteToStream()

void ProductTerm::WriteToStream ( ofstream &  ofs) const
virtual

Print this term to the stream ofs.

Parameters
ofsoutput file stream

Implements ConstraintTermIF.

Member Data Documentation

◆ m_coeff

double ProductTerm::m_coeff
private

Coefficient of this term.

◆ m_DVMap

multimap<string, ROCPPVarIF_Ptr> ProductTerm::m_DVMap
private

Multimap from decision variable name to decision variable. The variable appears in the map as many times as it is present in the term.

◆ m_UncMap

multimap<string, ROCPPUnc_Ptr> ProductTerm::m_UncMap
private

Multimap from uncertain parameter name to the uncertain parameter. The uncertain parameter appears in the map as many times as it is present in the term.