This class describes a model (block) in the flat model tree. More...
#include <AmplModel.h>
Public Member Functions | |
AmplModel (const std::string &orig_name, AmplModel *par=NULL) | |
Constructor. | |
virtual | ~AmplModel () |
Destructor. | |
void | setGlobalName () |
Set the global name by concatenating ancestor names. | |
void | setGlobalNameRecursive () |
Set the global name recursively for this and all submodels. | |
void | writeTaggedComponents (std::ostream &fout) |
Recursively write out all tagged model components in this model and submodels to file. | |
ExpandedModel * | createExpandedModel (const std::string &smodelname, const std::string &sinstanceStub) |
Recursively create an ExpandedModel tree from the flat AmplModel. | |
void | addDummyObjective () |
Add a dummy objective that uses (sums up) all variables in the model. | |
virtual void | addComp (ModelComp *comp) |
Add a model component to the model. | |
void | removeComp (const ModelComp *comp) |
Remove a model component from the model. | |
void | reassignDependencies () |
Recursively recalculate dependency list and re-resolve IDREF nodes. | |
void | print () const |
Print debugging output recursively. | |
void | dump (const char *filename) const |
Recursive detailed debugging output. | |
void | dump (std::ostream &fout) const |
Recursive detailed debugging output. | |
const SymbolTable::Entry * | findComponent (const std::string &id) const |
Find a component with name id in correct scoping order. | |
std::list< SymbolTable::Entry > | getObjList () const |
Returns a list of all objective functions in context. | |
virtual SyntaxNodeIDREF * | find_var_ref_in_context (IDNode *ref) |
virtual AmplModel * | expandToFlatModel () |
virtual SyntaxNode * | getProbs () const |
Static Public Member Functions | |
static void | applyChanges () |
Public Attributes | |
SymbolTable | symbol_table |
Hash table of entries in this model. | |
std::string | name |
Name of the block defining this (sub)model. | |
std::string | global_name |
Name with ancestors name prepended (excluding root). | |
int | n_vars |
number of variable declarations | |
int | n_cons |
number of constraint declarations | |
int | n_params |
number of parameter declarations | |
int | n_sets |
number of set declarations | |
int | n_objs |
number of objective declarations | |
int | n_submodels |
number of submodel/block declarations | |
int | n_total |
total number of declarations | |
int | level |
level of this model on the flat model tree (root=0) | |
ModelComp * | node |
The ModelComp node corresponding to this model (defined if this is not root). | |
std::list< ModelComp * > | comps |
The list of components of this model. | |
AmplModel * | parent |
The parent if this is a submodel of another model. | |
SyntaxNodeIx * | ix |
Indexing expression. | |
Static Public Attributes | |
static std::list< changeitem > | changes |
List of changes that should be applied to the models. | |
static AmplModel * | root = NULL |
The root model of the AmplModel tree. | |
Private Member Functions | |
void | check () const |
Check instance for consistency. |
This class describes a model (block) in the flat model tree.
It should really be called FlatModelNode (or something like that). It keeps track of the components (vars/cons/sets/params/submodels) associated with this model. Each component is stored in *symbolic* form: i.e. a tree of AMPL expressions for the body of the component definition and a tree of AMPL expressions for the indexing expression. It does not know about the cardinality of each component (it does not expand indexing expressions). It keeps track of both the number of every type registered and a linked list of entries describing each of the entities in more detail.
AmplModel::AmplModel | ( | const std::string & | orig_name, | |
AmplModel * | par = NULL | |||
) |
AmplModel::~AmplModel | ( | ) | [virtual] |
Destructor.
References comps.
void AmplModel::addComp | ( | ModelComp * | comp | ) | [virtual] |
Add a model component to the model.
Reimplemented in StochModel.
References comps, ModelComp::model, n_cons, n_objs, n_params, n_sets, n_submodels, n_total, n_vars, ModelComp::other, parent, ModelComp::setUpDependencies(), TCON, TMAX, TMIN, TMODEL, TPARAM, TSET, TVAR, and ModelComp::type.
Referenced by addDummyObjective(), applyChanges(), begin_model(), begin_smodel(), StochModel::expandToFlatModel(), and yyparse().
void AmplModel::addDummyObjective | ( | ) |
Add a dummy objective that uses (sums up) all variables in the model.
AMPL will remove variables from the model that are not used in any constraint/objective within the model. In order to prevent this, we need to add a dummy objective that uses every defined variable (by simply summing them up).
References addComp(), addDummyObjective(), COMMA, comps, SyntaxNode::front(), SyntaxNodeIx::getDummyVarExpr(), SyntaxNodeIx::getNComp(), SyntaxNode::getOpCode(), SyntaxNodeIx::getSet(), IN, ModelComp::indexing, LBRACE, ModelComp::other, SyntaxNode::push_back(), SUM, TMIN, TMODEL, to_string(), TVAR, and ModelComp::type.
Referenced by addDummyObjective(), and sml_generate().
void AmplModel::applyChanges | ( | ) | [static] |
References changeitem::action, addComp(), CHANGE_ADD, CHANGE_REM, changes, changeitem::comp, changeitem::model, and removeComp().
Referenced by StochModel::expandToFlatModel().
void AmplModel::check | ( | ) | const [private] |
ExpandedModel * AmplModel::createExpandedModel | ( | const std::string & | smodelname, | |
const std::string & | sinstanceStub | |||
) |
Recursively create an ExpandedModel tree from the flat AmplModel.
This method is given a location in the Expanded tree and the corresponding node of the AmplModel tree and creates recursively the ExpandedModel instances corresponding to it. The location in the ExpandedTree to be created is encoded in two strings:
smodelname | Name of model in flat model tree (this is identical to this->global_name?) | |
sinstanceStub | The instance that should be created. Concatenating of the instances up to here: INS1_INS2... where INSn is the value of the indexing variable at the n-th level. |
The expanded tree is created by concatenating strings and reading the instance names of the nodes in the next level from the corresponding *.set file.
References ExpandedModel::appendLocalVarDef(), ExpandedModelInterface::children, comps, createExpandedModel(), crush(), getGlobalName(), getListOfInstances(), ModelComp::id, is_int(), name, NOARG, ModelComp::other, ExpandedModelInterface::parent, ExpandedModel::pathToNodeStack, PRINT_LOG, GlobalVariables::prtLvl, ExpandedModel::setLocalVarInfo(), ExpandedModel::setupNlFile(), TMODEL, TVAR, and ModelComp::type.
Referenced by createExpandedModel(), and sml_generate().
void AmplModel::dump | ( | const char * | filename | ) | const |
Recursive detailed debugging output.
Referenced by dump(), print(), and sml_generate().
void AmplModel::dump | ( | std::ostream & | fout | ) | const |
Recursive detailed debugging output.
References comps, dump(), SyntaxNode::dump(), global_name, ix, level, n_cons, n_objs, n_params, n_sets, n_submodels, n_vars, name, ModelComp::other, parent, TMODEL, and ModelComp::type.
virtual AmplModel* AmplModel::expandToFlatModel | ( | ) | [inline, virtual] |
Reimplemented in StochModel.
Referenced by end_smodel().
SyntaxNodeIDREF * AmplModel::find_var_ref_in_context | ( | IDNode * | ref | ) | [virtual] |
Reimplemented in StochModel.
References ModelComp::attributes, comps, find_var_ref_in_context(), ModelComp::id, IDNode::id(), IDREF, IDREFM, ModelComp::indexing, GlobalVariables::logParseModel, ModelComp::nameTypes, parent, TMODEL, and ModelComp::type.
Referenced by find_var_ref_in_context(), and find_var_ref_in_context().
const SymbolTable::Entry * AmplModel::findComponent | ( | const std::string & | id | ) | const |
Find a component with name id in correct scoping order.
It will first search this model's SymbolTable, and if it cannot find the component it will recurse to its parent node and so on up to the root.
References findComponent(), SymbolTable::findSymbol(), parent, and symbol_table.
Referenced by findComponent().
list< SymbolTable::Entry > AmplModel::getObjList | ( | ) | const |
Returns a list of all objective functions in context.
References SymbolTable::getListByType(), getObjList(), parent, SymbolTable::ST_OBJ, and symbol_table.
Referenced by ExpandedModel::getObjList(), and getObjList().
virtual SyntaxNode* AmplModel::getProbs | ( | ) | const [inline, virtual] |
Reimplemented in StochModel.
void AmplModel::print | ( | ) | const |
Print debugging output recursively.
References dump().
Referenced by StochModel::_transcribeComponents(), and StochModel::expandToFlatModel().
void AmplModel::reassignDependencies | ( | ) |
Recursively recalculate dependency list and re-resolve IDREF nodes.
In the process of building the AmplModel tree from the StochModelTree some of the IDREF dependency nodes still point to the StochModelComp nodes from the StochModel tree (or the intermediate tree)
This routine goes through all components and makes sure that IDREF nodes are resolved with respect to the correct ModelComp and that the dependency lists are in order. Recursively follows down submodels.
References comps, reassignDependencies(), and TMODEL.
Referenced by StochModel::expandToFlatModel(), and reassignDependencies().
void AmplModel::removeComp | ( | const ModelComp * | comp | ) |
Remove a model component from the model.
References comps, ModelComp::id, n_cons, n_objs, n_params, n_sets, n_submodels, n_total, n_vars, name, TCON, TMAX, TMIN, TMODEL, TPARAM, TSET, TVAR, and ModelComp::type.
Referenced by applyChanges().
void AmplModel::setGlobalName | ( | ) |
Set the global name by concatenating ancestor names.
References global_name, name, and parent.
Referenced by AmplModel(), begin_model(), begin_smodel(), and setGlobalNameRecursive().
void AmplModel::setGlobalNameRecursive | ( | ) |
Set the global name recursively for this and all submodels.
References comps, ModelComp::other, setGlobalName(), setGlobalNameRecursive(), TMODEL, and ModelComp::type.
Referenced by StochModel::expandToFlatModel(), and setGlobalNameRecursive().
void AmplModel::writeTaggedComponents | ( | std::ostream & | fout | ) |
Recursively write out all tagged model components in this model and submodels to file.
Write all tagged model components in this model and submodels to a file.
fout | Name of the stream to which to write. |
References comps, SyntaxNode::default_model, add_index::dummyVar, SyntaxNodeIx::getDummyVarExpr(), SyntaxNodeIx::getNComp(), SyntaxNodeIx::getSet(), ModelComp::indexing, ModelComp::isTagged(), l_addIndex, modified_write(), node, ModelComp::other, SyntaxNode::print(), SyntaxNode::push_back(), add_index::set, TMODEL, ModelComp::type, and writeTaggedComponents().
Referenced by write_ampl_for_submodel_(), and writeTaggedComponents().
list< changeitem > AmplModel::changes [static] |
List of changes that should be applied to the models.
Referenced by applyChanges(), and ModelComp::moveUp().
std::list<ModelComp*> AmplModel::comps |
The list of components of this model.
Referenced by StochModel::_transcribeComponents(), addComp(), addDummyObjective(), createExpandedModel(), dump(), expandSet(), StochModel::expandStagesOfComp(), StochModel::expandToFlatModel(), fill_model_list_(), find_var_ref_in_context(), print_entries(), print_model(), process_model(), ModelComp::reassignDependencies(), reassignDependencies(), removeComp(), setGlobalNameRecursive(), StochModelComp::transcribeToModelComp(), ModelComp::untagAll(), write_ampl_for_submodel(), write_ampl_for_submodel_(), ModelComp::writeAllTagged(), writeTaggedComponents(), and ~AmplModel().
std::string AmplModel::global_name |
Name with ancestors name prepended (excluding root).
Referenced by check(), dump(), setGlobalName(), and write_ampl_for_submodel_().
Indexing expression.
All models except root might have an indexing expression: block name{i in SET}.
Referenced by dump(), StochModel::expandToFlatModel(), and ModelComp::moveUp().
int AmplModel::level |
level of this model on the flat model tree (root=0)
Referenced by dump(), fill_model_list_(), and process_model().
number of constraint declarations
Referenced by addComp(), check(), dump(), print_model(), and removeComp().
number of objective declarations
Referenced by addComp(), check(), dump(), print_model(), and removeComp().
number of parameter declarations
Referenced by addComp(), check(), dump(), print_model(), and removeComp().
number of set declarations
Referenced by addComp(), check(), dump(), print_model(), and removeComp().
number of submodel/block declarations
Referenced by addComp(), check(), dump(), fill_model_list_(), print_model(), process_model(), and removeComp().
total number of declarations
Referenced by addComp(), check(), and removeComp().
number of variable declarations
Referenced by addComp(), check(), dump(), print_model(), and removeComp().
std::string AmplModel::name |
Name of the block defining this (sub)model.
Referenced by AmplModel(), begin_smodel(), check(), createExpandedModel(), ModelComp::dump(), dump(), end_model(), end_smodel(), StochModel::expandToFlatModel(), getGlobalName(), getGlobalNameNew(), print_model(), process_model(), removeComp(), setGlobalName(), write_ampl_for_submodel(), and ModelComp::writeAllTagged().
The ModelComp node corresponding to this model (defined if this is not root).
Referenced by StochModel::_transcribeComponents(), begin_model(), begin_smodel(), buildPathProbTerm(), check(), end_smodel(), StochModel::expandToFlatModel(), getGlobalNameNew(), process_model(), StochModelComp::transcribeToModelComp(), and writeTaggedComponents().
The parent if this is a submodel of another model.
Referenced by addComp(), buildModelPath(), buildPathProbTerm(), check(), dump(), end_model(), end_smodel(), StochModel::expandStagesOfComp(), StochModel::expandToFlatModel(), fill_model_list_(), find_var_ref_in_context(), findComponent(), getGlobalName(), getGlobalNameNew(), getObjList(), modified_write(), ModelComp::moveUp(), process_model(), setGlobalName(), StochModel::StochModel(), StochModelComp::transcribeToModelComp(), and write_ampl_for_submodel().
AmplModel * AmplModel::root = NULL [static] |
The root model of the AmplModel tree.
Referenced by expandSet(), StochModel::expandStagesOfComp(), parse_model(), sml_generate(), and write_ampl_for_submodel().
Hash table of entries in this model.
The symb_entry encodes name and type of the model component.
Referenced by StochModel::expandToFlatModel(), findComponent(), getObjList(), and yyparse().