diff options
author | jkinnebrew <jkinnebrew@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-12-18 01:03:07 +0000 |
---|---|---|
committer | jkinnebrew <jkinnebrew@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-12-18 01:03:07 +0000 |
commit | f73891659a9df43681a1fcff9fac22e2e9eb1347 (patch) | |
tree | 6310cddf968df8b8dfe0b6ee8184863a27c36b13 | |
parent | e5143f6445021c57a72751c126a9829612c4cd0c (diff) | |
download | ATCD-f73891659a9df43681a1fcff9fac22e2e9eb1347.tar.gz |
Fri Dec 18 01:00:33 UTC 2009 John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
18 files changed, 1083 insertions, 803 deletions
diff --git a/SA_POP/ChangeLog b/SA_POP/ChangeLog index 4c4f7531860..32e7713993b 100644 --- a/SA_POP/ChangeLog +++ b/SA_POP/ChangeLog @@ -1,3 +1,38 @@ +Fri Dec 18 01:00:33 UTC 2009 John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + + * SA_Builder.h: + * SA_Builder.cpp: + + Updated initialization of SA_Builder so overridden init() + method will work correctly. + + + * SAPOP_Exp_EU.mwc: + * experiments/EU_Performance: + * experiments/EU_Performance/Exp_Core: + * experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h: + * experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp: + * experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.h: + * experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.cpp: + * experiments/EU_Performance/SAPOP_Exp_EU.cpp: + * experiments/EU_Performance/SAPOP_Exp_EU.mpc: + * experiments/EU_Performance/UserInput.h: + * experiments/EU_Performance/UserInput.cpp: + * experiments/EU_Performance/readme.txt: + + Added EU performance experiment skeleton. + + + + * experiments/EU_Test: + * experiments/EU_Test/EU_Test.mpc: + * experiments/EU_Test/EU_Test.cpp: + * experiments/EU_Test/Histogram.h: + * experiments/EU_Test/RandomGenerator.h: + * experiments/EU_Test/RandomGenerator.cpp: + + Removed these files (old EU experiment skeleton). + Fri Dec 11 23:54:51 UTC 2009 Ben Podgursky <bpodgursky@gmail.com> * Planner.cpp: @@ -5,7 +40,7 @@ Fri Dec 11 23:54:51 UTC 2009 Ben Podgursky <bpodgursky@gmail.com> * SANet/SANet.h: * SANet/SANet.cpp: - Fixed (hopefully) plan EU calculations + Fixed (hopefully) plan EU calculations Fri Dec 11 05:37:26 UTC 2009 Ben Podgursky <bpodgursky@gmail.com> diff --git a/SA_POP/SAPOP_Exp_EU.mwc b/SA_POP/SAPOP_Exp_EU.mwc new file mode 100644 index 00000000000..de718d6c1ed --- /dev/null +++ b/SA_POP/SAPOP_Exp_EU.mwc @@ -0,0 +1,5 @@ +workspace { + cmdline += -include $SAPOP_ROOT/MPC/config + Standalone/XML_Utils/XML/XML.mpc + experiments/EU_Performance/SAPOP_Exp_EU.mpc +} diff --git a/SA_POP/SA_Builder.cpp b/SA_POP/SA_Builder.cpp index e02fda91ebe..a4623ffb702 100644 --- a/SA_POP/SA_Builder.cpp +++ b/SA_POP/SA_Builder.cpp @@ -37,9 +37,9 @@ impl_choice_ (0), plan_strat_ (0), sched_strat_ (0), working_plan_ (0), -task_map_ (0) +task_map_ (0), +is_init_ (false) { - this->init (); }; // Destructor. @@ -50,9 +50,12 @@ SA_Builder::~SA_Builder (void) }; // Reset for building a new set of SA-POP objects. +// WARNING: Assumes that planner has been handed off and will be +// deleted by someone else. void SA_Builder::reset (void) { // Reset planning object pointers to null. + this->is_init_ = false; this->planner_ = 0; this->sanet_ = 0; this->cond_choice_ = 0; @@ -70,6 +73,8 @@ void SA_Builder::reset (void) // Get Planner object. Planner *SA_Builder::get_planner (void) { + if (!this->is_init_) + this->init (); return this->planner_; }; @@ -77,6 +82,8 @@ Planner *SA_Builder::get_planner (void) void SA_Builder::add_task (TaskID id, double prior_prob, std::string name) { + if (!this->is_init_) + this->init (); this->sanet_->add_task (id, name, 1, 0, prior_prob); }; @@ -84,6 +91,8 @@ std::string name) void SA_Builder::add_cond (CondID id, Utility utility, double init_prob_true, std::string name, CondKind cond_kind) { + if (!this->is_init_) + this->init (); this->sanet_->add_cond (id, name, 1, init_prob_true, 1.0 - init_prob_true, utility, cond_kind); }; @@ -92,6 +101,8 @@ double init_prob_true, std::string name, CondKind cond_kind) void SA_Builder::set_precond (CondID cond_id, TaskID task_id, PortID port, double true_prob, double false_prob) { + if (!this->is_init_) + this->init (); this->sanet_->add_precond_link (cond_id, task_id, true_prob, false_prob, port); }; @@ -100,18 +111,24 @@ PortID port, double true_prob, double false_prob) void SA_Builder::set_effect (TaskID task_id, CondID cond_id, PortID port, double weight) { + if (!this->is_init_) + this->init (); this->sanet_->add_effect_link (task_id, cond_id, weight, port); }; // Add a resource. void SA_Builder::add_resource (Resource resource) { + if (!this->is_init_) + this->init (); this->task_map_->add_resource (resource); }; // Add an implementation. void SA_Builder::add_task_impl (TaskImpl *task_impl) { + if (!this->is_init_) + this->init (); this->task_map_->add_task_impl (task_impl); }; @@ -119,6 +136,8 @@ void SA_Builder::add_task_impl (TaskImpl *task_impl) void SA_Builder::assoc_task_with_impl (TaskID task_id, TaskImplID task_impl_id, TimeValue duration) { + if (!this->is_init_) + this->init (); this->task_map_->assoc_task_with_impl (task_id, task_impl_id, duration); }; @@ -126,6 +145,8 @@ void SA_Builder::assoc_task_with_impl (TaskID task_id, TaskImplID task_impl_id, void SA_Builder::assoc_impl_with_resource (TaskImplID impl_id, ResourceID resource_id, ResourceValue resource_usage) { + if (!this->is_init_) + this->init (); this->task_map_->assoc_impl_with_resource (impl_id, resource_id, resource_usage); }; @@ -133,6 +154,9 @@ ResourceID resource_id, ResourceValue resource_usage) // Create SA-POP objects. void SA_Builder::init (void) { + // Set init flag. + this->is_init_ = true; + // Create objects. this->planner_ = new Planner (); this->sanet_ = new SANet::Network (); diff --git a/SA_POP/SA_Builder.h b/SA_POP/SA_Builder.h index 59d769deb7e..ba252acc831 100644 --- a/SA_POP/SA_Builder.h +++ b/SA_POP/SA_Builder.h @@ -51,6 +51,10 @@ namespace SA_POP { virtual ~SA_Builder (void); /// Reset for building a new set of SA-POP objects. + /** + * WARNING: Assumes that planner has been handed off and will be + * deleted by someone else. + */ virtual void reset (void); /// Get Planner object. @@ -170,6 +174,9 @@ namespace SA_POP { ResourceID resource_id, ResourceValue resource_usage); protected: + /// Is the builder initialized? + bool is_init_; + /// Planner object to centralize/mediate planning. Planner *planner_; diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp new file mode 100644 index 00000000000..70adb1b7377 --- /dev/null +++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp @@ -0,0 +1,86 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file Exp_EU_Builder.cpp + * + * This file contains the implementation of the Exp_EU_Builder concrete class, + * which implements a Builder creating SA_Planner and associated + * objects for planning with spreading activation networks and scheduling + * with the "roadblock" scheduler (Exp_EU_SchedStrategy). + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + + +#include "SA_POP_Types.h" + +//#include "SA_Builder.h" +#include "Exp_EU_Builder.h" + +#include "Planner.h" +#include "SANet/SANet.h" +#include "SA_PlanHeuristics.h" +#include "SA_PlanStrategy.h" + +//#include "SA_SchedStrategy.h" +#include "Exp_EU_SchedStrategy.h" + +#include "SA_WorkingPlan.h" +#include "TaskMap.h" + +using namespace SA_POP; + +// Constructor. +Exp_EU_Builder::Exp_EU_Builder (void) +{ + // Nothing to do. +}; + +// Destructor. +Exp_EU_Builder::~Exp_EU_Builder (void) +{ + // Nothing to do because client deletes Planner and Planner + // handles deletion of the rest of the objects. +}; + +// Create SA-POP objects. +void Exp_EU_Builder::init (void) +{ + // Set init flag. + this->is_init_ = true; + + // Create objects. + this->planner_ = new Planner (); + this->sanet_ = new SANet::Network (); + this->cond_choice_ = new SA_CondStrategy (this->planner_); + this->task_choice_ = new SA_TaskStrategy (this->planner_); + this->impl_choice_ = new SA_ImplStrategy (this->planner_); + this->plan_strat_ = new SA_PlanStrategy (this->planner_, + this->cond_choice_, this->task_choice_, this->impl_choice_); + this->sched_strat_ = new Exp_EU_SchedStrategy (this->planner_); + this->working_plan_ = new SA_WorkingPlan (this->planner_); + this->task_map_ = new TaskMap (); + + // Provide PlanCommand prototypes to objects. + this->plan_strat_->set_commands ( + this->working_plan_->get_AddTaskCmd (), + this->working_plan_->get_AssocTaskImplCmd (), + this->working_plan_->get_ResolveCLThreatCmd()); + this->sched_strat_->set_commands ( + this->working_plan_->get_ResolveSchedOrderCmd (), + this->working_plan_->get_AdjustMinTimesCmd (), + this->working_plan_->get_AdjustMaxTimesCmd ()); + this->working_plan_->set_commands ( + this->plan_strat_->get_AddOpenThreatsCmd ()); + + // Provide planning objects to Planner. + this->planner_->set_objects ( + this->sanet_, + this->plan_strat_, + this->sched_strat_, + this->working_plan_, + this->task_map_); +}; diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h new file mode 100644 index 00000000000..dd5abd51391 --- /dev/null +++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h @@ -0,0 +1,66 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file Exp_EU_Builder.h + * + * This file contains the definition of the Exp_EU_Builder concrete class, + * which implements a Builder creating SA_Planner and associated + * objects for planning with spreading activation networks and scheduling + * with the "roadblock" scheduler (Exp_EU_SchedStrategy). + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SA_POP_EXP_EU_BUILDER_H_ +#define SA_POP_EXP_EU_BUILDER_H_ + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "SA_POP_Types.h" + +//#include "Builder.h" +#include "SA_Builder.h" + +#include "Planner.h" +#include "SANet/SANet.h" +#include "SA_PlanHeuristics.h" +#include "SA_PlanStrategy.h" + +//#include "SA_SchedStrategy.h" +#include "Exp_EU_SchedStrategy.h" + +#include "SA_WorkingPlan.h" +#include "TaskMap.h" + +//#include "SA_Builder_Export.h" + +namespace SA_POP { + + /** + * @class Exp_EU_Builder + * + * @brief Builder concrete class for creating SA_Planner and + * associated objects for planning with spreading activation networks + * and scheduling with the "roadblock" scheduler (Exp_EU_SchedStrategy). + */ + class Exp_EU_Builder : public SA_Builder { + public: + /// Constructor. + Exp_EU_Builder (void); + + /// Destructor. + virtual ~Exp_EU_Builder (void); + + protected: + /// Create SA-POP objects. + virtual void init (void); + }; + +}; /* SA_POP namespace */ + +#endif /* SA_POP_EXP_EU_BUILDER_H_ */ diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.cpp b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.cpp new file mode 100644 index 00000000000..ed166b95314 --- /dev/null +++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.cpp @@ -0,0 +1,284 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file Exp_EU_SchedStrategy.cpp + * + * This file contains the Exp_EU_SchedStrategy concrete class implementation, which + * implements a SchedStrategy for "roadblock" scheduling that only updates the + * precedence graph without any other scheduling and which can randomly choose a + * "roadblock" of a set of tasks in the working plan. It considers any working + * plan with the "roadblock" set of tasks to be unschedulable and any other + * working plan to be schedulable. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#include "SA_POP_Types.h" + +//#include "SA_SchedStrategy.h" +#include "Exp_EU_SchedStrategy.h" + +#include "SA_WorkingPlan.h" +#include "Planner.h" +#include <list> +#include <set> +#include <fstream> +#include <algorithm> +#include <vector> +using namespace SA_POP; + +// Constructor. +Exp_EU_SchedStrategy::Exp_EU_SchedStrategy (SA_POP::Planner *planner) +: SA_SchedStrategy (planner) +{ + // Nothing to do. +}; + +// Destructor. +Exp_EU_SchedStrategy::~Exp_EU_SchedStrategy (void) +{ + // Nothing to do. +}; + + +// Recursively satisfy all scheduling constraints (and continue +// satisfaction of open conditions by recursive call back to planning). +bool Exp_EU_SchedStrategy::satisfy_sched (TaskInstID task_inst) +{ + + + + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****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 this->planner_->recurse_plan (); + // Adjust schedule. + double THRESHOLD_CRIT = 0.8; + // Get the current command id to backtrack to. + CommandID cur_cmd_id = this->planner_->cur_command_id(); + this->cur_seq_num_=1; + + SA_POP_DEBUG (SA_POP_DEBUG_MINIMAL, "NO SCHEDULING with ROADBLOCK SCHEDULER"); + // Don't do any propagation for roadblock scheduler. +/* + // Do the energy propogation for this task instance + // This function automatically does this for the task instances before and after it. + if(!this->energy_prop(task_inst)) + { + + + this->planner_->undo_through(cur_cmd_id); + return false; + } + + // Do the balance propogation related to time windows for this task instance + // and those unranked with respect to it + if(!this->time_balance_prop(task_inst)) + { + this->planner_->undo_through(cur_cmd_id); + return false; + } + const TaskInstSet *unranked = this->planner_->get_prec_insts(task_inst,UNRANKED); + for(TaskInstSet::const_iterator iter = unranked->begin();iter!=unranked->end();iter++) + { + if(!this->time_balance_prop(*iter)) + { + this->planner_->undo_through(cur_cmd_id); + return false; + } + } + // Do the balance propogation related to precedence graph links for this task instance + // and those unranked with respect to it + // if(!this->prec_balance_prop(task_inst)) + // { + // this->planner_->undo_through(cur_cmd_id); + // return false; + // } + // unranked = this->planner_->get_prec_insts(task_inst,UNRANKED); + //for(TaskInstSet::const_iterator iter = unranked->begin();iter!=unranked->end();iter++) + //{ + // if(!this->prec_balance_prop(*iter)) + // { + // this->planner_->undo_through(cur_cmd_id); + // return false; + // } + //} + + // Recalculate all the levels + TaskInstSet all = this->planner_->get_all_insts(); + for(TaskInstSet::iterator iter=all.begin();iter!=all.end();iter++) + this->calculate_levels(*iter); + + // start the search + if(!search(THRESHOLD_CRIT)) + { + this->planner_->undo_through(cur_cmd_id); + return false; + } +*/ + + + if(!this->planner_->recurse_plan ()){ + this->planner_->undo_through(cur_cmd_id); + return false; + }else{ + return true; + } +}; + +// Satisfy fully instantiated plan. +bool Exp_EU_SchedStrategy::satisfy_full_sched () +{ + // Just use normal satisfy schedule for "roadblock" scheduler. + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****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 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****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + + // Don't do normal scheduling for "roadblock" scheduler. +/* + + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****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 true; + // Adjust schedule. + CommandID cur_cmd_id = this->planner_->cur_command_id(); + this->cur_seq_num_=1; + if(!search(0)) + { + this->planner_->undo_through(cur_cmd_id); + return false; + } + + SA_WorkingPlan* working_plan_tmp = (SA_WorkingPlan*)this->planner_->get_working_plan(); + + // working_plan_tmp->get_precedence_graph() + PrecedenceSet befores = (working_plan_tmp->get_precedence_graph().find(BEFORE)->second); + PrecedenceSet afters = (working_plan_tmp->get_precedence_graph().find(AFTER)->second); + PrecedenceSet simuls = (working_plan_tmp->get_precedence_graph().find(SIMUL)->second); + PrecedenceSet unrankeds = (working_plan_tmp->get_precedence_graph().find(UNRANKED)->second); + + //double current_execution_time = 0 + //vector currently executing actions + + + std::vector<TaskInstEndTimeSet> executing_tasks; + + double current_execution_time = 0; + + int total_tasks = befores.size(); + int completed_tasks = 0; + + while(completed_tasks < total_tasks){ + + for(PrecedenceSet::iterator it = befores.begin(); it != befores.end();){ + + PrecedenceSet::iterator prev_it = it++; + if((befores.find(prev_it->first))->second.empty()){ + + TaskInstEndTimeSet new_execute; + new_execute.inst = prev_it->first; + + + if(prev_it->first == INIT_TASK_INST_ID){ + new_execute.end_time = current_execution_time + 0; + }else{ + new_execute.end_time = current_execution_time + this->planner_->get_impl(working_plan_tmp->get_impl_id(prev_it->first)) + ->get_duration(); + } + + executing_tasks.push_back(new_execute); + befores.erase(prev_it); + } + } + + std::sort(executing_tasks.begin(), executing_tasks.end()); + + TaskInstEndTimeSet next_done = *executing_tasks.begin(); + current_execution_time = next_done.end_time; + + std::list<TaskInstEndTimeSet> to_remove; + + for(std::vector<TaskInstEndTimeSet>::iterator it3 = executing_tasks.begin(); + it3 != executing_tasks.end();){ + + if(it3->end_time != current_execution_time){ + break; + } + std::vector<TaskInstEndTimeSet>::iterator prev_it = it3++; + + std::cout<<"Task "<<prev_it->inst<<" finishes at time "<<prev_it->end_time<<std::endl; + completed_tasks++; + + for(PrecedenceSet::iterator it2 = befores.begin(); it2 != befores.end(); it2++){ + it2->second.erase(prev_it->inst); + } + befores.erase(prev_it->inst); + to_remove.push_front(*prev_it); + // executing_tasks.erase(prev_it); + } + + for( std::list<TaskInstEndTimeSet>::iterator it3 = to_remove.begin(); it3 != to_remove.end(); it3++){ + std::vector<TaskInstEndTimeSet>::iterator it4; + for(it4 = executing_tasks.begin(); it4 != executing_tasks.end(); it4++){ + if(it4->inst == it3->inst){ + break; + } + } + executing_tasks.erase(it4); + } + } + + //while #actions finished != total actions + //find all actions with no more befores + //add to currently executing actions sorted by current_time + their duration + //take action(s if there are multiple that end at the same time) off currently executing actions + // + //remove them from the befores of all other actions + //remove them from befores + //current execution time = when they finish +*/ + + + + + + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + // DON'T KNOW WHO'S CODE THIS IS OR WHY IT WAS COMMENTED OUT... + // PLEASE REMOVE CODE OR ADD COMMENTS TO EXPLAIN. + //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + /* + std::list<TaskInstID> execute_this_time; + + int time = 0; + while(!befores.empty()){ + + execute_this_time.clear(); + + for(PrecedenceSet::iterator it = befores.begin(); it != befores.end();){ + + PrecedenceSet::iterator prev_it = it++; + + if((befores.find(prev_it->first))->second.empty()){ + + execute_this_time.push_front(prev_it->first); + + befores.erase(prev_it); + } + } + + + for(std::list<TaskInstID>::iterator it = execute_this_time.begin(); it != execute_this_time.end(); it++){ + + std::cout<<"Task "<<(*it)<<" can execute at time "<<time<<std::endl; + + for(PrecedenceSet::iterator it2 = befores.begin(); it2 != befores.end(); it2++){ + it2->second.erase(*it); + } + } + time++; + } + */ + + return true; +}; + diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.h b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.h new file mode 100644 index 00000000000..8eab68394b1 --- /dev/null +++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_SchedStrategy.h @@ -0,0 +1,76 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file Exp_EU_SchedStrategy.h + * + * This file contains the Exp_EU_SchedStrategy concrete class definition, which + * implements a SchedStrategy for "roadblock" scheduling that only updates the + * precedence graph without any other scheduling and which can randomly choose a + * "roadblock" of a set of tasks in the working plan. It considers any working + * plan with the "roadblock" set of tasks to be unschedulable and any other + * working plan to be schedulable. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SA_POP_EXP_EU_SCHED_STRATEGY_H_ +#define SA_POP_EXP_EU_SCHED_STRATEGY_H_ + +#include<map> +#include "SA_POP_Types.h" + +//#include "SchedStrategy.h" +#include "SA_SchedStrategy.h" + +#include "PlanCommands.h" + +namespace SA_POP { + + /** + * @class Exp_EU_SchedStrategy + * + * @brief Concrete class of SchedStrategy for "roadblock" scheduling + * that only updates precedence graph without any other + * scheduling and which can randomly choose a "roadblock" + * of a set of tasks in the working plan. It considers + * any working plan with the "roadblock" set of tasks to be + * unschedulable and any other working plan to be schedulable. + */ + class Exp_EU_SchedStrategy : public SA_SchedStrategy { + public: + /// Constructor. + /** + * @param planner Planner object to use. + */ + Exp_EU_SchedStrategy (SA_POP::Planner *planner); + + /// Destructor. + virtual ~Exp_EU_SchedStrategy (void); + + /// Recursively satisfy all scheduling constraints (and continue + /// satisfaction of open conditions by recursive call back to planning). + /** + * @param task_inst Current task instance being tried in the plan. + * + * @return True if fully satisfied plan found, false otherwise. + */ + virtual bool satisfy_sched (TaskInstID task_inst); + + /// Satisfy fully instantiated plan. + /** + * @param task_inst Current task instance being tried in the plan. + * + * @return True if fully satisfied plan found, false otherwise. + */ + virtual bool satisfy_full_sched (); + + protected: + + }; + +}; /* SA_POP namespace */ + +#endif /* SA_POP_EXP_EU_SCHED_STRATEGY_H_ */ diff --git a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp new file mode 100644 index 00000000000..257e989d3d0 --- /dev/null +++ b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp @@ -0,0 +1,309 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file SA_POP_Demo.cpp + * + * This file contains the main() function for the SA-POP demo. + * 11/19/08 Added the ability for multiple goals - dmack + * 11/25/08 Added the use of the LogGraph Out Adapter for Visual purposes - dmack + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + * @author Daniel L.C. Mack <daniel.l.mack@vanderbilt.edu> + */ +//============================================================================= + +#define _CRTDBG_MAP_ALLOC +#include <stdlib.h> +#include <crtdbg.h> + +#include <iostream> +#include <fstream> +#include "SA_POP_Types.h" +#include "Exp_Core/Exp_EU_Builder.h" +#include "UserInput.h" +#include "TaskMapFileIn.h" +#include "SANet/SANetFileIn.h" +#include "LogScreenOut.h" +#include "LogGraphOut.h" +//#include "SA_POP_Utils.h" + +#include <vector> +#include <map> + +//Commands to run in the thread +unsigned long WINAPI ThirdThread(PVOID pvParam) +{ + system("dot -Tgif cond.dot -o conds.gif"); + //system("conds.gif"); + return 0; +} + +//for displaying conditions +void displayConds(SA_POP::Planner *plans, std::vector<SANet::CondID> checks, std::map<SANet::CondID, double> *cMap) +{ + + std::ofstream cfile; + cfile.open("Cond.dot"); + //Produce Graph + std::cout << "Create Digraph" << std::endl; + cfile << "strict digraph conds {\n"; + for(size_t node = 0; node< checks.size(); node++) + { + std::cout << "Next Cond" << std::endl; + + if(plans->get_cond_val(checks[node]) == 1) + { + std::map<SANet::CondID, double>::iterator cmp = cMap->find(checks[node]); + if(cmp != cMap->end()) + { + (*cmp).second = 1; + } + cfile << "\t" << "\"" << plans->get_cond_name(checks[node]) << " " << checks[node] << "\" [shape = box, color = green];\n"; + } + else + { + std::map<SANet::CondID, double>::iterator cmp = cMap->find(checks[node]); + if(cmp != cMap->end()) + { + (*cmp).second = 0; + } + cfile << "\t" << "\"" << plans->get_cond_name(checks[node]) << " " << checks[node] << "\" [shape = box, color = red];\n"; + } + std::cout << "Ready for Next Cond" << std::endl; + + } + cfile << "}\n"; + + cfile.close(); + + unsigned long dwThreadId; + // Create a new thread. + char *imageName = "conds.gif"; + HANDLE tThread = CreateThread(NULL, 0, ThirdThread, (PVOID) imageName, + 0, &dwThreadId); + CloseHandle(tThread); + +} + +int main (int argc, char* argv[]) +{ + SA_POP::Exp_EU_Builder builder; + SANet::SANetFileIn sanet_in; + SA_POP::TaskMapFileIn tm_in; + std::string sanet_filename = ""; + std::string tm_filename = ""; + std::vector<SA_POP::CondID> * kconds = new std::vector<SA_POP::CondID>; + std::vector<SANet::CondID> toCheck; + std::map<SANet::CondID, double> condMap; + + // Get filenames from user. + std::cout << "Task Network file: "; +// sanet_filename = "../../examples/simple/simple.san.xml"; + std::cin >> sanet_filename; + + std::cout << "Task Map file: "; +// tm_filename = "../../examples/simple/simple.tm.xml"; + std::cin >> tm_filename; + + SA_POP::Goal goal; + goal.goal_id = "UserSpecifiedGoal ID"; + goal.name = "User specified goal"; + goal.abs_times.clear (); + goal.rel_times.clear (); + goal.goal_conds.clear (); + goal.start_window = std::make_pair (0, 0); + + // Get goal(s). + int goal_num = 0; + std::cout << "Number of goals to find: "; + std::cin >> goal_num; + for(int g = 0; g < goal_num; g++) + { + SA_POP::CondID goal_id; + SA_POP::Utility goal_util; + std::cout << "Goal condition ID: "; + std::cin >> goal_id; + std::cout << "Goal utility: "; + std::cin >> goal_util; + goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); + } + + + try { + + + sanet_in.build_net (sanet_filename, &builder); + tm_in.build_task_map (tm_filename, &builder); + + + } + + catch (std::string e) { + std::cerr << "ERROR while building task network and task map from files:"; + std::cerr << std::endl; + std::cerr << e; + } catch (...) { + std::cerr << "UNKNOWN ERROR while building task network and task map from files." << std::endl; + } + + + SA_POP::Planner *planner = 0; + SA_POP::LogGraphOut graph_out (std::cout, false); + + + + // try { + planner = builder.get_planner (); + + //Set any probabilities not listed in the XML + int knownconds = 0; + + std::cout << "How many conditions do we know? "; + std::cin >> knownconds; + + for(int k = 0; k < knownconds; k++) + { + int cid = 0; + std::cout << "Enter the Condition ID you know:"; + std::cin >> cid; + SA_POP::CondID ccid = SA_POP::CondID(cid); + SANet::Probability newprob = SANet::Probability(1); + planner->update_cond_val(ccid, 1); + kconds->push_back(ccid); + + } + + int track = 0; + //Conditions to be potentially displayed + std::cout << "How many conditions to track? "; + std::cin >> 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)); + toCheck.push_back(ccid); + + } + + //Configure the OutAdapters to use + SA_POP::LogScreenOut screen_out (std::cout); + graph_out.addTracking(toCheck); + 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 (15, goal); + planner->calculate_plan_utility(15); + + //} + /* + catch (std::string e) { + std::cerr << "ERROR while planning:" << std::endl; + std::cerr << e; + delete planner; + } catch (...) { + std::cerr << "UNKNOWN ERROR while planning." << std::endl; + delete planner; + } + */ + + bool stop = false; + while(!stop) + { + + std::string step; + std::cout << "Would you like to advance to the next time step? (Y or N): "; + displayConds(planner, toCheck, &condMap); + std::cin >> step; + if(step == "Y" || step == "y") + { + graph_out.moveStep(); + planner->plan (100, goal); + } + else + { + std::string eff; + std::cout << "Would you like to negate an effect, change an external condition, or stop? (E or C or S): "; + std::cin >>eff; + if(eff == "E" || eff == "e") + { + 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; + /* + SA_POP::SA_Builder rebuilder; + sanet_in.build_net (sanet_filename, &rebuilder); + tm_in.build_task_map (tm_filename, &rebuilder); + planner = rebuilder.get_planner (); + planner->add_out_adapter (&graph_out); + */ + 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->plan(100, goal); + planner->replan(100, goal); + + } + else if(eff == "C" || eff == "c") + { + 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; + } + /* + SA_POP::SA_Builder rebuilder; + sanet_in.build_net (sanet_filename, &rebuilder); + tm_in.build_task_map (tm_filename, &rebuilder); + planner = rebuilder.get_planner (); + planner->add_out_adapter (&graph_out); +*/ + for(std::map<SANet::CondID, double>::iterator cIter = condMap.begin(); cIter != condMap.end(); cIter++) + { + planner->update_cond_val((*cIter).first, (*cIter).second); + } + //planner->plan (100, goal); + planner->replan(100, goal); + + } + else + { + stop = true; + } + } + } + + delete planner; + +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + std::cout << "Enter any character to end program: "; + char temp_; + std::cin>>temp_; +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + + + _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 new file mode 100644 index 00000000000..5ae4ee81b6e --- /dev/null +++ b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc @@ -0,0 +1,112 @@ +project(SAPOP_Exp_EU) : xerces, aceexe, sapop_xml { + exename = SAPOP_Exp_EU + + includes += $(SAPOP_ROOT) + + macros = SA_POP_HAS_ACE ACE_AS_STATIC_LIBS + + + Source_Files { + SAPOP_Exp_EU.cpp + UserInput.cpp + } + + Inline_Files { + } + + Header_Files { + UserInput.h + } + + Documentation_Files { + readme.txt + } + + + + + Header_Files { + Exp_Core/Exp_EU_Builder.h + Exp_Core/Exp_EU_SchedStrategy.h + + + $(SAPOP_ROOT)/SA_POP_Types.h + $(SAPOP_ROOT)/SA_POP_Exceptions.h + + $(SAPOP_ROOT)/SA_POP_Utils.h + + $(SAPOP_ROOT)/Builder.h + $(SAPOP_ROOT)/SA_Builder.h + + $(SAPOP_ROOT)/Planner.h + + $(SAPOP_ROOT)/TaskMap.h + $(SAPOP_ROOT)/TaskImpl.h + + $(SAPOP_ROOT)/WorkingPlan.h + $(SAPOP_ROOT)/SA_WorkingPlan.h + + $(SAPOP_ROOT)/SchedStrategy.h + $(SAPOP_ROOT)/SA_SchedStrategy.h + + $(SAPOP_ROOT)/PlanStrategy.h + $(SAPOP_ROOT)/SA_PlanStrategy.h + $(SAPOP_ROOT)/PlanHeuristics.h + $(SAPOP_ROOT)/SA_PlanHeuristics.h + $(SAPOP_ROOT)/PlanCommands.h + $(SAPOP_ROOT)/SA_PlanCommands.h + + $(SAPOP_ROOT)/SANet/SANet_Types.h + $(SAPOP_ROOT)/SANet/SANet.h + $(SAPOP_ROOT)/SANet/SANode.h + $(SAPOP_ROOT)/SANet/SANet_Exceptions.h + + $(SAPOP_ROOT)/OutAdapter.h + $(SAPOP_ROOT)/LogScreenOut.h + $(SAPOP_ROOT)/LogFileOut.h + $(SAPOP_ROOT)/LogGraphOut.h + + $(SAPOP_ROOT)/SA_POP_XML_Typedefs.h + $(SAPOP_ROOT)/SANet/SANetFileIn.h + $(SAPOP_ROOT)/TaskMapFileIn.h + } + + Source_Files { + Exp_Core/Exp_EU_Builder.cpp + Exp_Core/Exp_EU_SchedStrategy.cpp + + + $(SAPOP_ROOT)/SA_POP_Exceptions.cpp + + $(SAPOP_ROOT)/SA_POP_Utils.cpp + + $(SAPOP_ROOT)/SA_Builder.cpp + $(SAPOP_ROOT)/Planner.cpp + + $(SAPOP_ROOT)/TaskMap.cpp + $(SAPOP_ROOT)/TaskImpl.cpp + + $(SAPOP_ROOT)/SA_WorkingPlan.cpp + + $(SAPOP_ROOT)/SA_SchedStrategy.cpp + + $(SAPOP_ROOT)/SA_PlanStrategy.cpp + $(SAPOP_ROOT)/SA_PlanHeuristics.cpp + $(SAPOP_ROOT)/SA_PlanCommands.cpp + + $(SAPOP_ROOT)/SANet/SANet.cpp + $(SAPOP_ROOT)/SANet/SANode.cpp + $(SAPOP_ROOT)/SANet/SANet_Exceptions.cpp + + $(SAPOP_ROOT)/LogScreenOut.cpp + $(SAPOP_ROOT)/LogFileOut.cpp + $(SAPOP_ROOT)/LogGraphOut.cpp + + $(SAPOP_ROOT)/SA_POP_XML_Typedefs.cpp + $(SAPOP_ROOT)/SANet/SANetFileIn.cpp + $(SAPOP_ROOT)/SANet/XML_SANet.cpp + $(SAPOP_ROOT)/TaskMapFileIn.cpp + $(SAPOP_ROOT)/XML_TaskMap.cpp + } + +} diff --git a/SA_POP/experiments/EU_Performance/UserInput.cpp b/SA_POP/experiments/EU_Performance/UserInput.cpp new file mode 100644 index 00000000000..a216b91cbff --- /dev/null +++ b/SA_POP/experiments/EU_Performance/UserInput.cpp @@ -0,0 +1,33 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file UserInput.cpp + * + * This file contains the UserInput class implementation for the input adapter + * that provides a user interface for testing SA-POP. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#include "SA_POP_Types.h" +#include "UserInput.h" +#include "Builder.h" +#include "Planner.h" + + +using namespace SA_POP; + +// Constructor. +UserInput::UserInput (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 +}; + +// Destructor. +UserInput::~UserInput (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 +}; diff --git a/SA_POP/experiments/EU_Performance/UserInput.h b/SA_POP/experiments/EU_Performance/UserInput.h new file mode 100644 index 00000000000..b1b2b52111c --- /dev/null +++ b/SA_POP/experiments/EU_Performance/UserInput.h @@ -0,0 +1,42 @@ +// -*- C++ -*- +// $Id$ + +//============================================================================= +/** + * @file UserInput.h + * + * This file contains the UserInput class definition for the input adapter + * that provides a user interface for testing SA-POP. + * + * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> + */ +//============================================================================= + +#ifndef SA_POP_USER_INPUT_H_ +#define SA_POP_USER_INPUT_H_ + +#include "SA_POP_Types.h" +#include "UserInput.h" +#include "Builder.h" +#include "Planner.h" + + +namespace SA_POP { + + /** + * @class UserInput + * + * @brief Input adapter that provides a user interface for testing SA-POP. + */ + class UserInput { + public: + /// Constructor. + UserInput (void); + + /// Destructor. + virtual ~UserInput (void); + }; + +}; /* SA_POP namespace */ + +#endif /* SA_POP_USER_INPUT_H_ */ diff --git a/SA_POP/experiments/EU_Performance/readme.txt b/SA_POP/experiments/EU_Performance/readme.txt new file mode 100644 index 00000000000..76ef177d5e2 --- /dev/null +++ b/SA_POP/experiments/EU_Performance/readme.txt @@ -0,0 +1 @@ +Run SAPOP_Exp_EU.exe to perform SA-POP Expected Utility performance experiment. diff --git a/SA_POP/experiments/EU_Test/EU_Test.cpp b/SA_POP/experiments/EU_Test/EU_Test.cpp deleted file mode 100644 index 2e4afef8a8a..00000000000 --- a/SA_POP/experiments/EU_Test/EU_Test.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// -*- C++ -*- -// $Id$ - -//============================================================================= -/** - * @file SA_POP_Demo.cpp - * - * This file contains the main() function for the SA-POP demo. - * - * @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> - */ -//============================================================================= - -#include <iostream> -#include "SA_POP_Types.h" -#include "SA_Builder.h" -#include "TaskMapFileIn.h" -#include "SANet/SANetFileIn.h" -#include "LogScreenOut.h" - - -int main (int argc, char* argv[]) -{ - SA_POP::SA_Builder builder; - SANet::SANetFileIn sanet_in; - SA_POP::TaskMapFileIn tm_in; - - // Get filenames from user. - std::cout << "Task Network file: "; - std::string sanet_filename = "../examples/SPACE.san.xml"; -// std::string sanet_filename = "examples/test_graph1.san.xml"; -// std::cin >> sanet_filename; - - std::cout << "Task Map file: "; - std::string tm_filename = "../examples/SPACE.tm.xml"; -// std::string tm_filename = "examples/test_graph.tm.xml"; -// std::cin >> tm_filename; - - SA_POP::Goal goal; - goal.goal_id = "UserSpecifiedGoal ID"; - goal.name = "User specified goal"; - goal.abs_times.clear (); - goal.rel_times.clear (); - goal.goal_conds.clear (); - goal.start_window = std::make_pair (0, 0); - - // Get goal. - SA_POP::CondID goal_id; - SA_POP::Utility goal_util; - std::cout << "Goal condition ID: "; - std::cin >> goal_id; - std::cout << "Goal utility: "; - std::cin >> goal_util; - goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); - - try { - sanet_in.build_net (sanet_filename, &builder); - tm_in.build_task_map (tm_filename, &builder); - } catch (std::string e) { - std::cerr << "ERROR while building task network and task map from files:"; - std::cerr << std::endl; - std::cerr << e; - } catch (...) { - std::cerr << "UNKNOWN ERROR while planning." << std::endl; - } - - - SA_POP::Planner *planner = 0; - - try { - planner = builder.get_planner (); - - SA_POP::LogScreenOut screen_out (std::cout); - planner->add_out_adapter (&screen_out); - - planner->plan (100, goal); - } catch (std::string e) { - std::cerr << "ERROR while planning:" << std::endl; - std::cerr << e; - delete planner; - } catch (...) { - std::cerr << "UNKNOWN ERROR while planning." << std::endl; - delete planner; - } - - delete planner; - -//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP - std::cout << "Enter any character to end program: "; - char temp_; - std::cin>>temp_; -//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****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 0; -} diff --git a/SA_POP/experiments/EU_Test/EU_Test.mpc b/SA_POP/experiments/EU_Test/EU_Test.mpc deleted file mode 100644 index 1dd6c368e60..00000000000 --- a/SA_POP/experiments/EU_Test/EU_Test.mpc +++ /dev/null @@ -1,28 +0,0 @@ -project(SA_POP_EU_Test) : xerces, aceexe { - exename = EU_Test - - after += SA_POP - - includes += $(SAPOP_ROOT) \ - $(SAPOP_ROOT)/XML_Utils - - libs += SA_POP - - dynamicflags = CIAO_XML_UTILS_BUILD_DLL - - macros = SA_POP_HAS_ACE - - Source_Files { - EU_Test.cpp - } - - Inline_Files { - } - - Header_Files { - } - - Documentation_Files { - readme.txt - } -} diff --git a/SA_POP/experiments/EU_Test/Histogram.h b/SA_POP/experiments/EU_Test/Histogram.h deleted file mode 100644 index 66672711d04..00000000000 --- a/SA_POP/experiments/EU_Test/Histogram.h +++ /dev/null @@ -1,389 +0,0 @@ -// Histogram.h: interface for the THistogram class. -// -////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_HISTOGRAM_H__DF74A789_2878_4CB0_BAA9_125272F0E7E1__INCLUDED_) -#define AFX_HISTOGRAM_H__DF74A789_2878_4CB0_BAA9_125272F0E7E1__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -#include <valarray> - -/*! \brief A histogram class - - This class computes the histogram of a vector. - -\par Template parameters - - - T type of input data (can be any: float, double, int, UINT, etc...) - - TOut type of output data: float or double. (default is double) - -\par Moments: - - The moments (average, standard deviation, skewness, etc.) are computed using -the algorithm of the Numerical recipies (see Numerical recipies in C, Chapter 14.1, pg 613). - -\par Example: - - This example shows the typical use of the class: -\code - // a vector containing the data - vector<float> vData; - // Creating histogram using float data and with 101 containers, - THistogram<float> histo(101); - // computing the histogram - histo.Compute(vData); -\endcode - -Once this is done, you can get a vector with the histogram or the normalized histogram (such that it's area is 1): -\code - // getting normalized histogram - vector<float> v=histo.GetNormalizedHistogram(); -\endcode - -\par Reference - - Equally spaced acsissa function integration (used in #GetArea): Numerical Recipies in C, Chapter 4.1, pg 130. - -\author Jonathan de Halleux, dehalleux@auto.ucl.ac.be, 2002 -*/ - -template<class T, class TOut = double> -class THistogram -{ -public: - //! \name Constructors - //@{ - /*! Default constructor - \param nCounters the number of histogram containers (default value is 10) - */ - THistogram(UINT nCounters = 10); - virtual ~THistogram() { Clear();}; - //@} - - //! \name Histogram computation, update - //@{ - /*! Computes histogram of vector v - \param v vector to compute histogram - \param bComputeMinMax set to true if min/max of v have to be used to get the histogram limits - - This function computes the histogram of v and stores it internally. - \sa Update, GetHistogram - */ - void Compute( const std::vector<T>& v, bool bComputeMinMax = true); - //! Update histogram with the vector v - void Update( const std::vector<T>& v); - //! Update histogram with t - void Update( const T& t); - //@} - - //! \name Resetting functions - //@{ - //! Resize the histogram. Warning this function clear the histogram. - void Resize( UINT nCounters ); - //! Clears the histogram - void Clear() { m_vCounters.clear();}; - //@} - - //! \name Setters - //@{ - /*! This function sets the minimum of the histogram spectrum. - The spectrum is not recomputed, use it with care - */ - void SetMinSpectrum( const T& tMin ) { m_tMin = tMin; ComputeStep();}; - /*! This function sets the minimum of the histogram spectrum. - The spectrum is not recomputed, use it with care - */ - void SetMaxSpectrum( const T& tMax ) { m_tMax = tMax; ComputeStep();}; - //@} - //! \name Getters - //@{ - //! return minimum of histogram spectrum - const T& GetMinSpectrum() const { return m_tMin;}; - //! return maximum of histogram spectrum - const T& GetMaxSpectrum() const { return m_tMax;}; - //! return step size of histogram containers - TOut GetStep() const { return m_dStep;}; - //! return number of points in histogram - UINT GetSum() const; - /*! \brief returns area under the histogram - - The Simpson rule is used to integrate the histogram. - */ - TOut GetArea() const; - - /*! \brief Computes the moments of the histogram - - \param vData dataset - \param fAve mean - \f[ \bar x = \frac{1}{N} \sum_{j=1}^N x_j\f] - \param fAdev mean absolute deviation - \f[ Adev(X) = \frac{1}{N} \sum_{j=1}^N | x_j - \bar x |\f] - \param fVar average deviation: - \f[ \mbox{Var}(X) = \frac{1}{N-1} \sum_{j=1}^N (x_j - \bar x)^2\f] - \param fSdev standard deviation: - \f[ \sigma(X) = \sqrt{Var(\bar x) }\f] - \param fSkew skewness - \f[ \mbox{Skew}(X) = \frac{1}{N}\sum_{j=1}^N \left[ \frac{x_j - \bar x}{\sigma}\right]^3\f] - \param fKurt kurtosis - \f[ \mbox{Kurt}(X) = \left\{ \frac{1}{N}\sum_{j=1}^N \left[ \frac{x_j - \bar x}{\sigma}\right]^4 \right\} - 3\f] - - */ - static void GetMoments(const std::vector<T>& vData, TOut& fAve, TOut& fAdev, TOut& fSdev, TOut& fVar, TOut& fSkew, TOut& fKurt); - - //! return number of containers - UINT GetSize() const { return m_vCounters.size();}; - //! returns i-th counter - UINT operator [] (UINT i) const { ASSERT( i < m_vCounters.size() ); return m_vCounters[i];}; - //! return the computed histogram - const std::vector<UINT>& GetHistogram() const { return m_vCounters;}; - //! return the computed histogram, in TOuts - std::vector<TOut> GetHistogramD() const; - /*! return the normalized computed histogram - - \return the histogram such that the area is equal to 1 - */ - std::vector<TOut> GetNormalizedHistogram() const; - //! returns left containers position - std::vector<TOut> GetLeftContainers() const; - //! returns center containers position - std::vector<TOut> GetCenterContainers() const; - //@} -protected: - //! Computes the step - void ComputeStep() { m_dStep = (TOut)(((TOut)(m_tMax-m_tMin)) / (m_vCounters.size()-1));}; - //! Data accumulators - std::vector<UINT> m_vCounters; - //! minimum of dataset - T m_tMin; - //! maximum of dataset - T m_tMax; - //! width of container - TOut m_dStep; -}; - -template<class T, class TOut> -THistogram<T,TOut>::THistogram<T,TOut>(UINT nCounters) -: m_vCounters(nCounters,0), m_tMin(0), m_tMax(0), m_dStep(0) -{ - -} - -template<class T, class TOut> -void THistogram<T,TOut>::Resize( UINT nCounters ) -{ - Clear(); - - m_vCounters.resize(nCounters,0); - - ComputeStep(); -} - -template<class T, class TOut> -void THistogram<T,TOut>::Compute( const std::vector<T>& v, bool bComputeMinMax) -{ - using namespace std; - UINT i; - int index; - - if (m_vCounters.empty()) - return; - - if (bComputeMinMax) - { - m_tMax = m_tMin = v[0]; - for (i=1;i<v.size();i++) - { - m_tMax = __max( m_tMax, v[i]); - m_tMin = __min( m_tMin, v[i]); - } - } - - ComputeStep(); - - for (i = 0;i < v.size() ; i++) - { - index=(int) floor( ((TOut)(v[i]-m_tMin))/m_dStep ) ; - - if (index >= m_vCounters.size() || index < 0) - return; - - m_vCounters[index]++; - } -} - -template<class T, class TOut> -void THistogram<T,TOut>::Update( const std::vector<T>& v) -{ - if (m_vCounters.empty()) - return; - - ComputeStep(); - - TOut uSize = m_vCounters.size(); - - int index; - for (UINT i = 0;i < uSize ; i++) - { - index = (int)floor(((TOut)(v[i]-m_tMin))/m_dStep); - - if (index >= m_vCounters.size() || index < 0) - return; - - m_vCounters[index]++; - } -} - -template<class T, class TOut> -void THistogram<T,TOut>::Update( const T& t) -{ - int index=(int) floor( ((TOut)(t-m_tMin))/m_dStep ) ; - - if (index >= m_vCounters.size() || index < 0) - return; - - m_vCounters[index]++; -}; - -template<class T, class TOut> -std::vector<TOut> THistogram<T,TOut>::GetHistogramD() const -{ - std::vector<TOut> v(m_vCounters.size()); - for (UINT i = 0;i<m_vCounters.size(); i++) - v[i]=(TOut)m_vCounters[i]; - - return v; -} - -template <class T, class TOut> -std::vector<TOut> THistogram<T,TOut>::GetLeftContainers() const -{ - std::vector<TOut> vX( m_vCounters.size()); - - for (UINT i = 0;i<m_vCounters.size(); i++) - vX[i]= m_tMin + i*m_dStep; - - return vX; -} - -template <class T, class TOut> -std::vector<TOut> THistogram<T,TOut>::GetCenterContainers() const -{ - std::vector<TOut> vX( m_vCounters.size()); - - for (UINT i = 0;i<m_vCounters.size(); i++) - vX[i]= m_tMin + (i+0.5)*m_dStep; - - return vX; -} - -template <class T, class TOut> -UINT THistogram<T,TOut>::GetSum() const -{ - UINT uSum = 0; - for (UINT i = 0;i<m_vCounters.size(); i++) - uSum+=m_vCounters[i]; - - return uSum; -} - -template <class T, class TOut> -TOut THistogram<T,TOut>::GetArea() const -{ - const size_t n=m_vCounters.size(); - TOut area=0; - - if (n>6) - { - area=3.0/8.0*(m_vCounters[0]+m_vCounters[n-1]) - +7.0/6.0*(m_vCounters[1]+m_vCounters[n-2]) - +23.0/24.0*(m_vCounters[2]+m_vCounters[n-3]); - for (UINT i=3;i<n-3;i++) - { - area+=m_vCounters[i]; - } - } - else if (n>4) - { - area=5.0/12.0*(m_vCounters[0]+m_vCounters[n-1]) - +13.0/12.0*(m_vCounters[1]+m_vCounters[n-2]); - for (UINT i=2;i<n-2;i++) - { - area+=m_vCounters[i]; - } - } - else if (n>1) - { - area=1/2.0*(m_vCounters[0]+m_vCounters[n-1]); - for (UINT i=1;i<n-1;i++) - { - area+=m_vCounters[i]; - } - } - else - area=0; - - return area*m_dStep; -} - -template <class T, class TOut> -std::vector<TOut> THistogram<T,TOut>::GetNormalizedHistogram() const -{ - std::vector<TOut> vNormCounters( m_vCounters.size()); - TOut dArea = (TOut)GetArea(); - - for (UINT i = 0;i<m_vCounters.size(); i++) - { - vNormCounters[i]= (TOut)m_vCounters[i]/dArea; - } - - return vNormCounters; -}; - -template <class T, class TOut> -void THistogram<T,TOut>::GetMoments(const std::vector<T>& vData, TOut& fAve, TOut& fAdev, TOut& fSdev, TOut& fVar, TOut& fSkew, TOut& fKurt) -{ - int j; - double ep=0.0,s,p; - const size_t n = vData.size(); - - if (n <= 1) - // nrerror("n must be at least 2 in moment"); - return; - - s=0.0; // First pass to get the mean. - for (j=0;j<n;j++) - s += vData[j]; - - fAve=s/(n); - fAdev=fVar=fSkew=fKurt=0.0; - /* Second pass to get the first (absolute), second, - third, and fourth moments of the - deviation from the mean. */ - - for (j=0;j<n;j++) - { - fAdev += fabs(s=vData[j]-(fAve)); - ep += s; - fVar += (p=s*s); - fSkew += (p *= s); - fKurt += (p *= s); - } - - - fAdev /= n; - fVar=(fVar-ep*ep/n)/(n-1); // Corrected two-pass formula. - fSdev=sqrt(fVar); // Put the pieces together according to the conventional definitions. - if (fVar) - { - fSkew /= (n*(fVar)*(fSdev)); - fKurt=(fKurt)/(n*(fVar)*(fVar))-3.0; - } - else - //nrerror("No skew/kurtosis when variance = 0 (in moment)"); - return; -} - -#endif // !defined(AFX_HISTOGRAM_H__DF74A789_2878_4CB0_BAA9_125272F0E7E1__INCLUDED_) diff --git a/SA_POP/experiments/EU_Test/RandomGenerator.cpp b/SA_POP/experiments/EU_Test/RandomGenerator.cpp deleted file mode 100644 index 39ffd9954ab..00000000000 --- a/SA_POP/experiments/EU_Test/RandomGenerator.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// RandomGenerator.cpp: implementation of the CRandomGenerator class. -// -////////////////////////////////////////////////////////////////////// - -#include "stdafx.h" -#include "HistogramDemo.h" -#include "RandomGenerator.h" - -#ifdef _DEBUG -#undef THIS_FILE -static char THIS_FILE[]=__FILE__; -#define new DEBUG_NEW -#endif - - - -unsigned long CRandomGenerator::jz; -unsigned long CRandomGenerator::jsr=123456789; - -long CRandomGenerator::hz; -unsigned long CRandomGenerator::iz; -unsigned long CRandomGenerator::kn[128]; -unsigned long CRandomGenerator::ke[256]; -float CRandomGenerator::wn[128]; -float CRandomGenerator::fn[128]; -float CRandomGenerator::we[256]; -float CRandomGenerator::fe[256]; - -CRandomGenerator::CRandomGenerator( unsigned long jsreed ) -{ - zigset(jsreed); -} - - -/* nfix() generates variates from the residue when rejection in RNOR occurs. */ -float CRandomGenerator::nfix(void) -{ - const float r = 3.442620f; /* The starting of the right tail */ - static float x, y; - for(;;) - { - x=hz*wn[iz]; - if(iz==0) - { /* iz==0, handle the base strip */ - do - { - x=-log(UNI())*0.2904764; - /* .2904764 is 1/r */ - y=-log(UNI()); - } while(y+y<x*x); - return (hz>0)? r+x : -r-x; - } - - - - /* iz>0, handle the wedges of other strips */ - if( fn[iz]+UNI()*(fn[iz-1]-fn[iz]) < exp(-.5*x*x) ) - return x; - /* start all over */ - hz=SHR3(); - iz=hz&127; - if(abs(hz)<kn[iz]) - return (hz*wn[iz]); - } - -} - - - -/* efix() generates variates from the residue when rejection in REXP occurs. */ - -float CRandomGenerator::efix(void) -{ - float x; - for(;;) - { - if(iz==0) - return (7.69711-log(UNI())); /* iz==0 */ - - x=jz*we[iz]; - if( fe[iz]+UNI()*(fe[iz-1]-fe[iz]) < exp(-x) ) - return (x); - - /* Start all over again */ - jz=SHR3(); - iz=(jz&255); - if(jz<ke[iz]) - return (jz*we[iz]); - } -} - - - -/*--------This procedure sets the seed and creates the tables------*/ -void CRandomGenerator::zigset(unsigned long jsrseed) -{ - const double m1 = 2147483648.0, m2 = 4294967296.; - - double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q; - double de=7.697117470131487, te=de, ve=3.949659822581572e-3; - int i; - jsr^=jsrseed; - - /* Set up tables for RNOR */ - q=vn/exp(-.5*dn*dn); - kn[0]=(dn/q)*m1; - kn[1]=0; - wn[0]=q/m1; - wn[127]=dn/m1; - fn[0]=1.; - fn[127]=exp(-.5*dn*dn); - for(i=126;i>=1;i--) - { - dn=sqrt(-2.*log(vn/dn+exp(-.5*dn*dn))); - kn[i+1]=(dn/tn)*m1; tn=dn; - fn[i]=exp(-.5*dn*dn); - wn[i]=dn/m1; - } - - /* Set up tables for REXP */ - q = ve/exp(-de); - ke[0]=(de/q) * m2; ke[1]=0; - we[0]=q/m2; we[255]=de/m2; - fe[0]=1.; fe[255]=exp(-de); - for(i=254;i>=1;i--) - { - de=-log(ve/de+exp(-de)); - ke[i+1]= (de/te)*m2; - te=de; - fe[i]=exp(-de); - we[i]=de/m2; - } -} diff --git a/SA_POP/experiments/EU_Test/RandomGenerator.h b/SA_POP/experiments/EU_Test/RandomGenerator.h deleted file mode 100644 index 2c8ddbc947d..00000000000 --- a/SA_POP/experiments/EU_Test/RandomGenerator.h +++ /dev/null @@ -1,155 +0,0 @@ -// RandomGenerator.h: interface for the CRandomGenerator class. -// -////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_RANDOMGENERATOR_H__AB45B41B_98D1_489A_8F0C_E0243C8F122E__INCLUDED_) -#define AFX_RANDOMGENERATOR_H__AB45B41B_98D1_489A_8F0C_E0243C8F122E__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - - -#include <math.h> -#include <time.h> -#include <vector> - - -/*! \brief Normalized and Exponential random number generator - -\par Normal distribution - - - RNOR in any expression will provide a standard normal variate with mean zero, variance 1. - - TNOR will provide the theoretical value - - The normal distribution is characterized by a probability density function - \f[ y=\frac{1}{\sigma \sqrt{2 \pi}}e^{-\frac{(x-\mu)^2}{2 \sigma^2}}\f] - -\par Exponential distribtion - - REXP in any expression will provide an exponential variate -with density - - TEXP will provide the theoretical value - - The exponential distribution is characterized by a probability density function - \f[ f(x) = \mu e^{\mu x} \f] - -\par Random generator initialization - - Before using #RNOR or #REXP in your application, construct a #CRandomGenerator -object. It will seed the generator, by default (unsigned long)time( NULL ) is used but you cand -give your own choice of seed >0. (If you do not invoke CRandomGenerator(...), you will get all zeros for RNOR and REXP.) - -\par Example: - -\code -// build an object somewhere, -// In CWinApp::InitInstance for example -CRandomGenerator randn; - -// anywhere, for normal distribution -CRandomGenerator::RNOR(); -// and for exponential distribution -CRandomGenerator::REXP(); -\endcode - -\par Reference - - For details on the methods #RNOR and #REXP, see Marsaglia and Tsang, "The ziggurat method -for generating random variables", Journ. Statistical Software. - -\author Jonathan de Halleux, dehalleux@auto.ucl.ac.be, 2002 (putting it together) -*/ -class CRandomGenerator -{ -public: - - /*! Constructor - The consturctor seeds the generator with jsreed. - - By default, jsreed = (unsigned long)time( NULL ) - */ - CRandomGenerator( unsigned long jsreed = (unsigned long)time( NULL ) ); - virtual ~CRandomGenerator(){}; - - /*! \brief Standard normal variate with mean zero, variance 1, - - \param fAve mean, \f$\mu\f$, - \param fSdev standard deviation, \f$\sigma\f$ - - */ - static float RNOR( float fAve = 0, float fSdev = 1) - { - hz=SHR3(); - iz=hz&127; - float x=(abs(hz)<kn[iz])? hz*wn[iz] : nfix(); - return x*fSdev + fAve ; - }; - - /*! \brief Estimates the theoretical probability density function at x - - \param x position where to estimate probability - \param fAve mean, \f$\mu\f$, - \param fSdev standard deviation, \f$\sigma\f$ - - The normal distribution is characterized by a probability density function - \f[ f(x)=\frac{1}{\sigma \sqrt{2 \pi}}e^{-\frac{(x-\mu)^2}{2 \sigma^2}}\f] - */ - static double TNOR(double x, double fAve = 0, double fSdev = 1) - { - return exp ( -( x - fAve )*( x - fAve )/(2*fSdev*fSdev) ) /(fSdev*sqrt(2*PGL_PI)); - } - - /*! \brief exponential variate - - The exponential distribution is characterized by a probability density function - \f[ f(x) = \mu e^{-\mu x} \f] - where \f$\mu=1\f$. - */ - static float REXP() - { - jz=SHR3(); - iz=jz&255; - return (jz <ke[iz])? jz*we[iz] : efix(); - }; - - /*! \brief Estimates the theoretical probability density function at x - - \param x value where to estimate probability - \param fAve average of distribution, \f$\mu\f$, - - The exponential distribution is characterized by a probability density function - \f[ f(x) = \mu e^{-\mu x} \f] - */ - static double TEXP( double x, double fAve) - { - return exp(-fAve*x)/fAve; - } - -private: - - //! This procedure sets the seed and creates the tables - static void zigset(unsigned long jsrseed); - //! generates variates from the residue when rejection in RNOR occurs. - static float nfix(void); - //! Generates variates from the residue when rejection in REXP occurs. - static float efix(void); - -private: - - static unsigned long SHR3() { jz=jsr; jsr^=(jsr<<13); jsr^=(jsr>>17); jsr^=(jsr<<5); return jz+jsr;}; - static float UNI() { return .5 + (signed)SHR3() * .2328306e-9;}; - -private: - static unsigned long jz; - static unsigned long jsr; - static long hz; - static unsigned long iz; - static unsigned long kn[128]; - static unsigned long ke[256]; - static float wn[128]; - static float fn[128]; - static float we[256]; - static float fe[256]; -}; - -#endif // !defined(AFX_RANDOMGENERATOR_H__AB45B41B_98D1_489A_8F0C_E0243C8F122E__INCLUDED_) |