Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes

ExpandedModel Class Reference

A submodel (block) in the expanded model tree, which carries all the information to describe a block of the problem to the solver. More...

#include <ExpandedModel.h>

Inheritance diagram for ExpandedModel:
ExpandedModelInterface

List of all members.

Public Member Functions

 ExpandedModel (AmplModel *src_model)
 Constructor.
 ~ExpandedModel ()
 Destructor.
void print () const
 Recursively print the contents of this instance and of its children.
int getNLocalVars () const
 Return the number of variables local to this node.
int getNLocalCons () const
 Return the number of constraints local to this node.
const std::list< std::string > & getLocalVarNames () const
 Return the names of the variables local to this node.
const std::list< std::string > & getLocalConNames () const
 Return the names of the constraints local to this node.
int getNzJacobianOfIntersection (ExpandedModelInterface *emcol)
 Return the number of nonzeros in the Jacobian of a section of the model.
void getJacobianOfIntersection (ExpandedModelInterface *emcol, int *colbeg, int *collen, int *rownbs, double *el)
 Return the Jacobian of a section of the model in sparse matrix format.
void getRowBounds (double *lower, double *upper) const
 Return the arrays of bounds for the constraints in this model.
void getColLowBounds (double *elts)
 Return the lower bounds for the local variables defined in this model.
void getColUpBounds (double *elts)
 Return the upper bounds for the local variables defined in this model.
void getObjGradient (double *elts)
 Return the gradient of the objective defined in this model.
void setPrimalSolColumns (const double *elts)
 Upload the local variable solutions.
void setDualSolColumns (const double *elts)
 Upload the local variable duals (multipliers on bounds).
void setPrimalSolRows (const double *elts)
 Upload the local constraints slacks.
void setDualSolRows (const double *elts)
 Upload the local constraints duals (multipliers on constraints).
void setupNlFile (const std::string &name)
 Set up the nl file for this block.
int findIxOfLocalVarsInNlFile (NlFile *nlf, int *lvar)
 Find the indices of the local variables of this model in a given nl file.
std::string getName () const
 Return the unique name of this block.
void outputSolution (std::ostream &out, int indent=0)
 Output the solution to the supplied stream with the given indent.
void appendLocalVarDef (const std::string &name)
 Append the variable to the list of local variable declarations.
void setLocalVarInfo ()
 Set nLocalVar, listOfLocalVars, nLocalCons, listOfVarNames.

Static Public Attributes

static std::list< std::string > pathToNodeStack
 Stack of instance names.

Private Member Functions

std::list< SymbolTable::EntrygetObjList () const

Private Attributes

int nLocalVars
 Number of local variables.
int nLocalCons
 Number of local constraints.
bool localVarInfoSet
 Indicator if information on local variables (nLocalVars, listLocalVars, nLocalCons) has been obtained by comparing the localVarDef's with the *.col file.
double * pvar
double * dvar
double * prow
double * drow
AmplModelsrc
 The flat model from which this expanded model was created.
std::string model_file
 Name of the *.nl file that describes the problem data.
NlFilenlfile
 The NlFile object associated with model_file.
std::list< std::string > listOfVarNames
 list of global names of local variables
std::list< std::string > listOfLocalVarNames
 list of local names of local variables
std::list< std::string > listOfConNames
 list of global names of local constraints
std::list< std::string > listOfLocalConNames
 list of local names of local constraints
std::list< int > listOfLocalVars
 indices of local variables in the corresponding *.nl file
std::list< std::string > localVarDef
 the locally applicable variable declarations

Detailed Description

A submodel (block) in the expanded model tree, which carries all the information to describe a block of the problem to the solver.

The ExpandedModel object describes a (sub)block of the model together with pointers to its children (depended sub-blocks). A tree of ExpandedModel objects describes the whole problem together with its structure.

A tree of ExpandedModel objects is the means by which the problem (after being parsed by SML) is communicated to a solver backend. It thus forms the interface between SML and a solver.

An ExpandedModel object has information on the variables, constraints and objectives that describe this sub-block of the problem as well as pointers to its children (sub-blocks). It further (through NlFile) provides routines to evaluate the constraint and objectives defined in this block (and their derivatives).

Information about the sub-block is handled as a two-layer structure. The first layer (represented by an ExpandedModel object) provides 'static' information about the block, such as the dimensions (number of local constraints and variables), list of variable and constraint names and a list of children.

