- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Mers::Models::Base::BaseModel Class Reference

`#include <BaseModel.h>`

Inheritance diagram for Mers::Models::Base::BaseModel:

[legend]
Collaboration diagram for Mers::Models::Base::BaseModel:

[legend]
List of all members.

## Public Member Functions
| BaseModel (char const *myName="Basic Model")
| BaseModel (BaseModel const &other)
virtual | ~BaseModel ()
int | setName (char const *newName)
char const * | getName () const
int | addDomain (char const *domainName, BaseModelValueArray &values, BaseModelDomain::DomainType domainType=BaseModelDomain::Normal)
int | addDomain (BaseModelDomain *domain)
BaseModelDomain * | getDomain (unsigned int domainUID)
BaseModelDomain const * | getDomain (unsigned int domainUID) const
BaseModelDomain * | getDomain (char const *domainName)
BaseModelDomain const * | getDomain (char const *domainName) const
BaseModelDomainArray * | getDomains ()
BaseModelDomainArray const * | getDomains () const
virtual int | addVariable (char const *variableName, BaseModelVariable::VariableType variableType, BaseModelDomain *domain)
virtual int | addVariable (BaseModelVariable *variable)
BaseModelVariable * | getVariable (unsigned int variableUID)
BaseModelVariable const * | getVariable (unsigned int variableUID) const
BaseModelVariable * | getVariable (char const *variableName)
BaseModelVariable const * | getVariable (char const *variableName) const
BaseModelVariableArray * | getVariables ()
BaseModelVariableArray const * | getVariables () const
BaseModelAssignment * | getAssignment (char const *variableName, char const *valueName, BaseModelAssignment::OperatorType opType=BaseModelAssignment::Positive) const
void | clear ()
bool | operator== (BaseModel const &other) const
bool | operator!= (BaseModel const &other) const
BaseModel const & | operator= (BaseModel const &other)
virtual void | print (std::ostream &out) const
## Protected Member Functions
virtual BaseModelAssignment * | newAssignment (BaseModelVariable const *variable, BaseModelValue const *value, BaseModelAssignment::OperatorType opType) const
virtual BaseModelVariable * | newVariable (char const *variableName, unsigned int variableUID, BaseModelVariable::VariableType variableType, BaseModelDomain *domain)
virtual BaseModelDomain * | newDomain (char const *domainName, unsigned int domainUID, BaseModelValueArray &values, BaseModelDomain::DomainType domainType)
virtual BaseModelDomainArray * | newDomainArray (BaseModelDomainArray const *other=NULL)
virtual BaseModelVariableArray * | newVariableArray (BaseModelVariableArray const *other=NULL)
virtual void | destroy ()
virtual int | copy (BaseModel const &other)
## Protected Attributes
char * | name
| the model name
BaseModelDomainArray * | domains
| all the domains of the model
BaseModelVariableArray * | variables
| all the variables of the model

## Detailed Description

A basic model that contains a reference to all the domains and all the variables. It also does assignment generation from the variables and values.

Author:
  Paul H. Elliott

Definition at line 38 of file BaseModel.h.

## Constructor & Destructor Documentation

BaseModel::BaseModel | ( | char const * | myName = `"Basic Model"` | ) |

Creates an empty model named myName

Parameters:

  | myName | the name of this model, setting to NULL will give this model no name

Definition at line 31 of file BaseModel.cpp.

References domains, name, newDomainArray(), newVariableArray(), setName(), and variables.

Here is the call graph for this function:

BaseModel::BaseModel | ( | BaseModel const & | other | ) |

Creates the new model by copying all of the components from the other model Note that this can be a very expensive operation as all the BaseModelDomains, BaseModelValues, and BaseModelVariables will be duplicated

Parameters:

  | other | the model will be copied to this new model

Definition at line 47 of file BaseModel.cpp.

References copy().

Here is the call graph for this function:

BaseModel::~BaseModel | ( |  | ) | `[virtual]`

Deletes all of the Domains/Values/Variables in this model

Definition at line 55 of file BaseModel.cpp.

References destroy().

Here is the call graph for this function:

## Member Function Documentation

int BaseModel::setName | ( | char const * | newName | ) |

Sets the name of this model to newName - this function makes a copy of the string if the string is NULL, this model will not have a name

Parameters:

  | newName | the new name of the model

Returns:
  0 on success or a positive number if there was insufficient memory to copy newName

Definition at line 62 of file BaseModel.cpp.

References name, and BaseModelUtils::setName().

Referenced by BaseModel(), and copy().

Here is the call graph for this function:

