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

AmplModel Class Reference

This class describes a model (block) in the flat model tree. More...

#include <AmplModel.h>

Inheritance diagram for AmplModel:
StochModel

List of all members.

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.
ExpandedModelcreateExpandedModel (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::EntryfindComponent (const std::string &id) const
 Find a component with name id in correct scoping order.
std::list< SymbolTable::EntrygetObjList () const
 Returns a list of all objective functions in context.
virtual SyntaxNodeIDREFfind_var_ref_in_context (IDNode *ref)
virtual AmplModelexpandToFlatModel ()
virtual SyntaxNodegetProbs () 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)
ModelCompnode
 The ModelComp node corresponding to this model (defined if this is not root).
std::list< ModelComp * > comps
 The list of components of this model.
AmplModelparent
 The parent if this is a submodel of another model.
SyntaxNodeIxix
 Indexing expression.

Static Public Attributes

static std::list< changeitemchanges
 List of changes that should be applied to the models.
static AmplModelroot = NULL
 The root model of the AmplModel tree.

Private Member Functions

void check () const
 Check instance for consistency.

Detailed Description

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.


Constructor & Destructor Documentation

AmplModel::AmplModel ( const std::string &  orig_name,
AmplModel par = NULL 
)

Constructor.

References name, and setGlobalName().

Referenced by StochModel::expandToFlatModel().

AmplModel::~AmplModel (  )  [virtual]

Destructor.

References comps.


Member Function Documentation

void AmplModel::addComp ( ModelComp comp  )  [virtual]
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]
void AmplModel::check (  )  const [private]

Check instance for consistency.

References global_name, n_cons, n_objs, n_params, n_sets, n_submodels, n_total, n_vars, name, node, and parent.

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:

  1. one gives the location in the flat AmplModel tree;
  2. the other gives the instance of the node.
Parameters:
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.

Attention:
It seems that the first parameter (name of flat model tree node is redundant, since this could be obtained from the current AmplModel instance.

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
virtual AmplModel* AmplModel::expandToFlatModel (  )  [inline, virtual]

Reimplemented in StochModel.

Referenced by end_smodel().

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.

Parameters:
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().


Member Data Documentation

list< changeitem > AmplModel::changes [static]

List of changes that should be applied to the models.

Referenced by applyChanges(), and ModelComp::moveUp().

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().

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().

Hash table of entries in this model.

The symb_entry encodes name and type of the model component.

Attention:
This does not seem to be ever used to lookup model components by name.
Should have a global hash table of *all* defined model components. Could be used in find_var_ref_in_context which does the job of finding the ModelComponent object reference for components referred to in expressions. => Need a way to only look for a match in the current part of the model tree.

Referenced by StochModel::expandToFlatModel(), findComponent(), getObjList(), and yyparse().


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