From ce01c7d1341c7ba53deca80ce74e3a5986a2402a Mon Sep 17 00:00:00 2001 From: dmack Date: Fri, 4 Dec 2009 18:18:55 +0000 Subject: Fri Dec 4 18:16:57 UTC 2009 Daniel L.C. Mack --- SA_POP/ChangeLog | 18 +++++-- SA_POP/SANet/SANet.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++++---- SA_POP/SANet/SANet.h | 41 ++++++++++++++++ SA_POP/SANet/SANode.cpp | 29 ++++++++++- SA_POP/SANet/SANode.h | 11 +++++ 5 files changed, 211 insertions(+), 13 deletions(-) diff --git a/SA_POP/ChangeLog b/SA_POP/ChangeLog index 210cd50e76c..2b7856a2ade 100644 --- a/SA_POP/ChangeLog +++ b/SA_POP/ChangeLog @@ -1,18 +1,28 @@ +Fri Dec 4 18:16:57 UTC 2009 Daniel L.C. Mack + + * SANet/SANet.h: + * SANet/SANet.cpp: + * SANet/SANode.h: + * SANet/SANode.cpp: + + These files were modified to take the new active and disabled flags + for computing expected utilities of plans. + Tue Nov 10 21:55:22 UTC 2009 Daniel L.C. Mack * utils/SANetGenerator/Net_Complete.py: * utils/SANetGenerator/Net_Skeleton.py: * utils/SANetGenerator/Rand_Params.py: - - Added the capability of the SANet Generator to utilize some simple parameterization - and output a SANet .xml file + + Added the capability of the SANet Generator to utilize some simple parameterization + and output a SANet .xml file Tue Nov 10 21:54:59 UTC 2009 Daniel L.C. Mack * utils/SANetGenerator/Net_Skeleton.py: - Updated to fix a bug with knowing when to stop. + Updated to fix a bug with knowing when to stop. Mon Nov 9 00:49:19 UTC 2009 William R. Otte diff --git a/SA_POP/SANet/SANet.cpp b/SA_POP/SANet/SANet.cpp index 13b6275485c..c29dbe5ce8d 100644 --- a/SA_POP/SANet/SANet.cpp +++ b/SA_POP/SANet/SANet.cpp @@ -63,6 +63,9 @@ void SANet::Network::add_task (TaskID ID, std::string name, MultFactor atten_fac // Task node pointer. TaskNode *node; + // Set initially to active + active_tasks.insert(ID); + // 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) @@ -129,6 +132,9 @@ void SANet::Network::add_cond (CondID ID, std::string name, MultFactor atten_fac // Condition node pointer. CondNode *node; + // Set initially to active + active_conds.insert(ID); + // Add condition node, throwing exception if insertion fails. node = new CondNode (ID, name, atten_factor, true_prob, false_prob, goal_util, cond_kind); @@ -385,22 +391,26 @@ void SANet::Network::update (int max_steps) // Reset net_changed flag. net_changed = false; - // Update all task nodes. - for (TaskNodeMap::iterator node_iter = task_nodes_.begin (); - node_iter != task_nodes_.end (); node_iter++) + // Update all active task nodes. + //for (TaskNodeMap::iterator node_iter = task_nodes_.begin (); + // node_iter != task_nodes_.end (); node_iter++) + for(std::set::iterator node_iter = active_tasks.begin(); + node_iter != active_tasks.end(); node_iter++) { // Update node, setting net_changed flag if node changed. - if (node_iter->second->update ()) { + if (task_nodes_.find(*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 all active condition nodes. + //for (CondNodeMap::iterator node_iter = cond_nodes_.begin (); + // node_iter != cond_nodes_.end (); node_iter++) + for(std::set::iterator node_iter = active_conds.begin(); + node_iter != active_conds.end(); node_iter++) { // Update node, setting net_changed flag if node changed. - if (node_iter->second->update ()) { + if (cond_nodes_.find(*node_iter)->second->update ()) { net_changed = true; } } @@ -651,3 +661,102 @@ LinkPorts SANet::Network::get_clink_ports (TaskID task1_id, CondID cond_id, return std::make_pair (this->get_effect_port (task1_id, cond_id), this->get_precond_port (cond_id, task2_id)); }; + +/// Set Task State. +void SANet::Network::set_task_state(TaskID task_ID, bool state) +{ + + task_nodes_.find(task_ID)->second->set_activity(state); + + if(state) + { + //insetr into active, remove from disabled + active_tasks.insert(task_ID); + + disabled_tasks.erase(task_ID); + + } + else + { + //remove from active, insert into disabled + + active_tasks.erase(task_ID); + + disabled_tasks.insert(task_ID); + } +} + +/// Set Cond State. +void SANet::Network::set_cond_state(CondID cond_ID, bool state) +{ + + cond_nodes_.find(cond_ID)->second->set_activity(state); + if(state) + { + //insetr into active, remove from disabled + active_conds.insert(cond_ID); + + + disabled_conds.erase(cond_ID); + + } + else + { + //remove from active, insert into disabled + + active_conds.erase(cond_ID); + + disabled_conds.insert(cond_ID); + } + +} + +/// Set All nodes to State. +void SANet::Network::set_nodes_state(bool state) +{ + if(state) + { + + //insetr all tasks into active, remove from disabled + for (TaskNodeMap::iterator node_iter = task_nodes_.begin (); + node_iter != task_nodes_.end (); node_iter++) + { + node_iter->second->set_activity(state); + active_tasks.insert(node_iter->first); + + disabled_tasks.erase(node_iter->first); + } + + for (CondNodeMap::iterator node_iter = cond_nodes_.begin (); + node_iter != cond_nodes_.end (); node_iter++) + { + node_iter->second->set_activity(state); + active_conds.insert(node_iter->first); + + disabled_conds.erase(node_iter->first); + } + } + else + { + //remove from active, insert into disabled + + for (TaskNodeMap::iterator node_iter = task_nodes_.begin (); + node_iter != task_nodes_.end (); node_iter++) + { + node_iter->second->set_activity(state); + active_tasks.erase(node_iter->first); + + disabled_tasks.insert(node_iter->first); + } + + for (CondNodeMap::iterator node_iter = cond_nodes_.begin (); + node_iter != cond_nodes_.end (); node_iter++) + { + node_iter->second->set_activity(state); + active_conds.erase(node_iter->first); + + disabled_conds.insert(node_iter->first); + } + } + +} \ No newline at end of file diff --git a/SA_POP/SANet/SANet.h b/SA_POP/SANet/SANet.h index 7368037de24..a0b726119a6 100644 --- a/SA_POP/SANet/SANet.h +++ b/SA_POP/SANet/SANet.h @@ -16,6 +16,7 @@ #include #include +#include #include #include "SANet_Types.h" #include "SANode.h" @@ -153,6 +154,34 @@ namespace SANet { virtual void update_effect_link(TaskID task_ID, CondID cond_ID, LinkWeight weight, PortID port_ID= ""); + /// Set Task State. + /** + * + * @param task_ID Task node ID. + * + * + * @param state State for the task to be set to; + */ + virtual void set_task_state(TaskID task_ID, bool state); + + /// Set Cond State. + /** + * + * @param cond_ID Condition node ID. + * + * + * @param state State for the condition to be set to; + */ + virtual void set_cond_state(CondID cond_ID, bool state); + + /// Set All nodes to State. + /** + * + * + * @param state State to set all nodes to; + */ + virtual void set_nodes_state(bool state); + /// Update the task prior. /** * @@ -368,6 +397,18 @@ namespace SANet { /// Map from ID to node pointer for all condition nodes in network. CondNodeMap cond_nodes_; + //Set of Active Task Nodes + std::set active_tasks; + + //Set of Disabled Task Nodes + std::set disabled_tasks; + + //Set of Active Condition Nodes + std::set active_conds; + + //Set of Active Task Nodes + std::set disabled_conds; + /// Map from precondition links to associated ports. PrecondLinkPortMap precond_links_; diff --git a/SA_POP/SANet/SANode.cpp b/SA_POP/SANet/SANode.cpp index 3bc88337ad3..8dae4e4eb0f 100644 --- a/SA_POP/SANet/SANode.cpp +++ b/SA_POP/SANet/SANode.cpp @@ -24,7 +24,8 @@ Node::Node (NodeID ID, std::string name, MultFactor atten_factor) atten_factor_ (atten_factor), step_ (0), prob_changed_ (false), - util_changed_ (false) + util_changed_ (false) , + active(true) { // Initialize probability and utility info. pos_util_.utility = 0; @@ -89,6 +90,12 @@ std::string Node::get_name (void) return name_; }; +/// Set activity flag +void Node::set_activity (bool state) +{ + active = state; +} + NodeID Node::get_ID (void) { return ID_; @@ -128,8 +135,18 @@ void TaskNode::set_pos_util(double util){ this->pos_util_.utility = util; } + + bool TaskNode::update (void) { + + //Check to see if node is active before updating + if(!active) + { + //the node should return as not changing the network + return false; + } + // Reset change flags. prob_changed_ = false; util_changed_ = false; @@ -140,6 +157,8 @@ bool TaskNode::update (void) 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; @@ -972,6 +991,14 @@ void CondNode::print (std::basic_ostream >& bool CondNode::update (void) { + + //Check to see if node is active before updating + if(!active) + { + //the node should return as not changing the network + return false; + } + // Reset change flags. prob_changed_ = false; util_changed_ = false; diff --git a/SA_POP/SANet/SANode.h b/SA_POP/SANet/SANode.h index f478d6887b0..f10462ffbc1 100644 --- a/SA_POP/SANet/SANode.h +++ b/SA_POP/SANet/SANode.h @@ -128,6 +128,13 @@ namespace SANet { */ virtual NodeID get_ID (void); + /// Set activity flag + /** + * + * @param state the new state for the node + */ + virtual void set_activity (bool state); + /// Get pre-links (nodes with links to this node). /** * @return Map of pre-node IDs to link weights. @@ -161,6 +168,9 @@ namespace SANet { /// Unique ID of node (for identification within network). NodeID ID_; + /// Flag indicating whether the node is active. + bool active; + /// Name of node (descriptive only). std::string name_; @@ -299,6 +309,7 @@ namespace SANet { */ virtual void update_prior (Probability prior); + /// Add precondition link. /** * @param ID Node ID. -- cgit v1.2.1