char const * BaseModel::getName | ( |  | ) | const

Returns the current name of the model. This may be NULL

Returns:
  the current name of the model or NULL if none present

Definition at line 69 of file BaseModel.cpp.

References name.

Referenced by Mers::Models::CCA::CCAModel::operator==(), and Mers::Models::CCA::CCAModel::print().

int BaseModel::addDomain | ( | char const * | domainName,
|  | BaseModelValueArray & | values,
|  | BaseModelDomain::DomainType | domainType = `BaseModelDomain::Normal` |
| ) |  |  |

appends a new domain into the model using the construction parameters passed to this function This function calls BaseModel::newDomain to obtain the new domain

Parameters:

  | domainName | The name of the new domain. This domainName should be unique for this model (non-NULL). This will be copied
  | values | The list of values that make up the new domain. This list has its contents moved over to the new domain so will be empty after this function the value ordering is maintained in the move.
  | domainType | the domain type.

Returns:
  0 on success or a positive number if ther was insufficient memory to create the new domain

Definition at line 76 of file BaseModel.cpp.

References domains, Mers::Utils::Containers::DynamicArray::getLength(), Mers::Utils::Containers::DynamicArray::makeEmpty(), and newDomain().

Referenced by Mers::Models::CCA::createSimpleTechsat21Model(), Mers::Models::CCA::createValveDriverModel(), Mers::Models::CCA::CCAModel::insert_domain(), tut::BMHelper::loadModelData(), Mers::Models::CCA::Io::Mof::MOFReader::loadMOFFromString(), TestSuiteParser::variable(), and TestSuiteParser::variableWithProbs().

Here is the call graph for this function:

int BaseModel::addDomain | ( | BaseModelDomain * | domain | ) |

appends the domain to the list of domains This object will assume ownership of the domain so it should not be deleted by an outside source.

Parameters:

  | domain | the domain being added to the current list of domains. It should not be deleted by the calling program. If there was insufficient memory to add the domain, this procedure will immediately delete the domain.

Returns:
  0 on success or a positive number if there was insufficient memory to add the domain

Definition at line 96 of file BaseModel.cpp.

References domains, Mers::Utils::Containers::DynamicArray::getLength(), Mers::Models::Base::BaseModelDomainArray::pushBack(), and Mers::Models::Base::BaseModelDomain::setUID().

Here is the call graph for this function:

BaseModelDomain * BaseModel::getDomain | ( | unsigned int | domainUID | ) |

returns a handle to the domain that matches the domainUID or NULL if none is found. This function will return NULL if the domain requested is out of range

Parameters:

  | domainUID | the UID of the domain to find

Returns:
  the domain, if found, or NULL

Definition at line 110 of file BaseModel.cpp.

References domains.

Referenced by copy(), Mers::Models::CCA::CCAModel::get_domain_p(), Mers::Models::CCA::CCAModel::insert_variable(), tut::BMHelper::loadModelData(), TestSuiteParser::variable(), and TestSuiteParser::variableWithProbs().

BaseModelDomain const * BaseModel::getDomain | ( | unsigned int | domainUID | ) | const

returns a handle to the domain that matches the domainUID or NULL if none is found. This function will return NULL if the domain requested is out of range

Parameters:

  | domainUID | the UID of the domain to find

Returns:
  the domain, if found, or NULL

Definition at line 117 of file BaseModel.cpp.

References domains.

BaseModelDomain * BaseModel::getDomain | ( | char const * | domainName | ) |

returns a handle to the domain that matches the domainName or NULL if none is found. the search for the domain name is case sensitive.

Parameters:

  | domainName | the name of the domain to find

Returns:
  the domain, if found, or NULL

Definition at line 124 of file BaseModel.cpp.

References domains, and Mers::Models::Base::BaseModelDomainArray::find().

Here is the call graph for this function:

BaseModelDomain const * BaseModel::getDomain | ( | char const * | domainName | ) | const

returns a handle to the domain that matches the domainName or NULL if none is found. the search for the domain name is case sensitive.

Parameters:

  | domainName | the name of the domain to find

Returns:
  the domain, if found, or NULL

Definition at line 131 of file BaseModel.cpp.

References domains, and Mers::Models::Base::BaseModelDomainArray::find().

Here is the call graph for this function:

BaseModelDomainArray * BaseModel::getDomains | ( |  | ) |

returns a handle to the list of domains maintained by this model.object

Returns:
  the handle to the internal list of domains maintained by this model object

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 138 of file BaseModel.cpp.

References domains.

Referenced by tut::BMHelper::loadModelData(), and Mers::Models::Base::Io::Mof::BaseModelReader::saveBaseModel().

