Object to represent a component of an AMPL/SML model/block. More...
#include <ModelComp.h>
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. | |
CompDescr * | getValue () 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 ModelComp * | clone () const |
Duplicate the object: shallow copy. | |
ModelComp * | deep_copy () const |
Duplicate the object: deep copy. | |
virtual void | setStochModel (StochModel *stoch) |
virtual void | setStageSet (SyntaxNode *stageSet) |
virtual void | setDeterministic (bool det) |
virtual const SyntaxNode * | getStageSet () const |
virtual void | addStageName (const std::string &name) |
virtual const std::vector < std::string > & | getStageNames () const |
virtual ModelComp * | transcribeToModelComp (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. | |
SyntaxNode * | attributes |
A tree of specifications (which includes :=, within, default, >=). | |
SyntaxNodeIx * | indexing |
Indexing expression. | |
AmplModel * | model |
The model this component belongs to. | |
AmplModel * | other |
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. | |
CompDescr * | value |
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. |
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:
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
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.
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] |
Reimplemented in StochModelComp.
Referenced by StochModel::expandStagesOfComp(), and StochModel::expandToFlatModel().
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] |
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.
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 |
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
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] |
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.
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.
start | The AmplModel where to start the recursion. |
References AmplModel::comps, AmplModel::name, and TMODEL.
Referenced by write_ampl_for_submodel().
A tree of specifications (which includes :=, within, default, >=).
Referenced by StochModelComp::clone(), clone(), deep_copy(), dump(), AmplModel::find_var_ref_in_context(), modified_write(), moveUp(), print_entry(), reassignDependencies(), setTo(), setUpDependencies(), and StochModelComp::transcribeToModelComp().
const string ModelComp::compTypes [static] |
{ "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().
std::string ModelComp::id |
Name of the component.
Referenced by CompDescrParam::CompDescrParam(), AmplModel::createExpandedModel(), end_smodel(), AmplModel::find_var_ref_in_context(), getGlobalName(), getGlobalNameNew(), labelToSetElement(), modified_write(), print_entry(), print_SyntaxNodesymb(), process_model(), SyntaxNodeIDREF::put(), reassignDependencies(), AmplModel::removeComp(), StochModelComp::transcribeToModelComp(), and write_ampl_for_submodel_().
Indexing expression.
Referenced by StochModel::_transcribeComponents(), AmplModel::addDummyObjective(), buildPathProbTerm(), StochModelComp::clone(), clone(), CompDescrParam::CompDescrParam(), deep_copy(), dump(), StochModel::expandToFlatModel(), AmplModel::find_var_ref_in_context(), getGlobalNameNew(), ModelComp(), modified_write(), moveUp(), print_entry(), process_model(), reassignDependencies(), setTo(), setUpDependencies(), StochModelComp::transcribeToModelComp(), write_ampl_for_submodel_(), and AmplModel::writeTaggedComponents().
The model this component belongs to.
Referenced by AmplModel::addComp(), StochModelComp::clone(), clone(), deep_copy(), dump(), getGlobalName(), getGlobalNameNew(), modified_write(), moveUp(), reassignDependencies(), StochModelComp::transcribeToModelComp(), and write_ampl_for_submodel_().
const string ModelComp::nameTypes [static] |
{ "variable","constraint","parameter", "set", "objective min","objective max", "submodel"}
Referenced by dump(), AmplModel::find_var_ref_in_context(), and printBrief().
A pointer to an AmplModel structure for components of type MODEL.
Referenced by StochModel::_transcribeComponents(), AmplModel::addComp(), AmplModel::addDummyObjective(), begin_model(), begin_smodel(), StochModelComp::clone(), clone(), AmplModel::createExpandedModel(), deep_copy(), AmplModel::dump(), end_smodel(), StochModel::expandToFlatModel(), fill_model_list_(), print_model(), process_model(), AmplModel::setGlobalNameRecursive(), write_ampl_for_submodel_(), and AmplModel::writeTaggedComponents().
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().
Type of the component.
Referenced by StochModel::_transcribeComponents(), AmplModel::addComp(), AmplModel::addDummyObjective(), StochModelComp::clone(), clone(), AmplModel::createExpandedModel(), deep_copy(), dump(), AmplModel::dump(), StochModel::expandStagesOfComp(), StochModel::expandToFlatModel(), fill_model_list_(), AmplModel::find_var_ref_in_context(), modified_write(), print_entries(), print_model(), printBrief(), process_model(), AmplModel::removeComp(), AmplModel::setGlobalNameRecursive(), setTo(), StochModelComp::transcribeToModelComp(), write_ampl_for_submodel_(), and AmplModel::writeTaggedComponents().
CompDescr* ModelComp::value [protected] |
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().