The second layer (represented by an NlFile object) provides access to the 'non-static' information such as function and derivative values.

An ExpandedModel object roughly corresponds to a "diagonal" node in the OOPS matrix tree. The difference is that in the ExpandedModel tree complicating variables/constraints belong to the parent node, whereas in the OOPS matrix tree they would belong to the final diagonal child node.

The ExpandedModel tree is the natural representation for a (Benders) decomposition solver, where complicating variables/constraints do indeed belong to the master problem.

The ExpandedModel tree is created (constructed) from the (flat) AmplModel tree by expanding the indexing sets associated with every AmplModel object. From the AmplModel it gets passed a list of local variable and constraint name stubs (in ExpandedModel::localVarDef - consisting of the global entity name together with the first part (identifying the particular node) of the indexing parameters). The ExpandedModel object is also passed the corresponding *.nl file (which provides only the local constraints, but not just the local variables, but all the variables that are referred to in the local constraints). The constructor then compares the (alphanumeric) list of variable name stubs with the variables defined in the *.nl file (from the corresponding *.col file) to generate the list of local variables (ExpandedModel::listOfVarNames), and their indices within the *.nl file (ExpandedModel::listOfLocalVars). This information is then used by the routines in ExpandedModel and NlFile to provide an interface into the problem to the solver.

Todo:
The Amplsolver interface routines (currently accessed through the field nlfile) should be made accessible from this object (by providing some wrapper routines).

Constructor & Destructor Documentation

ExpandedModel::ExpandedModel ( AmplModel src_model  ) 

Constructor.

ExpandedModel::~ExpandedModel (  ) 

Member Function Documentation

void ExpandedModel::appendLocalVarDef ( const std::string &  name  )  [inline]

Append the variable to the list of local variable declarations.

References localVarDef.

Referenced by AmplModel::createExpandedModel().

int ExpandedModel::findIxOfLocalVarsInNlFile ( NlFile nlf,
int *  lvar 
)

Find the indices of the local variables of this model in a given nl file.

Parameters:
[in] nlf The NlFile that defines local constraints and all variables that are used by these constraints.
[out] lvar Assumed to be allocated with em->nLocalVar elements: lvar[i] is the the index of the ith local variable in em in the nlfile.
Returns:
The number of matches found.

For the full doumentation see NlFile::findIxOfLocalVarsInNlFile. This method belongs logically to the NlFile class, since it calculates (column) sections of the columns defined in the NlFile. However since we cannot use lists in the NlFile class, the actual code is here.

References IndexListValue::count, getNLocalVars(), NlFile::indexList, listOfVarNames, LogEM, IndexListValue::lvar, model_file, NlFile::nlfilename, IndexListValue::nvar, PRINT_VERBOSE, and GlobalVariables::prtLvl.

Referenced by NlFile::findIxOfLocalVarsInNlFile().

void ExpandedModel::getColLowBounds ( double *  elts  )  [virtual]

Return the lower bounds for the local variables defined in this model.

Parameters:
[out] elts The variable lower bounds.

Implements ExpandedModelInterface.

References NlFile::findIxOfLocalVarsInNlFile(), NlFile::getColLowBoundsAMPL(), nlfile, and nLocalVars.

void ExpandedModel::getColUpBounds ( double *  elts  )  [virtual]

Return the upper bounds for the local variables defined in this model.

Parameters:
[out] elts The variable upper bounds.

Implements ExpandedModelInterface.

References NlFile::findIxOfLocalVarsInNlFile(), NlFile::getColUpBoundsAMPL(), nlfile, and nLocalVars.

void ExpandedModel::getJacobianOfIntersection ( ExpandedModelInterface emcol_,
int *  colbeg,
int *  collen,
int *  rownbs,
double *  el 
) [virtual]

Return the Jacobian of a section of the model in sparse matrix format.

The matrix is defined by the intersection of the local constraints in this model with the local variables of this or another model.

Parameters:
[in] emcol_ The model w.r.t. whose local variables the Jacobian should be evaluated. This parameter can be NULL, in which case the method works on the intersection of the local constraints with the local variables (a "diagonal" block).
[out] colbeg Column starts of the Jacobian.
[out] collen Column lengths of the Jacobian (not returned if NULL on call).
[out] rownbs Row indices of nonzeros entries.
[out] el Values of the nonzero entries.
Note:
Parameters colbeg, collen, rownbs, el are assumes to be of appropriate dimensions before the method is called, namely colbeg[n+1], collen[n], rownbs[nz], el[nz] (n=number of columns, nz=number nonzeros). The number of nonzeros in this section of the Jacobian can be obtained from a call to getNzJacobianOfIntersection().