BaseModelDomainArray const * BaseModel::getDomains | ( |  | ) | const

returns a handle to the list of domains maintained by this model.object

Returns:
  the handle to the internal list of domains maintained by this model object

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 145 of file BaseModel.cpp.

References domains.

int BaseModel::addVariable | ( | char const * | variableName,
|  | BaseModelVariable::VariableType | variableType,
|  | BaseModelDomain * | domain |
| ) |  |  | `[virtual]`

appends a new variable into the model using the construction parameters passed to this function This function calls BaseModel::newVariable to obtain the new variable

Parameters:

  | variableName | a model-unique name for the new variable. This will be copied.
  | variableType | the type of the new variable
  | domain | the domain of the new variable. This should referenece a domain in this model

Returns:
  0 on success or a positive value if there was insufficient memory to complete the requested addition

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 152 of file BaseModel.cpp.

References Mers::Utils::Containers::DynamicArray::getLength(), newVariable(), and variables.

Referenced by tut::BMHelper::loadModelData(), TestSuiteParser::variable(), and TestSuiteParser::variableWithProbs().

Here is the call graph for this function:

int BaseModel::addVariable | ( | BaseModelVariable * | variable | ) | `[virtual]`

appends the variable into the model

Parameters:

  | variable | the variable being added. This model object assumes ownership of the variable object and will delete it when it terminates so do not delete this object elsewhere. The variable should have a unique name for this model.

Returns:
  0 on success or a positive value if there was insufficient memory to complete the requested addition

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 168 of file BaseModel.cpp.

References Mers::Models::Base::BaseModelVariableArray::pushBack(), and variables.

Here is the call graph for this function:

BaseModelVariable * BaseModel::getVariable | ( | unsigned int | variableUID | ) |

returns the variable with the matching variableUID.

Parameters:

  | variableUID | the UID of the variable to find

Returns:
  the requested variable or NULL if the UID was out of range

Definition at line 181 of file BaseModel.cpp.

References variables.

Referenced by Mers::Models::CCA::CCAModel::addAutomaton(), Mers::Models::CCA::CCAModel::addVariable(), Mers::Estimation::Discrete::assign(), Mers::Models::CCA::CCAModel::assignment_(), Mers::Models::Base::Io::Xml::Sax::BMAssignmentCH::endElement(), Mers::Models::CCA::CCAModel::get_assignment(), Mers::Models::CCA::CCAModel::get_variable_p(), getAssignment(), Mers::Models::CCA::CCAModel::insert_transition(), Mers::Estimation::Discrete::read_trajectory(), Mers::Solvers::Entailment::GI::GoalInterpreter::updateGoal(), and Mers::Estimation::Discrete::variableExists().

BaseModelVariable const * BaseModel::getVariable | ( | unsigned int | variableUID | ) | const

returns the variable with the matching variableUID.

Parameters:

  | variableUID | the UID of the variable to find

Returns:
  the requested variable or NULL if the UID was out of range

Definition at line 188 of file BaseModel.cpp.

References variables.

BaseModelVariable * BaseModel::getVariable | ( | char const * | variableName | ) |

returns the variable requested if available or NULL if not found. Search is case sensitive.

Parameters:

  | variableName | name of the variable to find

Returns:
  the requrested variable or NULL if not found

Definition at line 195 of file BaseModel.cpp.

References Mers::Models::Base::BaseModelVariableArray::find(), and variables.

Here is the call graph for this function:

BaseModelVariable const * BaseModel::getVariable | ( | char const * | variableName | ) | const

returns the variable requested if available or NULL if not found. Search is case sensitive.

Parameters:

  | variableName | name of the variable to find

Returns:
  the requrested variable or NULL if not found

Definition at line 202 of file BaseModel.cpp.

References Mers::Models::Base::BaseModelVariableArray::find(), and variables.

Here is the call graph for this function:

BaseModelVariableArray * BaseModel::getVariables | ( |  | ) |

returns the internal list of variables

Returns:
  a handle to the list of variables maintained by this model

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 209 of file BaseModel.cpp.

References variables.

Referenced by Mers::Estimation::Discrete::CompiledME::CompiledModeEstimator::generateTrajectories(), Mers::Executives::DeductiveController::DCInterface::init(), TestSuiteParser::probTest(), Mers::Estimation::Discrete::read_trajectory(), Mers::Models::Base::Io::Mof::BaseModelReader::saveBaseModel(), Mers::Executives::DeductiveController::DCInterface::setExecutionInterface(), Mers::Executives::DeductiveController::Command::CommandDispatcher::setModel(), Mers::Executives::DeductiveController::TaskFactory::TaskFactory(), TestSuiteParser::test(), and Mers::Estimation::Discrete::variableExists().

