Public Member Functions | Private Member Functions | Private Attributes

StochModel Class Reference

This class describes a stochastic model (block). More...

#include <StochModel.h>

Inheritance diagram for StochModel:
AmplModel

List of all members.

Public Member Functions

 StochModel (SyntaxNode *onStages, SyntaxNode *onNodes, SyntaxNode *onAncs, SyntaxNode *onProb, AmplModel *parent)
 Constructor.
AmplModelexpandToFlatModel ()
 Expand the StochModel to a nested set of flat models.
void expandStages ()
 Expand the STAGES set into the actual elements to be stored in stagenames.
void expandStagesOfComp ()
 Expand the STAGES set of all StochModelComps in this model.
void addComp (ModelComp *comp)
 Expand on AmplModel::addComp to setup stochmodel of component too.
SyntaxNodegetProbs () const
 Retrieve the SyntaxNode corresponding to the probability term.
SyntaxNodeIDREFfind_var_ref_in_context (IDNode *ref)

Private Member Functions

void _transcribeComponents (AmplModel *current, int level)
 Recursive helper function for expandToFlatModel.

Private Attributes

SyntaxNodestageset
 The set of STAGES.
IDNodestagedummy
 The dummy variable for the STAGES set.
std::vector< std::string > stagenames
 Explicit set of STAGES.
bool is_symbolic_stages
 Whether stage names are symbolic or numeric.
SyntaxNodenodeset
 The set of NODES.
IDNodenodedummy
 The dummy variable for the NODES set.
SyntaxNodeanc
 The parameter array of ancestors.
SyntaxNodeprob
 The parameter array of probabilities.

Detailed Description

This class describes a stochastic model (block).

It will gather the information present in the SML model file for this block much in the same way that AmplModel does for ordinary blocks. The difference is that sets and parameters that define the Scenario tree are associated with it. These are

In principle the stochastic model block can also be repeated "horizontally" in the same manner as all other blocks by specifying an indexing expression. The stochastic model block will be expanded at processing time into a nested set of AmplModels.


Constructor & Destructor Documentation

StochModel::StochModel ( SyntaxNode onStages,
SyntaxNode onNodes,
SyntaxNode onAncs,
SyntaxNode onProb,
AmplModel parent 
)

Member Function Documentation

void StochModel::_transcribeComponents ( AmplModel current,
int  lev 
) [private]

Recursive helper function for expandToFlatModel.

Call recursively StochModelComp::transcribeToModelComp() for all components of this StochModel.

It sets SyntaxNode::stage and SyntaxNode::node to the correct values for each new AmplModel encountered in the recursion.

Parameters:
current The AmplModel that is currently worked on. I.e. in the current level of the recursion the routine is working on AmplModel current within this StochModel.
lev The recursion level (to work out the correct way to resolve the 'stage' and 'node' keywords and 'ancestor' references).

References AmplModel::comps, SyntaxNodeIx::getListDummyVars(), IDNode::id(), ModelComp::indexing, is_symbolic_stages, AmplModel::node, StageNodeNode::node, nodedummy, ModelComp::other, AmplModel::print(), StageNodeNode::stage, stagedummy, stagenames, TMODEL, StochModelComp::transcribeToModelComp(), and ModelComp::type.

Referenced by expandToFlatModel().

void StochModel::addComp ( ModelComp comp  )  [virtual]

Expand on AmplModel::addComp to setup stochmodel of component too.

Reimplemented from AmplModel.

References ModelComp::setStochModel().

void StochModel::expandStages (  ) 

Expand the STAGES set into the actual elements to be stored in stagenames.

An AMPL model file and correspoding script file is created that when executed writes the components of the set to disk. This routine also reads in that file and stores the set members in the StochModel::stagenames list.

References expandSet(), stagenames, and stageset.

Referenced by StochModel().

void StochModel::expandStagesOfComp (  ) 

Expand the STAGES set of all StochModelComps in this model.