Implements ExpandedModelInterface.

References NlFile::fillSparseAMPL(), NlFile::findIxOfLocalVarsInNlFile(), getNLocalVars(), and nlfile.

const list< string > & ExpandedModel::getLocalConNames (  )  const [virtual]

Return the names of the constraints local to this node.

Returns:
Names of local constraints.

Implements ExpandedModelInterface.

References listOfLocalConNames, and localVarInfoSet.

Referenced by outputSolution().

const list< string > & ExpandedModel::getLocalVarNames (  )  const [virtual]

Return the names of the variables local to this node.

Returns:
Names of the local variables.

Implements ExpandedModelInterface.

References listOfLocalVarNames, and localVarInfoSet.

Referenced by outputSolution().

std::string ExpandedModel::getName (  )  const [inline, virtual]

Return the unique name of this block.

Implements ExpandedModelInterface.

References model_file.

Referenced by outputSolution(), and setLocalVarInfo().

int ExpandedModel::getNLocalCons (  )  const [virtual]

Return the number of constraints local to this node.

Returns:
Number of local constraints.

Implements ExpandedModelInterface.

References localVarInfoSet, and nLocalCons.

int ExpandedModel::getNLocalVars (  )  const [virtual]

Return the number of variables local to this node.

Returns:
Number of local variables.

Implements ExpandedModelInterface.

References localVarInfoSet, and nLocalVars.

Referenced by findIxOfLocalVarsInNlFile(), getJacobianOfIntersection(), and getNzJacobianOfIntersection().

int ExpandedModel::getNzJacobianOfIntersection ( ExpandedModelInterface emcol_  )  [virtual]

Return the number of nonzeros in the Jacobian of a section of the model.

The matrix is defined by the intersection of the local constraints in this model with the local variables of this or another model.

Parameters:
emcol_ The model w.r.t. whose local variables the Jacobian should be evaluated. This parameter can be NULL, in which case the method works on the intersection of the local constraints with the local variables (a "diagonal" block).
Returns:
The number of nonzeros in the given part of the Jacobian.

Implements ExpandedModelInterface.

References NlFile::findIxOfLocalVarsInNlFile(), getNLocalVars(), NlFile::getNoNonzerosAMPL(), and nlfile.

void ExpandedModel::getObjGradient ( double *  elts  )  [virtual]

Return the gradient of the objective defined in this model.

Parameters:
[out] elts The objective gradient with respect to the local variables.

Implements ExpandedModelInterface.

References NlFile::findIxOfLocalVarsInNlFile(), NlFile::getObjAMPL(), nlfile, and nLocalVars.

list< SymbolTable::Entry > ExpandedModel::getObjList (  )  const [private]

References AmplModel::getObjList(), and src.

Referenced by setLocalVarInfo().

void ExpandedModel::getRowBounds ( double *  lower,
double *  upper 
) const [virtual]

Return the arrays of bounds for the constraints in this model.

Return the upper and lower bounds for the constraints in this model.

Parameters:
[out] lower The lower bounds on the constraints.
[out] upper The upper bounds on the constraints.

The method is simply a wrapper around NlFile::getRowBoundsAMPL().

Implements ExpandedModelInterface.

References NlFile::getRowBoundsAMPL(), and nlfile.

void ExpandedModel::outputSolution ( std::ostream &  out,
int  indent = 0 
) [virtual]
void ExpandedModel::print (  )  const

Recursively print the contents of this instance and of its children.

Used only for debugging.

References ExpandedModelInterface::children, listOfLocalVars, localVarDef, localVarInfoSet, nlfile, NlFile::nlfilename, nLocalCons, nLocalVars, and print().

Referenced by print(), and sml_generate().

void ExpandedModel::setDualSolColumns ( const double *  elts  )  [virtual]

Upload the local variable duals (multipliers on bounds).

Implements ExpandedModelInterface.

References dvar, localVarInfoSet, and nLocalVars.

void ExpandedModel::setDualSolRows ( const double *  elts  )  [virtual]

