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

ModelComp Class Reference

Object to represent a component of an AMPL/SML model/block. More...

#include <ModelComp.h>

Inheritance diagram for ModelComp:
StochModelComp

List of all members.

Public Member Functions

 ModelComp (const std::string &id_, compType type_, SyntaxNode *indexing_, SyntaxNode *attrib)
 Constructor.
 ModelComp (const std::string &id)
 Default constructor.
virtual ~ModelComp ()
 Destructor.
void setTo (const std::string &id_, compType type_, SyntaxNodeIx *indexing_, SyntaxNode *attrib)
 Set up an existing model comp to specified values.
void setUpDependencies ()
 Set up list of dependencies for this component.
void dump (std::ostream &fout) const
 Detailed debugging output.
void print () const
 Print a detailed description of this model component and all its fields.
void printBrief () const
 Print a one line description of the object (type and name).
void tagDependencies ()
 Tag this components and all its dependencies recursively.
void reassignDependencies ()
 Recalculate dependency list and re-resolve IDREF nodes.
bool isTagged () const
 Whether the component has a tag.
CompDescrgetValue () const
 Retrieve the value of this component (if a set or parameter).
void setValue (CompDescr *val)
 Set the value for this component.
void moveUp (int level)
 Move this model component up in the model tree.
virtual ModelCompclone () const
 Duplicate the object: shallow copy.
ModelCompdeep_copy () const
 Duplicate the object: deep copy.
virtual void setStochModel (StochModel *stoch)
virtual void setStageSet (SyntaxNode *stageSet)
virtual void setDeterministic (bool det)
virtual const SyntaxNodegetStageSet () const
virtual void addStageName (const std::string &name)
virtual const std::vector
< std::string > & 
getStageNames () const
virtual ModelComptranscribeToModelComp (AmplModel *current_model, const std::string &nodedummy, const std::string &stagedummy, const int level)

Static Public Member Functions

static void untagAll ()
 Set the tag to false for all models: using global_list.
static void untagAll (AmplModel *start)
 Recursively set the tag to false for all models.
static void writeAllTagged (AmplModel *start)
 Recursively write name of all tagged components.
static void modifiedWriteAllTagged (std::ostream &fout)
 Write definition of all tagged components to file, using global_list.

Public Attributes

compType type
 Type of the component.
std::string id
 Name of the component.
SyntaxNodeattributes
 A tree of specifications (which includes :=, within, default, >=).
SyntaxNodeIxindexing
 Indexing expression.
AmplModelmodel
 The model this component belongs to.
AmplModelother
 A pointer to an AmplModel structure for components of type MODEL.

Static Public Attributes

static const std::string nameTypes []
static const std::string compTypes []

Protected Attributes

std::list< ModelComp * > dependencies
 List of all entities that this model component depends on.
