diff options
Diffstat (limited to 'SA_POP/SANet')
-rw-r--r-- | SA_POP/SANet/SANet.cpp | 476 | ||||
-rw-r--r-- | SA_POP/SANet/SANet.h | 328 | ||||
-rw-r--r-- | SA_POP/SANet/SANetFileIn.cpp | 219 | ||||
-rw-r--r-- | SA_POP/SANet/SANetFileIn.h | 64 | ||||
-rw-r--r-- | SA_POP/SANet/SANet_Exceptions.cpp | 47 | ||||
-rw-r--r-- | SA_POP/SANet/SANet_Exceptions.h | 79 | ||||
-rw-r--r-- | SA_POP/SANet/SANet_Types.h | 208 | ||||
-rw-r--r-- | SA_POP/SANet/SANode.cpp | 1020 | ||||
-rw-r--r-- | SA_POP/SANet/SANode.h | 393 | ||||
-rw-r--r-- | SA_POP/SANet/XML_SANet.cpp | 3467 | ||||
-rw-r--r-- | SA_POP/SANet/XML_SANet.hpp | 1830 |
11 files changed, 8131 insertions, 0 deletions
diff --git a/SA_POP/SANet/SANet.cpp b/SA_POP/SANet/SANet.cpp new file mode 100644 index 00000000000..e46f0d94f23 --- /dev/null +++ b/SA_POP/SANet/SANet.cpp @@ -0,0 +1,476 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file SANet.cpp + * + * This file contains the Network class implementation for spreading + * activation networks. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#include <map> +#include <iostream> +#include "SANet_Types.h" +#include "SANet.h" +#include "SANode.h" +#include "SANet_Exceptions.h" + +#if !defined (SANET_STANDALONE) +#include "SA_POP_Types.h" +#endif /* SANET_STANDALONE not defined */ + +using namespace SANet; + + +SANet::Network::Network (void) +: step_ (0) +{ + // Clear maps. + this->task_nodes_.clear (); + this->cond_nodes_.clear (); + this->precond_links_.clear (); + this->effect_links_.clear (); + this->goals_.clear (); +}; + +SANet::Network::~Network () +{ + // Deallocate task nodes. + for (TaskNodeMap::iterator node_iter = task_nodes_.begin (); + node_iter != task_nodes_.end (); node_iter++) + { + delete node_iter->second; + } + + // Deallocate condition nodes. + for (CondNodeMap::iterator node_iter = cond_nodes_.begin (); + node_iter != cond_nodes_.end (); node_iter++) + { + delete node_iter->second; + } +}; + +void SANet::Network::add_task (TaskID ID, std::string name, MultFactor atten_factor, + TaskCost cost, Probability prior_prob) +{ + // If this ID has already been used, throw exception. + if (task_nodes_.find (ID) != task_nodes_.end ()) { + throw Duplicate_ID (); + } + if (cond_nodes_.find (ID) != cond_nodes_.end ()) { + throw Duplicate_ID (); + } + + // Task node pointer. + TaskNode *node; + + // Add task node, throwing exception if insertion fails. + node = new TaskNode (ID, name, atten_factor, cost, prior_prob); + if (!(task_nodes_.insert (std::make_pair (ID, node))).second) + { + throw Insertion_Error (); + } +}; + + +void SANet::Network::add_cond (CondID ID, std::string name, MultFactor atten_factor, + Probability true_prob, Probability false_prob, + Utility goal_util, CondKind cond_kind) +{ + // If this ID has already been used, throw exception. + if (task_nodes_.find (ID) != task_nodes_.end ()) { + throw Duplicate_ID (); + } + if (cond_nodes_.find (ID) != cond_nodes_.end ()) { + throw Duplicate_ID (); + } + + // Condition node pointer. + CondNode *node; + + // Add condition node, throwing exception if insertion fails. + node = new CondNode (ID, name, atten_factor, + true_prob, false_prob, goal_util, cond_kind); + if (!(cond_nodes_.insert (std::make_pair (ID, node))).second) + { + throw Insertion_Error (); + } + + if (goal_util != 0) + this->goals_.insert (std::make_pair (ID, goal_util)); +}; + +void SANet::Network::add_precond_link (CondID cond_ID, TaskID task_ID, + Probability true_prob, Probability false_prob, + PortID port_ID) +{ + // Find task node pointer, throwing exception if not found. + TaskNodeMap::iterator task_iter = task_nodes_.find (task_ID); + if (task_iter == task_nodes_.end ()) { + throw UnknownNode (); + } + TaskNode *task_node = task_iter->second; + + // Find condition node pointer, throwing exception if not found. + CondNodeMap::iterator cond_iter = cond_nodes_.find (cond_ID); + if (cond_iter == cond_nodes_.end ()) { + throw UnknownNode (); + } + CondNode *cond_node = cond_iter->second; + + // Add link to task node. + task_node->add_precond (cond_ID, cond_node, true_prob, false_prob); + + // Add link to port map. + this->precond_links_.insert (std::make_pair (std::make_pair (cond_ID, + task_ID), port_ID)); +}; + +void SANet::Network::add_effect_link (TaskID task_ID, CondID cond_ID, + LinkWeight weight, PortID port_ID) +{ + // Find task node pointer, throwing exception if not found. + TaskNodeMap::iterator task_iter = task_nodes_.find (task_ID); + if (task_iter == task_nodes_.end ()) { + throw UnknownNode (); + } + TaskNode *task_node = task_iter->second; + + // Find condition node pointer, throwing exception if not found. + CondNodeMap::iterator cond_iter = cond_nodes_.find (cond_ID); + if (cond_iter == cond_nodes_.end ()) { + throw UnknownNode (); + } + CondNode *cond_node = cond_iter->second; + + // Add link. + task_node->add_effect (cond_ID, cond_node, weight); + + // Add link to port map. + this->effect_links_.insert (std::make_pair (std::make_pair (task_ID, + cond_ID), port_ID)); +}; + +void SANet::Network::print (std::basic_ostream<char, std::char_traits<char> >& strm, + bool verbose) +{ + // Print current step. + strm << "Current Step: " << step_ << std::endl << std::endl; + + // Print all task nodes. + for (TaskNodeMap::iterator node_iter = task_nodes_.begin (); + node_iter != task_nodes_.end (); node_iter++) + { + node_iter->second->print (strm, verbose); + strm << std::endl; + } + + // Print all condition nodes. + for (CondNodeMap::iterator node_iter = cond_nodes_.begin (); + node_iter != cond_nodes_.end (); node_iter++) + { + node_iter->second->print (strm, verbose); + strm << std::endl; + } + strm << std::endl; +}; + +// Print links and ports. +void SANet::Network::print_link_ports (std::basic_ostream<char, + std::char_traits<char> >& strm, + bool verbose) +{ + + // Print all precondition links. + strm << "Precondition Links: " << std::endl; + for (PrecondLinkPortMap::iterator precond_iter = precond_links_.begin (); + precond_iter != precond_links_.end (); precond_iter++) + { + strm << " " << "Cond " << precond_iter->first.first; + strm << " -> " << "Task " << precond_iter->first.second << "("; + strm << precond_iter->second << ")" << std::endl; + } + + // Print all effect links. + strm << "Effect Links: " << std::endl; + for (EffectLinkPortMap::iterator effect_iter = effect_links_.begin (); + effect_iter != effect_links_.end (); effect_iter++) + { + strm << " " << "Task " << effect_iter->first.first << "("; + strm << effect_iter->second << ") -> " << "Cond "; + strm << effect_iter->first.second << std::endl; + } + strm << std::endl; +}; + +void SANet::Network::update (int max_steps) +{ + // Flag for whether network changed on last step, initially true. + bool net_changed = true; + + // Set step limit. + int step_limit = step_ + max_steps; + + // Run spreading activation until step limit is reached or no changes made. + while (net_changed && (step_ < step_limit)) { + // Update step. + step_++; + + // Reset net_changed flag. + net_changed = false; + +#if defined (SANET_DEBUG) + std::cout << std::endl << "DEBUG in SANet::Network::update()... step_=" << step_ << std::endl << std::endl; +#endif /* SANET_DEBUG */ + // Update all task nodes. + for (TaskNodeMap::iterator node_iter = task_nodes_.begin (); + node_iter != task_nodes_.end (); node_iter++) + { + // Update node, setting net_changed flag if node changed. + if (node_iter->second->update ()) { + net_changed = true; + } + } + + // Update all condition nodes. + for (CondNodeMap::iterator node_iter = cond_nodes_.begin (); + node_iter != cond_nodes_.end (); node_iter++) + { + // Update node, setting net_changed flag if node changed. + if (node_iter->second->update ()) { + net_changed = true; + } + } + } +}; + +// Update a condition's current value (probability of being true). +void SANet::Network::update_cond_val (CondID cond_id, Probability true_prob) +{ + CondNodeMap::iterator iter = this->cond_nodes_.find (cond_id); + if (iter == this->cond_nodes_.end ()) + throw "SANet::Network::update_cond_val (): Unknown condition node."; + iter->second->set_init_prob (true_prob); +}; + +// Update a condition's (goal) utility. +void SANet::Network::update_cond_util (CondID cond_id, Probability utility) +{ + // ****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + throw "Plan monitoring/updating/replanning not yet implemented: SANet::SANet::Network::updated_cond_val ()."; +}; + +// Update all condition utilities based on new goal set. +void SANet::Network::update_goals (GoalMap goals) +{ + // ****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + throw "Plan monitoring/updating/replanning not yet implemented: SANet::SANet::Network::update_goals ()."; +}; + +// Get a condition's current value (probability of being true). +Probability SANet::Network::get_cond_val (CondID cond_id) +{ + CondNodeMap::iterator iter = this->cond_nodes_.find (cond_id); + if (iter == this->cond_nodes_.end ()) + throw "SANet::Network::get_cond_val (): Unknown condition node."; + return iter->second->get_init_prob (); +}; + +// Get all goals. +const GoalMap& SANet::Network::get_goals (void) +{ + return this->goals_; +}; + +// Get a task's name. +std::string SANet::Network::get_task_name (TaskID task_id) +{ + // Find task node. + TaskNodeMap::iterator task_iter = task_nodes_.find (task_id); + if (task_iter == task_nodes_.end ()) { + throw UnknownNode (); + } + + return task_iter->second->get_name (); +}; + +// Get a condition's name. +std::string SANet::Network::get_cond_name (CondID cond_id) +{ + // Find condition node. + CondNodeMap::iterator cond_iter = cond_nodes_.find (cond_id); + if (cond_iter == cond_nodes_.end ()) { + throw UnknownNode (); + } + + return cond_iter->second->get_name (); +}; + +// Get a condition's type/kind. +CondKind SANet::Network::get_cond_type (CondID cond_id) +{ + // Find condition node. + CondNodeMap::iterator cond_iter = cond_nodes_.find (cond_id); + if (cond_iter == cond_nodes_.end ()) { + throw UnknownNode (); + } + + return cond_iter->second->get_cond_kind (); +}; + +// Get a task's current expected utility. +Utility SANet::Network::get_task_current_eu (TaskID task_id) +{ + // ****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + throw "Plan monitoring/updating/replanning not yet implemented: SANet::SANet::Network::get_task_current_eu ()."; +}; + +// Get a task's future expected utility. +Utility SANet::Network::get_task_future_eu (TaskID task_id) +{ + TaskNodeMap::iterator task_iter = task_nodes_.find (task_id); + if (task_iter == task_nodes_.end ()) { + throw UnknownNode (); + } + return task_iter->second->get_utility (this->step_); +}; + +// Get all preconditions of a task. +CondSet SANet::Network::get_preconds (TaskID task_id) +{ + // Find task node. + TaskNodeMap::iterator task_iter = task_nodes_.find (task_id); + if (task_iter == task_nodes_.end ()) { + throw UnknownNode (); + } + + // Create set of preconditions from pre-nodes set. + CondSet preconds; + preconds.clear (); + LinkMap pre_links = task_iter->second->get_pre (); + for (LinkMap::iterator iter = pre_links.begin (); iter != pre_links.end (); + iter++) + { + Condition cond; + cond.id = iter->first; + CondNode* cond_node = this->cond_nodes_.find(iter->first)->second; + cond.kind = cond_node->get_cond_kind(); + + if (iter->second > 0) + cond.value = true; + else + cond.value = false; + preconds.insert (cond); + } + + return preconds; +}; + +// Get all effects of a task. +CondSet SANet::Network::get_effects (TaskID task_id) +{ + // Find task node. + TaskNodeMap::iterator task_iter = task_nodes_.find (task_id); + if (task_iter == task_nodes_.end ()) { + throw UnknownNode (); + } + + // Create set of effects from pre-nodes set. + CondSet effects; + effects.clear (); + LinkMap post_links = task_iter->second->get_post (); + for (LinkMap::iterator iter = post_links.begin (); iter != post_links.end (); + iter++) + { + Condition cond; + cond.id = iter->first; + // ****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP +#if defined (SANET_STANDALONE) + cond.kind = SANet::DATA; +#else // SANET_STANDALONE not defined + cond.kind = SA_POP::DATA; +#endif /* SANET_STANDALONE */ + // ****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + if (iter->second > 0) + cond.value = true; + else + cond.value = false; + effects.insert (cond); + } + + return effects; +}; + +// Get the duration of a task. +TimeValue SANet::Network::get_duration (TaskID task_id) +{ + TaskNode *temp = this->task_nodes_.find(task_id)->second; + return NULL_TIME; +} + +// Get all tasks that satisfy a condition. +TaskSet SANet::Network::get_satisfying_tasks (Condition cond) +{ + // Find condition node. + CondNodeMap::iterator cond_iter = this->cond_nodes_.find (cond.id); + if (cond_iter == this->cond_nodes_.end ()) { + throw UnknownNode (); + } + + // Create set of tasks from pre-nodes set. + TaskSet tasks; + tasks.clear (); + LinkMap pre_links = cond_iter->second->get_pre (); + for (LinkMap::iterator iter = pre_links.begin (); iter != pre_links.end (); + iter++) + { + // Add tasks with positive link weights for true condition or + // tasks with negative link weights for false condition. + if (cond.value) { + if (iter->second > 0) + tasks.insert (iter->first); + } else { + if (iter->second < 0) + tasks.insert (iter->first); + } + } + + return tasks; +}; + +// Get effect link port. +PortID SANet::Network::get_effect_port (TaskID task_id, CondID cond_id) +{ + // Find port, throwing exception if not found. + EffectLinkPortMap::iterator iter = this->effect_links_.find ( + std::make_pair (task_id, cond_id)); + if (iter == this->effect_links_.end ()) { + throw UnknownNode (); + } + + return iter->second; +}; + +// Get precondition link port. +PortID SANet::Network::get_precond_port (CondID cond_id, TaskID task_id) +{ + // Find port, throwing exception if not found. + PrecondLinkPortMap::iterator iter = this->precond_links_.find ( + std::make_pair (cond_id, task_id)); + if (iter == this->precond_links_.end ()) { + throw UnknownNode (); + } + + return iter->second; +}; + +// Get ports for a causal link. +LinkPorts SANet::Network::get_clink_ports (TaskID task1_id, CondID cond_id, + TaskID task2_id) +{ + return std::make_pair (this->get_effect_port (task1_id, cond_id), + this->get_precond_port (cond_id, task2_id)); +}; diff --git a/SA_POP/SANet/SANet.h b/SA_POP/SANet/SANet.h new file mode 100644 index 00000000000..50a8eb8c98f --- /dev/null +++ b/SA_POP/SANet/SANet.h @@ -0,0 +1,328 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file SANet.h + * + * This file contains the Network class definition for spreading activation + * networks. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SA_NETWORK_H_ +#define SA_NETWORK_H_ + +#include <iostream> +#include <map> +#include <stdexcept> +#include "SANet_Types.h" +#include "SANode.h" + +namespace SANet { + /// Map from task node ID to pointer. + typedef std::map<TaskID, TaskNode *> TaskNodeMap; + + /// Map from condition node ID to pointer. + typedef std::map<CondID, CondNode *> CondNodeMap; + + /// Map of precondition links to ports. + typedef std::map<PrecondLink, PortID> PrecondLinkPortMap; + + /// Map of effect links to ports. + typedef std::map<EffectLink, PortID> EffectLinkPortMap; + + /** + * @class Network + * + * @brief Spreading activation network class. + */ + class Network { + public: + /// Constructor. + Network (void); + + /// Destructor. + virtual ~Network (); + + + + // ************************************************************************ + // Network creations methods. + // ************************************************************************ + + /// Add a new task node to the network. + /** + * @param ID Node ID. + * + * @param name Node name. + * + * @param atten_factor Attenuation factor (to bias toward shorter plans). + * + * @param cost Cost of performing task. + * + * @param prior_prob Prior probability of success. + */ + virtual void add_task (TaskID ID, std::string name, + MultFactor atten_factor, TaskCost cost, Probability prior_prob); + + /// Add a new condition node to the network. + /** + * @param ID Node ID. + * + * @param name Node name. + * + * @param atten_factor Attenuation factor (to bias toward shorter plans). + * + * @param true_prob Initial probability that value is true. + * + * @param false_prob Initial probability that value is false. + * + * @param cond_kind The type of condition + * + * @param goal_util Initial utility (positive for goals, zero otherwise). + */ + virtual void add_cond (CondID ID, std::string name, + MultFactor atten_factor, Probability true_prob, Probability false_prob, + Utility goal_util, CondKind cond_kind); + + /// Add condition to task link. + /** + * @param cond_ID Condition node ID. + * + * @param task_ID Task node ID. + * + * @param true_prob Conditional probability of task success given + * condition node = true. + * + * @param false_prob Conditional probability of task success given + * condition node = false. + * + * @param port_ID ID of port (on task) associated with this condition + * (used for data nodes). + */ + virtual void add_precond_link (CondID cond_ID, TaskID task_ID, + Probability true_prob, Probability false_prob, PortID port_ID = ""); + + /// Add task to condition link. + /** + * @param cond_ID Condition node ID. + * + * @param task_ID Task node ID. + * + * @param weight Link weight (probability task sets condition to + * true, or negative of the probability task sets condition to false). + * + * @param port_ID ID of port (on task) associated with this condition + * (used for data nodes). + */ + virtual void add_effect_link (TaskID task_ID, CondID cond_ID, + LinkWeight weight, PortID port_ID = ""); + + + + // ************************************************************************ + // Print methods. + // ************************************************************************ + + /// Print network. + /** + * @param strm Output stream on which to print network representation. + * + * @param verbose Whether to print verbose representation. + */ + virtual void print (std::basic_ostream<char, std::char_traits<char> >& strm + = std::cout, bool verbose = false); + + /// Print links and ports. + /** + * @param strm Output stream on which to print network representation. + * + * @param verbose Whether to print verbose representation. + */ + virtual void print_link_ports (std::basic_ostream<char, + std::char_traits<char> >& strm = std::cout, bool verbose = false); + + + + // ************************************************************************ + // Network update methods (spreading activation, environment/system state + // changes, and goal changes). + // ************************************************************************ + + /// Run spreading activation. + /** + * @param max_steps Maximum steps for which to run spreading activation. + */ + virtual void update (int max_steps); + + /// Update a condition's current value (probability of being true). + /** + * @param cond_id The condition id. + * + * @param true_prob New probability that condition is true. + */ + virtual void update_cond_val (CondID cond_id, Probability true_prob); + + /// Update a condition's (goal) utility. + /** + * @param cond_id The condition id. + * + * @param utility New goal utility of condition. + */ + virtual void update_cond_util (CondID cond_id, Utility utility); + + /// Update all condition utilities based on new goal set. + /** + * @param goals Set of goal condition ids and associated utilities. + */ + virtual void update_goals (GoalMap goals); + + + + // ************************************************************************ + // General task/condition accessor methods. + // ************************************************************************ + + /// Get a task's name. + /** + * @param task_id The task id. + * + * @return Task name. + */ + virtual std::string get_task_name (TaskID task_id); + + /// Get a condition's name. + /** + * @param cond_id The condition id. + * + * @return Condition name. + */ + virtual std::string get_cond_name (CondID cond_id); + + /// Get a condition's type/kind. + /** + * @param cond_id The condition id. + * + * @return Condition type. + */ + virtual CondKind get_cond_type (CondID cond_id); + + /// Get a condition's current value (probability of being true). + /** + * @param cond_id The condition id. + * + * @return Probability that condition is true. + */ + virtual Probability get_cond_val (CondID cond_id); + + /// Get all goals. + /** + * @return Set of condition ids and associated utilities. + */ + virtual const GoalMap& get_goals (void); + + /// Get a task's current expected utility. + /** + * @param task_id The task id. + * + * @return Current task expected utility. + */ + virtual Utility get_task_current_eu (TaskID task_id); + + /// Get a task's future expected utility. + /** + * @param task_id The task id. + * + * @return Future task expected utility. + */ + virtual Utility get_task_future_eu (TaskID task_id); + + /// Get all preconditions of a task. + /** + * @param task_id The task id. + * + * @return Set of all preconditions with associated values. + */ + virtual CondSet get_preconds (TaskID task_id); + + /// Get all effects of a task. + /** + * @param task_id The task id. + * + * @return Set of all effects with associated values. + */ + virtual CondSet get_effects (TaskID task_id); + + /// Get all tasks that satisfy a condition. + /** + * @param cond_id The condition id. + * + * @return Set of all tasks that satisfy the given condition. + */ + virtual TaskSet get_satisfying_tasks (Condition cond); + + /// Get the name of the port associated with a precondition of a task. + /** + * @param cond_id The precondition id. + * + * @param task_id The task id. + * + * @return Port id. + */ + virtual PortID get_precond_port (CondID cond_id, TaskID task_id); + + /// Get the name of the port associated with an effect of a task. + /** + * @param task_id The task id. + * + * @param cond_id The effect condition id. + * + * @return Port id. + */ + virtual PortID get_effect_port (TaskID task_id, CondID cond_id); + + /// Get ports for a causal link. + /** + * @param task1_id ID of start task node in causal link. + * + * @param cond_id ID of condition node in both precondition and effect + * links. + * + * @param task2_id ID of end task node in causal link. + */ + virtual LinkPorts get_clink_ports (TaskID task1_id, CondID cond_id, + TaskID task2_id); + + /// Get the duration of a task + /** + * @param task_id ID of the Task + * + * @return duration of the task + */ + virtual TimeValue get_duration (TaskID task_id); + + protected: + /// Map from ID to node pointer for all task nodes in network. + TaskNodeMap task_nodes_; + + /// Map from ID to node pointer for all condition nodes in network. + CondNodeMap cond_nodes_; + + /// Map from precondition links to associated ports. + PrecondLinkPortMap precond_links_; + + /// Map from effect links to associated ports. + EffectLinkPortMap effect_links_; + + /// Goals. + GoalMap goals_; + + /// Current step. + int step_; + }; +}; + + +#endif /* SA_NETWORK_H_ */ diff --git a/SA_POP/SANet/SANetFileIn.cpp b/SA_POP/SANet/SANetFileIn.cpp new file mode 100644 index 00000000000..6105985f440 --- /dev/null +++ b/SA_POP/SANet/SANetFileIn.cpp @@ -0,0 +1,219 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file SANetFileIn.cpp + * + * This file contains the SANetFileIn class implementation for the input adapter + * that initializes a SANet object using an XML SANet file. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#include "SANet_Types.h" +#include "SANetFileIn.h" + +#if !defined (SANET_STANDALONE) +#include "Builder.h" +#endif + +#include "Utils/XML_Helper.h" +#include "XML_SANet.hpp" + +using namespace SANet; + +// Constructor. +SANetFileIn::SANetFileIn (void) +{ + // Nothing to do. +}; + +// Destructor. +SANetFileIn::~SANetFileIn (void) +{ + // Nothing to do. +}; + +// Build network from XML file. +Network *SANetFileIn::build_net (std::string filename) +{ + CIAO::Config_Handlers::XML_Helper helper; + if (!helper.is_initialized ()) + return 0; + + // Parse file with Xerces. + XERCES_CPP_NAMESPACE::DOMDocument *dom = +#if defined (SA_POP_HAS_CIAO) + helper.create_dom (filename.c_str ()); +#else + helper.create_dom (filename.c_str (), ""); +#endif /* SA_POP_HAS_CIAO */ + if (!dom) + return 0; + + SANet::XML::Network xml_net = SANet::XML::network (dom); + + SANet::Network *net = new SANet::Network (); + + // Get task nodes. + for (SANet::XML::Network::taskNode_iterator iter = xml_net.begin_taskNode (); + iter != xml_net.end_taskNode (); iter++) + { + TaskID nodeID = (*iter).nodeID (); + Probability priorProb = (*iter).priorProb (); + MultFactor attenFactor = (*iter).attenFactor (); + TaskCost cost = (*iter).cost (); +// TimeValue dur = + char name[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (name, (*iter).name ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + + net->add_task (nodeID, name, attenFactor, cost, priorProb); + } + + // Get condition nodes. + for (SANet::XML::Network::condNode_iterator iter = xml_net.begin_condNode (); + iter != xml_net.end_condNode (); iter++) + { + CondID nodeID = (*iter).nodeID (); + Probability probTrue = (*iter).probTrue (); + Utility utility = (*iter).utility (); + MultFactor attenFactor = (*iter).attenFactor (); +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP +// CondKind + char name[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (name, (*iter).name ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + + SANet::XML::CondKind cond_kind = (*iter).kind(); + ::SA_POP::CondKind cond; + if(cond_kind==cond_kind.ENVIRON) cond=::SA_POP::ENVIRON; + else if(cond_kind==cond_kind.SYSTEM) cond=::SA_POP::SYSTEM; + else cond=::SA_POP::DATA; + + net->add_cond (nodeID, name, attenFactor, + probTrue, 1.0 - probTrue, utility, cond); + } + + // Get precondition->task links. + for (SANet::XML::Network::precondLink_iterator iter = xml_net.begin_precondLink (); + iter != xml_net.end_precondLink (); iter++) + { + CondID condID = (*iter).condID (); + TaskID taskID = (*iter).taskID (); + Probability trueProb = (*iter).trueProb (); + Probability falseProb = (*iter).falseProb (); + +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + char portID[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (portID, (*iter).portID ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + + net->add_precond_link (condID, taskID, trueProb, falseProb); + } + + // Get task->effect links. + for (SANet::XML::Network::effectLink_iterator iter = xml_net.begin_effectLink (); + iter != xml_net.end_effectLink (); iter++) + { + TaskID taskID = (*iter).taskID (); + CondID condID = (*iter).condID (); + Probability weight = (*iter).weight (); + +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + char portID[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (portID, (*iter).portID ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + + net->add_effect_link (taskID, condID, weight); + } + + return net; +}; + +#if !defined (SANET_STANDALONE) +// Build network from XML file. +void SANetFileIn::build_net (std::string filename, SA_POP::Builder *builder) +{ + CIAO::Config_Handlers::XML_Helper helper; + if (!helper.is_initialized ()) + return; + + // Parse file with Xerces. + XERCES_CPP_NAMESPACE::DOMDocument *dom = +#if defined (SA_POP_HAS_CIAO) + helper.create_dom (filename.c_str ()); +#else + helper.create_dom (filename.c_str (), ""); +#endif /* SA_POP_HAS_CIAO */ + if (!dom) + return; + + SANet::XML::Network xml_net = SANet::XML::network (dom); + + // Get task nodes. + for (SANet::XML::Network::taskNode_iterator iter = xml_net.begin_taskNode (); + iter != xml_net.end_taskNode (); iter++) + { + TaskID nodeID = (*iter).nodeID (); + Probability priorProb = (*iter).priorProb (); + MultFactor attenFactor = (*iter).attenFactor (); + TaskCost cost = (*iter).cost (); + + char name[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (name, (*iter).name ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + + builder->add_task (nodeID, priorProb, name); + } + + // Get condition nodes. + for (SANet::XML::Network::condNode_iterator iter = xml_net.begin_condNode (); + iter != xml_net.end_condNode (); iter++) + { + CondID nodeID = (*iter).nodeID (); + Probability probTrue = (*iter).probTrue (); + Utility utility = (*iter).utility (); + MultFactor attenFactor = (*iter).attenFactor (); + +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP +// CondKind + char name[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (name, (*iter).name ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + SANet::XML::CondKind cond_kind = (*iter).kind(); + SA_POP::CondKind cond; + if(cond_kind==cond_kind.ENVIRON) cond=::SA_POP::ENVIRON; + else if(cond_kind==cond_kind.SYSTEM) cond=::SA_POP::SYSTEM; + else cond=::SA_POP::DATA; + builder->add_cond (nodeID, utility, probTrue, name, cond); + } + + // Get precondition->task links. + for (SANet::XML::Network::precondLink_iterator iter = xml_net.begin_precondLink (); + iter != xml_net.end_precondLink (); iter++) + { + CondID condID = (*iter).condID (); + TaskID taskID = (*iter).taskID (); + Probability trueProb = (*iter).trueProb (); + Probability falseProb = (*iter).falseProb (); + +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + char portID[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (portID, (*iter).portID ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + + builder->set_precond (condID, taskID, portID, trueProb, falseProb); + } + + // Get task->effect links. + for (SANet::XML::Network::effectLink_iterator iter = xml_net.begin_effectLink (); + iter != xml_net.end_effectLink (); iter++) + { + TaskID taskID = (*iter).taskID (); + CondID condID = (*iter).condID (); + Probability weight = (*iter).weight (); + +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + char portID[SANet::SANetFileIn::STR_BUF_SIZE]; + wcstombs (portID, (*iter).portID ().c_str (), SANet::SANetFileIn::STR_BUF_SIZE); + + builder->set_effect (taskID, condID, portID, weight); + } +}; +#endif /* SANET_STANDALONE */ diff --git a/SA_POP/SANet/SANetFileIn.h b/SA_POP/SANet/SANetFileIn.h new file mode 100644 index 00000000000..97e019644e0 --- /dev/null +++ b/SA_POP/SANet/SANetFileIn.h @@ -0,0 +1,64 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file SANetFileIn.h + * + * This file contains the SANetFileIn class definition for the input adapter + * that initializes a SANet object using an XML SANet file. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SANET_SANET_FILE_IN_H_ +#define SANET_SANET_FILE_IN_H_ + +#include "SANet_Types.h" +#include "SANet.h" + +#if !defined (SANET_STANDALONE) +#include "Builder.h" +#endif + +namespace SANet { + + /** + * @class SANetFileIn + * + * @brief Input adapter that initializes a SANet object using an XML + * SANet file. + */ + class SANetFileIn { + public: + /// Constructor. + SANetFileIn (void); + + /// Destructor. + virtual ~SANetFileIn (void); + + /// Buffer size for string conversion. + const static size_t STR_BUF_SIZE = 129; + + /// Create network from XML file. + /** + * @param filename Name of XML SANet network file. + * + * @return New SANet network. + */ + virtual Network *build_net (std::string filename); + +#if !defined (SANET_STANDALONE) + /// Build network from XML file. + /** + * @param filename Name of XML SANet network file. + * + * @param builder SA-POP builder to use in building the SANet network. + */ + virtual void build_net (std::string filename, SA_POP::Builder *builder); +#endif /* SANET_STANDALONE not defined */ + }; +}; /* SANet namespace */ + +#endif /* SANET_SANET_FILE_IN_H_ */ diff --git a/SA_POP/SANet/SANet_Exceptions.cpp b/SA_POP/SANet/SANet_Exceptions.cpp new file mode 100644 index 00000000000..e394a8767f7 --- /dev/null +++ b/SA_POP/SANet/SANet_Exceptions.cpp @@ -0,0 +1,47 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file SANet_Exceptions.cpp + * + * This file contains the exception implementations for spreading activation + * networks. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#include "SANet_Exceptions.h" + +using namespace SANet; + +Invalid_Step::Invalid_Step (void) +: std::invalid_argument ("Invalid step argument") +{ + // Nothing to do. +}; + +Update_Error::Update_Error (void) +: std::logic_error ("Update error") +{ + // Nothing to do. +}; + +Duplicate_ID::Duplicate_ID (void) +: std::invalid_argument ("Duplicate ID provided for node creation") +{ + // Nothing to do. +}; + +Insertion_Error::Insertion_Error (void) +: std::logic_error ("Error while attempting to insert a value in map or set") +{ + // Nothing to do. +}; + +UnknownNode::UnknownNode (void) +: std::invalid_argument ("Unknown node lookup") +{ + // Nothing to do. +}; diff --git a/SA_POP/SANet/SANet_Exceptions.h b/SA_POP/SANet/SANet_Exceptions.h new file mode 100644 index 00000000000..1934cdbc789 --- /dev/null +++ b/SA_POP/SANet/SANet_Exceptions.h @@ -0,0 +1,79 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file SANet_Exceptions.h + * + * This file contains the exception definitions for spreading activation + * networks. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SANET_EXCEPTIONS_H_ +#define SANET_EXCEPTIONS_H_ + +#include <stdexcept> + +namespace SANet { + /** + * @class Invalid_Step + * + * @brief Exception class for invalid step arguments. + */ + class Invalid_Step : public std::invalid_argument { + public: + /// Constructor. + Invalid_Step (void); + }; + + /** + * @class Update_Error + * + * @brief Exception class for unrecoverable update errors. + */ + class Update_Error : public std::logic_error { + public: + /// Constructor. + Update_Error (void); + }; + + /** + * @class Duplicate_ID + * + * @brief Exception class for duplicate ID value during node creation. + */ + class Duplicate_ID : public std::invalid_argument { + public: + /// Constructor. + Duplicate_ID (void); + }; + + /** + * @class Insertion_Error + * + * @brief Exception class for unknown errors during map/set insertion. + */ + class Insertion_Error : public std::logic_error { + public: + /// Constructor. + Insertion_Error (void); + }; + + /** + * @class UnknownNode + * + * @brief Exception class for unknown node error when looking up a node. + */ + class UnknownNode : public std::invalid_argument { + public: + /// Constructor. + UnknownNode (void); + }; + +}; /* SANet namespace */ + + +#endif /* SANET_EXCEPTIONS_H_ */ diff --git a/SA_POP/SANet/SANet_Types.h b/SA_POP/SANet/SANet_Types.h new file mode 100644 index 00000000000..c4f20f090f9 --- /dev/null +++ b/SA_POP/SANet/SANet_Types.h @@ -0,0 +1,208 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file SANet_Types.h + * + * This file contains the definitions of types used throughout SANet. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SANET_TYPES_H_ +#define SANET_TYPES_H_ + +#include <string> +#include <set> +#include <list> +#include <map> +#include <utility> + + +#if !defined (SANET_STANDALONE) + +#include "SA_POP_Types.h" + +namespace SANet { + /// Type of a node id (tasks and conditions). + /// (must be > 0 and unique across all tasks *and* conditions). + typedef SA_POP::NodeID NodeID; + + /// Type of a condition id. + /// (must be > 0 and unique across all tasks *and* conditions). + typedef SA_POP::CondID CondID; + + /// Type of a condition value. + typedef SA_POP::CondValue CondValue; + + /// Type of a condition kind/type. + typedef SA_POP::CondKind CondKind; + + /// Type of a condition. + typedef SA_POP::Condition Condition; + + /// Type of a task ID. + /// (must be > 0 and unique across all tasks *and* conditions). + typedef SA_POP::TaskID TaskID; + + /// NULL task ID (for unknown/uninitialized tasks). + const TaskID NULL_TASK_ID = SA_POP::NULL_TASK_ID; + + /// NULL condition ID (for unknown/uninitialized conditions). + const CondID NULL_COND_ID = SA_POP::NULL_TASK_ID; + + /// Type of a port id. + typedef SA_POP::PortID PortID; + + /// Type of an expected utility calculation (basetype for others). + /// (N.B. this must be a double or float to handle [0,1] range probabilities + /// and multiplication factors). + typedef SA_POP::EUCalc EUCalc; + + /// Type of a condition utility. + typedef SA_POP::Utility Utility; + + /// Type of a probability. + typedef SA_POP::Probability Probability; + + /// Type of a (precondition or effect) link weight. + typedef SA_POP::LinkWeight LinkWeight; + + /// Type of a task cost. + typedef SA_POP::TaskCost TaskCost; + + /// Type of a multiplicative factor (e.g. attenuation factor). + typedef SA_POP::MultFactor MultFactor; + + /// Type of a precondition link. + typedef SA_POP::PrecondLink PrecondLink; + + /// Type of an effect link. + typedef SA_POP::EffectLink EffectLink; + + /// Type of a pair of ports for a link. + typedef SA_POP::LinkPorts LinkPorts; + + /// Type of a list of tasks. + typedef SA_POP::TaskList TaskList; + + /// Type of a set of goal conditions with associated utilities. + typedef SA_POP::GoalMap GoalMap; + + /// Type of a set of tasks with associated expected utilities. + typedef SA_POP::TaskEUMap TaskEUMap; + + /// Type of a set of conditions (condition & value). + typedef SA_POP::CondSet CondSet; + + /// Type of a set of task ids. + typedef SA_POP::TaskSet TaskSet; + + /// Type of duration + typedef SA_POP::TimeValue TimeValue; + + /// NULL time (for unknown or unconstrained times). + #define NULL_TIME -1 + +}; /* SANet namespace */ + +#endif /* SANET_STANDALONE not defined */ + + +#if defined (SANET_STANDALONE) + +namespace SANet { + + /// Type of a node id (tasks and conditions). + /// (must be > 0 and unique across all tasks *and* conditions). + typedef int NodeID; + + /// Type of a condition id. + /// (must be > 0 and unique across all tasks *and* conditions). + typedef NodeID CondID; + + /// Type of a condition value. + typedef bool CondValue; + + /// Type of a condition kind/type. + enum CondKind {ENVIRON, SYSTEM, DATA}; + + /// Type of a condition. + struct Condition { + CondID id; + CondValue value; + CondKind kind; + bool operator== (const Condition &s) const { return this->id == s.id; }; + bool operator!= (const Condition &s) const { return !(*this == s); }; + bool operator< (const Condition &s) const { return this->id < s.id; }; + }; + + /// Type of a task ID. + /// (must be > 0 and unique across all tasks *and* conditions). + typedef NodeID TaskID; + + /// NULL task ID (for unknown/uninitialized tasks). + const TaskID NULL_TASK_ID = 0; + + /// NULL condition ID (for unknown/uninitialized conditions). + const CondID NULL_COND_ID = 0; + + /// Type of a port id. + typedef std::string PortID; + + /// Type of an expected utility calculation (basetype for others). + /// (N.B. this must be a double or float to handle [0,1] range probabilities + /// and multiplication factors). + typedef double EUCalc; + + /// Type of a condition utility. + typedef EUCalc Utility; + + /// Type of a probability. + typedef EUCalc Probability; + + /// Type of a (precondition or effect) link weight. + typedef EUCalc LinkWeight; + + /// Type of a task cost. + typedef EUCalc TaskCost; + + /// Type of a multiplicative factor (e.g. attenuation factor). + typedef EUCalc MultFactor; + + /// Type of duration + typedef int TimeValue; + + /// NULL time (for unknown or unconstrained times). + #define NULL_TIME -1 + + /// Type of a precondition link. + typedef std::pair<CondID, TaskID> PrecondLink; + + /// Type of an effect link. + typedef std::pair<TaskID, CondID> EffectLink; + + /// Type of a pair of ports for a link. + typedef std::pair<PortID, PortID> LinkPorts; + + /// Type of a list of tasks. + typedef std::list<TaskID> TaskList; + + /// Type of a set of goal conditions with associated utilities. + typedef std::map<CondID, Utility> GoalMap; + + /// Type of a set of tasks with associated expected utilities. + typedef std::map<TaskID, Utility> TaskEUMap; + + /// Type of a set of conditions (condition & value). + typedef std::set<Condition> CondSet; + + /// Type of a set of task ids. + typedef std::set<TaskID> TaskSet; + +}; /* SANet namespace */ +#endif /* SANET_STANDALONE */ + +#endif /* SANET_TYPES_H_ */ diff --git a/SA_POP/SANet/SANode.cpp b/SA_POP/SANet/SANode.cpp new file mode 100644 index 00000000000..4ce882526d0 --- /dev/null +++ b/SA_POP/SANet/SANode.cpp @@ -0,0 +1,1020 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file SANode.cpp + * + * This file contains the Node, CondNode, & TaskNode class + * implementations for spreading activation network nodes. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#include "SANode.h" +#include "SANet_Exceptions.h" +#include <utility> +#include <iostream> + +using namespace SANet; + +Node::Node (NodeID ID, std::string name, MultFactor atten_factor) +: ID_ (ID), + name_ (name), + atten_factor_ (atten_factor), + step_ (0), + prob_changed_ (false), + util_changed_ (false) +{ + // Initialize probability and utility info. + pos_util_.utility = 0; + pos_util_.common.clear (); + neg_util_.utility = 0; + neg_util_.common.clear (); + true_prob_.probability = 0; + true_prob_.common.clear (); + false_prob_.probability = 0; + false_prob_.common.clear (); + + // Initialize (empty) pre and post node maps and links. + pre_nodes_.clear (); + pre_links_.clear (); + post_nodes_.clear (); + post_links_.clear (); +}; + +Node::~Node () +{ + // Nothing to do. +}; + +Utility_Info Node::get_reward (int step) +{ + // Check to ensure step is the current step, or else throw exception + if (step != step_) { + throw Invalid_Step (); + } + + // Return positive utility info. + return pos_util_; +}; + +Probability_Info Node::get_prob (int step, bool value) +{ + // Check to ensure step is the current step, or else throw exception + if (step != step_) { + throw Invalid_Step (); + } + + // Return probability for true if value is true. + if (value) { + return true_prob_; + } + // Otherwise return probability for false. + return false_prob_; +}; + +bool Node::prob_changed (void) +{ + return prob_changed_; +}; + +bool Node::util_changed (void) +{ + return util_changed_; +}; + +std::string Node::get_name (void) +{ + return name_; +}; + +NodeID Node::get_ID (void) +{ + return ID_; +}; + +// Get pre-links (nodes with links to this node). +const LinkMap& Node::get_pre (void) +{ + return this->pre_links_; +}; + +// Get post-links (nodes with links from this node). +const LinkMap& Node::get_post (void) +{ + return this->post_links_; +}; + +TaskNode::TaskNode (NodeID ID, std::string name, MultFactor atten_factor, + TaskCost cost, Probability prior_prob) +: Node (ID, name, atten_factor), + cost_ (cost), + prior_prob_ (prior_prob) +{ + // Nothing to do. +}; + +TaskNode::~TaskNode (void) +{ + // Nothing to do. +}; + +bool TaskNode::update (void) +{ + // Reset change flags. + prob_changed_ = false; + util_changed_ = false; + + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + // Probability flag is not being set correctly, so run to max steps... + prob_changed_ = true; + util_changed_ = true; + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + + // Flag for detection of loops. + bool is_loop = false; + + // Variables for current node and link in updates. + CondNode *cur_node; + CondID cur_ID; + LinkMap::iterator link_iter; + LinkWeight cur_weight; + MultFactor cur_mult; + + // Variables for current probability value. + Probability_Info cur_prob; + ProbabilityMap::iterator true_prob_iter; + ProbabilityMap::iterator false_prob_iter; + ProbabilityMap::iterator prev_prob_iter; + + // Reset probability info. + true_prob_.probability = prior_prob_; + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + // clearing common probabilities set removes self (if "loop" found where + // this node is receiving utility from same goal on multiple paths). so + // will never realize that nothing has changed. + // and (possible) common probabilities are never removed from the set once + // detected so this does not need to be cleared as long as any + // changed probabilities are appropriately changed in common set... right??? + true_prob_.common.clear (); + + // Update probability. + for (NodeMap::iterator node_iter = pre_nodes_.begin (); + node_iter != pre_nodes_.end (); node_iter++) + { + // Get current node info. + cur_ID = node_iter->first; + cur_node = (CondNode *) node_iter->second; + + // Get current link info. + link_iter = pre_links_.find(cur_ID); + if (link_iter == pre_links_.end ()) { + throw Update_Error (); + } + cur_weight = link_iter->second; + + // Get current probability info. + try { + if (cur_weight >= 0) { + cur_prob = cur_node->get_prob (step_, true); + } else { + cur_prob = cur_node->get_prob (step_, false); + } + } catch (Invalid_Step e) { + std::cerr << "Error in task node update: Invalid step value."; + std::cerr << std::endl; + return false; + } catch (...) { + std::cerr << "Unexpected exception thrown in task node update."; + std::cerr << std::endl; + return false; + } + + // Get conditional probability of success for true precondition. + true_prob_iter = pre_true_probs_.find (cur_ID); + if (true_prob_iter == pre_true_probs_.end ()) { + throw Update_Error (); + } + + // Get conditional probability of success for false precondition. + false_prob_iter = pre_false_probs_.find (cur_ID); + if (false_prob_iter == pre_false_probs_.end ()) { + throw Update_Error (); + } + + // Update true probability depending on sign of link weight. + if (cur_weight >= 0) { + // Update conditional probability of success given this node. + cur_prob.probability = ((cur_prob.probability * true_prob_iter->second) + + ((1 - cur_prob.probability) * false_prob_iter->second)); + + // Update probability. + true_prob_.probability = true_prob_.probability * cur_prob.probability / + prior_prob_; + } else { + // Update conditional probability of success given this node. + cur_prob.probability = ((cur_prob.probability * false_prob_iter->second) + + ((1 - cur_prob.probability) * true_prob_iter->second)); + + // Update probability. + true_prob_.probability = true_prob_.probability * cur_prob.probability / + prior_prob_; + } + + // Update prob_changed_ flag if necessary. + if (cur_node->prob_changed ()) { + prob_changed_ = true; + } + + // Update common probabilities and handle duplicates. + for (ProbabilityMap::iterator prob_iter = cur_prob.common.begin (); + prob_iter != cur_prob.common.end (); prob_iter++) + { + prev_prob_iter = true_prob_.common.find (prob_iter->first); + + // If a common probability is already in the probability map, + // divide from probability, otherwise add it to the probability map. + if (prev_prob_iter != true_prob_.common.end ()) + { +#if defined (SANET_DEBUG) + std::cout << std::endl << "DEBUG in TaskNode::update()... (" << ID_ << ") Duplicate common probability found:" << std::endl; + std::cout << "Probability from " << prev_prob_iter->first << " = " << prev_prob_iter->second << std::endl << std::endl; +#endif /* SANET_DEBUG */ + true_prob_.probability = true_prob_.probability / + prev_prob_iter->second; + } else { + true_prob_.common.insert (std::make_pair (prob_iter->first, + prob_iter->second)); + } + } + } + + // Variables for current utility updates. + Utility_Info cur_util; + UtilityMap::iterator prev_util_iter; + + // Reset utility info. + pos_util_.utility = 0; + pos_util_.common.clear (); + neg_util_.utility = 0; + neg_util_.common.clear (); + + // Update utility. + for (NodeMap::iterator node_iter = post_nodes_.begin (); + node_iter != post_nodes_.end (); node_iter++) + { + // Get current node info. + cur_ID = node_iter->first; + cur_node = (CondNode *) node_iter->second; + + // Update util_changed_ flag if necessary. + if (cur_node->util_changed ()) { + util_changed_ = true; + } + + // Get current link info. + link_iter = post_links_.find(cur_ID); + if (link_iter == post_links_.end ()) { + throw Update_Error (); + } + cur_weight = link_iter->second; + + // Set multiplier as attenuation factor times link weight, probability + // that task will succeed, and probability that effect node has the + // opposite value from what task would change it to. + if (cur_weight >= 0) { + cur_mult = atten_factor_ * cur_weight * true_prob_.probability * + cur_node->get_prob (step_, false).probability; + } else { + cur_mult = atten_factor_ * cur_weight * true_prob_.probability * + cur_node->get_prob (step_, true).probability; + } + + // Get current utility info. + try { + cur_util = cur_node->get_reward (step_); + } catch (Invalid_Step e) { + std::cerr << "Error in task node update: Invalid step value."; + std::cerr << std::endl; + return false; + } catch (...) { + std::cerr << "Unexpected exception thrown in task node update."; + std::cerr << std::endl; + return false; + } + + // Updated utility based on current multiplier. + cur_util.utility = cur_mult * cur_util.utility; + + // Update positive or negative utilities depending on sign of link weight. + if (cur_weight >= 0) { + // Add utility to expected utility value. + pos_util_.utility += cur_util.utility; + + // Update all component utilities based on link weight, and handle + // utilities from common goals. + for (UtilityMap::iterator util_iter = cur_util.common.begin (); + util_iter != cur_util.common.end (); util_iter++) + { + util_iter->second = cur_mult * util_iter->second; + prev_util_iter = pos_util_.common.find (util_iter->first); + + // If a utility from this goal is already in the utility map, + // delete smaller utility value, otherwise add the utility from this + // goal to the utility map. + if (prev_util_iter != pos_util_.common.end ()) + { +#if defined (SANET_DEBUG) + std::cout << std::endl << "DEBUG in TaskNode::update()... (" << ID_ << ") Duplicate utility from goal found:" << std::endl; + std::cout << "Utility from " << prev_util_iter->first << " = " << prev_util_iter->second << std::endl << std::endl; +#endif /* SANET_DEBUG */ + if (prev_util_iter->second < util_iter->second) { + pos_util_.utility -= prev_util_iter->second; + } else { + pos_util_.utility -= util_iter->second; + } + // Set loop flag. + is_loop = true; + } else { + pos_util_.common.insert (std::make_pair (util_iter->first, + util_iter->second)); + } + } + } else { + // Add utility to expected utility value. + neg_util_.utility += cur_util.utility; + + // Update all component utilities based on link weight, and handle + // utilities from common goals. + for (UtilityMap::iterator util_iter = cur_util.common.begin (); + util_iter != cur_util.common.end (); util_iter++) + { + util_iter->second = cur_mult * util_iter->second; + prev_util_iter = neg_util_.common.find (util_iter->first); + + // If a utility from this goal is already in the utility map, + // delete larger (less negative) utility value, otherwise add the + // utility from this goal to the utility map. + if (prev_util_iter != neg_util_.common.end ()) + { + if (prev_util_iter->second > util_iter->second) { + neg_util_.utility -= prev_util_iter->second; + } else { + neg_util_.utility -= util_iter->second; + } + // Set loop flag. + is_loop = true; + } else { + neg_util_.common.insert (std::make_pair (util_iter->first, + util_iter->second)); + } + } + } + } + +//*****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG**** + // Include cost in current expected utility. +// pos_util_.utility -= cost_; +//*****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG****DEBUG**** + + // If a loop was detected, add current probability to common probabilities. + if (is_loop) { +#if defined (SANET_DEBUG) + if (DEBUG) { + std::cout << std::endl << "DEBUG in TaskNode::update()... (" << ID_ << ") Loop detected, adding this node to common probabilities" << std::endl << std::endl; +#endif /* SANET_DEBUG */ + // Update common probabilities for true probability. + ProbabilityMap::iterator prob_iter = true_prob_.common.find (ID_); + if (prob_iter != true_prob_.common.end ()) { + if (prob_iter->second != true_prob_.probability) { + prob_iter->second = true_prob_.probability; + prob_changed_ = true; + } + } else { + true_prob_.common.insert (std::make_pair (ID_, + true_prob_.probability)); + // Update prob_changed_ flag. + prob_changed_ = true; + } + } + + // Set false probability (i.e. probability of task failure) to 1 minus + // probability of success. + false_prob_.probability = 1 - true_prob_.probability; + + // Update step (at end of step for task node). + step_++; + + // Return boolean changed value based on change flags. + return (prob_changed_ || util_changed_); + +}; + +Utility TaskNode::get_utility (int step) +{ + // Check to ensure step is the current step, or else throw exception + if (step != step_) { + throw Invalid_Step (); + } + + // Variable for summing expected utility. + Utility utility = 0; + + // Add positive expected utility, negative expected utility values, and + // subtract cost. + utility += pos_util_.utility + neg_util_.utility - cost_; + + return utility; +}; + +void TaskNode::print (std::basic_ostream<char, std::char_traits<char> >& + strm, bool verbose) +{ + // Print node name and ID. + strm << "Task Node \"" << name_ << "\":" << std::endl; + strm << " ID: " << ID_ << std::endl; + + // Print cost and expected utility. + strm << " Cost: " << cost_ << std::endl; + strm << " Expected Utility: " << get_utility (step_) << std::endl; + + // If verbose, print positive and negative component utilities from goals. + if (verbose) { + // Print positive utility and its component utilities. + strm << " Positive utility received: " << pos_util_.utility << std::endl; + for (UtilityMap::iterator iter = pos_util_.common.begin (); + iter != pos_util_.common.end (); iter++) + { + strm << " Component expected utility from goal " << iter->first; + strm << " = " << iter->second; + strm << std::endl; + } + + // Print negative utility and its component utilities. + strm << " Negative utility received: " << neg_util_.utility << std::endl; + for (UtilityMap::iterator iter = neg_util_.common.begin (); + iter != neg_util_.common.end (); iter++) + { + strm << " Component expected utility from goal " << iter->first; + strm << " = " << iter->second; + strm << std::endl; + } + } + + // Print probability of task success. + strm << " Probability (success): " << true_prob_.probability << std::endl; + + // If verbose, print common utility + if (verbose) { + for (ProbabilityMap::iterator iter = true_prob_.common.begin (); + iter != true_prob_.common.end (); iter++) + { + strm << " Component probability (possible loops only) from "; + strm << iter->first << " = " << iter->second; + strm << std::endl; + } + } + + // If verbose, print probability of task failure. + if (verbose) { + strm << " Probability (failure): " << false_prob_.probability; + strm << std::endl; + } + + // Current link map iterator input and output link printing loops. + LinkMap::iterator cur_link_iter; + + // Print node input links. + strm << " In Links (preconditions):" << std::endl; + for (NodeMap::iterator node_iter = pre_nodes_.begin (); + node_iter != pre_nodes_.end (); node_iter++) + { + // Print input node name and ID. + strm << " " << node_iter->first << " "; + strm << "(" << node_iter->second->get_name () << "); "; + + // Find link for this node. + cur_link_iter = pre_links_.find (node_iter->first); + + // If this node couldn't be found in pre_links_ print error, + // otherwise print link weight. + if (cur_link_iter == pre_links_.end ()) { + strm << "ERROR: weight not found"; + } else { + strm << "weight = " << cur_link_iter->second; + } + strm << std::endl; + + // If verbose, print conditional probabilities of success for precondition. + if (verbose) { + strm << " Conditional probability if true: "; + strm << pre_true_probs_.find (node_iter->first)->second << std::endl; + strm << " Conditional probability if false: "; + strm << pre_false_probs_.find (node_iter->first)->second << std::endl; + } + } + + // Print node output links. + strm << " Out Links (effects):" << std::endl; + for (NodeMap::iterator node_iter = post_nodes_.begin (); + node_iter != post_nodes_.end (); node_iter++) + { + // Print output node name and ID. + strm << " " << node_iter->first << " "; + strm << "(" << node_iter->second->get_name () << "); "; + + // Find link for this node. + cur_link_iter = post_links_.find (node_iter->first); + + // If this node couldn't be found in post_links_ print error, + // otherwise print link weight. + if (cur_link_iter == post_links_.end ()) { + strm << "ERROR: weight not found"; + } else { + strm << "weight = " << cur_link_iter->second; + } + strm << std::endl; + } +}; + +void TaskNode::add_precond (CondID ID, CondNode *node, Probability true_prob, + Probability false_prob) +{ + // Add node to pre-nodes. + pre_nodes_.insert (std::make_pair (ID, node)); + + // Add probabilities. + pre_true_probs_.insert (std::make_pair (ID, true_prob)); + pre_false_probs_.insert (std::make_pair (ID, false_prob)); + + // Add link weight. + LinkWeight weight = (true_prob - false_prob)/(true_prob + false_prob); + pre_links_.insert (std::make_pair (ID, weight)); + + // Add link for precondition node. + node->add_post_link (ID_, this, weight); +}; + +void TaskNode::add_effect (CondID ID, CondNode *node, LinkWeight weight) +{ + // Add node to post-nodes. + post_nodes_.insert (std::make_pair (ID, node)); + + // Add link weight. + post_links_.insert (std::make_pair (ID, weight)); + + // Add link for precondition node. + node->add_pre_link (ID_, this, weight); +}; + +CondNode::CondNode (CondID ID, std::string name, MultFactor atten_factor, + Probability true_prob, Probability false_prob, Utility goal_util, CondKind condkind) +: Node (ID, name, atten_factor), + goal_util_ (goal_util), + init_true_prob_ (true_prob), + true_prob_from_ (ID), + false_prob_from_ (ID), + cond_kind_ (condkind) +{ + // Set initial probabilities. + true_prob_.probability = true_prob; + false_prob_.probability = false_prob; + + // Set prob_changed_ flag. + prob_changed_ = true; + + // If this node is a goal, set util_changed_ flag and add goal utility + // to positive utilities. + if (goal_util > 0) { + util_changed_ = true; + pos_util_.utility = goal_util; + pos_util_.common.insert (std::make_pair (ID, goal_util)); + } +}; + +CondNode::~CondNode (void) +{ + // Nothing to do. +}; + +// Get initial/current probability. +Probability CondNode::get_init_prob (bool value) +{ + if (value) + return this->init_true_prob_; + + return (1.0 - this->init_true_prob_); +}; + +// Update initial/current probability. +void CondNode::set_init_prob (Probability init_true_prob) +{ + this->init_true_prob_ = init_true_prob; + this->prob_changed_ = true; +}; + +void CondNode::print (std::basic_ostream<char, std::char_traits<char> >& + strm, bool verbose) +{ + // Print node name and ID. + strm << "Condition Node \"" << name_ << "\":" << std::endl; + strm << " ID: " << ID_ << std::endl; + + // Print goal utility. + strm << " Goal utility: " << goal_util_ << std::endl; + + // Print positive utility. + strm << " Expected utility for true value: " << pos_util_.utility; + strm << std::endl; + + // If verbose, print component utilities from all goals. + if (verbose) { + for (UtilityMap::iterator iter = pos_util_.common.begin (); + iter != pos_util_.common.end (); iter++) + { + strm << " Component expected utility from goal " << iter->first; + strm << " = " << iter->second; + strm << std::endl; + } + } + + // Print negative utility. + strm << " Expected utility for false value: " << neg_util_.utility; + strm << std::endl; + + // If verbose, print component utilities from all goals. + if (verbose) { + for (UtilityMap::iterator iter = neg_util_.common.begin (); + iter != neg_util_.common.end (); iter++) + { + strm << " Component expected utility from goal " << iter->first; + strm << " = " << iter->second; + strm << std::endl; + } + } + + // Print probability (maximum) that condition is true. + strm << " Probability (true): " << true_prob_.probability << std::endl; + + // If verbose, print component probabilities for loops. + if (verbose) { + for (ProbabilityMap::iterator iter = true_prob_.common.begin (); + iter != true_prob_.common.end (); iter++) + { + strm << " Component probability (possible loops only) from "; + strm << iter->first << " = " << iter->second; + strm << std::endl; + } + } + + // Print probability (maximum) that condition is false. + strm << " Probability (false): " << false_prob_.probability << std::endl; + + // If verbose, print component probabilities for loops. + if (verbose) { + for (ProbabilityMap::iterator iter = false_prob_.common.begin (); + iter != false_prob_.common.end (); iter++) + { + strm << " Component probability (possible loops only) from "; + strm << iter->first << " = " << iter->second; + strm << std::endl; + } + } + + // Current link map iterator input and output link printing loops. + LinkMap::iterator cur_link_iter; + + // Print node input links. + strm << " In Links (tasks that change this condition):" << std::endl; + for (NodeMap::iterator node_iter = pre_nodes_.begin (); + node_iter != pre_nodes_.end (); node_iter++) + { + // Print input node name and ID. + strm << " " << node_iter->first << " "; + strm << "(" << node_iter->second->get_name () << "); "; + + // Find link for this node. + cur_link_iter = pre_links_.find (node_iter->first); + + // If this node couldn't be found in pre_links_ print error, + // otherwise print link weight. + if (cur_link_iter == pre_links_.end ()) { + strm << "ERROR: weight not found"; + } else { + strm << "weight = " << cur_link_iter->second; + } + strm << std::endl; + } + + // Print node output links. + strm << " Out Links (tasks that have this precondition):" << std::endl; + for (NodeMap::iterator node_iter = post_nodes_.begin (); + node_iter != post_nodes_.end (); node_iter++) + { + // Print output node name and ID. + strm << " " << node_iter->first << " "; + strm << "(" << node_iter->second->get_name () << "); "; + + // Find link for this node. + cur_link_iter = post_links_.find (node_iter->first); + + // If this node couldn't be found in post_links_ print error, + // otherwise print link weight. + if (cur_link_iter == post_links_.end ()) { + strm << "ERROR: weight not found"; + } else { + strm << "weight = " << cur_link_iter->second; + } + strm << std::endl; + } +}; + +bool CondNode::update (void) +{ + // Reset change flags. + prob_changed_ = false; + util_changed_ = false; + + // Update step (at beginning of step for condition node). + step_++; + + // Flag for detection of loops. + bool is_loop = false; + + // Variables for current node and link in updates. + TaskNode *cur_node; + TaskID cur_ID; + LinkMap::iterator link_iter; + LinkWeight cur_weight; + MultFactor cur_mult; + + // Reset utility info. + pos_util_.utility = 0; + pos_util_.common.clear (); + neg_util_.utility = 0; + neg_util_.common.clear (); + // If this node is a goal, set add goal utility to positive utilities. + if (goal_util_ > 0) { + pos_util_.utility = goal_util_; + pos_util_.common.insert (std::make_pair (ID_, goal_util_)); + }; + + // Variables for current utility updates. + Utility_Info cur_util; + UtilityMap::iterator prev_util_iter; + + // Update utility. + for (NodeMap::iterator node_iter = post_nodes_.begin (); + node_iter != post_nodes_.end (); node_iter++) + { + // Get current node info. + cur_ID = node_iter->first; + cur_node = (TaskNode *) node_iter->second; + + // Update util_changed_ flag if necessary. + if (cur_node->util_changed ()) { + util_changed_ = true; + } + + // Get current link info. + link_iter = post_links_.find(cur_ID); + if (link_iter == post_links_.end ()) { + throw Update_Error (); + } + cur_weight = link_iter->second; + + // Set multiplier as attenuation factor times link weight. + cur_mult = atten_factor_ * cur_weight; + + // Get current utility info. + try { + cur_util = cur_node->get_reward (step_); + } catch (Invalid_Step e) { + std::cerr << "Error in condition node update: Invalid step value."; + std::cerr << std::endl; + return false; + } catch (...) { + std::cerr << "Unexpected exception thrown in condition node update."; + std::cerr << std::endl; + return false; + } + + // Updated utility based on current multiplier. + cur_util.utility = cur_mult * cur_util.utility; + + // Update positive or negative utilities depending on sign of link weight. + if (cur_weight >= 0) { + // Add utility to expected utility value. + pos_util_.utility += cur_util.utility; + + // Update all component utilities based on link weight, and handle + // utilities from common goals. + for (UtilityMap::iterator util_iter = cur_util.common.begin (); + util_iter != cur_util.common.end (); util_iter++) + { + util_iter->second = cur_mult * util_iter->second; + prev_util_iter = pos_util_.common.find (util_iter->first); + + // If a utility from this goal is already in the utility map, + // delete smaller utility value, otherwise add the utility from this + // goal to the utility map. + if (prev_util_iter != pos_util_.common.end ()) + { +#if defined (SANET_DEBUG) + std::cout << std::endl << "DEBUG in CondNode::update()... (" << ID_ << ") Duplicate utility from goal found:" << std::endl; + std::cout << "Utility from " << prev_util_iter->first << " = " << prev_util_iter->second << std::endl << std::endl; +#endif /* SANET_DEBUG */ + if (prev_util_iter->second < util_iter->second) { + pos_util_.utility -= prev_util_iter->second; + } else { + pos_util_.utility -= util_iter->second; + } + // Set loop flag. + is_loop = true; + } else { + pos_util_.common.insert (std::make_pair (util_iter->first, + util_iter->second)); + } + } + } else { + // Add utility to expected utility value. + neg_util_.utility += cur_util.utility; + + // Update all component utilities based on link weight, and handle + // utilities from common goals. + for (UtilityMap::iterator util_iter = cur_util.common.begin (); + util_iter != cur_util.common.end (); util_iter++) + { + util_iter->second = cur_mult * util_iter->second; + prev_util_iter = neg_util_.common.find (util_iter->first); + + // If a utility from this goal is already in the utility map, + // delete larger (less negative) utility value, otherwise add the + // utility from this goal to the utility map. + if (prev_util_iter != neg_util_.common.end ()) + { + if (prev_util_iter->second > util_iter->second) { + neg_util_.utility -= prev_util_iter->second; + } else { + neg_util_.utility -= util_iter->second; + } + // Set loop flag. + is_loop = true; + } else { + neg_util_.common.insert (std::make_pair (util_iter->first, + util_iter->second)); + } + } + } + } + + // Variables for current probability value. + Probability_Info cur_prob; + ProbabilityMap::iterator prob_iter; + + // Update probability. + for (NodeMap::iterator node_iter = pre_nodes_.begin (); + node_iter != pre_nodes_.end (); node_iter++) + { + // Get current node info. + cur_ID = node_iter->first; + cur_node = (TaskNode *) node_iter->second; + + // Get current link info. + link_iter = pre_links_.find(cur_ID); + if (link_iter == pre_links_.end ()) { + throw Update_Error (); + } + cur_weight = link_iter->second; + + // Set multiplier as absolute value of link weight. + if (cur_weight >= 0) { + cur_mult = cur_weight; + } else { + cur_mult = -1 * cur_weight; + } + + // Get current probability info. + try { + cur_prob = cur_node->get_prob (step_); + } catch (Invalid_Step e) { + std::cerr << "Error in condition node update: Invalid step value."; + std::cerr << std::endl; + return false; + } catch (...) { + std::cerr << "Unexpected exception thrown in condition node update."; + std::cerr << std::endl; + return false; + } + + // Update probability based on current multiplier. + cur_prob.probability = cur_mult * cur_prob.probability; + + // Update true or false probability depending on sign of link weight. + if (cur_weight >= 0) { + // Change true probability if this probability is higher than previous. + if (cur_prob.probability > true_prob_.probability) { + true_prob_ = cur_prob; + true_prob_from_ = cur_ID; + + // Update prob_changed_ flag. + prob_changed_ = true; + } + // Otherwise check for newly detected common probabilities if current + // probability is from this node. + else if (true_prob_from_ == cur_ID) { + for (prob_iter = cur_prob.common.begin (); + prob_iter != cur_prob.common.end (); prob_iter++) + { + // If this common probability is not in current common probability + // map, add it. + if (true_prob_.common.find (prob_iter->first) == + true_prob_.common.end ()) + { + // Add common probability. + true_prob_.common.insert (std::make_pair (prob_iter->first, + prob_iter->second)); + + // Update prob_changed_ flag. + prob_changed_ = true; + } + } + } + } else { + // Change false probability if this probability is higher than previous. + if (cur_prob.probability > false_prob_.probability) { + false_prob_ = cur_prob; + false_prob_from_ = cur_ID; + + // Update prob_changed_ flag. + prob_changed_ = true; + } + // Otherwise check for newly detected common probabilities if current + // probability is from this node. + else if (false_prob_from_ == cur_ID) { + for (prob_iter = cur_prob.common.begin (); + prob_iter != cur_prob.common.end (); prob_iter++) + { + // If this common probability is not in current common probability + // map, add it. + if (false_prob_.common.find (prob_iter->first) == + false_prob_.common.end ()) + { + // Add common probability. + false_prob_.common.insert (std::make_pair (prob_iter->first, + prob_iter->second)); + + // Update prob_changed_ flag. + prob_changed_ = true; + } + } + } + } + } + + // If a loop was detected, add current probability to common probabilities. + if (is_loop) { +#if defined (SANET_DEBUG) + std::cout << std::endl << "DEBUG in CondNode::update()... (" << ID_ << ") Loop detected, adding this node to common probabilities" << std::endl << std::endl; +#endif /* SANET_DEBUG */ + // Update common probabilities for true probability. + prob_iter = true_prob_.common.find (ID_); + if (prob_iter != true_prob_.common.end ()) { + prob_iter->second = true_prob_.probability; + } else { + true_prob_.common.insert (std::make_pair (ID_, + true_prob_.probability)); + // Update prob_changed_ flag. + prob_changed_ = true; + } + } + + // Return boolean changed value based on change flags. + return (prob_changed_ || util_changed_); +}; + +void CondNode::add_pre_link (TaskID ID, TaskNode *node, LinkWeight weight) +{ + // Add node to pre-nodes. + pre_nodes_.insert (std::make_pair (ID, node)); + + // Add link weight. + pre_links_.insert (std::make_pair (ID, weight)); +}; + +void CondNode::add_post_link (TaskID ID, TaskNode *node, LinkWeight weight) +{ + // Add node to post-nodes. + post_nodes_.insert (std::make_pair (ID, node)); + + // Add link weight. + post_links_.insert (std::make_pair (ID, weight)); +}; + +/// Get the kind +CondKind CondNode::get_cond_kind() +{ + return this->cond_kind_; +} + diff --git a/SA_POP/SANet/SANode.h b/SA_POP/SANet/SANode.h new file mode 100644 index 00000000000..92788ddb91e --- /dev/null +++ b/SA_POP/SANet/SANode.h @@ -0,0 +1,393 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file SANode.h + * + * This file contains the Node, CondNode, TaskNode and class + * definitions for spreading activation network nodes. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SA_NODE_H_ +#define SA_NODE_H_ + +#include <map> +#include <string> +#include <stdexcept> +#include <iostream> +#include "SANet_Types.h" + +namespace SANet { + // Forward declaration of Node class. + class Node; + + /// Map from node ID to pointer. + typedef std::map<NodeID, Node *> NodeMap; + + /// Map from node ID to link weight or conditional probability. + typedef std::map<NodeID, LinkWeight> LinkMap; + + /// Map from node ID to expected utility. + typedef std::map<NodeID, Utility> UtilityMap; + + /// Expected utility info for a single node (at a particular step). + typedef struct { + /// Composite utility value. + Utility utility; + + /// Map of goal node ID's to expected utilities (to avoid loops). + UtilityMap common; + } Utility_Info; + + /// Probability map from node ID to probability (positive ID's indicate + /// probability node value is true and negative ID's indicate probability + /// node value is false). + typedef std::map<CondID, Probability> ProbabilityMap; + + /// Probability info for a single node (at a particular step). + struct Probability_Info { + /// Composite probability value for the node (maximum probability for + /// condition nodes or conditional probability divided by prior + /// probability for task nodes). + Probability probability; + + /// Map of node ID's to component probabilities needed to avoid loops. + ProbabilityMap common; + }; + + + + /** + * @class Node + * + * @brief Abstract base class for nodes in the network. + */ + class Node { + public: + /// Constructor. + /** + * @param ID Node ID. + * + * @param name Node name. + * + * @param atten_factor Attenuation factor (to bias toward shorter plans). + */ + Node (NodeID ID, std::string name, MultFactor atten_factor); + + /// Destructor. + virtual ~Node (); + + /// Get (positive) expected utility info (from goals) for a given step. + /** + * @param step Step for which to get reward map. + * + * @return Positive expected utility info. + */ + virtual Utility_Info get_reward (int step); + + /// Get (maximum) probability info for a given step and true/false value. + /** + * @param step Step for which to get probability info. + * + * @param value Value for which to get probability (default = true). + * + * @return Probability info. + */ + virtual Probability_Info get_prob (int step, bool value = true); + + /// Update node to next step. + /** + * @return True if node changed probability or utility, false otherwise. + */ + virtual bool update (void) = 0; + + /// Did node change probability info on last update? + /** + * @return True if node changed probability info, false otherwise. + */ + virtual bool prob_changed (void); + + /// Did node change utility info on last update? + /** + * @return True if node changed utility info, false otherwise. + */ + virtual bool util_changed (void); + + /// Get node name. + /** + * @return Name of node. + */ + virtual std::string get_name (void); + + /// Get node ID. + /** + * @return ID of node. + */ + virtual NodeID get_ID (void); + + /// Get pre-links (nodes with links to this node). + /** + * @return Map of pre-node IDs to link weights. + */ + virtual const LinkMap& get_pre (void); + + /// Get post-links (nodes with links from this node). + /** + * @return Map of post-node IDs to link weights. + */ + virtual const LinkMap& get_post (void); + + /// Print node. + /** + * @param strm Output stream on which to print node representation. + * + * @param verbose Whether to print verbose representation. + */ + virtual void print (std::basic_ostream<char, std::char_traits<char> >& strm + = std::cout, bool verbose = false) = 0; + + protected: + /// Unique ID of node (for identification within network). + NodeID ID_; + + /// Name of node (descriptive only). + std::string name_; + + /// Attenuation factor (to bias toward shorter plans). + MultFactor atten_factor_; + + /// Current step. + int step_; + + /// Nodes with links TO this node. + NodeMap pre_nodes_; + + /// Nodes with links FROM this node. + NodeMap post_nodes_; + + /// Link weights for pre-nodes. + LinkMap pre_links_; + + /// Link weights for post-nodes. + LinkMap post_links_; + + /// Flag for whether probability info was changed on last update. + bool prob_changed_; + + /// Flag for whether utility info was changed on last update. + bool util_changed_; + + /// Positive expected utility info. + Utility_Info pos_util_; + + /// Negative expected utility info. + Utility_Info neg_util_; + + /// Probability that value is true (equivalent to success for tasks). + Probability_Info true_prob_; + + /// Probability that value is false (equivalent to failure for tasks). + Probability_Info false_prob_; + }; + + // Forward declaration of CondNode class. + class CondNode; + + /** + * @class TaskNode + * + * @brief Task nodes in the network. + */ + class TaskNode : public Node { + public: + /// Constructor. + /** + * @param ID Node ID. + * + * @param name Node name. + * + * @param atten_factor Attenuation factor (to bias toward shorter plans). + * + * @param cost Cost of performing task. + * + * @param prior_prob Prior probability of success. + */ + TaskNode (TaskID ID, std::string name, MultFactor atten_factor, TaskCost cost, + Probability prior_prob); + + /// Destructor. + virtual ~TaskNode (void); + + /// Print node. + /** + * @param strm Output stream on which to print node representation. + * + * @param verbose Whether to print verbose representation. + */ + virtual void print (std::basic_ostream<char, std::char_traits<char> >& strm + = std::cout, bool verbose = false); + + /// Update node to next step. + /** + * @return True if node changed probability or utility, false otherwise. + */ + virtual bool update (void); + + /// Get expected utility for a given step. + /** + * @param step Step for which to get expected utility. + * + * @return Expected utility. + */ + virtual Utility get_utility (int step); + + /// Add precondition link. + /** + * @param ID Node ID. + * + * @param node Node pointer. + * + * @param true_prob Conditional probability of success given + * node = true. + * + * @param false_prob Conditional probability of success given + * node = false. + */ + virtual void add_precond (CondID ID, CondNode *node, Probability true_prob, + Probability false_prob); + + /// Add effect link. + /** + * @param ID Node ID. + * + * @param node Node pointer. + * + * @param weight Link weight (probability task sets condition to + * true, or negative of the probability task sets condition to false). + */ + virtual void add_effect (CondID ID, CondNode *node, LinkWeight weight); + + protected: + /// Unconditional prior probability of success. + Probability prior_prob_; + + /// Cost of performing task. + TaskCost cost_; + + /// Conditional probabilities of success for pre-nodes having true values. + LinkMap pre_true_probs_; + + /// Conditional probabilities of success for pre-nodes having false values. + LinkMap pre_false_probs_; + }; + + /** + * @class CondNode + * + * @brief Condition nodes in the network. + */ + class CondNode : public Node { + public: + /// Constructor. + /** + * @param ID Node ID. + * + * @param name Node name. + * + * @param atten_factor Attenuation factor (to bias toward shorter plans). + * + * @param true_prob Initial probability that value is true. + * + * @param false_prob Initial probability that value is false. + * + * @param goal_util Initial utility (positive for goals, zero otherwise). + * + * @param cond_kind The type of condition. + * + */ + CondNode (CondID ID, std::string name, MultFactor atten_factor, + Probability true_prob, Probability false_prob, Utility goal_util, CondKind cond_kind); + + /// Destructor. + virtual ~CondNode (void); + + /// Get initial/current probability. + /** + * @param value Value for which to get probability (default = true). + * + * @return Initial probability of given value. + */ + virtual Probability get_init_prob (bool value = true); + + /// Update initial/current probability. + /** + * @param init_true_prob Initial/current probability of truth. + */ + virtual void set_init_prob (Probability init_true_prob); + + /// Print node. + /** + * @param strm Output stream on which to print node representation. + * + * @param verbose Whether to print verbose representation. + */ + virtual void print (std::basic_ostream<char, std::char_traits<char> >& strm + = std::cout, bool verbose = false); + + /// Update node to next step. + /** + * @return True if node changed probability or utility, false otherwise. + */ + virtual bool update (void); + + /// Add pre-link. + /** + * @param ID Node ID. + * + * @param node Node pointer. + * + * @param weight Link weight. + */ + virtual void add_pre_link (TaskID ID, TaskNode *node, LinkWeight weight); + + /// Add post-link. + /** + * @param ID Node ID. + * + * @param node Node pointer. + * + * @param weight Link weight. + */ + virtual void add_post_link (TaskID ID, TaskNode *node, LinkWeight weight); + + /// Get the kind/type of condition. + /** + * @return The kind of the condition. + */ + virtual CondKind get_cond_kind(); + + protected: + /// Goal utility for this node. + Utility goal_util_; + + /// Initial probability (of truth/success) for this node. + Probability init_true_prob_; + + /// Which node (ID) the current true probability value came from. + TaskID true_prob_from_; + + /// Which node (ID) the current false probability value came from. + TaskID false_prob_from_; + + /// Kind/type of the condition. + CondKind cond_kind_; + }; + + +}; + + +#endif /* SA_NODE_H_ */ diff --git a/SA_POP/SANet/XML_SANet.cpp b/SA_POP/SANet/XML_SANet.cpp new file mode 100644 index 00000000000..6739be66f72 --- /dev/null +++ b/SA_POP/SANet/XML_SANet.cpp @@ -0,0 +1,3467 @@ +#include "XML_SANet.hpp" + +namespace SANet +{ + namespace XML + { + // NodeID + // + + NodeID:: + NodeID (::XMLSchema::int_ const& b__) + : + Base__ (b__), + regulator__ () + { + } + + NodeID:: + NodeID (::SANet::XML::NodeID const& s) + : + Base__ (s), + regulator__ () + { + } + + ::SANet::XML::NodeID& NodeID:: + operator= (::SANet::XML::NodeID const& s) + { + static_cast< Base__& > (*this) = static_cast< Base__ const& > (s); + + return *this; + } + + + + // PortID + // + + PortID:: + PortID (::XMLSchema::string< wchar_t > const& b__) + : + Base__ (b__), + regulator__ () + { + } + + PortID:: + PortID (::SANet::XML::PortID const& s) + : + Base__ (s), + regulator__ () + { + } + + ::SANet::XML::PortID& PortID:: + operator= (::SANet::XML::PortID const& s) + { + static_cast< Base__& > (*this) = static_cast< Base__ const& > (s); + + return *this; + } + + + + // TaskCost + // + + TaskCost:: + TaskCost (::XMLSchema::double_ const& b__) + : + Base__ (b__), + regulator__ () + { + } + + TaskCost:: + TaskCost (::SANet::XML::TaskCost const& s) + : + Base__ (s), + regulator__ () + { + } + + ::SANet::XML::TaskCost& TaskCost:: + operator= (::SANet::XML::TaskCost const& s) + { + static_cast< Base__& > (*this) = static_cast< Base__ const& > (s); + + return *this; + } + + + + // CondUtil + // + + CondUtil:: + CondUtil (::XMLSchema::double_ const& b__) + : + Base__ (b__), + regulator__ () + { + } + + CondUtil:: + CondUtil (::SANet::XML::CondUtil const& s) + : + Base__ (s), + regulator__ () + { + } + + ::SANet::XML::CondUtil& CondUtil:: + operator= (::SANet::XML::CondUtil const& s) + { + static_cast< Base__& > (*this) = static_cast< Base__ const& > (s); + + return *this; + } + + + + // CondKind + // + + CondKind::Value CondKind:: + integral () const + { + return v_; + } + + bool + operator== (::SANet::XML::CondKind const& a, ::SANet::XML::CondKind const& b) + { + return a.v_ == b.v_; + } + + bool + operator!= (::SANet::XML::CondKind const& a, ::SANet::XML::CondKind const& b) + { + return a.v_ != b.v_; + } + + CondKind:: + CondKind (CondKind::Value v) + : v_ (v) + { + } + + // Probability + // + + Probability:: + Probability (::XMLSchema::double_ const& b__) + : + Base__ (b__), + regulator__ () + { + } + + Probability:: + Probability (::SANet::XML::Probability const& s) + : + Base__ (s), + regulator__ () + { + } + + ::SANet::XML::Probability& Probability:: + operator= (::SANet::XML::Probability const& s) + { + static_cast< Base__& > (*this) = static_cast< Base__ const& > (s); + + return *this; + } + + + + // LinkWeight + // + + LinkWeight:: + LinkWeight (::XMLSchema::double_ const& b__) + : + Base__ (b__), + regulator__ () + { + } + + LinkWeight:: + LinkWeight (::SANet::XML::LinkWeight const& s) + : + Base__ (s), + regulator__ () + { + } + + ::SANet::XML::LinkWeight& LinkWeight:: + operator= (::SANet::XML::LinkWeight const& s) + { + static_cast< Base__& > (*this) = static_cast< Base__ const& > (s); + + return *this; + } + + + + // MultFactor + // + + MultFactor:: + MultFactor (::XMLSchema::double_ const& b__) + : + Base__ (b__), + regulator__ () + { + } + + MultFactor:: + MultFactor (::SANet::XML::MultFactor const& s) + : + Base__ (s), + regulator__ () + { + } + + ::SANet::XML::MultFactor& MultFactor:: + operator= (::SANet::XML::MultFactor const& s) + { + static_cast< Base__& > (*this) = static_cast< Base__ const& > (s); + + return *this; + } + + + + // TaskNode + // + + TaskNode:: + TaskNode (::SANet::XML::NodeID const& nodeID__, + ::XMLSchema::string< wchar_t > const& name__, + ::SANet::XML::Probability const& priorProb__, + ::SANet::XML::MultFactor const& attenFactor__, + ::SANet::XML::TaskCost const& cost__) + : + ::XSCRT::Type (), + nodeID_ (new ::SANet::XML::NodeID (nodeID__)), + name_ (new ::XMLSchema::string< wchar_t > (name__)), + priorProb_ (new ::SANet::XML::Probability (priorProb__)), + attenFactor_ (new ::SANet::XML::MultFactor (attenFactor__)), + cost_ (new ::SANet::XML::TaskCost (cost__)), + regulator__ () + { + nodeID_->container (this); + name_->container (this); + priorProb_->container (this); + attenFactor_->container (this); + cost_->container (this); + } + + TaskNode:: + TaskNode (::SANet::XML::TaskNode const& s) + : + ::XSCRT::Type (), + nodeID_ (new ::SANet::XML::NodeID (*s.nodeID_)), + name_ (new ::XMLSchema::string< wchar_t > (*s.name_)), + priorProb_ (new ::SANet::XML::Probability (*s.priorProb_)), + attenFactor_ (new ::SANet::XML::MultFactor (*s.attenFactor_)), + cost_ (new ::SANet::XML::TaskCost (*s.cost_)), + regulator__ () + { + nodeID_->container (this); + name_->container (this); + priorProb_->container (this); + attenFactor_->container (this); + cost_->container (this); + } + + ::SANet::XML::TaskNode& TaskNode:: + operator= (::SANet::XML::TaskNode const& s) + { + nodeID (s.nodeID ()); + + name (s.name ()); + + priorProb (s.priorProb ()); + + attenFactor (s.attenFactor ()); + + cost (s.cost ()); + + return *this; + } + + + // TaskNode + // + ::SANet::XML::NodeID const& TaskNode:: + nodeID () const + { + return *nodeID_; + } + + void TaskNode:: + nodeID (::SANet::XML::NodeID const& e) + { + *nodeID_ = e; + } + + // TaskNode + // + ::XMLSchema::string< wchar_t > const& TaskNode:: + name () const + { + return *name_; + } + + void TaskNode:: + name (::XMLSchema::string< wchar_t > const& e) + { + *name_ = e; + } + + // TaskNode + // + ::SANet::XML::Probability const& TaskNode:: + priorProb () const + { + return *priorProb_; + } + + void TaskNode:: + priorProb (::SANet::XML::Probability const& e) + { + *priorProb_ = e; + } + + // TaskNode + // + ::SANet::XML::MultFactor const& TaskNode:: + attenFactor () const + { + return *attenFactor_; + } + + void TaskNode:: + attenFactor (::SANet::XML::MultFactor const& e) + { + *attenFactor_ = e; + } + + // TaskNode + // + ::SANet::XML::TaskCost const& TaskNode:: + cost () const + { + return *cost_; + } + + void TaskNode:: + cost (::SANet::XML::TaskCost const& e) + { + *cost_ = e; + } + + + // CondNode + // + + CondNode:: + CondNode (::SANet::XML::NodeID const& nodeID__, + ::XMLSchema::string< wchar_t > const& name__, + ::SANet::XML::Probability const& probTrue__, + ::SANet::XML::CondUtil const& utility__, + ::SANet::XML::CondKind const& kind__, + ::SANet::XML::MultFactor const& attenFactor__) + : + ::XSCRT::Type (), + nodeID_ (new ::SANet::XML::NodeID (nodeID__)), + name_ (new ::XMLSchema::string< wchar_t > (name__)), + probTrue_ (new ::SANet::XML::Probability (probTrue__)), + utility_ (new ::SANet::XML::CondUtil (utility__)), + kind_ (new ::SANet::XML::CondKind (kind__)), + attenFactor_ (new ::SANet::XML::MultFactor (attenFactor__)), + regulator__ () + { + nodeID_->container (this); + name_->container (this); + probTrue_->container (this); + utility_->container (this); + kind_->container (this); + attenFactor_->container (this); + } + + CondNode:: + CondNode (::SANet::XML::CondNode const& s) + : + ::XSCRT::Type (), + nodeID_ (new ::SANet::XML::NodeID (*s.nodeID_)), + name_ (new ::XMLSchema::string< wchar_t > (*s.name_)), + probTrue_ (new ::SANet::XML::Probability (*s.probTrue_)), + utility_ (new ::SANet::XML::CondUtil (*s.utility_)), + kind_ (new ::SANet::XML::CondKind (*s.kind_)), + attenFactor_ (new ::SANet::XML::MultFactor (*s.attenFactor_)), + regulator__ () + { + nodeID_->container (this); + name_->container (this); + probTrue_->container (this); + utility_->container (this); + kind_->container (this); + attenFactor_->container (this); + } + + ::SANet::XML::CondNode& CondNode:: + operator= (::SANet::XML::CondNode const& s) + { + nodeID (s.nodeID ()); + + name (s.name ()); + + probTrue (s.probTrue ()); + + utility (s.utility ()); + + kind (s.kind ()); + + attenFactor (s.attenFactor ()); + + return *this; + } + + + // CondNode + // + ::SANet::XML::NodeID const& CondNode:: + nodeID () const + { + return *nodeID_; + } + + void CondNode:: + nodeID (::SANet::XML::NodeID const& e) + { + *nodeID_ = e; + } + + // CondNode + // + ::XMLSchema::string< wchar_t > const& CondNode:: + name () const + { + return *name_; + } + + void CondNode:: + name (::XMLSchema::string< wchar_t > const& e) + { + *name_ = e; + } + + // CondNode + // + ::SANet::XML::Probability const& CondNode:: + probTrue () const + { + return *probTrue_; + } + + void CondNode:: + probTrue (::SANet::XML::Probability const& e) + { + *probTrue_ = e; + } + + // CondNode + // + ::SANet::XML::CondUtil const& CondNode:: + utility () const + { + return *utility_; + } + + void CondNode:: + utility (::SANet::XML::CondUtil const& e) + { + *utility_ = e; + } + + // CondNode + // + ::SANet::XML::CondKind const& CondNode:: + kind () const + { + return *kind_; + } + + void CondNode:: + kind (::SANet::XML::CondKind const& e) + { + *kind_ = e; + } + + // CondNode + // + ::SANet::XML::MultFactor const& CondNode:: + attenFactor () const + { + return *attenFactor_; + } + + void CondNode:: + attenFactor (::SANet::XML::MultFactor const& e) + { + *attenFactor_ = e; + } + + + // PrecondLink + // + + PrecondLink:: + PrecondLink (::SANet::XML::NodeID const& condID__, + ::SANet::XML::NodeID const& taskID__, + ::SANet::XML::PortID const& portID__, + ::SANet::XML::Probability const& trueProb__, + ::SANet::XML::Probability const& falseProb__) + : + ::XSCRT::Type (), + condID_ (new ::SANet::XML::NodeID (condID__)), + taskID_ (new ::SANet::XML::NodeID (taskID__)), + portID_ (new ::SANet::XML::PortID (portID__)), + trueProb_ (new ::SANet::XML::Probability (trueProb__)), + falseProb_ (new ::SANet::XML::Probability (falseProb__)), + regulator__ () + { + condID_->container (this); + taskID_->container (this); + portID_->container (this); + trueProb_->container (this); + falseProb_->container (this); + } + + PrecondLink:: + PrecondLink (::SANet::XML::PrecondLink const& s) + : + ::XSCRT::Type (), + condID_ (new ::SANet::XML::NodeID (*s.condID_)), + taskID_ (new ::SANet::XML::NodeID (*s.taskID_)), + portID_ (new ::SANet::XML::PortID (*s.portID_)), + trueProb_ (new ::SANet::XML::Probability (*s.trueProb_)), + falseProb_ (new ::SANet::XML::Probability (*s.falseProb_)), + regulator__ () + { + condID_->container (this); + taskID_->container (this); + portID_->container (this); + trueProb_->container (this); + falseProb_->container (this); + } + + ::SANet::XML::PrecondLink& PrecondLink:: + operator= (::SANet::XML::PrecondLink const& s) + { + condID (s.condID ()); + + taskID (s.taskID ()); + + portID (s.portID ()); + + trueProb (s.trueProb ()); + + falseProb (s.falseProb ()); + + return *this; + } + + + // PrecondLink + // + ::SANet::XML::NodeID const& PrecondLink:: + condID () const + { + return *condID_; + } + + void PrecondLink:: + condID (::SANet::XML::NodeID const& e) + { + *condID_ = e; + } + + // PrecondLink + // + ::SANet::XML::NodeID const& PrecondLink:: + taskID () const + { + return *taskID_; + } + + void PrecondLink:: + taskID (::SANet::XML::NodeID const& e) + { + *taskID_ = e; + } + + // PrecondLink + // + ::SANet::XML::PortID const& PrecondLink:: + portID () const + { + return *portID_; + } + + void PrecondLink:: + portID (::SANet::XML::PortID const& e) + { + *portID_ = e; + } + + // PrecondLink + // + ::SANet::XML::Probability const& PrecondLink:: + trueProb () const + { + return *trueProb_; + } + + void PrecondLink:: + trueProb (::SANet::XML::Probability const& e) + { + *trueProb_ = e; + } + + // PrecondLink + // + ::SANet::XML::Probability const& PrecondLink:: + falseProb () const + { + return *falseProb_; + } + + void PrecondLink:: + falseProb (::SANet::XML::Probability const& e) + { + *falseProb_ = e; + } + + + // EffectLink + // + + EffectLink:: + EffectLink (::SANet::XML::NodeID const& taskID__, + ::SANet::XML::NodeID const& condID__, + ::SANet::XML::PortID const& portID__, + ::SANet::XML::LinkWeight const& weight__) + : + ::XSCRT::Type (), + taskID_ (new ::SANet::XML::NodeID (taskID__)), + condID_ (new ::SANet::XML::NodeID (condID__)), + portID_ (new ::SANet::XML::PortID (portID__)), + weight_ (new ::SANet::XML::LinkWeight (weight__)), + regulator__ () + { + taskID_->container (this); + condID_->container (this); + portID_->container (this); + weight_->container (this); + } + + EffectLink:: + EffectLink (::SANet::XML::EffectLink const& s) + : + ::XSCRT::Type (), + taskID_ (new ::SANet::XML::NodeID (*s.taskID_)), + condID_ (new ::SANet::XML::NodeID (*s.condID_)), + portID_ (new ::SANet::XML::PortID (*s.portID_)), + weight_ (new ::SANet::XML::LinkWeight (*s.weight_)), + regulator__ () + { + taskID_->container (this); + condID_->container (this); + portID_->container (this); + weight_->container (this); + } + + ::SANet::XML::EffectLink& EffectLink:: + operator= (::SANet::XML::EffectLink const& s) + { + taskID (s.taskID ()); + + condID (s.condID ()); + + portID (s.portID ()); + + weight (s.weight ()); + + return *this; + } + + + // EffectLink + // + ::SANet::XML::NodeID const& EffectLink:: + taskID () const + { + return *taskID_; + } + + void EffectLink:: + taskID (::SANet::XML::NodeID const& e) + { + *taskID_ = e; + } + + // EffectLink + // + ::SANet::XML::NodeID const& EffectLink:: + condID () const + { + return *condID_; + } + + void EffectLink:: + condID (::SANet::XML::NodeID const& e) + { + *condID_ = e; + } + + // EffectLink + // + ::SANet::XML::PortID const& EffectLink:: + portID () const + { + return *portID_; + } + + void EffectLink:: + portID (::SANet::XML::PortID const& e) + { + *portID_ = e; + } + + // EffectLink + // + ::SANet::XML::LinkWeight const& EffectLink:: + weight () const + { + return *weight_; + } + + void EffectLink:: + weight (::SANet::XML::LinkWeight const& e) + { + *weight_ = e; + } + + + // Network + // + + Network:: + Network (::SANet::XML::MultFactor const& defaultAttenFactor__, + ::SANet::XML::TaskCost const& defaultTaskCost__, + ::SANet::XML::CondUtil const& defaultCondUtil__, + ::SANet::XML::Probability const& defaultCondProbTrue__, + ::SANet::XML::LinkWeight const& linkThresh__) + : + ::XSCRT::Type (), + defaultAttenFactor_ (new ::SANet::XML::MultFactor (defaultAttenFactor__)), + defaultTaskCost_ (new ::SANet::XML::TaskCost (defaultTaskCost__)), + defaultCondUtil_ (new ::SANet::XML::CondUtil (defaultCondUtil__)), + defaultCondProbTrue_ (new ::SANet::XML::Probability (defaultCondProbTrue__)), + linkThresh_ (new ::SANet::XML::LinkWeight (linkThresh__)), + regulator__ () + { + defaultAttenFactor_->container (this); + defaultTaskCost_->container (this); + defaultCondUtil_->container (this); + defaultCondProbTrue_->container (this); + linkThresh_->container (this); + } + + Network:: + Network (::SANet::XML::Network const& s) + : + ::XSCRT::Type (), + defaultAttenFactor_ (new ::SANet::XML::MultFactor (*s.defaultAttenFactor_)), + defaultTaskCost_ (new ::SANet::XML::TaskCost (*s.defaultTaskCost_)), + defaultCondUtil_ (new ::SANet::XML::CondUtil (*s.defaultCondUtil_)), + defaultCondProbTrue_ (new ::SANet::XML::Probability (*s.defaultCondProbTrue_)), + linkThresh_ (new ::SANet::XML::LinkWeight (*s.linkThresh_)), + regulator__ () + { + defaultAttenFactor_->container (this); + defaultTaskCost_->container (this); + defaultCondUtil_->container (this); + defaultCondProbTrue_->container (this); + linkThresh_->container (this); + { + for (taskNode_const_iterator i (s.taskNode_.begin ());i != s.taskNode_.end ();++i) add_taskNode (*i); + } + + { + for (condNode_const_iterator i (s.condNode_.begin ());i != s.condNode_.end ();++i) add_condNode (*i); + } + + { + for (precondLink_const_iterator i (s.precondLink_.begin ());i != s.precondLink_.end ();++i) add_precondLink (*i); + } + + { + for (effectLink_const_iterator i (s.effectLink_.begin ());i != s.effectLink_.end ();++i) add_effectLink (*i); + } + } + + ::SANet::XML::Network& Network:: + operator= (::SANet::XML::Network const& s) + { + defaultAttenFactor (s.defaultAttenFactor ()); + + defaultTaskCost (s.defaultTaskCost ()); + + defaultCondUtil (s.defaultCondUtil ()); + + defaultCondProbTrue (s.defaultCondProbTrue ()); + + linkThresh (s.linkThresh ()); + + taskNode_.clear (); + { + for (taskNode_const_iterator i (s.taskNode_.begin ());i != s.taskNode_.end ();++i) add_taskNode (*i); + } + + condNode_.clear (); + { + for (condNode_const_iterator i (s.condNode_.begin ());i != s.condNode_.end ();++i) add_condNode (*i); + } + + precondLink_.clear (); + { + for (precondLink_const_iterator i (s.precondLink_.begin ());i != s.precondLink_.end ();++i) add_precondLink (*i); + } + + effectLink_.clear (); + { + for (effectLink_const_iterator i (s.effectLink_.begin ());i != s.effectLink_.end ();++i) add_effectLink (*i); + } + + return *this; + } + + + // Network + // + ::SANet::XML::MultFactor const& Network:: + defaultAttenFactor () const + { + return *defaultAttenFactor_; + } + + void Network:: + defaultAttenFactor (::SANet::XML::MultFactor const& e) + { + *defaultAttenFactor_ = e; + } + + // Network + // + ::SANet::XML::TaskCost const& Network:: + defaultTaskCost () const + { + return *defaultTaskCost_; + } + + void Network:: + defaultTaskCost (::SANet::XML::TaskCost const& e) + { + *defaultTaskCost_ = e; + } + + // Network + // + ::SANet::XML::CondUtil const& Network:: + defaultCondUtil () const + { + return *defaultCondUtil_; + } + + void Network:: + defaultCondUtil (::SANet::XML::CondUtil const& e) + { + *defaultCondUtil_ = e; + } + + // Network + // + ::SANet::XML::Probability const& Network:: + defaultCondProbTrue () const + { + return *defaultCondProbTrue_; + } + + void Network:: + defaultCondProbTrue (::SANet::XML::Probability const& e) + { + *defaultCondProbTrue_ = e; + } + + // Network + // + ::SANet::XML::LinkWeight const& Network:: + linkThresh () const + { + return *linkThresh_; + } + + void Network:: + linkThresh (::SANet::XML::LinkWeight const& e) + { + *linkThresh_ = e; + } + + // Network + // + Network::taskNode_iterator Network:: + begin_taskNode () + { + return taskNode_.begin (); + } + + Network::taskNode_iterator Network:: + end_taskNode () + { + return taskNode_.end (); + } + + Network::taskNode_const_iterator Network:: + begin_taskNode () const + { + return taskNode_.begin (); + } + + Network::taskNode_const_iterator Network:: + end_taskNode () const + { + return taskNode_.end (); + } + + void Network:: + add_taskNode (::SANet::XML::TaskNode const& e) + { + taskNode_.push_back (e); + } + + size_t Network:: + count_taskNode(void) const + { + return taskNode_.size (); + } + + // Network + // + Network::condNode_iterator Network:: + begin_condNode () + { + return condNode_.begin (); + } + + Network::condNode_iterator Network:: + end_condNode () + { + return condNode_.end (); + } + + Network::condNode_const_iterator Network:: + begin_condNode () const + { + return condNode_.begin (); + } + + Network::condNode_const_iterator Network:: + end_condNode () const + { + return condNode_.end (); + } + + void Network:: + add_condNode (::SANet::XML::CondNode const& e) + { + condNode_.push_back (e); + } + + size_t Network:: + count_condNode(void) const + { + return condNode_.size (); + } + + // Network + // + Network::precondLink_iterator Network:: + begin_precondLink () + { + return precondLink_.begin (); + } + + Network::precondLink_iterator Network:: + end_precondLink () + { + return precondLink_.end (); + } + + Network::precondLink_const_iterator Network:: + begin_precondLink () const + { + return precondLink_.begin (); + } + + Network::precondLink_const_iterator Network:: + end_precondLink () const + { + return precondLink_.end (); + } + + void Network:: + add_precondLink (::SANet::XML::PrecondLink const& e) + { + precondLink_.push_back (e); + } + + size_t Network:: + count_precondLink(void) const + { + return precondLink_.size (); + } + + // Network + // + Network::effectLink_iterator Network:: + begin_effectLink () + { + return effectLink_.begin (); + } + + Network::effectLink_iterator Network:: + end_effectLink () + { + return effectLink_.end (); + } + + Network::effectLink_const_iterator Network:: + begin_effectLink () const + { + return effectLink_.begin (); + } + + Network::effectLink_const_iterator Network:: + end_effectLink () const + { + return effectLink_.end (); + } + + void Network:: + add_effectLink (::SANet::XML::EffectLink const& e) + { + effectLink_.push_back (e); + } + + size_t Network:: + count_effectLink(void) const + { + return effectLink_.size (); + } + } +} + +namespace SANet +{ + namespace XML + { + // NodeID + // + + NodeID:: + NodeID (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + } + + NodeID:: + NodeID (::XSCRT::XML::Attribute< wchar_t > const& a) + : + Base__ (a), + regulator__ () + { + } + + // PortID + // + + PortID:: + PortID (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + } + + PortID:: + PortID (::XSCRT::XML::Attribute< wchar_t > const& a) + : + Base__ (a), + regulator__ () + { + } + + // TaskCost + // + + TaskCost:: + TaskCost (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + } + + TaskCost:: + TaskCost (::XSCRT::XML::Attribute< wchar_t > const& a) + : + Base__ (a), + regulator__ () + { + } + + // CondUtil + // + + CondUtil:: + CondUtil (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + } + + CondUtil:: + CondUtil (::XSCRT::XML::Attribute< wchar_t > const& a) + : + Base__ (a), + regulator__ () + { + } + + // CondKind + // + + CondKind:: + CondKind (::XSCRT::XML::Element< wchar_t > const& e) + : ::XSCRT::Type (e) + { + ::std::basic_string< wchar_t > v (e.value ()); + + if (v == L"ENVIRON") v_ = ENVIRON_l; + else if (v == L"SYSTEM") v_ = SYSTEM_l; + else if (v == L"DATA") v_ = DATA_l; + else + { + } + } + + CondKind:: + CondKind (::XSCRT::XML::Attribute< wchar_t > const& a) + : ::XSCRT::Type (a) + { + ::std::basic_string< wchar_t > v (a.value ()); + + if (v == L"ENVIRON") v_ = ENVIRON_l; + else if (v == L"SYSTEM") v_ = SYSTEM_l; + else if (v == L"DATA") v_ = DATA_l; + else + { + } + } + + CondKind const CondKind::ENVIRON (CondKind::ENVIRON_l); + CondKind const CondKind::SYSTEM (CondKind::SYSTEM_l); + CondKind const CondKind::DATA (CondKind::DATA_l); + + // Probability + // + + Probability:: + Probability (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + } + + Probability:: + Probability (::XSCRT::XML::Attribute< wchar_t > const& a) + : + Base__ (a), + regulator__ () + { + } + + // LinkWeight + // + + LinkWeight:: + LinkWeight (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + } + + LinkWeight:: + LinkWeight (::XSCRT::XML::Attribute< wchar_t > const& a) + : + Base__ (a), + regulator__ () + { + } + + // MultFactor + // + + MultFactor:: + MultFactor (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + } + + MultFactor:: + MultFactor (::XSCRT::XML::Attribute< wchar_t > const& a) + : + Base__ (a), + regulator__ () + { + } + + // TaskNode + // + + TaskNode:: + TaskNode (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + + ::XSCRT::Parser< wchar_t > p (e); + + while (p.more_elements ()) + { + ::XSCRT::XML::Element< wchar_t > e (p.next_element ()); + ::std::basic_string< wchar_t > n (::XSCRT::XML::uq_name (e.name ())); + + if (n == L"nodeID") + { + nodeID_ = ::std::auto_ptr< ::SANet::XML::NodeID > (new ::SANet::XML::NodeID (e)); + nodeID_->container (this); + } + + else if (n == L"name") + { + name_ = ::std::auto_ptr< ::XMLSchema::string< wchar_t > > (new ::XMLSchema::string< wchar_t > (e)); + name_->container (this); + } + + else if (n == L"priorProb") + { + priorProb_ = ::std::auto_ptr< ::SANet::XML::Probability > (new ::SANet::XML::Probability (e)); + priorProb_->container (this); + } + + else if (n == L"attenFactor") + { + attenFactor_ = ::std::auto_ptr< ::SANet::XML::MultFactor > (new ::SANet::XML::MultFactor (e)); + attenFactor_->container (this); + } + + else if (n == L"cost") + { + cost_ = ::std::auto_ptr< ::SANet::XML::TaskCost > (new ::SANet::XML::TaskCost (e)); + cost_->container (this); + } + + else + { + } + } + } + + // CondNode + // + + CondNode:: + CondNode (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + + ::XSCRT::Parser< wchar_t > p (e); + + while (p.more_elements ()) + { + ::XSCRT::XML::Element< wchar_t > e (p.next_element ()); + ::std::basic_string< wchar_t > n (::XSCRT::XML::uq_name (e.name ())); + + if (n == L"nodeID") + { + nodeID_ = ::std::auto_ptr< ::SANet::XML::NodeID > (new ::SANet::XML::NodeID (e)); + nodeID_->container (this); + } + + else if (n == L"name") + { + name_ = ::std::auto_ptr< ::XMLSchema::string< wchar_t > > (new ::XMLSchema::string< wchar_t > (e)); + name_->container (this); + } + + else if (n == L"probTrue") + { + probTrue_ = ::std::auto_ptr< ::SANet::XML::Probability > (new ::SANet::XML::Probability (e)); + probTrue_->container (this); + } + + else if (n == L"utility") + { + utility_ = ::std::auto_ptr< ::SANet::XML::CondUtil > (new ::SANet::XML::CondUtil (e)); + utility_->container (this); + } + + else if (n == L"kind") + { + kind_ = ::std::auto_ptr< ::SANet::XML::CondKind > (new ::SANet::XML::CondKind (e)); + kind_->container (this); + } + + else if (n == L"attenFactor") + { + attenFactor_ = ::std::auto_ptr< ::SANet::XML::MultFactor > (new ::SANet::XML::MultFactor (e)); + attenFactor_->container (this); + } + + else + { + } + } + } + + // PrecondLink + // + + PrecondLink:: + PrecondLink (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + + ::XSCRT::Parser< wchar_t > p (e); + + while (p.more_elements ()) + { + ::XSCRT::XML::Element< wchar_t > e (p.next_element ()); + ::std::basic_string< wchar_t > n (::XSCRT::XML::uq_name (e.name ())); + + if (n == L"condID") + { + condID_ = ::std::auto_ptr< ::SANet::XML::NodeID > (new ::SANet::XML::NodeID (e)); + condID_->container (this); + } + + else if (n == L"taskID") + { + taskID_ = ::std::auto_ptr< ::SANet::XML::NodeID > (new ::SANet::XML::NodeID (e)); + taskID_->container (this); + } + + else if (n == L"portID") + { + portID_ = ::std::auto_ptr< ::SANet::XML::PortID > (new ::SANet::XML::PortID (e)); + portID_->container (this); + } + + else if (n == L"trueProb") + { + trueProb_ = ::std::auto_ptr< ::SANet::XML::Probability > (new ::SANet::XML::Probability (e)); + trueProb_->container (this); + } + + else if (n == L"falseProb") + { + falseProb_ = ::std::auto_ptr< ::SANet::XML::Probability > (new ::SANet::XML::Probability (e)); + falseProb_->container (this); + } + + else + { + } + } + } + + // EffectLink + // + + EffectLink:: + EffectLink (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + + ::XSCRT::Parser< wchar_t > p (e); + + while (p.more_elements ()) + { + ::XSCRT::XML::Element< wchar_t > e (p.next_element ()); + ::std::basic_string< wchar_t > n (::XSCRT::XML::uq_name (e.name ())); + + if (n == L"taskID") + { + taskID_ = ::std::auto_ptr< ::SANet::XML::NodeID > (new ::SANet::XML::NodeID (e)); + taskID_->container (this); + } + + else if (n == L"condID") + { + condID_ = ::std::auto_ptr< ::SANet::XML::NodeID > (new ::SANet::XML::NodeID (e)); + condID_->container (this); + } + + else if (n == L"portID") + { + portID_ = ::std::auto_ptr< ::SANet::XML::PortID > (new ::SANet::XML::PortID (e)); + portID_->container (this); + } + + else if (n == L"weight") + { + weight_ = ::std::auto_ptr< ::SANet::XML::LinkWeight > (new ::SANet::XML::LinkWeight (e)); + weight_->container (this); + } + + else + { + } + } + } + + // Network + // + + Network:: + Network (::XSCRT::XML::Element< wchar_t > const& e) + :Base__ (e), regulator__ () + { + + ::XSCRT::Parser< wchar_t > p (e); + + while (p.more_elements ()) + { + ::XSCRT::XML::Element< wchar_t > e (p.next_element ()); + ::std::basic_string< wchar_t > n (::XSCRT::XML::uq_name (e.name ())); + + if (n == L"defaultAttenFactor") + { + defaultAttenFactor_ = ::std::auto_ptr< ::SANet::XML::MultFactor > (new ::SANet::XML::MultFactor (e)); + defaultAttenFactor_->container (this); + } + + else if (n == L"defaultTaskCost") + { + defaultTaskCost_ = ::std::auto_ptr< ::SANet::XML::TaskCost > (new ::SANet::XML::TaskCost (e)); + defaultTaskCost_->container (this); + } + + else if (n == L"defaultCondUtil") + { + defaultCondUtil_ = ::std::auto_ptr< ::SANet::XML::CondUtil > (new ::SANet::XML::CondUtil (e)); + defaultCondUtil_->container (this); + } + + else if (n == L"defaultCondProbTrue") + { + defaultCondProbTrue_ = ::std::auto_ptr< ::SANet::XML::Probability > (new ::SANet::XML::Probability (e)); + defaultCondProbTrue_->container (this); + } + + else if (n == L"linkThresh") + { + linkThresh_ = ::std::auto_ptr< ::SANet::XML::LinkWeight > (new ::SANet::XML::LinkWeight (e)); + linkThresh_->container (this); + } + + else if (n == L"taskNode") + { + ::SANet::XML::TaskNode t (e); + add_taskNode (t); + } + + else if (n == L"condNode") + { + ::SANet::XML::CondNode t (e); + add_condNode (t); + } + + else if (n == L"precondLink") + { + ::SANet::XML::PrecondLink t (e); + add_precondLink (t); + } + + else if (n == L"effectLink") + { + ::SANet::XML::EffectLink t (e); + add_effectLink (t); + } + + else + { + } + } + } + } +} + +namespace SANet +{ + namespace XML + { + ::SANet::XML::Network + network (xercesc::DOMDocument const* d) + { + std::cout << "In create netwokr!\n"; + ::XSCRT::XML::Element< wchar_t > e (d->getDocumentElement ()); + std::cout << "Got the element from the network!\n"; + if (e.name () == L"network") + { + + ::SANet::XML::Network r (e); + std::cout << "Done creating the network\n"; + return r; + } + + else + { + std::wcout << "The network name is not equal to network, but it is " << e.name().c_str() << std::endl; + throw 1; + } + } + } +} + +#include "XMLSchema/TypeInfo.hpp" + +namespace SANet +{ + namespace XML + { + namespace + { + ::XMLSchema::TypeInfoInitializer < wchar_t > XMLSchemaTypeInfoInitializer_ (::XSCRT::extended_type_info_map ()); + + struct NodeIDTypeInfoInitializer + { + NodeIDTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (NodeID)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XMLSchema::int_)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + NodeIDTypeInfoInitializer NodeIDTypeInfoInitializer_; + + struct PortIDTypeInfoInitializer + { + PortIDTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (PortID)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XMLSchema::string< wchar_t >)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + PortIDTypeInfoInitializer PortIDTypeInfoInitializer_; + + struct TaskCostTypeInfoInitializer + { + TaskCostTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (TaskCost)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XMLSchema::double_)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + TaskCostTypeInfoInitializer TaskCostTypeInfoInitializer_; + + struct CondUtilTypeInfoInitializer + { + CondUtilTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (CondUtil)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XMLSchema::double_)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + CondUtilTypeInfoInitializer CondUtilTypeInfoInitializer_; + + struct CondKindTypeInfoInitializer + { + CondKindTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (CondKind)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XSCRT::Type)); + + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + CondKindTypeInfoInitializer CondKindTypeInfoInitializer_; + + struct ProbabilityTypeInfoInitializer + { + ProbabilityTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (Probability)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XMLSchema::double_)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + ProbabilityTypeInfoInitializer ProbabilityTypeInfoInitializer_; + + struct LinkWeightTypeInfoInitializer + { + LinkWeightTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (LinkWeight)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XMLSchema::double_)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + LinkWeightTypeInfoInitializer LinkWeightTypeInfoInitializer_; + + struct MultFactorTypeInfoInitializer + { + MultFactorTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (MultFactor)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XMLSchema::double_)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + MultFactorTypeInfoInitializer MultFactorTypeInfoInitializer_; + + struct TaskNodeTypeInfoInitializer + { + TaskNodeTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (TaskNode)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XSCRT::Type)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + TaskNodeTypeInfoInitializer TaskNodeTypeInfoInitializer_; + + struct CondNodeTypeInfoInitializer + { + CondNodeTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (CondNode)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XSCRT::Type)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + CondNodeTypeInfoInitializer CondNodeTypeInfoInitializer_; + + struct PrecondLinkTypeInfoInitializer + { + PrecondLinkTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (PrecondLink)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XSCRT::Type)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + PrecondLinkTypeInfoInitializer PrecondLinkTypeInfoInitializer_; + + struct EffectLinkTypeInfoInitializer + { + EffectLinkTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (EffectLink)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XSCRT::Type)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + EffectLinkTypeInfoInitializer EffectLinkTypeInfoInitializer_; + + struct NetworkTypeInfoInitializer + { + NetworkTypeInfoInitializer () + { + ::XSCRT::TypeId id (typeid (Network)); + ::XSCRT::ExtendedTypeInfo nf (id); + + nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XSCRT::Type)); + ::XSCRT::extended_type_info_map ().insert (::std::make_pair (id, nf)); + } + }; + + NetworkTypeInfoInitializer NetworkTypeInfoInitializer_; + } + } +} + +namespace SANet +{ + namespace XML + { + namespace Traversal + { + // NodeID + // + // + + void NodeID:: + traverse (Type& o) + { + pre (o); + post (o); + } + + void NodeID:: + traverse (Type const& o) + { + pre (o); + post (o); + } + + void NodeID:: + pre (Type&) + { + } + + void NodeID:: + pre (Type const&) + { + } + + void NodeID:: + post (Type&) + { + } + + void NodeID:: + post (Type const&) + { + } + + // PortID + // + // + + void PortID:: + traverse (Type& o) + { + pre (o); + post (o); + } + + void PortID:: + traverse (Type const& o) + { + pre (o); + post (o); + } + + void PortID:: + pre (Type&) + { + } + + void PortID:: + pre (Type const&) + { + } + + void PortID:: + post (Type&) + { + } + + void PortID:: + post (Type const&) + { + } + + // TaskCost + // + // + + void TaskCost:: + traverse (Type& o) + { + pre (o); + post (o); + } + + void TaskCost:: + traverse (Type const& o) + { + pre (o); + post (o); + } + + void TaskCost:: + pre (Type&) + { + } + + void TaskCost:: + pre (Type const&) + { + } + + void TaskCost:: + post (Type&) + { + } + + void TaskCost:: + post (Type const&) + { + } + + // CondUtil + // + // + + void CondUtil:: + traverse (Type& o) + { + pre (o); + post (o); + } + + void CondUtil:: + traverse (Type const& o) + { + pre (o); + post (o); + } + + void CondUtil:: + pre (Type&) + { + } + + void CondUtil:: + pre (Type const&) + { + } + + void CondUtil:: + post (Type&) + { + } + + void CondUtil:: + post (Type const&) + { + } + + // Probability + // + // + + void Probability:: + traverse (Type& o) + { + pre (o); + post (o); + } + + void Probability:: + traverse (Type const& o) + { + pre (o); + post (o); + } + + void Probability:: + pre (Type&) + { + } + + void Probability:: + pre (Type const&) + { + } + + void Probability:: + post (Type&) + { + } + + void Probability:: + post (Type const&) + { + } + + // LinkWeight + // + // + + void LinkWeight:: + traverse (Type& o) + { + pre (o); + post (o); + } + + void LinkWeight:: + traverse (Type const& o) + { + pre (o); + post (o); + } + + void LinkWeight:: + pre (Type&) + { + } + + void LinkWeight:: + pre (Type const&) + { + } + + void LinkWeight:: + post (Type&) + { + } + + void LinkWeight:: + post (Type const&) + { + } + + // MultFactor + // + // + + void MultFactor:: + traverse (Type& o) + { + pre (o); + post (o); + } + + void MultFactor:: + traverse (Type const& o) + { + pre (o); + post (o); + } + + void MultFactor:: + pre (Type&) + { + } + + void MultFactor:: + pre (Type const&) + { + } + + void MultFactor:: + post (Type&) + { + } + + void MultFactor:: + post (Type const&) + { + } + + // TaskNode + // + // + + void TaskNode:: + traverse (Type& o) + { + pre (o); + nodeID (o); + name (o); + priorProb (o); + attenFactor (o); + cost (o); + post (o); + } + + void TaskNode:: + traverse (Type const& o) + { + pre (o); + nodeID (o); + name (o); + priorProb (o); + attenFactor (o); + cost (o); + post (o); + } + + void TaskNode:: + pre (Type&) + { + } + + void TaskNode:: + pre (Type const&) + { + } + + void TaskNode:: + nodeID (Type& o) + { + dispatch (o.nodeID ()); + } + + void TaskNode:: + nodeID (Type const& o) + { + dispatch (o.nodeID ()); + } + + void TaskNode:: + name (Type& o) + { + dispatch (o.name ()); + } + + void TaskNode:: + name (Type const& o) + { + dispatch (o.name ()); + } + + void TaskNode:: + priorProb (Type& o) + { + dispatch (o.priorProb ()); + } + + void TaskNode:: + priorProb (Type const& o) + { + dispatch (o.priorProb ()); + } + + void TaskNode:: + attenFactor (Type& o) + { + dispatch (o.attenFactor ()); + } + + void TaskNode:: + attenFactor (Type const& o) + { + dispatch (o.attenFactor ()); + } + + void TaskNode:: + cost (Type& o) + { + dispatch (o.cost ()); + } + + void TaskNode:: + cost (Type const& o) + { + dispatch (o.cost ()); + } + + void TaskNode:: + post (Type&) + { + } + + void TaskNode:: + post (Type const&) + { + } + + // CondNode + // + // + + void CondNode:: + traverse (Type& o) + { + pre (o); + nodeID (o); + name (o); + probTrue (o); + utility (o); + kind (o); + attenFactor (o); + post (o); + } + + void CondNode:: + traverse (Type const& o) + { + pre (o); + nodeID (o); + name (o); + probTrue (o); + utility (o); + kind (o); + attenFactor (o); + post (o); + } + + void CondNode:: + pre (Type&) + { + } + + void CondNode:: + pre (Type const&) + { + } + + void CondNode:: + nodeID (Type& o) + { + dispatch (o.nodeID ()); + } + + void CondNode:: + nodeID (Type const& o) + { + dispatch (o.nodeID ()); + } + + void CondNode:: + name (Type& o) + { + dispatch (o.name ()); + } + + void CondNode:: + name (Type const& o) + { + dispatch (o.name ()); + } + + void CondNode:: + probTrue (Type& o) + { + dispatch (o.probTrue ()); + } + + void CondNode:: + probTrue (Type const& o) + { + dispatch (o.probTrue ()); + } + + void CondNode:: + utility (Type& o) + { + dispatch (o.utility ()); + } + + void CondNode:: + utility (Type const& o) + { + dispatch (o.utility ()); + } + + void CondNode:: + kind (Type& o) + { + dispatch (o.kind ()); + } + + void CondNode:: + kind (Type const& o) + { + dispatch (o.kind ()); + } + + void CondNode:: + attenFactor (Type& o) + { + dispatch (o.attenFactor ()); + } + + void CondNode:: + attenFactor (Type const& o) + { + dispatch (o.attenFactor ()); + } + + void CondNode:: + post (Type&) + { + } + + void CondNode:: + post (Type const&) + { + } + + // PrecondLink + // + // + + void PrecondLink:: + traverse (Type& o) + { + pre (o); + condID (o); + taskID (o); + portID (o); + trueProb (o); + falseProb (o); + post (o); + } + + void PrecondLink:: + traverse (Type const& o) + { + pre (o); + condID (o); + taskID (o); + portID (o); + trueProb (o); + falseProb (o); + post (o); + } + + void PrecondLink:: + pre (Type&) + { + } + + void PrecondLink:: + pre (Type const&) + { + } + + void PrecondLink:: + condID (Type& o) + { + dispatch (o.condID ()); + } + + void PrecondLink:: + condID (Type const& o) + { + dispatch (o.condID ()); + } + + void PrecondLink:: + taskID (Type& o) + { + dispatch (o.taskID ()); + } + + void PrecondLink:: + taskID (Type const& o) + { + dispatch (o.taskID ()); + } + + void PrecondLink:: + portID (Type& o) + { + dispatch (o.portID ()); + } + + void PrecondLink:: + portID (Type const& o) + { + dispatch (o.portID ()); + } + + void PrecondLink:: + trueProb (Type& o) + { + dispatch (o.trueProb ()); + } + + void PrecondLink:: + trueProb (Type const& o) + { + dispatch (o.trueProb ()); + } + + void PrecondLink:: + falseProb (Type& o) + { + dispatch (o.falseProb ()); + } + + void PrecondLink:: + falseProb (Type const& o) + { + dispatch (o.falseProb ()); + } + + void PrecondLink:: + post (Type&) + { + } + + void PrecondLink:: + post (Type const&) + { + } + + // EffectLink + // + // + + void EffectLink:: + traverse (Type& o) + { + pre (o); + taskID (o); + condID (o); + portID (o); + weight (o); + post (o); + } + + void EffectLink:: + traverse (Type const& o) + { + pre (o); + taskID (o); + condID (o); + portID (o); + weight (o); + post (o); + } + + void EffectLink:: + pre (Type&) + { + } + + void EffectLink:: + pre (Type const&) + { + } + + void EffectLink:: + taskID (Type& o) + { + dispatch (o.taskID ()); + } + + void EffectLink:: + taskID (Type const& o) + { + dispatch (o.taskID ()); + } + + void EffectLink:: + condID (Type& o) + { + dispatch (o.condID ()); + } + + void EffectLink:: + condID (Type const& o) + { + dispatch (o.condID ()); + } + + void EffectLink:: + portID (Type& o) + { + dispatch (o.portID ()); + } + + void EffectLink:: + portID (Type const& o) + { + dispatch (o.portID ()); + } + + void EffectLink:: + weight (Type& o) + { + dispatch (o.weight ()); + } + + void EffectLink:: + weight (Type const& o) + { + dispatch (o.weight ()); + } + + void EffectLink:: + post (Type&) + { + } + + void EffectLink:: + post (Type const&) + { + } + + // Network + // + // + + void Network:: + traverse (Type& o) + { + pre (o); + defaultAttenFactor (o); + defaultTaskCost (o); + defaultCondUtil (o); + defaultCondProbTrue (o); + linkThresh (o); + taskNode (o); + condNode (o); + precondLink (o); + effectLink (o); + post (o); + } + + void Network:: + traverse (Type const& o) + { + pre (o); + defaultAttenFactor (o); + defaultTaskCost (o); + defaultCondUtil (o); + defaultCondProbTrue (o); + linkThresh (o); + taskNode (o); + condNode (o); + precondLink (o); + effectLink (o); + post (o); + } + + void Network:: + pre (Type&) + { + } + + void Network:: + pre (Type const&) + { + } + + void Network:: + defaultAttenFactor (Type& o) + { + dispatch (o.defaultAttenFactor ()); + } + + void Network:: + defaultAttenFactor (Type const& o) + { + dispatch (o.defaultAttenFactor ()); + } + + void Network:: + defaultTaskCost (Type& o) + { + dispatch (o.defaultTaskCost ()); + } + + void Network:: + defaultTaskCost (Type const& o) + { + dispatch (o.defaultTaskCost ()); + } + + void Network:: + defaultCondUtil (Type& o) + { + dispatch (o.defaultCondUtil ()); + } + + void Network:: + defaultCondUtil (Type const& o) + { + dispatch (o.defaultCondUtil ()); + } + + void Network:: + defaultCondProbTrue (Type& o) + { + dispatch (o.defaultCondProbTrue ()); + } + + void Network:: + defaultCondProbTrue (Type const& o) + { + dispatch (o.defaultCondProbTrue ()); + } + + void Network:: + linkThresh (Type& o) + { + dispatch (o.linkThresh ()); + } + + void Network:: + linkThresh (Type const& o) + { + dispatch (o.linkThresh ()); + } + + void Network:: + taskNode (Type& o) + { + // VC6 anathema strikes again + // + Network::Type::taskNode_iterator b (o.begin_taskNode()), e (o.end_taskNode()); + + if (b != e) + { + taskNode_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) taskNode_next (o); + } + + taskNode_post (o); + } + } + + void Network:: + taskNode (Type const& o) + { + // VC6 anathema strikes again + // + Network::Type::taskNode_const_iterator b (o.begin_taskNode()), e (o.end_taskNode()); + + if (b != e) + { + taskNode_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) taskNode_next (o); + } + + taskNode_post (o); + } + } + + void Network:: + taskNode_pre (Type&) + { + } + + void Network:: + taskNode_pre (Type const&) + { + } + + void Network:: + taskNode_next (Type&) + { + } + + void Network:: + taskNode_next (Type const&) + { + } + + void Network:: + taskNode_post (Type&) + { + } + + void Network:: + taskNode_post (Type const&) + { + } + + void Network:: + condNode (Type& o) + { + // VC6 anathema strikes again + // + Network::Type::condNode_iterator b (o.begin_condNode()), e (o.end_condNode()); + + if (b != e) + { + condNode_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) condNode_next (o); + } + + condNode_post (o); + } + } + + void Network:: + condNode (Type const& o) + { + // VC6 anathema strikes again + // + Network::Type::condNode_const_iterator b (o.begin_condNode()), e (o.end_condNode()); + + if (b != e) + { + condNode_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) condNode_next (o); + } + + condNode_post (o); + } + } + + void Network:: + condNode_pre (Type&) + { + } + + void Network:: + condNode_pre (Type const&) + { + } + + void Network:: + condNode_next (Type&) + { + } + + void Network:: + condNode_next (Type const&) + { + } + + void Network:: + condNode_post (Type&) + { + } + + void Network:: + condNode_post (Type const&) + { + } + + void Network:: + precondLink (Type& o) + { + // VC6 anathema strikes again + // + Network::Type::precondLink_iterator b (o.begin_precondLink()), e (o.end_precondLink()); + + if (b != e) + { + precondLink_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) precondLink_next (o); + } + + precondLink_post (o); + } + } + + void Network:: + precondLink (Type const& o) + { + // VC6 anathema strikes again + // + Network::Type::precondLink_const_iterator b (o.begin_precondLink()), e (o.end_precondLink()); + + if (b != e) + { + precondLink_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) precondLink_next (o); + } + + precondLink_post (o); + } + } + + void Network:: + precondLink_pre (Type&) + { + } + + void Network:: + precondLink_pre (Type const&) + { + } + + void Network:: + precondLink_next (Type&) + { + } + + void Network:: + precondLink_next (Type const&) + { + } + + void Network:: + precondLink_post (Type&) + { + } + + void Network:: + precondLink_post (Type const&) + { + } + + void Network:: + effectLink (Type& o) + { + // VC6 anathema strikes again + // + Network::Type::effectLink_iterator b (o.begin_effectLink()), e (o.end_effectLink()); + + if (b != e) + { + effectLink_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) effectLink_next (o); + } + + effectLink_post (o); + } + } + + void Network:: + effectLink (Type const& o) + { + // VC6 anathema strikes again + // + Network::Type::effectLink_const_iterator b (o.begin_effectLink()), e (o.end_effectLink()); + + if (b != e) + { + effectLink_pre (o); + for (; b != e;) + { + dispatch (*b); + if (++b != e) effectLink_next (o); + } + + effectLink_post (o); + } + } + + void Network:: + effectLink_pre (Type&) + { + } + + void Network:: + effectLink_pre (Type const&) + { + } + + void Network:: + effectLink_next (Type&) + { + } + + void Network:: + effectLink_next (Type const&) + { + } + + void Network:: + effectLink_post (Type&) + { + } + + void Network:: + effectLink_post (Type const&) + { + } + + void Network:: + post (Type&) + { + } + + void Network:: + post (Type const&) + { + } + } + } +} + +namespace SANet +{ + namespace XML + { + namespace Writer + { + // NodeID + // + // + + NodeID:: + NodeID (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + NodeID:: + NodeID () + { + } + + void NodeID:: + traverse (Type const& o) + { + ::XMLSchema::Writer::FundamentalType< ::XMLSchema::int_, wchar_t >::traverse (o); + Traversal::NodeID::traverse (o); + } + + // PortID + // + // + + PortID:: + PortID (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + PortID:: + PortID () + { + } + + void PortID:: + traverse (Type const& o) + { + ::XMLSchema::Writer::FundamentalType< ::XMLSchema::string< wchar_t >, wchar_t >::traverse (o); + Traversal::PortID::traverse (o); + } + + // TaskCost + // + // + + TaskCost:: + TaskCost (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + TaskCost:: + TaskCost () + { + } + + void TaskCost:: + traverse (Type const& o) + { + ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >::traverse (o); + Traversal::TaskCost::traverse (o); + } + + // CondUtil + // + // + + CondUtil:: + CondUtil (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + CondUtil:: + CondUtil () + { + } + + void CondUtil:: + traverse (Type const& o) + { + ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >::traverse (o); + Traversal::CondUtil::traverse (o); + } + + // CondKind + // + // + + CondKind:: + CondKind (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + CondKind:: + CondKind () + { + } + + void CondKind:: + traverse (Type const& o) + { + ::std::basic_string< wchar_t > s; + + if (o == ::SANet::XML::CondKind::ENVIRON) s = L"ENVIRON"; + else if (o == ::SANet::XML::CondKind::SYSTEM) s = L"SYSTEM"; + else if (o == ::SANet::XML::CondKind::DATA) s = L"DATA"; + else + { + } + + if (::XSCRT::XML::Attribute< wchar_t >* a = attr_ ()) + { + a->value (s); + } + + else + { + top_().value (s); + } + } + + // Probability + // + // + + Probability:: + Probability (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + Probability:: + Probability () + { + } + + void Probability:: + traverse (Type const& o) + { + ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >::traverse (o); + Traversal::Probability::traverse (o); + } + + // LinkWeight + // + // + + LinkWeight:: + LinkWeight (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + LinkWeight:: + LinkWeight () + { + } + + void LinkWeight:: + traverse (Type const& o) + { + ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >::traverse (o); + Traversal::LinkWeight::traverse (o); + } + + // MultFactor + // + // + + MultFactor:: + MultFactor (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + MultFactor:: + MultFactor () + { + } + + void MultFactor:: + traverse (Type const& o) + { + ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >::traverse (o); + Traversal::MultFactor::traverse (o); + } + + // TaskNode + // + // + + TaskNode:: + TaskNode (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + TaskNode:: + TaskNode () + { + } + + void TaskNode:: + traverse (Type const& o) + { + Traversal::TaskNode::traverse (o); + } + + void TaskNode:: + nodeID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"nodeID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::TaskNode::nodeID (o); + pop_ (); + } + + void TaskNode:: + name (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"name", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::TaskNode::name (o); + pop_ (); + } + + void TaskNode:: + priorProb (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"priorProb", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::TaskNode::priorProb (o); + pop_ (); + } + + void TaskNode:: + attenFactor (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"attenFactor", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::TaskNode::attenFactor (o); + pop_ (); + } + + void TaskNode:: + cost (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"cost", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::TaskNode::cost (o); + pop_ (); + } + + // CondNode + // + // + + CondNode:: + CondNode (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + CondNode:: + CondNode () + { + } + + void CondNode:: + traverse (Type const& o) + { + Traversal::CondNode::traverse (o); + } + + void CondNode:: + nodeID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"nodeID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::CondNode::nodeID (o); + pop_ (); + } + + void CondNode:: + name (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"name", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::CondNode::name (o); + pop_ (); + } + + void CondNode:: + probTrue (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"probTrue", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::CondNode::probTrue (o); + pop_ (); + } + + void CondNode:: + utility (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"utility", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::CondNode::utility (o); + pop_ (); + } + + void CondNode:: + kind (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"kind", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::CondNode::kind (o); + pop_ (); + } + + void CondNode:: + attenFactor (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"attenFactor", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::CondNode::attenFactor (o); + pop_ (); + } + + // PrecondLink + // + // + + PrecondLink:: + PrecondLink (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + PrecondLink:: + PrecondLink () + { + } + + void PrecondLink:: + traverse (Type const& o) + { + Traversal::PrecondLink::traverse (o); + } + + void PrecondLink:: + condID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"condID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::PrecondLink::condID (o); + pop_ (); + } + + void PrecondLink:: + taskID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"taskID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::PrecondLink::taskID (o); + pop_ (); + } + + void PrecondLink:: + portID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"portID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::PrecondLink::portID (o); + pop_ (); + } + + void PrecondLink:: + trueProb (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"trueProb", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::PrecondLink::trueProb (o); + pop_ (); + } + + void PrecondLink:: + falseProb (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"falseProb", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::PrecondLink::falseProb (o); + pop_ (); + } + + // EffectLink + // + // + + EffectLink:: + EffectLink (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + EffectLink:: + EffectLink () + { + } + + void EffectLink:: + traverse (Type const& o) + { + Traversal::EffectLink::traverse (o); + } + + void EffectLink:: + taskID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"taskID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::EffectLink::taskID (o); + pop_ (); + } + + void EffectLink:: + condID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"condID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::EffectLink::condID (o); + pop_ (); + } + + void EffectLink:: + portID (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"portID", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::EffectLink::portID (o); + pop_ (); + } + + void EffectLink:: + weight (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"weight", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::EffectLink::weight (o); + pop_ (); + } + + // Network + // + // + + Network:: + Network (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + + Network:: + Network () + { + } + + void Network:: + traverse (Type const& o) + { + Traversal::Network::traverse (o); + } + + void Network:: + defaultAttenFactor (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"defaultAttenFactor", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::Network::defaultAttenFactor (o); + pop_ (); + } + + void Network:: + defaultTaskCost (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"defaultTaskCost", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::Network::defaultTaskCost (o); + pop_ (); + } + + void Network:: + defaultCondUtil (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"defaultCondUtil", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::Network::defaultCondUtil (o); + pop_ (); + } + + void Network:: + defaultCondProbTrue (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"defaultCondProbTrue", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::Network::defaultCondProbTrue (o); + pop_ (); + } + + void Network:: + linkThresh (Type const& o) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"linkThresh", L"http://www.vanderbilt.edu/SANet", top_ ())); + Traversal::Network::linkThresh (o); + pop_ (); + } + + void Network:: + taskNode_pre (Type const&) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"taskNode", L"http://www.vanderbilt.edu/SANet", top_ ())); + } + + void Network:: + taskNode_next (Type const& o) + { + taskNode_post (o); + taskNode_pre (o); + } + + void Network:: + taskNode_post (Type const&) + { + pop_ (); + } + + void Network:: + condNode_pre (Type const&) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"condNode", L"http://www.vanderbilt.edu/SANet", top_ ())); + } + + void Network:: + condNode_next (Type const& o) + { + condNode_post (o); + condNode_pre (o); + } + + void Network:: + condNode_post (Type const&) + { + pop_ (); + } + + void Network:: + precondLink_pre (Type const&) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"precondLink", L"http://www.vanderbilt.edu/SANet", top_ ())); + } + + void Network:: + precondLink_next (Type const& o) + { + precondLink_post (o); + precondLink_pre (o); + } + + void Network:: + precondLink_post (Type const&) + { + pop_ (); + } + + void Network:: + effectLink_pre (Type const&) + { + push_ (::XSCRT::XML::Element< wchar_t > (L"effectLink", L"http://www.vanderbilt.edu/SANet", top_ ())); + } + + void Network:: + effectLink_next (Type const& o) + { + effectLink_post (o); + effectLink_pre (o); + } + + void Network:: + effectLink_post (Type const&) + { + pop_ (); + } + } + } +} + +namespace SANet +{ + namespace XML + { + void + network (::SANet::XML::Network const& s, xercesc::DOMDocument* d) + { + ::XSCRT::XML::Element< wchar_t > e (d->getDocumentElement ()); + if (e.name () != L"network") + { + throw 1; + } + + struct W : virtual ::SANet::XML::Writer::Network, + virtual ::SANet::XML::Writer::MultFactor, + virtual ::SANet::XML::Writer::TaskCost, + virtual ::SANet::XML::Writer::CondUtil, + virtual ::SANet::XML::Writer::Probability, + virtual ::SANet::XML::Writer::LinkWeight, + virtual ::SANet::XML::Writer::TaskNode, + virtual ::SANet::XML::Writer::NodeID, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::string< wchar_t >, wchar_t >, + virtual ::SANet::XML::Writer::CondNode, + virtual ::SANet::XML::Writer::CondKind, + virtual ::SANet::XML::Writer::PrecondLink, + virtual ::SANet::XML::Writer::PortID, + virtual ::SANet::XML::Writer::EffectLink, + virtual ::XSCRT::Writer< wchar_t > + { + W (::XSCRT::XML::Element< wchar_t >& e) + : ::XSCRT::Writer< wchar_t > (e) + { + } + }; + + W w (e); + w.dispatch (s); + } + } +} + diff --git a/SA_POP/SANet/XML_SANet.hpp b/SA_POP/SANet/XML_SANet.hpp new file mode 100644 index 00000000000..865926a9a36 --- /dev/null +++ b/SA_POP/SANet/XML_SANet.hpp @@ -0,0 +1,1830 @@ +#ifndef XML_SANET_HPP +#define XML_SANET_HPP + +// Forward declarations. +// +namespace SANet +{ + namespace XML + { + class NodeID; + class PortID; + class TaskCost; + class CondUtil; + class CondKind; + class Probability; + class LinkWeight; + class MultFactor; + class TaskNode; + class CondNode; + class PrecondLink; + class EffectLink; + class Network; + } +} + +#include <memory> +#include <list> +#include "XMLSchema/Types.hpp" + +namespace SANet +{ + namespace XML + { + class NodeID : public ::XMLSchema::int_ + { + //@@ VC6 anathema + typedef ::XMLSchema::int_ Base__; + + public: + NodeID (::XMLSchema::int_ const& b__); + + NodeID (::XSCRT::XML::Element< wchar_t > const&); + NodeID (::XSCRT::XML::Attribute< wchar_t > const&); + NodeID (NodeID const& s); + + NodeID& + operator= (NodeID const& s); + + private: + char regulator__; + }; + + class PortID : public ::XMLSchema::string< wchar_t > + { + //@@ VC6 anathema + typedef ::XMLSchema::string< wchar_t > Base__; + + public: + PortID (::XMLSchema::string< wchar_t > const& b__); + + PortID (::XSCRT::XML::Element< wchar_t > const&); + PortID (::XSCRT::XML::Attribute< wchar_t > const&); + PortID (PortID const& s); + + PortID& + operator= (PortID const& s); + + private: + char regulator__; + }; + + class TaskCost : public ::XMLSchema::double_ + { + //@@ VC6 anathema + typedef ::XMLSchema::double_ Base__; + + public: + TaskCost (::XMLSchema::double_ const& b__); + + TaskCost (::XSCRT::XML::Element< wchar_t > const&); + TaskCost (::XSCRT::XML::Attribute< wchar_t > const&); + TaskCost (TaskCost const& s); + + TaskCost& + operator= (TaskCost const& s); + + private: + char regulator__; + }; + + class CondUtil : public ::XMLSchema::double_ + { + //@@ VC6 anathema + typedef ::XMLSchema::double_ Base__; + + public: + CondUtil (::XMLSchema::double_ const& b__); + + CondUtil (::XSCRT::XML::Element< wchar_t > const&); + CondUtil (::XSCRT::XML::Attribute< wchar_t > const&); + CondUtil (CondUtil const& s); + + CondUtil& + operator= (CondUtil const& s); + + private: + char regulator__; + }; + + class CondKind : public ::XSCRT::Type + { + public: + CondKind (::XSCRT::XML::Element< wchar_t > const&); + CondKind (::XSCRT::XML::Attribute< wchar_t > const&); + + static CondKind const ENVIRON; + static CondKind const SYSTEM; + static CondKind const DATA; + + enum Value + { + ENVIRON_l,SYSTEM_l,DATA_l, + }; + + + Value + integral () const; + + friend bool + operator== (CondKind const& a, CondKind const& b); + + friend bool + operator!= (CondKind const& a, CondKind const& b); + + private: + CondKind (Value v); + + Value v_; + }; + + bool operator== (CondKind const &a, CondKind const &b); + + bool operator!= (CondKind const &a, CondKind const &b); + + + class Probability : public ::XMLSchema::double_ + { + //@@ VC6 anathema + typedef ::XMLSchema::double_ Base__; + + public: + Probability (::XMLSchema::double_ const& b__); + + Probability (::XSCRT::XML::Element< wchar_t > const&); + Probability (::XSCRT::XML::Attribute< wchar_t > const&); + Probability (Probability const& s); + + Probability& + operator= (Probability const& s); + + private: + char regulator__; + }; + + class LinkWeight : public ::XMLSchema::double_ + { + //@@ VC6 anathema + typedef ::XMLSchema::double_ Base__; + + public: + LinkWeight (::XMLSchema::double_ const& b__); + + LinkWeight (::XSCRT::XML::Element< wchar_t > const&); + LinkWeight (::XSCRT::XML::Attribute< wchar_t > const&); + LinkWeight (LinkWeight const& s); + + LinkWeight& + operator= (LinkWeight const& s); + + private: + char regulator__; + }; + + class MultFactor : public ::XMLSchema::double_ + { + //@@ VC6 anathema + typedef ::XMLSchema::double_ Base__; + + public: + MultFactor (::XMLSchema::double_ const& b__); + + MultFactor (::XSCRT::XML::Element< wchar_t > const&); + MultFactor (::XSCRT::XML::Attribute< wchar_t > const&); + MultFactor (MultFactor const& s); + + MultFactor& + operator= (MultFactor const& s); + + private: + char regulator__; + }; + + class TaskNode : public ::XSCRT::Type + { + //@@ VC6 anathema + typedef ::XSCRT::Type Base__; + + // nodeID + // + public: + ::SANet::XML::NodeID const& nodeID () const; + void nodeID (::SANet::XML::NodeID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::NodeID > nodeID_; + + // name + // + public: + ::XMLSchema::string< wchar_t > const& name () const; + void name (::XMLSchema::string< wchar_t > const& ); + + protected: + ::std::auto_ptr< ::XMLSchema::string< wchar_t > > name_; + + // priorProb + // + public: + ::SANet::XML::Probability const& priorProb () const; + void priorProb (::SANet::XML::Probability const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::Probability > priorProb_; + + // attenFactor + // + public: + ::SANet::XML::MultFactor const& attenFactor () const; + void attenFactor (::SANet::XML::MultFactor const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::MultFactor > attenFactor_; + + // cost + // + public: + ::SANet::XML::TaskCost const& cost () const; + void cost (::SANet::XML::TaskCost const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::TaskCost > cost_; + + public: + TaskNode (::SANet::XML::NodeID const& nodeID__, + ::XMLSchema::string< wchar_t > const& name__, + ::SANet::XML::Probability const& priorProb__, + ::SANet::XML::MultFactor const& attenFactor__, + ::SANet::XML::TaskCost const& cost__); + + TaskNode (::XSCRT::XML::Element< wchar_t > const&); + TaskNode (TaskNode const& s); + + TaskNode& + operator= (TaskNode const& s); + + private: + char regulator__; + }; + + + class CondNode : public ::XSCRT::Type + { + //@@ VC6 anathema + typedef ::XSCRT::Type Base__; + + // nodeID + // + public: + ::SANet::XML::NodeID const& nodeID () const; + void nodeID (::SANet::XML::NodeID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::NodeID > nodeID_; + + // name + // + public: + ::XMLSchema::string< wchar_t > const& name () const; + void name (::XMLSchema::string< wchar_t > const& ); + + protected: + ::std::auto_ptr< ::XMLSchema::string< wchar_t > > name_; + + // probTrue + // + public: + ::SANet::XML::Probability const& probTrue () const; + void probTrue (::SANet::XML::Probability const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::Probability > probTrue_; + + // utility + // + public: + ::SANet::XML::CondUtil const& utility () const; + void utility (::SANet::XML::CondUtil const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::CondUtil > utility_; + + // kind + // + public: + ::SANet::XML::CondKind const& kind () const; + void kind (::SANet::XML::CondKind const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::CondKind > kind_; + + // attenFactor + // + public: + ::SANet::XML::MultFactor const& attenFactor () const; + void attenFactor (::SANet::XML::MultFactor const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::MultFactor > attenFactor_; + + public: + CondNode (::SANet::XML::NodeID const& nodeID__, + ::XMLSchema::string< wchar_t > const& name__, + ::SANet::XML::Probability const& probTrue__, + ::SANet::XML::CondUtil const& utility__, + ::SANet::XML::CondKind const& kind__, + ::SANet::XML::MultFactor const& attenFactor__); + + CondNode (::XSCRT::XML::Element< wchar_t > const&); + CondNode (CondNode const& s); + + CondNode& + operator= (CondNode const& s); + + private: + char regulator__; + }; + + + class PrecondLink : public ::XSCRT::Type + { + //@@ VC6 anathema + typedef ::XSCRT::Type Base__; + + // condID + // + public: + ::SANet::XML::NodeID const& condID () const; + void condID (::SANet::XML::NodeID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::NodeID > condID_; + + // taskID + // + public: + ::SANet::XML::NodeID const& taskID () const; + void taskID (::SANet::XML::NodeID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::NodeID > taskID_; + + // portID + // + public: + ::SANet::XML::PortID const& portID () const; + void portID (::SANet::XML::PortID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::PortID > portID_; + + // trueProb + // + public: + ::SANet::XML::Probability const& trueProb () const; + void trueProb (::SANet::XML::Probability const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::Probability > trueProb_; + + // falseProb + // + public: + ::SANet::XML::Probability const& falseProb () const; + void falseProb (::SANet::XML::Probability const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::Probability > falseProb_; + + public: + PrecondLink (::SANet::XML::NodeID const& condID__, + ::SANet::XML::NodeID const& taskID__, + ::SANet::XML::PortID const& portID__, + ::SANet::XML::Probability const& trueProb__, + ::SANet::XML::Probability const& falseProb__); + + PrecondLink (::XSCRT::XML::Element< wchar_t > const&); + PrecondLink (PrecondLink const& s); + + PrecondLink& + operator= (PrecondLink const& s); + + private: + char regulator__; + }; + + + class EffectLink : public ::XSCRT::Type + { + //@@ VC6 anathema + typedef ::XSCRT::Type Base__; + + // taskID + // + public: + ::SANet::XML::NodeID const& taskID () const; + void taskID (::SANet::XML::NodeID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::NodeID > taskID_; + + // condID + // + public: + ::SANet::XML::NodeID const& condID () const; + void condID (::SANet::XML::NodeID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::NodeID > condID_; + + // portID + // + public: + ::SANet::XML::PortID const& portID () const; + void portID (::SANet::XML::PortID const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::PortID > portID_; + + // weight + // + public: + ::SANet::XML::LinkWeight const& weight () const; + void weight (::SANet::XML::LinkWeight const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::LinkWeight > weight_; + + public: + EffectLink (::SANet::XML::NodeID const& taskID__, + ::SANet::XML::NodeID const& condID__, + ::SANet::XML::PortID const& portID__, + ::SANet::XML::LinkWeight const& weight__); + + EffectLink (::XSCRT::XML::Element< wchar_t > const&); + EffectLink (EffectLink const& s); + + EffectLink& + operator= (EffectLink const& s); + + private: + char regulator__; + }; + + + class Network : public ::XSCRT::Type + { + //@@ VC6 anathema + typedef ::XSCRT::Type Base__; + + // defaultAttenFactor + // + public: + ::SANet::XML::MultFactor const& defaultAttenFactor () const; + void defaultAttenFactor (::SANet::XML::MultFactor const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::MultFactor > defaultAttenFactor_; + + // defaultTaskCost + // + public: + ::SANet::XML::TaskCost const& defaultTaskCost () const; + void defaultTaskCost (::SANet::XML::TaskCost const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::TaskCost > defaultTaskCost_; + + // defaultCondUtil + // + public: + ::SANet::XML::CondUtil const& defaultCondUtil () const; + void defaultCondUtil (::SANet::XML::CondUtil const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::CondUtil > defaultCondUtil_; + + // defaultCondProbTrue + // + public: + ::SANet::XML::Probability const& defaultCondProbTrue () const; + void defaultCondProbTrue (::SANet::XML::Probability const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::Probability > defaultCondProbTrue_; + + // linkThresh + // + public: + ::SANet::XML::LinkWeight const& linkThresh () const; + void linkThresh (::SANet::XML::LinkWeight const& ); + + protected: + ::std::auto_ptr< ::SANet::XML::LinkWeight > linkThresh_; + + // taskNode + // + public: + typedef ::std::list< ::SANet::XML::TaskNode >::iterator taskNode_iterator; + typedef ::std::list< ::SANet::XML::TaskNode >::const_iterator taskNode_const_iterator; + taskNode_iterator begin_taskNode (); + taskNode_iterator end_taskNode (); + taskNode_const_iterator begin_taskNode () const; + taskNode_const_iterator end_taskNode () const; + void add_taskNode (::SANet::XML::TaskNode const& ); + size_t count_taskNode (void) const; + + protected: + ::std::list< ::SANet::XML::TaskNode > taskNode_; + + // condNode + // + public: + typedef ::std::list< ::SANet::XML::CondNode >::iterator condNode_iterator; + typedef ::std::list< ::SANet::XML::CondNode >::const_iterator condNode_const_iterator; + condNode_iterator begin_condNode (); + condNode_iterator end_condNode (); + condNode_const_iterator begin_condNode () const; + condNode_const_iterator end_condNode () const; + void add_condNode (::SANet::XML::CondNode const& ); + size_t count_condNode (void) const; + + protected: + ::std::list< ::SANet::XML::CondNode > condNode_; + + // precondLink + // + public: + typedef ::std::list< ::SANet::XML::PrecondLink >::iterator precondLink_iterator; + typedef ::std::list< ::SANet::XML::PrecondLink >::const_iterator precondLink_const_iterator; + precondLink_iterator begin_precondLink (); + precondLink_iterator end_precondLink (); + precondLink_const_iterator begin_precondLink () const; + precondLink_const_iterator end_precondLink () const; + void add_precondLink (::SANet::XML::PrecondLink const& ); + size_t count_precondLink (void) const; + + protected: + ::std::list< ::SANet::XML::PrecondLink > precondLink_; + + // effectLink + // + public: + typedef ::std::list< ::SANet::XML::EffectLink >::iterator effectLink_iterator; + typedef ::std::list< ::SANet::XML::EffectLink >::const_iterator effectLink_const_iterator; + effectLink_iterator begin_effectLink (); + effectLink_iterator end_effectLink (); + effectLink_const_iterator begin_effectLink () const; + effectLink_const_iterator end_effectLink () const; + void add_effectLink (::SANet::XML::EffectLink const& ); + size_t count_effectLink (void) const; + + protected: + ::std::list< ::SANet::XML::EffectLink > effectLink_; + + public: + Network (::SANet::XML::MultFactor const& defaultAttenFactor__, + ::SANet::XML::TaskCost const& defaultTaskCost__, + ::SANet::XML::CondUtil const& defaultCondUtil__, + ::SANet::XML::Probability const& defaultCondProbTrue__, + ::SANet::XML::LinkWeight const& linkThresh__); + + Network (::XSCRT::XML::Element< wchar_t > const&); + Network (Network const& s); + + Network& + operator= (Network const& s); + + private: + char regulator__; + }; + } +} + +namespace SANet +{ + namespace XML + { + ::SANet::XML::Network + network (xercesc::DOMDocument const*); + } +} + +#include "XMLSchema/Traversal.hpp" + +namespace SANet +{ + namespace XML + { + namespace Traversal + { + struct NodeID : ::XMLSchema::Traversal::Traverser< ::SANet::XML::NodeID > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct PortID : ::XMLSchema::Traversal::Traverser< ::SANet::XML::PortID > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct TaskCost : ::XMLSchema::Traversal::Traverser< ::SANet::XML::TaskCost > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct CondUtil : ::XMLSchema::Traversal::Traverser< ::SANet::XML::CondUtil > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + typedef + ::XMLSchema::Traversal::Traverser< ::SANet::XML::CondKind > + CondKind; + + struct Probability : ::XMLSchema::Traversal::Traverser< ::SANet::XML::Probability > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct LinkWeight : ::XMLSchema::Traversal::Traverser< ::SANet::XML::LinkWeight > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct MultFactor : ::XMLSchema::Traversal::Traverser< ::SANet::XML::MultFactor > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct TaskNode : ::XMLSchema::Traversal::Traverser< ::SANet::XML::TaskNode > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + nodeID (Type&); + + virtual void + nodeID (Type const&); + + virtual void + name (Type&); + + virtual void + name (Type const&); + + virtual void + priorProb (Type&); + + virtual void + priorProb (Type const&); + + virtual void + attenFactor (Type&); + + virtual void + attenFactor (Type const&); + + virtual void + cost (Type&); + + virtual void + cost (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct CondNode : ::XMLSchema::Traversal::Traverser< ::SANet::XML::CondNode > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + nodeID (Type&); + + virtual void + nodeID (Type const&); + + virtual void + name (Type&); + + virtual void + name (Type const&); + + virtual void + probTrue (Type&); + + virtual void + probTrue (Type const&); + + virtual void + utility (Type&); + + virtual void + utility (Type const&); + + virtual void + kind (Type&); + + virtual void + kind (Type const&); + + virtual void + attenFactor (Type&); + + virtual void + attenFactor (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct PrecondLink : ::XMLSchema::Traversal::Traverser< ::SANet::XML::PrecondLink > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + condID (Type&); + + virtual void + condID (Type const&); + + virtual void + taskID (Type&); + + virtual void + taskID (Type const&); + + virtual void + portID (Type&); + + virtual void + portID (Type const&); + + virtual void + trueProb (Type&); + + virtual void + trueProb (Type const&); + + virtual void + falseProb (Type&); + + virtual void + falseProb (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct EffectLink : ::XMLSchema::Traversal::Traverser< ::SANet::XML::EffectLink > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + taskID (Type&); + + virtual void + taskID (Type const&); + + virtual void + condID (Type&); + + virtual void + condID (Type const&); + + virtual void + portID (Type&); + + virtual void + portID (Type const&); + + virtual void + weight (Type&); + + virtual void + weight (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + + struct Network : ::XMLSchema::Traversal::Traverser< ::SANet::XML::Network > + { + virtual void + traverse (Type&); + + virtual void + traverse (Type const&); + + virtual void + pre (Type&); + + virtual void + pre (Type const&); + + virtual void + defaultAttenFactor (Type&); + + virtual void + defaultAttenFactor (Type const&); + + virtual void + defaultTaskCost (Type&); + + virtual void + defaultTaskCost (Type const&); + + virtual void + defaultCondUtil (Type&); + + virtual void + defaultCondUtil (Type const&); + + virtual void + defaultCondProbTrue (Type&); + + virtual void + defaultCondProbTrue (Type const&); + + virtual void + linkThresh (Type&); + + virtual void + linkThresh (Type const&); + + virtual void + taskNode (Type&); + + virtual void + taskNode (Type const&); + + virtual void + taskNode_pre (Type&); + + virtual void + taskNode_pre (Type const&); + + virtual void + taskNode_next (Type&); + + virtual void + taskNode_next (Type const&); + + virtual void + taskNode_post (Type&); + + virtual void + taskNode_post (Type const&); + + virtual void + condNode (Type&); + + virtual void + condNode (Type const&); + + virtual void + condNode_pre (Type&); + + virtual void + condNode_pre (Type const&); + + virtual void + condNode_next (Type&); + + virtual void + condNode_next (Type const&); + + virtual void + condNode_post (Type&); + + virtual void + condNode_post (Type const&); + + virtual void + precondLink (Type&); + + virtual void + precondLink (Type const&); + + virtual void + precondLink_pre (Type&); + + virtual void + precondLink_pre (Type const&); + + virtual void + precondLink_next (Type&); + + virtual void + precondLink_next (Type const&); + + virtual void + precondLink_post (Type&); + + virtual void + precondLink_post (Type const&); + + virtual void + effectLink (Type&); + + virtual void + effectLink (Type const&); + + virtual void + effectLink_pre (Type&); + + virtual void + effectLink_pre (Type const&); + + virtual void + effectLink_next (Type&); + + virtual void + effectLink_next (Type const&); + + virtual void + effectLink_post (Type&); + + virtual void + effectLink_post (Type const&); + + virtual void + post (Type&); + + virtual void + post (Type const&); + }; + } + } +} + +#include "XMLSchema/Writer.hpp" + +namespace SANet +{ + namespace XML + { + namespace Writer + { + struct NodeID : Traversal::NodeID, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::int_, wchar_t >, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::NodeID Type; + NodeID (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + protected: + NodeID (); + }; + + struct PortID : Traversal::PortID, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::string< wchar_t >, wchar_t >, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::PortID Type; + PortID (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + protected: + PortID (); + }; + + struct TaskCost : Traversal::TaskCost, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::TaskCost Type; + TaskCost (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + protected: + TaskCost (); + }; + + struct CondUtil : Traversal::CondUtil, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::CondUtil Type; + CondUtil (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + protected: + CondUtil (); + }; + + struct CondKind : Traversal::CondKind, + virtual ::XSCRT::Writer< wchar_t > + { + CondKind (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + this->traverse (const_cast <Type const &> (o)); + } + + virtual void + traverse (Type const&); + + protected: + CondKind (); + }; + + struct Probability : Traversal::Probability, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::Probability Type; + Probability (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + protected: + Probability (); + }; + + struct LinkWeight : Traversal::LinkWeight, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::LinkWeight Type; + LinkWeight (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + protected: + LinkWeight (); + }; + + struct MultFactor : Traversal::MultFactor, + virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::double_, wchar_t >, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::MultFactor Type; + MultFactor (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + protected: + MultFactor (); + }; + + struct TaskNode : Traversal::TaskNode, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::TaskNode Type; + TaskNode (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + virtual void + nodeID (Type &o) + { + + this->nodeID (const_cast <Type const &> (o)); + } + + + virtual void + nodeID (Type const&); + + virtual void + name (Type &o) + { + + this->name (const_cast <Type const &> (o)); + } + + + virtual void + name (Type const&); + + virtual void + priorProb (Type &o) + { + + this->priorProb (const_cast <Type const &> (o)); + } + + + virtual void + priorProb (Type const&); + + virtual void + attenFactor (Type &o) + { + + this->attenFactor (const_cast <Type const &> (o)); + } + + + virtual void + attenFactor (Type const&); + + virtual void + cost (Type &o) + { + + this->cost (const_cast <Type const &> (o)); + } + + + virtual void + cost (Type const&); + + protected: + TaskNode (); + }; + + struct CondNode : Traversal::CondNode, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::CondNode Type; + CondNode (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + virtual void + nodeID (Type &o) + { + + this->nodeID (const_cast <Type const &> (o)); + } + + + virtual void + nodeID (Type const&); + + virtual void + name (Type &o) + { + + this->name (const_cast <Type const &> (o)); + } + + + virtual void + name (Type const&); + + virtual void + probTrue (Type &o) + { + + this->probTrue (const_cast <Type const &> (o)); + } + + + virtual void + probTrue (Type const&); + + virtual void + utility (Type &o) + { + + this->utility (const_cast <Type const &> (o)); + } + + + virtual void + utility (Type const&); + + virtual void + kind (Type &o) + { + + this->kind (const_cast <Type const &> (o)); + } + + + virtual void + kind (Type const&); + + virtual void + attenFactor (Type &o) + { + + this->attenFactor (const_cast <Type const &> (o)); + } + + + virtual void + attenFactor (Type const&); + + protected: + CondNode (); + }; + + struct PrecondLink : Traversal::PrecondLink, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::PrecondLink Type; + PrecondLink (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + virtual void + condID (Type &o) + { + + this->condID (const_cast <Type const &> (o)); + } + + + virtual void + condID (Type const&); + + virtual void + taskID (Type &o) + { + + this->taskID (const_cast <Type const &> (o)); + } + + + virtual void + taskID (Type const&); + + virtual void + portID (Type &o) + { + + this->portID (const_cast <Type const &> (o)); + } + + + virtual void + portID (Type const&); + + virtual void + trueProb (Type &o) + { + + this->trueProb (const_cast <Type const &> (o)); + } + + + virtual void + trueProb (Type const&); + + virtual void + falseProb (Type &o) + { + + this->falseProb (const_cast <Type const &> (o)); + } + + + virtual void + falseProb (Type const&); + + protected: + PrecondLink (); + }; + + struct EffectLink : Traversal::EffectLink, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::EffectLink Type; + EffectLink (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + virtual void + taskID (Type &o) + { + + this->taskID (const_cast <Type const &> (o)); + } + + + virtual void + taskID (Type const&); + + virtual void + condID (Type &o) + { + + this->condID (const_cast <Type const &> (o)); + } + + + virtual void + condID (Type const&); + + virtual void + portID (Type &o) + { + + this->portID (const_cast <Type const &> (o)); + } + + + virtual void + portID (Type const&); + + virtual void + weight (Type &o) + { + + this->weight (const_cast <Type const &> (o)); + } + + + virtual void + weight (Type const&); + + protected: + EffectLink (); + }; + + struct Network : Traversal::Network, + virtual ::XSCRT::Writer< wchar_t > + { + typedef ::SANet::XML::Network Type; + Network (::XSCRT::XML::Element< wchar_t >&); + + virtual void + traverse (Type &o) + { + + this->traverse (const_cast <Type const &> (o)); + } + + + virtual void + traverse (Type const&); + + virtual void + defaultAttenFactor (Type &o) + { + + this->defaultAttenFactor (const_cast <Type const &> (o)); + } + + + virtual void + defaultAttenFactor (Type const&); + + virtual void + defaultTaskCost (Type &o) + { + + this->defaultTaskCost (const_cast <Type const &> (o)); + } + + + virtual void + defaultTaskCost (Type const&); + + virtual void + defaultCondUtil (Type &o) + { + + this->defaultCondUtil (const_cast <Type const &> (o)); + } + + + virtual void + defaultCondUtil (Type const&); + + virtual void + defaultCondProbTrue (Type &o) + { + + this->defaultCondProbTrue (const_cast <Type const &> (o)); + } + + + virtual void + defaultCondProbTrue (Type const&); + + virtual void + linkThresh (Type &o) + { + + this->linkThresh (const_cast <Type const &> (o)); + } + + + virtual void + linkThresh (Type const&); + + virtual void + taskNode_pre (Type &o) + { + + this->taskNode_pre (const_cast <Type const &> (o)); + } + + + virtual void + taskNode_pre (Type const&); + + virtual void + taskNode_next (Type &o) + { + + this->taskNode_next (const_cast <Type const &> (o)); + } + + + virtual void + taskNode_next (Type const&); + + virtual void + taskNode_post (Type &o) + { + + this->taskNode_post (const_cast <Type const &> (o)); + } + + + virtual void + taskNode_post (Type const&); + + virtual void + condNode_pre (Type &o) + { + + this->condNode_pre (const_cast <Type const &> (o)); + } + + + virtual void + condNode_pre (Type const&); + + virtual void + condNode_next (Type &o) + { + + this->condNode_next (const_cast <Type const &> (o)); + } + + + virtual void + condNode_next (Type const&); + + virtual void + condNode_post (Type &o) + { + + this->condNode_post (const_cast <Type const &> (o)); + } + + + virtual void + condNode_post (Type const&); + + virtual void + precondLink_pre (Type &o) + { + + this->precondLink_pre (const_cast <Type const &> (o)); + } + + + virtual void + precondLink_pre (Type const&); + + virtual void + precondLink_next (Type &o) + { + + this->precondLink_next (const_cast <Type const &> (o)); + } + + + virtual void + precondLink_next (Type const&); + + virtual void + precondLink_post (Type &o) + { + + this->precondLink_post (const_cast <Type const &> (o)); + } + + + virtual void + precondLink_post (Type const&); + + virtual void + effectLink_pre (Type &o) + { + + this->effectLink_pre (const_cast <Type const &> (o)); + } + + + virtual void + effectLink_pre (Type const&); + + virtual void + effectLink_next (Type &o) + { + + this->effectLink_next (const_cast <Type const &> (o)); + } + + + virtual void + effectLink_next (Type const&); + + virtual void + effectLink_post (Type &o) + { + + this->effectLink_post (const_cast <Type const &> (o)); + } + + + virtual void + effectLink_post (Type const&); + + protected: + Network (); + }; + } + } +} + +namespace SANet +{ + namespace XML + { + void + network (::SANet::XML::Network const&, xercesc::DOMDocument*); + } +} + +#endif // XML_SANET_HPP |