Defines | Functions

ModelComp.cpp File Reference

#include "ModelComp.h"
#include "AmplModel.h"
#include "backend.h"
#include "GlobalVariables.h"
#include "nodes.h"
#include <cassert>
#include <cstdlib>
#include <iostream>

Defines

#define LogMC(X)

Functions

void modified_write (ostream &fout, ModelComp *comp)
 Writes out a component of a model.
static int buildModelPath (const AmplModel *path[], const AmplModel *model)
string getGlobalName (const ModelComp *node, const SyntaxNode *opn, const AmplModel *current_model, int witharg)
 Find the global name of the model component pointed to by 'node':

  • Generate the global name of a model component by pre-pending the names of models on the model-tree up to the model of this component to the name 'Flow' becomes 'MCNF_Net_Flow'.

string getGlobalNameNew (const ModelComp *node, const SyntaxNode *opn, const AmplModel *current_model, int witharg)
 New version of getGlobalName that does *not* use the addIndex stack but creates the modified argument list by looking at the indexing expressions of the submodel tree leading to this ModelComp.

Define Documentation

#define LogMC (   X  ) 

Function Documentation

static int buildModelPath ( const AmplModel path[],
const AmplModel model 
) [static]

References AmplModel::parent.

Referenced by getGlobalName(), and getGlobalNameNew().

string getGlobalName ( const ModelComp node,
const SyntaxNode opn,
const AmplModel current_model,
int  witharg 
)

Find the global name of the model component pointed to by 'node':

  • Generate the global name of a model component by pre-pending the names of models on the model-tree up to the model of this component to the name 'Flow' becomes 'MCNF_Net_Flow'.

  • If 'witharg' is set, then the argument list is also generated: The argument list is composed of + dummy variables of indexing expressions of block up to model_of_comp + original arguments of the component (as given in the SML file) The appropriate argument list depends on both the model of the component and in which model this instance of referal of the ModelComp is (the current_model) Basically we need to identify the common ancestor model of the current_model and the model_of_comp. The arguments originating from block indexing expressions between here and the model_of_comp are already included in the argument list of the ModelComp. Anything below needs to be prepended to the argument list
Parameters:
[in] node The model component in question.
[in] opn The node (IDREF) of the model component (needed for the (local) argument list).
[in] current_model The block for which this is written: indexing is given in the original SML model wrt a given node in the model tree. FIXME: what happens if the component referenced in the definition is not in the same model_tree node as the component to be defined? In the original ampl file this is correct, since the indexing will be given relative to the current_model. However the local indexing is lost(?) in the node representation => I don't think so, it is still encoded in the rest of the SyntaxNode structure
[in] witharg WITHARG: if the argument list should be processed, NOARG: only the global name, ONLYARG: only the argument list.
Precondition:
l_addIndex needs to be set. It is assumed that this is a stack of indexing expressions from the root at least to the common ancestor node (likely set up to the current_model).

References buildModelPath(), SyntaxNode::getArgumentList(), ModelComp::id, l_addIndex, ModelComp::model, AmplModel::name, SyntaxNode::nchild(), NOARG, AmplModel::parent, SyntaxNode::printDummyVar(), and WITHARG.

Referenced by AmplModel::createExpandedModel(), modified_write(), and process_model().

string getGlobalNameNew ( const ModelComp node,
const SyntaxNode opn,
const AmplModel current_model,
int  witharg 
)

New version of getGlobalName that does *not* use the addIndex stack but creates the modified argument list by looking at the indexing expressions of the submodel tree leading to this ModelComp.

Parameters:
[in] node The model component in question.
[in] opn The node (IDREF) of the model component (needed for the (local) argument list).
[in] current_model The block for which this is written: indexing is given in the original SML model wrt a given node in the model tree.
[in] witharg WITHARG: if the argument list should be processed, NOARG: only the global name, ONLYARG: only the argument list.

Find the global name of the model component pointed to by 'node':

  • Generate the global name of a model component by pre-pending the names of models on the model-tree up to the model of this component to the name 'Flow' becomes 'MCNF_Net_Flow'
  • If 'witharg' is set, then the argument list is also generated: The argument list is composed of + dummy variables of indexing expressions of block up to model_of_comp + original arguments of the component (as given in the SML file) The appropriate argument list depends on both the model of the component and in which model this instance of referal of the ModelComp is (the current_model). Basically we need to identify the common ancestor model of the current_model and the model_of_comp. The arguments originating from block indexing expressions between here and the model_of_comp are already included in the argument list of the ModelComp. Anything below needs to be prepended to the argument list.

References buildModelPath(), SyntaxNode::getArgumentList(), SyntaxNodeIx::getDummyVarExpr(), SyntaxNodeIx::getNComp(), ModelComp::id, ModelComp::indexing, ModelComp::model, AmplModel::name, SyntaxNode::nchild(), NOARG, AmplModel::node, AmplModel::parent, SyntaxNode::printDummyVar(), and WITHARG.

Referenced by SyntaxNodeIDREF::put().

void modified_write ( ostream &  fout,
ModelComp comp 
)

Writes out a component of a model.

Components can be modified: if this is down into a submodel, then

  • all declarations get new indexing expressions appended to it
  • all references to entities get new subscripts attached to it.
Parameters:
[in] fout The file to write to.
[in] comp The component definition to write out.
Precondition:
Depends on l_addIndex: currently applicable indexing expresssions.

Prints the global definition of the given ModelComponent to the given file.

  1. get the global name of the model component
  2. prepend all indexing expressions on the stack to the indexing expression of this entity
  3. for all components that are referenced in the definition
    1. use their global name
    2. prepend the dummy variables for all indexing expressions on the stack to the argument list

The last part is simply done by a call to (comp->attributes)->print() (SyntaxNode::print) (with SyntaxNode::use_global_names set to true => the argument list version of ModelComp::getGlobalName is called)

References ModelComp::attributes, ModelComp::compTypes, add_index::dummyVar, SyntaxNode::front(), getGlobalName(), SyntaxNode::getOpCode(), ModelComp::id, ModelComp::indexing, l_addIndex, ModelComp::model, NOARG, AmplModel::parent, prt_modwrite, add_index::set, TCON, TMAX, TMIN, TMODEL, and ModelComp::type.