Previous Page Parent Page Next Page TOC

Dependency Graph

Each mathematical object knows the prerequisites, which need to be up to date for the object to be calculated correctly. Based on these prerequisites a dependency graph which can be traversed in the direction of prerequisites and dependents can be constructed. This dependency graph can than be used to determine a sequence of calculations which is sufficient to update a list of required objects based on a list of changed objects.

CDependencyGraph

Interface

 
  /**
   * Constructor
   */
  CMathDependencyGraph();

  /**
   * Destructor
   */
  ~CMathDependencyGraph();

  /**
   * Clear the whole dependency tree
   */
  void clear();

  /**
   * Add an object and all its prerequisites to the tree
   * @param const CObjectInterface * pObject
   * @return std::map< const CObjectInterface *, CMathDependencyNode * >::iterator itObject
   */
  iterator addObject(const CObjectInterface * pObject);

  /**
   * Construct a update sequence for the given context. Please note the calculated objects
   * must be calculated based on the same changed values and context.
   * @param const CMath::SimulationContextFlag & context
   * @param CObjectInterface::UpdateSequence & updateSequence)
   * @param const CObjectInterface::ObjectSet & changedObjects
   * @param const CObjectInterface::ObjectSet & requestedObjects
   * @param const CObjectInterface::ObjectSet & calculatedObjects (default: none)
   * @return bool success
   */
  bool getUpdateSequence(CObjectInterface::UpdateSequence & updateSequence,
                         const CMath::SimulationContextFlag & context,
                         const CObjectInterface::ObjectSet & changedObjects,
                         const CObjectInterface::ObjectSet & requestedObjects,
                         const CObjectInterface::ObjectSet & calculatedObjects = CObjectInterface::ObjectSet());

  void exportDOTFormat(std::ostream & os, const std::string & name) const;


CDependencyNode

This class represents the nodes and their edges to dependent and prerequisite nodes. The information is duplicated for performance reasons. It is not expected that any other class except CDependencyGraph will utilizes this object.

Interface

 
  /**
   * Specific constructor
   * @param const CObjectInterface * pObject
   */
  CMathDependencyNode(const CObjectInterface * pObject);

  /**
   * Destructor
   */
  ~CMathDependencyNode(void);

  /**
   * Retrieve a pointer to the object the node is representing
   * @return   const CObjectInterface * pObject
   */
  const CObjectInterface * getObject() const;

  /**
   * Add a prerequisite
   * @param CMathDependencyNode * pNode
   */
  void addPrerequisite(CMathDependencyNode * pNode);

  /**
   * Retrieve the prerequisites
   * @return std::vector< CMathDependencyNode * > prerequisites
   */
  std::vector< CMathDependencyNode * > & getPrerequisites();

  /**
   * Add a dependent
   * @param CMathDependencyNode * pNode
   */
  void addDependent(CMathDependencyNode * pNode);

  /**
   * Retrieve the dependents
   * @return std::vector< CMathDependencyNode * > dependents
   */
  std::vector< CMathDependencyNode * > & getDependents();

  /**
   * Update the state of all dependents (and dependents thereof) to changed,
   * @param const CMath::SimulationContextFlag & context
   * @param const CObjectInterface::ObjectSet & changedObjects
   * @return bool success
   */
  bool updateDependentState(const CMath::SimulationContextFlag & context,
                            const CObjectInterface::ObjectSet & changedObjects);

  /**
   * Update the state of all prerequisites (and prerequisites thereof) to requested.
   * @param const CMath::SimulationContextFlag & context
   * @param const CObjectInterface::ObjectSet & changedObjects
   * @return bool success
   */
  bool updatePrerequisiteState(const CMath::SimulationContextFlag & context,
                               const CObjectInterface::ObjectSet & changedObjects);

  /**
   * Build the sequence of objects which need to be updated to calculate the object value.
   * @param const CMath::SimulationContextFlag & context
   * @param std::vector< CObjectInterface * > & updateSequence
   * @return bool success
   */
  bool buildUpdateSequence(const CMath::SimulationContextFlag & context,
                           std::vector< CObjectInterface * > & updateSequence);

  /**
   * Set whether the current node has changed its value
   * @param const bool & changed
   */
  void setChanged(const bool & changed);

  /**
   * Check whether the current nodes value is changed
   * @return const bool & isChanged
   */
  const bool & isChanged() const;

  /**
   * Set whether the current node's value is requested
   * @param const bool & requested
   */
  void setRequested(const bool & requested);

  /**
   * Check whether the current node's value is requested
   * @param const bool & isRequested
   */
  const bool & isRequested() const;