BaseModelVariableArray const * BaseModel::getVariables | ( |  | ) | const

returns the internal list of variables

Returns:
  a handle to the list of variables maintained by this model

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 216 of file BaseModel.cpp.

References variables.

BaseModelAssignment * BaseModel::getAssignment | ( | char const * | variableName,
|  | char const * | valueName,
|  | BaseModelAssignment::OperatorType | opType = `BaseModelAssignment::Positive` |
| ) |  |  | const

returns a new assignment between a variable and value. This routine uses BaseModel::getVariable(variableName) and BaseModelVariable;:getValue(valueName) to find the variable and value objects and then returns a new assignment generated from the function BaseModel::newAssignment(BaseModelVariable, BaseModelValue); If the variable or value is not found, this function returns NULL. The returned assignment should be deleted after use. Derived classes should implement BaseModel::newAssignment to change the type of assignment returned

Parameters:

  | variableName | the name of the variable used in the assignment the variable search is case sensitive
  | valueName | the name of the value in the domain of the variable the value search is case sensitive
  | opType | the operator used in the assignment

Returns:
  an assignment between the variable and value. NULL if the variable or value was not found or if there was insufficient memory

Definition at line 223 of file BaseModel.cpp.

References Mers::Models::Base::BaseModelVariable::getValue(), getVariable(), and newAssignment().

Referenced by Mers::Models::CCA::CCAModel::get_assignment(), Mers::Models::CCA::CCAModel::insert_transition(), TestSuiteParser::literal(), Mers::Executives::DeductiveController::DCInterface::loadInitialState(), Mers::Models::CCA::CCAModel::set_state_constraint(), and Mers::Models::CCA::CCAModel::set_state_type().

Here is the call graph for this function:

void BaseModel::clear | ( |  | ) |

Deletes all the domains and variables in this model object as well as the model name. This creates a clean slate for creating a new model with the same objects. This is done by calling destroy()

Definition at line 257 of file BaseModel.cpp.

References destroy().

Here is the call graph for this function:

bool BaseModel::operator== | ( | BaseModel const & | other | ) | const

Compares the two models deeply to see if they're the same. This can be rather expensive.

Parameters:

  | other | The other model being compared to this model.

Returns:
  true if this model is the same as the other model.

Definition at line 272 of file BaseModel.cpp.

References domains, name, and variables.

Referenced by operator!=().

bool Mers::Models::Base::BaseModel::operator!= | ( | BaseModel const & | other | ) | const`[inline]`

Compares the two models deeply to see if they're the same. This can be rather expensive.

Parameters:

  | other | The other model being compared to this model.

Returns:
  false if this model is the same as the other model.

Definition at line 269 of file BaseModel.h.

References operator==().

Here is the call graph for this function:

BaseModel const & BaseModel::operator= | ( | BaseModel const & | other | ) |

copies the contents of the other model to the current model if memory allows Note that this is an expensive operation as all the data structures in other are duplicated.

Parameters:

  | other | the object being copied

Returns:
  the BaseModel object other

Definition at line 264 of file BaseModel.cpp.

References copy().

Here is the call graph for this function:

void BaseModel::print | ( | std::ostream & | out | ) | const`[virtual]`

Prints this model's information to out Overload this to change what's printed for a derived BaseModel object

Parameters:

  | out | the ostream to print this object's information to

Implements Mers::Utils::Lang::BaseModelObject.

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 283 of file BaseModel.cpp.

References domains, name, and variables.

BaseModelAssignment * BaseModel::newAssignment | ( | BaseModelVariable const * | variable,
|  | BaseModelValue const * | value,
|  | BaseModelAssignment::OperatorType | opType |
| ) |  |  | const`[protected, virtual]`

called when a new assignment is needed. The assignment should be created with the variable and value pair. Derived classes should override this function if they wish to use a Derived BaseModelAssignment class.

Parameters:

  | variable | the variable of the assignment
  | value | the value of the assignment that is in the domain of the variable
  | opType | the operator of the assignment

Returns:
  a new assignment object or NULL if there is insufficient memory to create a new assignment object

Definition at line 302 of file BaseModel.cpp.

Referenced by getAssignment().

BaseModelVariable * BaseModel::newVariable | ( | char const * | variableName,
|  | unsigned int | variableUID,
|  | BaseModelVariable::VariableType | variableType,
|  | BaseModelDomain * | domain |
| ) |  |  | `[protected, virtual]`