Expand the STAGES sets of all StochModelComps in this model.

An AMPL model file and corresponding script file is created that when executed writes the components of the set to disk. This routine also reads in that file and stores the set members in the StochModel::stagenames list.

This is a StochModel method rather than a StochModelComp method in order to gather all expansions into a single call to AMPL.

Bug:
this is just so that the global data file can be read, eventually this should be removed

References ModelComp::addStageName(), callAmpl(), AmplModel::comps, GlobalVariables::datafilename, SyntaxNode::findIDREF(), ModelComp::getStageSet(), LogSM, ModelComp::modifiedWriteAllTagged(), AmplModel::parent, SyntaxNode::print(), AmplModel::root, ModelComp::tagDependencies(), TPARAM, TSET, ModelComp::type, and ModelComp::untagAll().

Referenced by expandToFlatModel().

AmplModel * StochModel::expandToFlatModel (  )  [virtual]

Expand the StochModel to a nested set of flat models.

This routine works in two passes:

  1. In the first pass the chain of AmplModel's is built. The StochModelComp components are just copied (references are copied), but dependencies are not resolved with respect to the new model chain. The chain of AmplModels is built from the leaves up
  2. In the second pass the StochModelComp components are transcribed into ModelComp's and their dependencies are resolved with respect to the new model chain. This pass is executed from root down to the leaves.

Bug:
Submodel components within sblock's is not supported yet This is not implemented when creating a nested AmplModel tree out of the StochModel.
Bug:
: NO! need to translate all references to ModelComp (IDREF) that will currently refer to ModelComps of the StochModel into ModelComps of the appropriate FlatModel on the FlatModel tree. This might be modified by any (-1;...) expressions that refer to parents in the FlatModel tree I guess also need to do something with the Exp(...) expression
Bug:
'this_nd' is a reserved variable now

Reimplemented from AmplModel.

References _transcribeComponents(), AmplModel::addComp(), AmplModel::AmplModel(), anc, AmplModel::applyChanges(), SyntaxNode::clone(), ModelComp::clone(), COLON, COMMA, AmplModel::comps, SymbolTable::copy(), DEFINED, EQ, expandStagesOfComp(), ModelComp::getStageNames(), ModelComp::getStageSet(), IN, ModelComp::indexing, AmplModel::ix, LBRACE, LogSM, LSBRACKET, AmplModel::name, AmplModel::node, nodeset, ModelComp::other, AmplModel::parent, AmplModel::print(), PRINT_INFO, GlobalVariables::prtLvl, AmplModel::reassignDependencies(), AmplModel::setGlobalNameRecursive(), stagenames, AmplModel::symbol_table, TMODEL, to_string(), TSET, and ModelComp::type.

SyntaxNodeIDREF * StochModel::find_var_ref_in_context ( IDNode ref  )  [virtual]

Reimplemented from AmplModel.

References IDNode::id(), nodedummy, and stagedummy.

SyntaxNode* StochModel::getProbs (  )  const [inline, virtual]

Retrieve the SyntaxNode corresponding to the probability term.

Reimplemented from AmplModel.

References prob.

Referenced by buildPathProbTerm().


Member Data Documentation

The parameter array of ancestors.

Referenced by expandToFlatModel(), and StochModel().

Whether stage names are symbolic or numeric.

Referenced by _transcribeComponents().

The dummy variable for the NODES set.

Referenced by _transcribeComponents(), find_var_ref_in_context(), and StochModel().

The set of NODES.

Referenced by expandToFlatModel(), and StochModel().

The parameter array of probabilities.

Referenced by getProbs(), and StochModel().

The dummy variable for the STAGES set.

Referenced by _transcribeComponents(), find_var_ref_in_context(), and StochModel().

std::vector<std::string> StochModel::stagenames [private]

Explicit set of STAGES.

Referenced by _transcribeComponents(), expandStages(), and expandToFlatModel().

The set of STAGES.

Referenced by expandStages(), and StochModel().


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