Upload the local constraints duals (multipliers on constraints).

Implements ExpandedModelInterface.

References drow, localVarInfoSet, and nLocalCons.

void ExpandedModel::setLocalVarInfo (  ) 

Set nLocalVar, listOfLocalVars, nLocalCons, listOfVarNames.

This routine identifies the indices of the local variables in the *.nl file that is associated with this ExpandedModel node.

The routine compares the variable name stubs stored in localVarDef (which are set up from the constructor using the corresponding flat model (AmplModel) and the instance (defined by appropriate values for the indexing variables), with the names of the variables defined in the *.nl file (obtained by reading the corresponding *.col file).

The routine sets the nLocalVar, listLocalVar, nLocalCons fields of the object.

Note:
The method works by comparing all stubs with all names in the *.col file, this uses a lot of string comparisons and is likely very inefficient.

References findIdxOfUncommonChar(), getName(), NlFile::getNoConstraints(), getObjList(), listOfConNames, listOfLocalConNames, listOfLocalVarNames, listOfLocalVars, listOfVarNames, localVarDef, localVarInfoSet, model_file, nlfile, nLocalCons, nLocalVars, PRINT_LOG, PRINT_VERBOSE, and GlobalVariables::prtLvl.

Referenced by AmplModel::createExpandedModel().

void ExpandedModel::setPrimalSolColumns ( const double *  elts  )  [virtual]

Upload the local variable solutions.

Implements ExpandedModelInterface.

References localVarInfoSet, nLocalVars, and pvar.

void ExpandedModel::setPrimalSolRows ( const double *  elts  )  [virtual]

Upload the local constraints slacks.

Implements ExpandedModelInterface.

References localVarInfoSet, nLocalCons, and prow.

void ExpandedModel::setupNlFile ( const std::string &  name  ) 

Set up the nl file for this block.

References model_file, and nlfile.

Referenced by AmplModel::createExpandedModel().


Member Data Documentation

double * ExpandedModel::drow [private]
std::list<std::string> ExpandedModel::listOfConNames [private]

list of global names of local constraints

Referenced by setLocalVarInfo().

std::list<std::string> ExpandedModel::listOfLocalConNames [private]

list of local names of local constraints

Referenced by getLocalConNames(), and setLocalVarInfo().

std::list<std::string> ExpandedModel::listOfLocalVarNames [private]

list of local names of local variables

Referenced by getLocalVarNames(), and setLocalVarInfo().

std::list<int> ExpandedModel::listOfLocalVars [private]

indices of local variables in the corresponding *.nl file

Referenced by print(), and setLocalVarInfo().

std::list<std::string> ExpandedModel::listOfVarNames [private]

list of global names of local variables

Referenced by findIxOfLocalVarsInNlFile(), and setLocalVarInfo().

std::list<std::string> ExpandedModel::localVarDef [private]

the locally applicable variable declarations

Referenced by appendLocalVarDef(), print(), and setLocalVarInfo().

Indicator if information on local variables (nLocalVars, listLocalVars, nLocalCons) has been obtained by comparing the localVarDef's with the *.col file.

Referenced by getLocalConNames(), getLocalVarNames(), getNLocalCons(), getNLocalVars(), outputSolution(), print(), setDualSolColumns(), setDualSolRows(), setLocalVarInfo(), setPrimalSolColumns(), and setPrimalSolRows().

std::string ExpandedModel::model_file [private]

Name of the *.nl file that describes the problem data.

Referenced by findIxOfLocalVarsInNlFile(), getName(), setLocalVarInfo(), and setupNlFile().

The NlFile object associated with model_file.

Provides interface to routines that evaluate objective and constraint functions.

Referenced by getColLowBounds(), getColUpBounds(), getJacobianOfIntersection(), getNzJacobianOfIntersection(), getObjGradient(), getRowBounds(), print(), setLocalVarInfo(), setupNlFile(), and ~ExpandedModel().

Number of local constraints.

Referenced by getNLocalCons(), print(), setDualSolRows(), setLocalVarInfo(), and setPrimalSolRows().

list< string > ExpandedModel::pathToNodeStack [static]

Stack of instance names.

A stack of block instances that encode the current path through the ExpandedModel tree during the construction phase.

Referenced by AmplModel::createExpandedModel().

The flat model from which this expanded model was created.

Referenced by getObjList(), and ~ExpandedModel().


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