called when a new variable is needed. The variable should be created with the creation parameters passed to this function Derived classes should override this function if they wish to use a Derived BaseModelVariable class

Parameters:

  | variableName | the name of the new variable. This name should be copied in the creation process.
  | variableUID | the UID of the variable. This will always be unique and will reflect the insertion point of the variable in the BaseModelVariableArray
  | variableType | the variable type as specified by BaseModelVariable::VariableType
  | domain | a handle to this variable's domain.

Returns:
  a new variable object or NULL if there was insufficient memory

Definition at line 310 of file BaseModel.cpp.

Referenced by addVariable().

BaseModelDomain * BaseModel::newDomain | ( | char const * | domainName,
|  | unsigned int | domainUID,
|  | BaseModelValueArray & | values,
|  | BaseModelDomain::DomainType | domainType |
| ) |  |  | `[protected, virtual]`

called when a new domain is needed. The domain should be created with the creation parameters passed to this function Derived classes should override this function if they wish to use a Derived BaseModelDomain class (This function also handles BaseModelDoubleDomain, BaseModelIntegerDomain, and BaseModelStringDomain)

Parameters:

  | domainName | the name of the new domain. This name should be copied in the creation process.
  | domainUID | the UID of the domain. This will always be unique and will reflect the insertion point of the domain in the BaseModelDomainArray
  | values | a handle to the values of the domain. The contents of this array should be moved to the new domain rather than copied. The values array is expected to be empty after the return of this function.
  | domainType | the domain type as specified by BaseModelDomain::DomainType

Returns:
  a new domain object or NULL if there was insufficient memory

Definition at line 319 of file BaseModel.cpp.

References Mers::Utils::Containers::DynamicArray::getLength(), Mers::Utils::Containers::DynamicArray::makeEmpty(), and Mers::Models::Base::BaseModelDomain::pushBack().

Referenced by addDomain().

Here is the call graph for this function:

BaseModelDomainArray * BaseModel::newDomainArray | ( | BaseModelDomainArray const * | other = `NULL` | ) | `[protected, virtual]`

returns a new BaseModelDomainArray for use by this model object Derived classes should override this function to use a different BaseModelDomainArray class. A parameter of NULL indicates that the an empty array should be created

Parameters:

  | other | if NULL, create an empty BaseModelDomainArray, otherwise use the data in BaseModelDomainArray to create the BaseModelDomainArray

Returns:
  the new BaseModelDomainArray

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 364 of file BaseModel.cpp.

Referenced by BaseModel(), and copy().

BaseModelVariableArray * BaseModel::newVariableArray | ( | BaseModelVariableArray const * | other = `NULL` | ) | `[protected, virtual]`

returns a new BaseModelVariableArray for use by this model object Derived classes should override this function to use a different BaseModelVariableArray class. A parameter of NULL indicates that the an empty array should be created

Parameters:

  | other | if NULL, create an empty BaseModelVariableArray, otherwise use the data in BaseModelVariableArray to create the BaseModelVariableArray

Returns:
  the new BaseModelVariableArray

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 374 of file BaseModel.cpp.

Referenced by BaseModel(), and copy().

void BaseModel::destroy | ( |  | ) | `[protected, virtual]`

Destroys the contents of this model object, freeing all allocated memory and reseting all values in preperation for a copy or delete operation. Derived classes should ensure this function is called as well

Reimplemented in Mers::Models::CCA::CCAModel.

Definition at line 384 of file BaseModel.cpp.

References domains, Mers::Utils::Containers::DynamicArray::makeEmpty(), name, and variables.

Referenced by clear(), copy(), and ~BaseModel().

Here is the call graph for this function:

int BaseModel::copy | ( | BaseModel const & | other | ) | `[protected, virtual]`

copies the contents of the other object to this object Derived classes that define this function should ensure that this function is also called: BaseModel::copy(other);

Parameters:

  | other | the model being copied to this model

Returns:
  0 on success or a positive number if there was insufficient memory to copy the model. It returns a negative number if it was only unable to copy the name. This (negative number) can be considered just a warning.

Definition at line 405 of file BaseModel.cpp.

References destroy(), domains, getDomain(), Mers::Utils::Containers::DynamicArray::getLength(), name, newDomainArray(), newVariableArray(), setName(), and variables.

Referenced by BaseModel(), and operator=().

Here is the call graph for this function:

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

- /Users/fpy/titan-1-5-MBARI/Mers/Models/Base/BaseModel.h
- /Users/fpy/titan-1-5-MBARI/Mers/Models/Base/BaseModel.cpp