bool tag
 Components can be tagged by the tagDependencies method which sets this tag for this components and everything that it depends on (i.e.
CompDescrvalue
 For sets and parameters, this points to an object that gives the values and further specific information (Set for sets).
int count
 Instance number of ModelComp.

Private Member Functions

void findDependencies (const SyntaxNode *nd)
 Find dependencies for this component.

Static Private Attributes

static std::list< ModelComp * > global_list
 Global list of all defined ModelComps.
static int tt_count = 0
 Number of ModelComps defined.

Detailed Description

Object to represent a component of an AMPL/SML model/block.

It usually represents one line of AMPL/SML which is a definition of a variable/parameter/set/constraint/objective/block.

A model component is broken down into the following parts:


Constructor & Destructor Documentation

ModelComp::ModelComp ( const std::string &  id_,
compType  type_,
SyntaxNode indexing_,
SyntaxNode attrib 
)

Constructor.

Construct a model component given its name, id, indexing and attribute sections.

Also analyses dependencies in indexing and attribute and set the dependencies list

Parameters:
id_ Name of the component
type_ Type of the component
indexing_ Root node of the indexing expression IDs should have been replaced by IDREFs
attrib Root node of the attribute expression IDs should have been replaced by IDREFs

References count, global_list, indexing, PRINT_LOG, GlobalVariables::prtLvl, and setUpDependencies().

Referenced by clone(), and deep_copy().

ModelComp::ModelComp ( const std::string &  id  ) 

Default constructor.

Default constructor: just sets all fields to -1/NULL/false.

ModelComp::~ModelComp (  )  [virtual]

Destructor.


Member Function Documentation

virtual void ModelComp::addStageName ( const std::string &  name  )  [inline, virtual]

Reimplemented in StochModelComp.

Referenced by StochModel::expandStagesOfComp().

ModelComp * ModelComp::clone (  )  const [virtual]

Duplicate the object: shallow copy.

Create a shallow copy of the object: only the top level object is copied, pointers below are reused.

Reimplemented in StochModelComp.

References attributes, count, dependencies, indexing, model, ModelComp(), other, tag, and type.

Referenced by StochModel::expandToFlatModel(), and write_ampl_for_submodel_().

ModelComp * ModelComp::deep_copy (  )  const

Duplicate the object: deep copy.

Create a deep-copy of the ModelComp object.

The tree of attributes and indexing expressions is recreated using entirely new objects.

References attributes, count, SyntaxNodeIx::deep_copy(), SyntaxNode::deep_copy(), dependencies, indexing, model, ModelComp(), other, tag, and type.

Referenced by StochModelComp::transcribeToModelComp().

void ModelComp::dump ( std::ostream &  fout  )  const

Detailed debugging output.

Print a detailed description of this model component and all its fields.

References attributes, count, dependencies, indexing, model, AmplModel::name, nameTypes, SyntaxNodeIx::splitExpression(), tag, CompDescr::toString(), type, and value.

Referenced by print().

void ModelComp::findDependencies ( const SyntaxNode nd  )  [private]

Find dependencies for this component.

References dependencies, SyntaxNode::findIDREF(), and LogMC.

Referenced by setUpDependencies().

virtual const std::vector<std::string>& ModelComp::getStageNames (  )  const [inline, virtual]

Reimplemented in StochModelComp.

Referenced by StochModel::expandToFlatModel().

virtual const SyntaxNode* ModelComp::getStageSet (  )  const [inline, virtual]
CompDescr* ModelComp::getValue (  )  const [inline]

Retrieve the value of this component (if a set or parameter).

References value.

Referenced by CompDescrParam::CompDescrParam().

bool ModelComp::isTagged (  )  const [inline]

Whether the component has a tag.

References tag.

Referenced by AmplModel::writeTaggedComponents().

void ModelComp::modifiedWriteAllTagged ( std::ostream &  fout  )  [static]

Write definition of all tagged components to file, using global_list.

Recursively write name of all tagged components.

Write out a list of all model components that have the tag set: write every component how it would appear in the global model file.

Bug:
modified_write should be called within the model writing process: it depends on addIndex/l_addIndex, i.e. some indexing expressions (and subbmodel names) should be added to entity names depending on where in the model it is called.

References global_list, and modified_write().

Referenced by expandSet(), and StochModel::expandStagesOfComp().

void ModelComp::moveUp ( int  level  ) 

Move this model component up in the model tree.

Queue the ModelComp to be moved up by 'level' levels in the model tree: Just removing the component from the current model and adding it to a parent is dangerous, since ModelComp::moveUp is typically called from within a (nested) loop over all ModelComps (->comps) in the AmplModels removing/adding items to list<ModelComp*> comps while there is an iterator running over it will invalidate that iterator.

=> hence the request to move is scheduled to be executed by AmplModel::applyChanges() after the loop over all components

This method will also re-write the component for the new model I.e. all IDREFs to components below the new model will have their local indexing expression expanded

References attributes, CHANGE_ADD, CHANGE_REM, AmplModel::changes, SyntaxNode::findIDREF(), SyntaxNodeIx::getDummyVarExpr(), SyntaxNodeIx::getNComp(), indexing, AmplModel::ix, model, AmplModel::parent, SyntaxNode::push_front(), and SyntaxNodeIDREF::ref.

Referenced by StochModelComp::transcribeToModelComp().

void ModelComp::print (  )  const

Print a detailed description of this model component and all its fields.

References dump().

void ModelComp::printBrief (  )  const

Print a one line description of the object (type and name).

References nameTypes, and type.

void ModelComp::reassignDependencies (  ) 

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 makes sure that IDREF nodes are resolved with respect to the correct ModelComp and rebuilds the dependency lists.

References attributes, AmplModel::comps, dependencies, SyntaxNode::findIDREF(), id, indexing, model, PRINT_INFO, GlobalVariables::prtLvl, and SyntaxNodeIDREF::ref.

virtual void ModelComp::setDeterministic ( bool  det  )  [inline, virtual]

Reimplemented in StochModelComp.

Referenced by addStochInfo().

virtual void ModelComp::setStageSet ( SyntaxNode stageSet  )  [inline, virtual]

Reimplemented in StochModelComp.

Referenced by addStochInfo().

virtual void ModelComp::setStochModel ( StochModel stoch  )  [inline, virtual]

Reimplemented in StochModelComp.

Referenced by StochModel::addComp().

void ModelComp::setTo ( const std::string &  id_,
compType  type_,
SyntaxNodeIx indexing_,
SyntaxNode attrib 
)

Set up an existing model comp to specified values.

Set a model component to a given name, id, indexing and attribute sections.

Also analyses dependencies in indexing and attribute and set the dependencies list

Parameters:
id_ Name of the component
type_ Type of the component
indexing_ Root node of the indexing expression IDs should have been replaced by IDREFs
attrib Root node of the attribute expression IDs should have been replaced by IDREFs

References attributes, count, global_list, indexing, setUpDependencies(), tag, tt_count, and type.

void ModelComp::setUpDependencies (  ) 

Set up list of dependencies for this component.

Set up the list of dependencies for this component.

References attributes, dependencies, findDependencies(), indexing, LogMC, and SyntaxNode::print().

Referenced by AmplModel::addComp(), ModelComp(), and setTo().

void ModelComp::setValue ( CompDescr val  )  [inline]

Set the value for this component.

References value.

Referenced by yyparse().

void ModelComp::tagDependencies (  ) 

Tag this components and all its dependencies recursively.

Recursively set tag=true for this model component and all components that it depends on (i.e. everything listed in its dependency list).

References dependencies, and tag.

Referenced by StochModel::expandStagesOfComp().

virtual ModelComp* ModelComp::transcribeToModelComp ( AmplModel current_model,
const std::string &  nodedummy,
const std::string &  stagedummy,
const int  level 
) [inline, virtual]

Reimplemented in StochModelComp.

void ModelComp::untagAll (  )  [static]

Set the tag to false for all models: using global_list.

Set tag=false for all model components.

References global_list.

Referenced by expandSet(), StochModel::expandStagesOfComp(), untagAll(), and write_ampl_for_submodel().

void ModelComp::untagAll ( AmplModel start  )  [static]

Recursively set the tag to false for all models.

Recursively set tag=false for all model components.

Parameters:
start The AmplModel where to start the recursion.

References AmplModel::comps, TMODEL, and untagAll().

void ModelComp::writeAllTagged ( AmplModel start  )  [static]

Recursively write name of all tagged components.

Recursively write out a list of all model components that have the tag set.

Parameters:
start The AmplModel where to start the recursion.

References AmplModel::comps, AmplModel::name, and TMODEL.

Referenced by write_ampl_for_submodel().


Member Data Documentation

const string ModelComp::compTypes [static]
Initial value:
 {
   "var","subject to","param",
   "set", "minimize","maximize","block"}

Referenced by modified_write().

int ModelComp::count [protected]

Instance number of ModelComp.

Referenced by StochModelComp::clone(), clone(), deep_copy(), dump(), ModelComp(), and setTo().

std::list<ModelComp*> ModelComp::dependencies [protected]

List of all entities that this model component depends on.

This lists all model components used in the definition of this component.

Referenced by StochModelComp::clone(), clone(), deep_copy(), dump(), findDependencies(), reassignDependencies(), setUpDependencies(), and tagDependencies().

list< ModelComp * > ModelComp::global_list [static, private]

Global list of all defined ModelComps.

Referenced by ModelComp(), modifiedWriteAllTagged(), setTo(), and untagAll().

const string ModelComp::nameTypes [static]
Initial value:
 {
   "variable","constraint","parameter",
   "set", "objective min","objective max", 
   "submodel"}

Referenced by dump(), AmplModel::find_var_ref_in_context(), and printBrief().

bool ModelComp::tag [protected]

Components can be tagged by the tagDependencies method which sets this tag for this components and everything that it depends on (i.e.

everything listed in the dependencies list). true if part of the current 'needed' set

Referenced by StochModelComp::clone(), clone(), deep_copy(), dump(), isTagged(), setTo(), and tagDependencies().

int ModelComp::tt_count = 0 [static, private]

Number of ModelComps defined.

Referenced by setTo().

For sets and parameters, this points to an object that gives the values and further specific information (Set for sets).

Referenced by dump(), getValue(), and setValue().


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