summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjkinnebrew <jkinnebrew@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2010-01-14 23:30:01 +0000
committerjkinnebrew <jkinnebrew@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2010-01-14 23:30:01 +0000
commit0a33250a5d8d60f66a44f079adbe81df90eaf8b9 (patch)
tree6a934dcb15a2fdd2bdc14d37b45ec188903ae825
parent2e3e405960262affe3f7d91ff5250aaa56f3e849 (diff)
downloadATCD-0a33250a5d8d60f66a44f079adbe81df90eaf8b9.tar.gz
Thu Jan 14 23:23:05 UTC 2010 John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
-rw-r--r--SA_POP/ChangeLog36
-rw-r--r--SA_POP/LogGraphOut.cpp25
-rw-r--r--SA_POP/LogScreenOut.cpp162
-rw-r--r--SA_POP/Planner.cpp106
-rw-r--r--SA_POP/Planner.h2
-rw-r--r--SA_POP/SANet/SANet.cpp18
-rw-r--r--SA_POP/SANet/SANet.h8
-rw-r--r--SA_POP/SANet/SANode.cpp93
-rw-r--r--SA_POP/SANet/SANode.h42
-rw-r--r--SA_POP/SAPOP_Exp_EU.mwc1
-rw-r--r--SA_POP/SA_POP_Types.h2
-rw-r--r--SA_POP/SA_WorkingPlan.cpp14
-rw-r--r--SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp118
-rw-r--r--SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.h56
-rw-r--r--SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp111
-rw-r--r--SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc5
16 files changed, 442 insertions, 357 deletions
diff --git a/SA_POP/ChangeLog b/SA_POP/ChangeLog
index 1f889ff40f1..8028821c607 100644
--- a/SA_POP/ChangeLog
+++ b/SA_POP/ChangeLog
@@ -1,3 +1,39 @@
+Thu Jan 14 23:23:05 UTC 2010 John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
+
+ * LogGraphOut.cpp:
+ * LogScreenOut.cpp:
+
+ Minor updates to plan output info & formatting.
+
+ * Planner.h:
+ * Planner.cpp:
+
+ Fixed calculation of plan EU to use a cloned SANet & activate relevant nodes (in calc_plan_eu()).
+
+ * SANet/SANet.h:
+ * SANet/SANet.cpp:
+ * SANet/SANode.h:
+ * SANet/SANode.cpp:
+
+ Corrected probability propagation for inactive nodes (in get_prob() methods) and added reset functionality (reset_sa() methods)
+
+ * SA_POP_Types.h:
+ * SA_WorkingPlan.cpp:
+
+ Set default debug output level to only temporary output and corrected debug levels in some existing debug statements.
+
+ * SAPOP_Exp_EU.mwc:
+
+ Updated SA-POP EU experiment to use Boost (for statistical analysis and random number generation).
+
+ * experiments/EU_Performance/Exp_Core/Exp_EU_Planner.h:
+ * experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp:
+ * experiments/EU_Performance/SAPOP_Exp_EU.mpc:
+ * experiments/EU_Performance/SAPOP_Exp_EU.cpp:
+
+ Updated SA-POP EU experiment interface and recursive planning to find all plans.
+
+
Thu Jan 14 00:06:06 UTC 2010 John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
* Planner.cpp:
diff --git a/SA_POP/LogGraphOut.cpp b/SA_POP/LogGraphOut.cpp
index 67f117f7945..3295f1249e1 100644
--- a/SA_POP/LogGraphOut.cpp
+++ b/SA_POP/LogGraphOut.cpp
@@ -100,18 +100,31 @@ void LogGraphOut::notify_plan (SA_POP::Planner *planner)
bool done = false;
- //This sends planning info not included in the graph to the console, about timing windows.
+ // This sends planning info not included in the graph to the console, about timing windows.
+ // REMOVED so both LogScreenOut and LogGraphOut can be used
+ // simultaneously without duplicate info sent to console.
+/*
this->out_ << std::endl;
- this->out_ << "Plan (" << plan.name << ") Changed at " << std::endl;
- this->out_ << ctime (&cur_time) << std::endl;
+ this->out_ << "Plan (" << plan.name << ")" << " changed at " << ctime (&cur_time);
this->out_ << "ID: " << plan.plan_id << std::endl;
-
+ this->out_ << "Goal Condition(s):";
+ for (GoalMap::iterator goal_iter = plan.goal.goal_conds.begin ();
+ goal_iter != plan.goal.goal_conds.end (); goal_iter++)
+ {
+ this->out_ << " " << planner->get_cond_name (goal_iter->first);
+ if (goal_iter->second >= 0)
+ this->out_ << " (TRUE) = " << goal_iter->second;
+ else
+ this->out_ << " (FALSE) = " << (-1.0 * goal_iter->second);
+ }
+ this->out_ << std::endl;
this->out_ << "Start Window: [" << plan.start_window.first << ", ";
this->out_ << plan.start_window.second << "]" << std::endl;
-
this->out_ << "End Window: [" << plan.end_window.first << ", ";
this->out_ << plan.end_window.second << "]" << std::endl;
-
+ this->out_ << "Expected Utility: " << planner->calc_plan_eu (plan) << std::endl << std::endl;
+*/
+
std::vector<int> startimes;
//Find the plan, and find the ealiest time for the latest time step
diff --git a/SA_POP/LogScreenOut.cpp b/SA_POP/LogScreenOut.cpp
index 531c4f9e3ae..18ba13b0522 100644
--- a/SA_POP/LogScreenOut.cpp
+++ b/SA_POP/LogScreenOut.cpp
@@ -59,108 +59,126 @@ void LogScreenOut::notify_plan (SA_POP::Planner *planner)
time_t cur_time = time(0);
this->out_ << std::endl;
- this->out_ << "Plan (" << plan.name << ") Changed at " << std::endl;
- this->out_ << ctime (&cur_time) << std::endl;
+ this->out_ << "Plan (" << plan.name << ")" << " changed at " << ctime (&cur_time);
this->out_ << "ID: " << plan.plan_id << std::endl;
-
+ this->out_ << "Goal Condition(s):";
+ for (GoalMap::iterator goal_iter = plan.goal.goal_conds.begin ();
+ goal_iter != plan.goal.goal_conds.end (); goal_iter++)
+ {
+ this->out_ << " " << planner->get_cond_name (goal_iter->first);
+ if (goal_iter->second >= 0)
+ this->out_ << " (TRUE) = " << goal_iter->second;
+ else
+ this->out_ << " (FALSE) = " << (-1.0 * goal_iter->second);
+ }
+ this->out_ << std::endl;
this->out_ << "Start Window: [" << plan.start_window.first << ", ";
this->out_ << plan.start_window.second << "]" << std::endl;
-
this->out_ << "End Window: [" << plan.end_window.first << ", ";
this->out_ << plan.end_window.second << "]" << std::endl;
-
+ this->out_ << "Expected Utility: " << planner->calc_plan_eu (plan) << std::endl << std::endl;
+
+
+ this->out_ << "ALL Task Instances:" << std::endl;
for (PlanInstSet::iterator inst_iter = plan.task_insts.begin ();
inst_iter != plan.task_insts.end ();
inst_iter++)
{
PlanTaskInst inst = *inst_iter;
- this->out_ << "Task Instance (" << inst.name << "):" << std::endl;
+ this->out_ << " Task Instance (" << inst.name << "):" << std::endl;
- this->out_ << " ID: " << inst.inst_id << std::endl;
+ this->out_ << " ID: " << inst.inst_id << std::endl;
- this->out_ << " Start Window: [" << inst.start_window.first << ", ";
+ this->out_ << " Start Window: [" << inst.start_window.first << ", ";
this->out_ << inst.start_window.second << "]" << std::endl;
- this->out_ << " End Window: [" << inst.end_window.first << ", ";
+ this->out_ << " End Window: [" << inst.end_window.first << ", ";
this->out_ << inst.end_window.second << "]" << std::endl;
- this->out_ << " Task ID: " << inst.task_id << std::endl;
+ this->out_ << " Task ID: " << inst.task_id << std::endl;
- this->out_ << " Task Type: " << inst.type_id << std::endl;
+ this->out_ << " Task Type: " << inst.type_id << std::endl;
- this->out_ << " Suggested Implementation: ";
+ this->out_ << " Suggested Implementation: ";
this->out_ << inst.suggested_impl << std::endl;
}
-
this->out_ << std::endl;
- for (PlanConnSet::iterator conn_iter = plan.connections.begin ();
- conn_iter != plan.connections.end ();
- conn_iter++)
- {
- PlanConnection conn = *conn_iter;
- this->out_ << "Data Connection:" << std::endl;
- this->out_ << " " << conn.first_task_inst << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (conn.first_task_inst)) << "--";
- this->out_ << conn.first_port << ") -";
- this->out_ << "(" << planner->get_cond_name (conn.cond) << ")-> ";
- this->out_ << conn.second_task_inst << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (conn.second_task_inst)) << "--";
- this->out_ << conn.second_port << ")" << std::endl;
+ if (plan.connections.size () > 0) {
+ this->out_ << "ALL Data Connections:" << std::endl;
+ for (PlanConnSet::iterator conn_iter = plan.connections.begin ();
+ conn_iter != plan.connections.end ();
+ conn_iter++)
+ {
+ PlanConnection conn = *conn_iter;
+ this->out_ << " Data Connection:" << std::endl;
+ this->out_ << " " << conn.first_task_inst << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (conn.first_task_inst)) << "--";
+ this->out_ << conn.first_port << ") -";
+ this->out_ << "(" << planner->get_cond_name (conn.cond) << ")-> ";
+ this->out_ << conn.second_task_inst << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (conn.second_task_inst)) << "--";
+ this->out_ << conn.second_port << ")" << std::endl;
+ }
+ this->out_ << std::endl;
}
- this->out_ << std::endl;
- for (CLSet::iterator cl_iter = plan.causal_links.begin ();
- cl_iter != plan.causal_links.end ();
- cl_iter++)
- {
- CausalLink clink = *cl_iter;
- this->out_ << "Causal Link:" << std::endl;
- this->out_ << " " << clink.first << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (clink.first)) << ") -";
- this->out_ << "(" << planner->get_cond_name (clink.cond.id) << ")-> ";
- this->out_ << clink.second << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (clink.second)) << ")" << std::endl;
+ if (plan.causal_links.size () > 0) {
+ this->out_ << "ALL Causal Links:" << std::endl;
+ for (CLSet::iterator cl_iter = plan.causal_links.begin ();
+ cl_iter != plan.causal_links.end ();
+ cl_iter++)
+ {
+ CausalLink clink = *cl_iter;
+ this->out_ << " " << clink.first << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (clink.first)) << ") -";
+ this->out_ << "(" << planner->get_cond_name (clink.cond.id) << ")-> ";
+ this->out_ << clink.second << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (clink.second)) << ")" << std::endl;
+ }
+ this->out_ << std::endl;
}
- this->out_ << std::endl;
-
- for (SchedLinkSet::iterator sched_iter = plan.sched_links.begin ();
- sched_iter != plan.sched_links.end ();
- sched_iter++)
- {
- SchedLink sched_link = (*sched_iter);
- this->out_ << "Scheduling Link:" << std::endl;
- this->out_ << " " << sched_link.first << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (sched_link.first)) << ") -> ";
- this->out_ << sched_link.second << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (sched_link.second)) << ")" << std::endl;
+ if (plan.sched_links.size () > 0) {
+ this->out_ << "ALL Scheduling Links:" << std::endl;
+ for (SchedLinkSet::iterator sched_iter = plan.sched_links.begin ();
+ sched_iter != plan.sched_links.end ();
+ sched_iter++)
+ {
+ SchedLink sched_link = (*sched_iter);
+ this->out_ << " " << sched_link.first << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (sched_link.first)) << ") -> ";
+ this->out_ << sched_link.second << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (sched_link.second)) << ")" << std::endl;
+
+ }
+ this->out_ << std::endl;
}
- this->out_ << std::endl;
-
- for (ThreatLinkSet::iterator threat_iter = plan.threat_links.begin ();
- threat_iter != plan.threat_links.end ();
- threat_iter++)
- {
- ThreatLink threat_link = (*threat_iter);
- this->out_ << "Threat Link:" << std::endl;
- this->out_ << " " << threat_link.first << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (threat_link.first)) << ") -> ";
- this->out_ << threat_link.second << " (";
- this->out_ << planner->get_task_name (
- planner->get_task_from_inst (threat_link.second)) << ")" << std::endl;
-
+ if (plan.threat_links.size () > 0) {
+ this->out_ << "ALL Threat Links:" << std::endl;
+ for (ThreatLinkSet::iterator threat_iter = plan.threat_links.begin ();
+ threat_iter != plan.threat_links.end ();
+ threat_iter++)
+ {
+ ThreatLink threat_link = (*threat_iter);
+ this->out_ << " " << threat_link.first << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (threat_link.first)) << ") -> ";
+ this->out_ << threat_link.second << " (";
+ this->out_ << planner->get_task_name (
+ planner->get_task_from_inst (threat_link.second)) << ")" << std::endl;
+
+ }
+ this->out_ << std::endl;
}
- this->out_ << std::endl;
};
diff --git a/SA_POP/Planner.cpp b/SA_POP/Planner.cpp
index 4646640e34f..77096b87fcb 100644
--- a/SA_POP/Planner.cpp
+++ b/SA_POP/Planner.cpp
@@ -18,6 +18,7 @@
#include <map>
#include <stdlib.h>
#include <fstream>
+#include <sstream>
#include "SA_POP_Types.h"
#include "Planner.h"
#include "PlanStrategy.h"
@@ -118,7 +119,8 @@ bool Planner::plan (size_t sa_max_steps, SA_POP::Goal goal)
this->working_plan_->set_goal (goal);
this->sanet_->update_goals (goal.goal_conds);
- // Run spreading activation.
+ // Reset network and run spreading activation.
+ this->sanet_->reset_sa ();
this->sanet_->update (sa_max_steps);
// Set planning strategy goals and satisfy open conditions.
@@ -151,7 +153,8 @@ bool Planner::replan (size_t sa_max_steps, SA_POP::Goal goal)
this->working_plan_->set_goal (goal);
this->sanet_->update_goals (goal.goal_conds);
- // Run spreading activation.
+ // Reset network and run spreading activation.
+ this->sanet_->reset_sa ();
this->sanet_->update (sa_max_steps);
// Set planning strategy goals and satisfy open conditions.
@@ -177,7 +180,8 @@ bool Planner::replan (size_t sa_max_steps)
// Reset the working plan
this->working_plan_->reset_plan ();
- // Run spreading activation.
+ // Reset network and run spreading activation.
+ this->sanet_->reset_sa ();
this->sanet_->update (sa_max_steps);
// Set planning strategy goals and satisfy open conditions.
@@ -495,14 +499,18 @@ void Planner::notify_plan_changed (void)
}
};
-double Planner::calc_plan_eu(Plan plan)
+Utility Planner::calc_plan_eu(Plan plan)
{
// Probability of goal conditions should be completely updated
// by spreading activation for <= 2 times the number of tasks
// in the plan (because even a serial plan will be of no longer
// than the number of tasks and times 2 to account for
// update of condition nodes between tasks).
- size_t sa_max_steps = 2 * plan.task_insts.size ();
+//*****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*****
+// size_t sa_max_steps = 2 * plan.task_insts.size ();
+ // Set to times 3 to be extra certain that sufficient SA is done.
+ size_t sa_max_steps = 3 * plan.task_insts.size ();
+//*****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*****
// Clone current SANet.
SANet::Network sanet (*(this->sanet_));
@@ -512,76 +520,80 @@ double Planner::calc_plan_eu(Plan plan)
SA_POP::Goal goal = plan.goal;
+// std::ostringstream goal_str;
+// goal_str << "Activated goal conditions: ";
+
// Activate goal conditions.
for (SA_POP::GoalMap::iterator goal_iter = goal.goal_conds.begin (); goal_iter != goal.goal_conds.end (); goal_iter++) {
+// goal_str << this->get_cond_name (goal_iter->first) << " ";
sanet.set_cond_state (goal_iter->first, true);
}
- // Activate only nodes relevant to the plan (tasks in plan and their preconditions).
+// SA_POP_DEBUG_STR(SA_POP_DEBUG_TEMP, goal_str.str ());
+
+ // Activate tasks in plan and their preconditions.
for (PlanInstSet::iterator inst_iter = plan.task_insts.begin (); inst_iter != plan.task_insts.end (); inst_iter++) {
if ((*inst_iter).inst_id == INIT_TASK_INST_ID) {
std::cerr << "SA_POP::Planner::calc_plan_eu(Plan plan): Initial state task instance found in plan." << std::endl;
throw "SA_POP::Planner::calc_plan_eu(Plan plan): Initial state task instance found in plan.";
}
+// std::ostringstream temp_str;
+// temp_str << "Activated task [instance] and ( preconditions ): ";
+// temp_str << this->get_task_name ((*inst_iter).task_id);
+// temp_str << " [" << (*inst_iter).name << "] and ( ";
+
// Activate task.
sanet.set_task_state ((*inst_iter).task_id, true);
// Activate preconditions.
SA_POP::CondSet preconds = this->get_preconds ((*inst_iter).task_id);
for (SA_POP::CondSet::iterator cond_iter = preconds.begin (); cond_iter != preconds.end (); cond_iter++) {
+// temp_str << this->get_cond_name ((*cond_iter).id) << " ";
sanet.set_cond_state ((*cond_iter).id, 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*****
-// Replace with correct code to activate all tasks and their preconditions on a clone of the network.
- /*
- size_t sa_max_steps = 100;
- sanet_->set_nodes_state(false);
-
- for(CLSet::iterator it = this->plan_.causal_links.begin(); it !=
- this->plan_.causal_links.end(); it++){
- if((*it).first != INIT_TASK_INST_ID){
- this->sanet_->set_task_state(this->working_plan_->get_task_from_inst((*it).first), true);
- }
-
- this->sanet_->set_task_state(this->working_plan_->get_task_from_inst((*it).second), true);
- this->sanet_->set_cond_state((*it).cond.id, true);
- std::cout<<(*it).cond.id<<" cond, "<<(*it).first<<" first, "<<(*it).second<<" second"<<std::endl;
+// temp_str << ")";
+// SA_POP_DEBUG_STR(SA_POP_DEBUG_TEMP, temp_str.str ());
+ }
- }
+ // Reset network and run spreading activation.
+ sanet.reset_sa ();
+ sanet.update(sa_max_steps);
+// std::ostringstream eu_str;
+// eu_str << "Goals (probability, EU): ";
- GoalMap goals = this->get_goals();
+ // Calculate sum of expected utility for goals.
+ SA_POP::Utility eu_total = 0.0;
+ for (SA_POP::GoalMap::iterator goal_iter = goal.goal_conds.begin (); goal_iter != goal.goal_conds.end (); goal_iter++) {
+// eu_str << this->get_cond_name (goal_iter->first) << " (";
+ SA_POP::Probability prob = 0.0;
+ SA_POP::Utility util = 0.0;
+ SA_POP::Utility eu = 0.0;
+
+ // Set probability and utility of goal condition achieving desired value
+ // of true (if positive utility) or false (if negative utility).
+ if (goal_iter->second > 0) {
+ prob = sanet.get_cond_future_val (goal_iter->first, true);
+ util = goal_iter->second;
+ }
+ else {
+ prob = sanet.get_cond_future_val (goal_iter->first, false);
+ util = -1 * goal_iter->second;
+ }
- for(GoalMap::iterator it = goals.begin(); it != goals.end(); it++){
- this->sanet_->set_cond_state(it->first, true);
- }
+ // Expected utility of the goal condition is its probability times utility.
+ eu = prob * util;
- sanet_->update(sa_max_steps);
-
- double conj_utils = 0;
- for(GoalMap::iterator it = goals.begin(); it != goals.end(); it++){
- std::cout<<it->second<<std::endl;
- if (it->second >= 0.0) {
- std::cout<<this->sanet_->get_cond_future_val(it->first, true)<<std::endl;
- conj_utils+=(it->second * this->sanet_->get_cond_future_val(it->first, true));
- } else {
- std::cout<<this->sanet_->get_cond_future_val(it->first, false)<<std::endl;
- conj_utils+=(it->second * this->sanet_->get_cond_future_val(it->first, false));
- }
- }
+ eu_total += eu;
- std::cout<<"Plan utility: "<<conj_utils<<std::endl;
+// eu_str << prob << ", " << eu << ") " ;
+ }
- sanet_->set_nodes_state(true);
- //TODO the rest
+// SA_POP_DEBUG_STR(SA_POP_DEBUG_TEMP, eu_str.str ());
- return conj_utils;
- */
- return 10;
-//*****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*****
+ return eu_total;
};
/// Get the Task instances in a particular set of the specified task instance
diff --git a/SA_POP/Planner.h b/SA_POP/Planner.h
index 73221389dbe..a0dc88d1abc 100644
--- a/SA_POP/Planner.h
+++ b/SA_POP/Planner.h
@@ -129,7 +129,7 @@ namespace SA_POP {
*
* @return Expected utility of provided plan given current conditions.
*/
- virtual EUCalc calc_plan_eu (Plan plan);
+ virtual Utility calc_plan_eu (Plan plan);
/// Get last set of expected utility changes.
/**
diff --git a/SA_POP/SANet/SANet.cpp b/SA_POP/SANet/SANet.cpp
index b978a2947e1..ffa09d5f29a 100644
--- a/SA_POP/SANet/SANet.cpp
+++ b/SA_POP/SANet/SANet.cpp
@@ -150,6 +150,24 @@ SANet::Network::~Network ()
}
};
+void SANet::Network::reset_sa (void)
+{
+ this->reset_step ();
+
+ // Reset all task and condition nodes.
+ for (TaskNodeMap::iterator node_iter = this->task_nodes_.begin ();
+ node_iter != this->task_nodes_.end (); node_iter++)
+ {
+ node_iter->second->reset_sa ();
+ }
+ for (CondNodeMap::iterator node_iter = this->cond_nodes_.begin ();
+ node_iter != this->cond_nodes_.end (); node_iter++)
+ {
+ node_iter->second->reset_sa ();
+ }
+
+};
+
void SANet::Network::add_task (TaskID ID, std::string name, MultFactor atten_factor,
TaskCost cost, Probability prior_prob)
{
diff --git a/SA_POP/SANet/SANet.h b/SA_POP/SANet/SANet.h
index 276fcc6b723..d0bbc5fe4aa 100644
--- a/SA_POP/SANet/SANet.h
+++ b/SA_POP/SANet/SANet.h
@@ -190,6 +190,14 @@ namespace SANet {
*/
virtual void update (int max_steps);
+ /// Reset saved probabilities and utilities from spreading activation
+ /// to initial state.
+ /// NOTE: This does not necessarily reset to original construction state
+ /// if pre-spreading-activation values (e.g., initial probability,
+ /// goal utility, links, prior probability) if those have been
+ /// changed after construction.
+ virtual void reset_sa (void);
+
/// Update a condition's current value (probability of being true).
/**
* @param cond_id The condition id.
diff --git a/SA_POP/SANet/SANode.cpp b/SA_POP/SANet/SANode.cpp
index 0eacee63dec..8976f7c2975 100644
--- a/SA_POP/SANet/SANode.cpp
+++ b/SA_POP/SANet/SANode.cpp
@@ -93,6 +93,24 @@ Node::~Node ()
// Nothing to do.
};
+void Node::reset_sa (void)
+{
+ // Initialize spreading activation step and flags.
+ this->reset_step ();
+ this->prob_changed_ = false;
+ this->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 ();
+};
+
Utility_Info Node::get_reward (int step)
{
// Check to ensure step is the current step, or else throw exception
@@ -217,6 +235,31 @@ TaskNode::~TaskNode (void)
// Nothing to do.
};
+void TaskNode::reset_sa (void)
+{
+ // Initialize base class spreading activation info.
+ Node::reset_sa ();
+};
+
+Probability_Info TaskNode::get_prob (int step, bool value)
+{
+ // If deactivated, return 0.0 probability.
+ if (!this->active_) {
+ Probability_Info prob;
+ prob.common.clear ();
+ prob.probability = 0.0;
+ return prob;
+ }
+
+ // Check to ensure step is the current step, or else throw exception
+ if (step != step_) {
+ throw Invalid_Step ();
+ }
+
+ // If active, use base class function to return correct probability.
+ return Node::get_prob (step, value);
+};
+
Utility_Info TaskNode::get_pos_util(void){
return this->pos_util_;
}
@@ -970,6 +1013,56 @@ CondNode::~CondNode (void)
// Nothing to do.
};
+void CondNode::reset_sa (void)
+{
+ // Initialize base class spreading activation info.
+ Node::reset_sa ();
+
+ // Reset probabilities from initial probability.
+ this->true_prob_.probability = this->init_true_prob_;
+ this->false_prob_.probability = (1 - this->init_true_prob_);
+ this->true_prob_from_ = this->ID_;
+ this->false_prob_from_ = this->ID_;
+
+ // Set prob_changed_ flag.
+ prob_changed_ = true;
+
+ // If this node is a goal, set util_changed_ flag and add goal utility.
+ if (this->goal_util_ > 0) {
+ this->util_changed_ = true;
+ this->pos_util_.utility = this->goal_util_;
+ this->pos_util_.common.insert (std::make_pair (this->ID_, this->goal_util_));
+ } else if (this->goal_util_ < 0) {
+ this->util_changed_ = true;
+ this->neg_util_.utility = this->goal_util_;
+ this->neg_util_.common.insert (std::make_pair (this->ID_, this->goal_util_));
+ }
+};
+
+Probability_Info CondNode::get_prob (int step, bool value)
+{
+ // If deactivated, return initial probability.
+ if (!this->active_) {
+ Probability_Info prob;
+ prob.common.clear ();
+ prob.probability = 0.0;
+ if (value)
+ prob.probability = this->init_true_prob_;
+ else
+ prob.probability = (1.0 - this->init_true_prob_);
+
+ return prob;
+ }
+
+ // Check to ensure step is the current step, or else throw exception
+ if (step != step_) {
+ throw Invalid_Step ();
+ }
+
+ // Use base class function to return correct probability.
+ return Node::get_prob (step, value);
+};
+
// Update goal utility.
void CondNode::set_goal_util (Utility util)
{
diff --git a/SA_POP/SANet/SANode.h b/SA_POP/SANet/SANode.h
index 2a344adf09b..67c0b888305 100644
--- a/SA_POP/SANet/SANode.h
+++ b/SA_POP/SANet/SANode.h
@@ -90,6 +90,14 @@ namespace SANet {
/// Destructor.
virtual ~Node ();
+ /// Reset saved probabilities and utilities from spreading activation
+ /// to initial state.
+ /// NOTE: This does not necessarily reset to original construction state
+ /// if pre-spreading-activation values (e.g., initial probability,
+ /// goal utility, links, prior probability) if those have been
+ /// changed after construction.
+ virtual void reset_sa (void);
+
/// Get (positive) expected utility info (from goals) for a given step.
/**
* @param step Step for which to get reward map.
@@ -263,6 +271,23 @@ namespace SANet {
/// Destructor.
virtual ~TaskNode (void);
+ /// Reset saved probabilities and utilities from spreading activation
+ /// to initial state.
+ /// NOTE: This does not necessarily reset to original construction state
+ /// if pre-spreading-activation values (e.g. links, prior probability)
+ /// if those have been changed after construction.
+ virtual void reset_sa (void);
+
+ /// 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);
+
/// Print node.
/**
* @param strm Output stream on which to print node representation.
@@ -441,6 +466,23 @@ namespace SANet {
/// Destructor.
virtual ~CondNode (void);
+ /// Reset saved probabilities and utilities from spreading activation
+ /// to initial state.
+ /// NOTE: This does not necessarily reset to original construction state
+ /// if pre-spreading-activation values (e.g., initial probability,
+ /// goal utility) if those have been changed after construction.
+ virtual void reset_sa (void);
+
+ /// 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 goal utility.
/**
* @param util Goal utility.
diff --git a/SA_POP/SAPOP_Exp_EU.mwc b/SA_POP/SAPOP_Exp_EU.mwc
index de718d6c1ed..95199536378 100644
--- a/SA_POP/SAPOP_Exp_EU.mwc
+++ b/SA_POP/SAPOP_Exp_EU.mwc
@@ -1,5 +1,6 @@
workspace {
cmdline += -include $SAPOP_ROOT/MPC/config
+ cmdline += -features boost=1
Standalone/XML_Utils/XML/XML.mpc
experiments/EU_Performance/SAPOP_Exp_EU.mpc
}
diff --git a/SA_POP/SA_POP_Types.h b/SA_POP/SA_POP_Types.h
index 098a80f6c20..bc82b7839db 100644
--- a/SA_POP/SA_POP_Types.h
+++ b/SA_POP/SA_POP_Types.h
@@ -36,7 +36,7 @@
#define SA_POP_DEBUG_VERBOSE 30
// SET current SA-POP Debug output level.
-#define SA_POP_DEBUG_LEVEL SA_POP_DEBUG_TEMP
+#define SA_POP_DEBUG_LEVEL SA_POP_DEBUG_QUIET
#define _CRTDBG_MAP_ALLOC
diff --git a/SA_POP/SA_WorkingPlan.cpp b/SA_POP/SA_WorkingPlan.cpp
index ebed6a9143c..bdeae07fcc5 100644
--- a/SA_POP/SA_WorkingPlan.cpp
+++ b/SA_POP/SA_WorkingPlan.cpp
@@ -307,7 +307,7 @@ void SA_WorkingPlan::generate_all_threats(void)
debug_text << " Task ("<<threatened_task<<") " << "Inst ("<<causal_threatened.first<<") -(" << causal_threatened.cond.id << ")-> Task ("<<this->task_insts_.find(causal_threatened.second)->second<< ") Inst ("<< causal_threatened.second << ")" << std::endl;
}
- SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_VERBOSE, debug_text.str ());
debug_text.str("");
@@ -324,7 +324,7 @@ void SA_WorkingPlan::generate_all_threats(void)
debug_text <<" Task (" <<threat_possibility_taskid << ")"<< ": Inst (" <<iterator->first << ")" << std::endl;
}
debug_text<<std::endl;
- SA_POP_DEBUG_STR (SA_POP_DEBUG_QUIET, debug_text.str ());
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_VERBOSE, debug_text.str ());
debug_text.str("");
debug_text << "SA_WorkingPlan::generate_all_threats: All Causal Threats: " << std::endl;
@@ -412,7 +412,7 @@ void SA_WorkingPlan::generate_all_threats(void)
}
- SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_VERBOSE, debug_text.str ());
debug_text.str("");
print_precedence_graph("SA_WorkingPlan::generate_all_threats");
@@ -436,7 +436,7 @@ void SA_WorkingPlan::print_precedence_graph(std::string source){
}
debug_text<<std::endl;
}
- SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_VERBOSE, debug_text.str ());
debug_text.str("");
debug_text << source<<": Precendence Sets: AFTER: " << std::endl;
@@ -448,7 +448,7 @@ void SA_WorkingPlan::print_precedence_graph(std::string source){
debug_text<<std::endl;
}
- SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_VERBOSE, debug_text.str ());
debug_text.str("");
@@ -461,7 +461,7 @@ void SA_WorkingPlan::print_precedence_graph(std::string source){
debug_text<<std::endl;
}
- SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_VERBOSE, debug_text.str ());
debug_text.str("");
debug_text << source<<": Precendence Sets: UNRANKED: " << std::endl;
@@ -473,7 +473,7 @@ void SA_WorkingPlan::print_precedence_graph(std::string source){
debug_text<<std::endl;
}
- SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_VERBOSE, debug_text.str ());
debug_text.str("");
}
diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp
index 3e2907a3b1c..5ed043c55b8 100644
--- a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp
+++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp
@@ -19,6 +19,7 @@
#include <map>
#include <stdlib.h>
#include <fstream>
+#include <sstream>
#include "SA_POP_Types.h"
#include "Exp_EU_Planner.h"
@@ -35,6 +36,9 @@ using namespace SA_POP;
// Constructor.
Exp_EU_Planner::Exp_EU_Planner (void)
+:do_pause_ (false),
+ input_ (0),
+ ques_ (0)
{
// All initialization handled by Planner base class constructor.
};
@@ -47,104 +51,21 @@ Exp_EU_Planner::~Exp_EU_Planner (void)
}
-
-
-// Run planning.
-bool Exp_EU_Planner::plan (size_t sa_max_steps, SA_POP::Goal goal)
-{
- // Add goal to working plan and task network.
- this->working_plan_->set_goal (goal);
- this->sanet_->update_goals (goal.goal_conds);
-
- // Run spreading activation.
- this->sanet_->update (sa_max_steps);
-
- // Set planning strategy goals and satisfy open conditions.
- this->plan_strat_->set_goals (goal.goal_conds);
-
- if (this->plan_strat_->satisfy_open_conds ()) {
- this->plan_ = this->working_plan_->get_plan ();
-
- this->notify_plan_changed ();
- return true;
- }
-
- return false;
-};
-
-// Replan with new goal.
-bool Exp_EU_Planner::replan (size_t sa_max_steps, SA_POP::Goal goal)
+// Set to pause and ask user whether to continue after each plan is generated.
+void Exp_EU_Planner::set_pause (UserInterface::InputCL *input_cl, UserInterface::QuestionBool *ques)
{
- //****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****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****
- // Full replanning not implemented, so just restart planning.
- //****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****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****
-
- // Clear plan.
- this->plan_.causal_links.clear ();
- this->plan_.connections.clear ();
- this->plan_.sched_links.clear ();
- this->plan_.task_insts.clear ();
- this->plan_.threat_links.clear ();
-
- // Add goal to working plan and task network.
- //****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****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****
- // Need to reset working plan.
- //****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****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****
- this->working_plan_->reset_plan();
- this->working_plan_->set_goal (goal);
- this->sanet_->update_goals (goal.goal_conds);
-
- // Run spreading activation.
- this->sanet_->update (sa_max_steps);
-
-
- // Set planning strategy goals and satisfy open conditions.
- this->plan_strat_->set_goals (goal.goal_conds);
- if (this->plan_strat_->satisfy_open_conds ()) {
- this->plan_ = this->working_plan_->get_plan ();
- this->notify_plan_changed ();
- return true;
- }
-
- return false;
+ this->input_ = input_cl;
+ this->ques_ = ques;
+ this->do_pause_ = true;
};
-// Replan with existing goal.
-bool Exp_EU_Planner::replan (size_t sa_max_steps)
+// Set to generate all plans without user input (instead of asking whether to continue after each plan is generated).
+void Exp_EU_Planner::unset_pause (void)
{
- //****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****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****
- // Full replanning not implemented, so just restart planning.
- //****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****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****
- // Clear plan.
- //TODO: Refactor this plan clearing into own function.
- this->plan_.causal_links.clear ();
- this->plan_.connections.clear ();
- this->plan_.sched_links.clear ();
- this->plan_.task_insts.clear ();
- this->plan_.threat_links.clear ();
- // Reset the working plan
-
- // Run spreading activation.
- this->sanet_->update (sa_max_steps);
-
- // Set planning strategy goals and satisfy open conditions.
- this->plan_strat_->set_goals (this->sanet_->get_goals ());
- if (this->plan_strat_->satisfy_open_conds ()) {
- this->plan_ = this->working_plan_->get_plan ();
- this->notify_plan_changed ();
- return true;
- }
-
- return false;
+ this->do_pause_ = false;
};
-// Recursively plan (satisfy all open conditions & schedule constraints).
-bool Exp_EU_Planner::recurse_plan (void)
-{
- return this->plan_strat_->satisfy_open_conds ();
-};
-
// Satisfy scheduling constraints in fully instantiated plan (no
// recursive call backs).
bool Exp_EU_Planner::full_sched ()
@@ -153,7 +74,20 @@ bool Exp_EU_Planner::full_sched ()
this->plan_ = this->working_plan_->get_plan ();
this->notify_plan_changed ();
Utility plan_eu = this->calc_plan_eu (this->plan_);
- std::cout << "Expected utility of generated plan: " << plan_eu << std::endl << std::endl;
+
+// std::ostringstream eu_str;
+// eu_str << "Plan EU: " << plan_eu << std::endl << std::endl;
+// SA_POP_DEBUG_STR(SA_POP_DEBUG_QUIET, eu_str.str ());
+
+ // If pausing to ask user whether to continue, ask question
+ // and return true (so the current plan will be returned instead
+ // of continuing planning) if user replies "No" to continuation
+ // question.
+ if (this->do_pause_) {
+ this->input_->ask ((*this->ques_));
+ if (!this->ques_->get_answer_bool ())
+ return true;
+ }
}
return false;
diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.h b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.h
index f46d87e5d2a..3e6e3d5b06a 100644
--- a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.h
+++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.h
@@ -26,6 +26,8 @@
#include "Planner.h"
+#include "InputCL.h"
+
//#include "PlanStrategy.h"
//#include "SchedStrategy.h"
//#include "WorkingPlan.h"
@@ -53,50 +55,39 @@ namespace SA_POP {
virtual ~Exp_EU_Planner (void);
+ /// Set to pause and ask user whether to continue after each plan is generated.
+ /**
+ * @param input_cl User in/out interface to use.
+ *
+ * @param ques Question to ask user whether to continue.
+ */
+ virtual void set_pause (UserInterface::InputCL *input_cl, UserInterface::QuestionBool *ques);
+
+ /// Set to generate all plans without user input (instead of asking whether to continue after each plan is generated).
+ virtual void unset_pause (void);
+
// ************************************************************************
// Planning/re-planning methods.
// ************************************************************************
- /// Run planning.
- /**
- * @param sa_max_steps Maximum steps to run spreading activation.
- *
- * @param goal Goal for which to plan.
- *
- * @return True if planning succeeded, false otherwise.
- */
- virtual bool plan (size_t sa_max_steps, SA_POP::Goal goal);
-
- /// Replan with new goal.
+ /// Run experiment planning.
/**
* @param sa_max_steps Maximum steps to run spreading activation.
*
* @param goal Goal for which to plan.
*
- * @return True if planning succeeded, false otherwise.
- */
- virtual bool replan (size_t sa_max_steps, SA_POP::Goal goal);
-
- /// Replan with current goal.
- /**
- * @param sa_max_steps Maximum steps to run spreading activation.
+ * @param pause True to pause after next plan is generated or
+ * false to find all remaining plans.
*
- * @return True if planning succeeded, false otherwise.
+ * @return True if plan generated, false otherwise.
*/
- virtual bool replan (size_t sa_max_steps);
-
-
+// virtual bool plan_exp (size_t sa_max_steps, SA_POP::Goal goal, bool pause = false);
+
// ************************************************************************
// Recursive planning/scheduling methods.
// ************************************************************************
- /// Recursively plan (satisfy all open conditions & schedule constraints).
- /**
- * @return True if fully satisfied plan found, false otherwise.
- */
- virtual bool recurse_plan (void);
-
/// Satisfy scheduling constraints in fully instantiated plan (no
/// recursive call backs).
/**
@@ -104,6 +95,15 @@ namespace SA_POP {
*/
virtual bool full_sched ();
+ protected:
+ /// Flag for whether to pause for user input after each plan is generated.
+ bool do_pause_;
+
+ /// User in/out interface to use for continuation question after each plan is generated.
+ UserInterface::InputCL *input_;
+
+ /// Question to ask user whether to continue after each plan is generated.
+ UserInterface::QuestionBool *ques_;
};
}; /* SA_POP namespace */
diff --git a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp
index 107af895733..099d2b9480f 100644
--- a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp
+++ b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp
@@ -141,9 +141,7 @@ int main (int argc, char* argv[])
std::string tm_filename = "";
size_t max_steps = SANet::Default::SA_MAX_STEPS;
- std::vector<SA_POP::CondID> track_conds;
std::vector<SA_POP::CondID> kconds;
- std::map<SA_POP::CondID, double> condMap;
// Get filenames from user.
UserInterface::Question sanet_file_ques ("Task Network file:");
@@ -261,114 +259,24 @@ int main (int argc, char* argv[])
- // Get number of conditions to track.
- int track = 0;
- //Conditions to be potentially displayed
- std::cout << "How many conditions to track? ";
- std::cin >> track;
-
- // Get conditions to track.
- for(int t = 0; t < track; t++)
- {
- int cid = 0;
- std::cout << "Enter the Condition ID to track:";
- std::cin >> cid;
- SA_POP::CondID ccid = SA_POP::CondID(cid);
- condMap.insert(std::make_pair(ccid, 1));
- track_conds.push_back(ccid);
-
- }
-
//Configure the OutAdapters to use
SA_POP::LogScreenOut screen_out (std::cout);
- graph_out.addTracking(track_conds);
+ planner->add_out_adapter (&screen_out);
planner->add_out_adapter (&graph_out);
//SA_POP::SchemaOut s_out (std::cout, kconds);
//planner->add_out_adapter (&s_out);
- planner->add_out_adapter (&screen_out);
-
- planner->plan (max_steps, goal);
- SA_POP::Plan plan = planner->get_plan ();
- SA_POP::Utility plan_eu = planner->calc_plan_eu (plan);
- std::cout << "Expected utility of generated plan: " << plan_eu << std::endl;
-
-
- UserInterface::QuestionChoice<UserInterface::ExpEU::NextKind> ques_next ("Negate an (E)ffect, change an external (C)ondition, or e(X)it:", UserInterface::ExpEU::INVALID, false);
- ques_next.add_mapping ("E", UserInterface::ExpEU::EFFECT);
- ques_next.add_mapping ("Effect", UserInterface::ExpEU::EFFECT);
- ques_next.add_mapping ("C", UserInterface::ExpEU::CONDITION);
- ques_next.add_mapping ("Condition", UserInterface::ExpEU::CONDITION);
- ques_next.add_mapping ("X", UserInterface::ExpEU::EXIT);
- ques_next.add_mapping ("Exit", UserInterface::ExpEU::EXIT);
+ // Set planner to ask whether continue after each plan is generated.
+ UserInterface::QuestionBool ques_cont_plan ("Continue planning to find next plan? [(Y)es or (N)o]:", false);
+ planner->set_pause (&user_input, &ques_cont_plan);
- bool stop = false;
- while(!stop)
- {
- displayConds(planner, track_conds, &condMap);
-
- UserInterface::QuestionBool adv_ques ("Advance to next time step? [(Y)es or (N)o]:", false);
- user_input.ask (adv_ques);
- if (adv_ques.get_answer_bool ())
- {
- graph_out.moveStep();
- planner->plan (max_steps, goal);
- }
- else
- {
- UserInterface::ExpEU::NextKind next_val = UserInterface::ExpEU::INVALID;
- user_input.ask (ques_next);
- next_val = ques_next.get_answer_val ();
-
- switch (next_val)
- {
- case UserInterface::ExpEU::EFFECT:
- SA_POP::TaskID curTask;
- SA_POP::CondID curEff;
- std::cout << "Enter the Task ID: ";
- std::cin >> curTask;
- std::cout << "Enter the Condition ID: ";
- std::cin >> curEff;
-
- for(std::map<SANet::CondID, double>::iterator cIter = condMap.begin(); cIter != condMap.end(); cIter++)
- {
- planner->update_cond_val((*cIter).first, (*cIter).second);
- }
- planner->update_effect(curTask, curEff, -1);
-
- planner->replan(max_steps, goal);
-
- break;
+ // Run experiment.
+ planner->plan (max_steps, goal);
- case UserInterface::ExpEU::CONDITION:
- {
- SA_POP::CondID envi;
- SA_POP::Probability newprob;
- std::cout << "Enter the Condition ID: ";
- std::cin >> envi;
- std::cout << "Enter the Probability: ";
- std::cin >> newprob;
- std::map<SANet::CondID, double>::iterator cmp = condMap.find(envi);
- if(cmp != condMap.end())
- (*cmp).second = newprob;
-
- for(std::map<SANet::CondID, double>::iterator cIter = condMap.begin(); cIter != condMap.end(); cIter++)
- {
- planner->update_cond_val((*cIter).first, (*cIter).second);
- }
-
- planner->replan(max_steps, goal);
- }
- break;
+// SA_POP::Plan plan = planner->get_plan ();
+// SA_POP::Utility plan_eu = planner->calc_plan_eu (plan);
+// std::cout << "Expected utility of generated plan: " << plan_eu << std::endl;
- case UserInterface::ExpEU::EXIT:
- case UserInterface::ExpEU::INVALID:
- default:
- stop = true;
- break;
- }
- }
- }
delete planner;
@@ -376,7 +284,6 @@ int main (int argc, char* argv[])
// UserInterface::Question end_ques ("Enter any character to end program:");
// user_input.ask (end_ques);
-
_CrtDumpMemoryLeaks();
return 0;
diff --git a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc
index b49247fc495..d88f383220d 100644
--- a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc
+++ b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc
@@ -1,9 +1,12 @@
-project(SAPOP_Exp_EU) : xerces, aceexe, sapop_xml {
+project(SAPOP_Exp_EU) : aceexe, xerces, boost_base, sapop_xml {
exename = SAPOP_Exp_EU
includes += $(SAPOP_ROOT)
includes += $(SAPOP_ROOT)/UserInput
+// includes += $(BOOST_ROOT)
+// libpaths += $(BOOST_ROOT)/lib
+
macros = SA_POP_HAS_ACE ACE_AS_STATIC_LIBS