This class describes a stochastic model (block). More...
#include <StochModel.h>
Public Member Functions | |
StochModel (SyntaxNode *onStages, SyntaxNode *onNodes, SyntaxNode *onAncs, SyntaxNode *onProb, AmplModel *parent) | |
Constructor. | |
AmplModel * | expandToFlatModel () |
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. | |
SyntaxNode * | getProbs () const |
Retrieve the SyntaxNode corresponding to the probability term. | |
SyntaxNodeIDREF * | find_var_ref_in_context (IDNode *ref) |
Private Member Functions | |
void | _transcribeComponents (AmplModel *current, int level) |
Recursive helper function for expandToFlatModel. | |
Private Attributes | |
SyntaxNode * | stageset |
The set of STAGES. | |
IDNode * | stagedummy |
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. | |
SyntaxNode * | nodeset |
The set of NODES. | |
IDNode * | nodedummy |
The dummy variable for the NODES set. | |
SyntaxNode * | anc |
The parameter array of ancestors. | |
SyntaxNode * | prob |
The parameter array of probabilities. |
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.
StochModel::StochModel | ( | SyntaxNode * | onStages, | |
SyntaxNode * | onNodes, | |||
SyntaxNode * | onAncs, | |||
SyntaxNode * | onProb, | |||
AmplModel * | parent | |||
) |
Constructor.
References anc, expandStages(), nodedummy, nodeset, AmplModel::parent, prob, splitIn(), stagedummy, and stageset.
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.
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.
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:
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().
SyntaxNode* StochModel::anc [private] |
The parameter array of ancestors.
Referenced by expandToFlatModel(), and StochModel().
bool StochModel::is_symbolic_stages [private] |
Whether stage names are symbolic or numeric.
Referenced by _transcribeComponents().
IDNode* StochModel::nodedummy [private] |
The dummy variable for the NODES set.
Referenced by _transcribeComponents(), find_var_ref_in_context(), and StochModel().
SyntaxNode* StochModel::nodeset [private] |
The set of NODES.
Referenced by expandToFlatModel(), and StochModel().
SyntaxNode* StochModel::prob [private] |
The parameter array of probabilities.
Referenced by getProbs(), and StochModel().
IDNode* StochModel::stagedummy [private] |
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().
SyntaxNode* StochModel::stageset [private] |
The set of STAGES.
Referenced by expandStages(), and StochModel().