summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbpodgursky <bpodgursky@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2009-07-16 06:15:38 +0000
committerbpodgursky <bpodgursky@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2009-07-16 06:15:38 +0000
commitb3ada3ed4d9ea2c188466c5fdc5b51f2ac88dc52 (patch)
tree7e1ed87f1a07a8221651693bb1c02a1da33482fb
parente5a42ed6f8d9c1b08b633281b99aadb4b2071ee4 (diff)
downloadATCD-b3ada3ed4d9ea2c188466c5fdc5b51f2ac88dc52.tar.gz
Thu Jul 16 06:13:54 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
-rw-r--r--ChangeLog19
-rw-r--r--PlanCommands.h4
-rw-r--r--SA_POP_Types.h171
-rw-r--r--SA_PlanCommands.cpp11
-rw-r--r--SA_PlanCommands.h8
-rw-r--r--SA_PlanStrategy.cpp209
-rw-r--r--SA_PlanStrategy.h6
-rw-r--r--SA_SchedStrategy.cpp118
-rw-r--r--SA_WorkingPlan.cpp378
-rw-r--r--SA_WorkingPlan.h2
-rw-r--r--WorkingPlan.h2
11 files changed, 690 insertions, 238 deletions
diff --git a/ChangeLog b/ChangeLog
index 01b659e1857..f71bdca723d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Thu Jul 16 06:13:54 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
+
+ * PlanCommands.h:
+ * SA_POP_Types.h:
+ * SA_PlanCommands.h:
+ * SA_PlanCommands.cpp:
+ * SA_PlanStrategy.h:
+ * SA_PlanStrategy.cpp:
+ * SA_SchedStrategy.cpp:
+ * SA_WorkingPlan.h:
+ * SA_WorkingPlan.cpp:
+ * WorkingPlan.h:
+
+ Added basic loop detection; has a map of open conditions at time of resolving open threat.
+
Fri Jul 10 22:27:30 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
* SA_POP_Types.h:
@@ -7,8 +22,8 @@ Fri Jul 10 22:27:30 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
* SA_PlanStrategy.cpp:
* SA_WorkingPlan.cpp:
- Iterative deeping, fix on last_task_inst_ in planstrat, fixed precedence graph inconsistencies,
- fixed unranked bug in init prec insert, different task choice strategy.
+ Iterative deeping, fix on last_task_inst_ in planstrat, fixed precedence graph inconsistencies,
+ fixed unranked bug in init prec insert, different task choice strategy.
Wed Jul 8 22:17:52 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
diff --git a/PlanCommands.h b/PlanCommands.h
index 5f7cf6a894f..a9df9c3d584 100644
--- a/PlanCommands.h
+++ b/PlanCommands.h
@@ -196,6 +196,8 @@ namespace SA_POP {
virtual bool inst_exists (void) = 0;
virtual TaskInstSet get_satisfied_tasks(void) = 0;
+
+ virtual Condition get_condition(void) = 0;
};
/**
@@ -224,6 +226,8 @@ namespace SA_POP {
* @return ID of instance of this command.
*/
virtual TaskInstID get_task_inst (void) = 0;
+
+ virtual void set_satisfied_insts(TaskInstSet set)=0;
};
/**
diff --git a/SA_POP_Types.h b/SA_POP_Types.h
index ca25b37aac8..79f713b41fb 100644
--- a/SA_POP_Types.h
+++ b/SA_POP_Types.h
@@ -19,6 +19,7 @@
#include <list>
#include <map>
#include <sstream>
+#include <iostream>
#include "SA_POP_Utils.h"
@@ -27,15 +28,17 @@
#include "ace/Log_Priority.h"
#endif /* SA_POP_HAS_ACE */
+#define ANKET 1
#define SA_POP_DEBUG_NORMAL 5
+#define SPARTAN 9
#define SA_POP_DEBUG_HIGH 10
#if defined (SA_POP_HAS_ACE)
#define SA_POP_DEBUG(x,y) \
-if (x > 0) \
+if (x > 8) \
ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT("SA-POP: %s\n"), y));
#define SA_POP_DEBUG_STR(x,y) \
-if (x > 0) \
+if (x > 8) \
ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT("SA-POP: %s\n"), y.c_str ()));
#else /* SA_POP_HAS_ACE not defined */
#include <iostream>
@@ -137,7 +140,7 @@ namespace SA_POP {
/// Type of a task instance id.
/// (must be unique across all task instances).
- typedef int TaskInstID;
+ typedef long TaskInstID;
/// Goal task instance ID (for task instance placeholders in open goals).
const TaskInstID GOAL_TASK_INST_ID = -1;
@@ -249,9 +252,9 @@ namespace SA_POP {
int step;
int decision_pt;
int seq_num;
- bool operator== (CommandID &s) const { return (this->step == s.step && this->decision_pt == s.decision_pt && this->seq_num == s.seq_num); };
- bool operator!= (CommandID &s) const { return !(*this == s); };
- bool operator< (CommandID &s) const
+ bool operator== (const CommandID &s) const { return (this->step == s.step && this->decision_pt == s.decision_pt && this->seq_num == s.seq_num); };
+ bool operator!= (const CommandID &s) const { return !(*this == s); };
+ bool operator< (const CommandID &s) const
{
if (this->step == s.step) {
if (this->decision_pt == s.decision_pt)
@@ -510,6 +513,162 @@ namespace SA_POP {
/// for which it is a precondition. With new list functionality
typedef SA_POP::ListMultiMap<Condition, TaskInstID> OpenCondMap;
+
+
+ struct StoredCondition{
+
+ Condition satisfied_cond;
+ TaskID satisfying_task;
+
+ StoredCondition(){};
+
+ StoredCondition(Condition cond, TaskID task){
+ this->satisfied_cond = cond;
+ this->satisfying_task = task;
+ }
+
+ bool operator==(const StoredCondition & s)const{
+ return (satisfied_cond == s.satisfied_cond &&
+ satisfying_task == s.satisfying_task);
+ };
+
+ bool operator<(const StoredCondition & s) const{
+ if(this->satisfied_cond == s.satisfied_cond)
+ return this->satisfying_task < s.satisfying_task;
+ return this->satisfied_cond < s.satisfied_cond;
+ };
+ };
+
+ struct StoredConditionKey{
+
+ CommandID satisfying_cmd;
+ StoredCondition satisfy_set;
+
+ StoredConditionKey(Condition cond, TaskID task, CommandID cmd){
+ satisfying_cmd = cmd;
+ satisfy_set.satisfied_cond = cond;
+ satisfy_set.satisfying_task = task;
+ }
+
+ bool operator==(const StoredConditionKey & s)const{
+ return (this->satisfy_set == s.satisfy_set);
+ };
+
+ bool operator<(const StoredConditionKey & s) const {
+ // if(this->satisfying_cmd == s.satisfying_cmd)
+ return this->satisfy_set < s.satisfy_set;
+ // return this->satisfying_cmd < s.satisfying_cmd;
+ };
+
+ };
+
+
+
+ typedef std::set<StoredCondition> StoredConditionSet;
+ typedef std::multimap<StoredConditionKey, StoredConditionSet> StoredConditionMap;
+
+ struct StoredConditionEvaluator{
+ StoredConditionMap condition_map;
+
+ bool should_continue(CommandID cur_cmd, Condition satisfied_cond,
+ TaskID satisfying_task, OpenCondMap & open_conds, InstToTaskMap & task_insts){
+
+
+
+ StoredConditionKey stored_cond (satisfied_cond, satisfying_task, cur_cmd);
+
+ std::pair<StoredConditionMap::iterator,
+ StoredConditionMap::iterator>
+ range
+ = condition_map.equal_range(stored_cond);
+
+ bool should_continue = true;
+
+ if(range.first != range.second)
+ {
+ for(StoredConditionMap::iterator it = range.first; it != range.second; it++)
+ {
+ bool all_pairs_in_open_conds = true;
+
+ StoredConditionSet old_open_conds = it->second;
+
+ for(StoredConditionSet::iterator it = old_open_conds.begin();
+ it != old_open_conds.end(); it++)
+ {
+ if((*it).satisfying_task == -1)
+ bool breakkk = 0;
+
+
+ std::pair<OpenCondMap::iterator, OpenCondMap::iterator>
+ cond_map_range = open_conds.equal_range((*it).satisfied_cond);
+
+ bool found_no_equiv_in_open = true;
+
+ for(OpenCondMap::iterator it2 = cond_map_range.first; it2 != cond_map_range.second; it2++){
+
+ if((*it).satisfying_task == task_insts.find((*it2).second)->second){
+ found_no_equiv_in_open = false;
+ }
+ }
+
+ if(found_no_equiv_in_open){
+ all_pairs_in_open_conds = false;
+ break;
+ }
+ }
+
+ if(all_pairs_in_open_conds){
+ should_continue = false;
+ break;
+ }
+ }
+ }else{
+ should_continue = true;
+ }
+
+ if(should_continue)
+ {
+
+ StoredConditionSet current_open;
+ for(OpenCondMap::iterator it = open_conds.begin(); it != open_conds.end(); it++)
+ {
+ if(it->second == -1)
+ {
+ current_open.insert(StoredCondition(it->first, -1));
+ }else{
+ current_open.insert(StoredCondition(it->first, task_insts.find(it->second)->second));
+ }
+ }
+
+ StoredConditionKey this_choice(satisfied_cond, satisfying_task, cur_cmd);
+
+ this->condition_map.insert(
+ std::pair<StoredConditionKey, StoredConditionSet>(this_choice, current_open));
+ }
+
+ return should_continue;
+ }
+
+ void undo_binding(CommandID cur_cmd, Condition satisfied_cond, TaskID satisfying_task){
+ StoredConditionKey key(satisfied_cond, satisfying_task, cur_cmd);
+
+ std::pair<StoredConditionMap::iterator, StoredConditionMap::iterator> range
+ = condition_map.equal_range(key);
+
+ StoredConditionMap::iterator it;
+
+ for(it = range.first; it != range.second; it++){
+ if(it->first.satisfying_cmd == cur_cmd){
+ break;
+ }
+ }
+
+ condition_map.erase(it);
+
+ }
+ };
+
+
inline std::string to_string(int x)
{
std::ostringstream o;
diff --git a/SA_PlanCommands.cpp b/SA_PlanCommands.cpp
index 6f2b22764b4..41b3bbcb267 100644
--- a/SA_PlanCommands.cpp
+++ b/SA_PlanCommands.cpp
@@ -186,18 +186,11 @@ bool SA_AddTaskCmd::execute_next (void)
this->undo();
-
-
bool isInitial = false;
if (this->tasks_.empty())
return false;
- /*
- if(this->tasks_.front().task_id == 20 && this->tasks_.front){
- isInitial = true;
- }
- */
this->working_plan_->execute (this);
this->num_tries_++;
@@ -388,6 +381,10 @@ TaskInstID SA_AssocTaskImplCmd::get_task_inst (void)
return this->task_inst_;
};
+void SA_AssocTaskImplCmd::set_satisfied_insts(TaskInstSet set){
+ this->satisfied_insts = set;
+}
+
// Constructor.
SA_AddOpenCondsCmd::SA_AddOpenCondsCmd (SA_PlanStrategy *plan_strat)
diff --git a/SA_PlanCommands.h b/SA_PlanCommands.h
index 2bef292181b..b81e049ce77 100644
--- a/SA_PlanCommands.h
+++ b/SA_PlanCommands.h
@@ -250,6 +250,8 @@ namespace SA_POP {
virtual TaskInstSet get_satisfied_tasks(void);
+ virtual Condition get_condition(void){return cond_;};
+
protected:
/// WorkingPlan object that this command works on.
SA_WorkingPlan *working_plan_;
@@ -338,6 +340,8 @@ namespace SA_POP {
*/
virtual TaskInstID get_task_inst (void);
+ virtual void set_satisfied_insts(TaskInstSet set);
+
protected:
/// WorkingPlan object that this command works on.
SA_WorkingPlan *working_plan_;
@@ -366,7 +370,8 @@ namespace SA_POP {
std::set< std::pair<TaskInstID,TaskInstID> > causal_insertions;
std::set< std::pair<TaskInstID,TaskInstID> > simul_insertions;
-
+ TaskInstSet satisfied_insts;
+/*
std::map <TaskInstID, TaskInstSet> befores;
std::map <TaskInstID, TaskInstSet> afters;
std::map <TaskInstID, TaskInstSet> simuls;
@@ -376,6 +381,7 @@ namespace SA_POP {
std::map <TaskInstID, TaskInstSet> afters_after_ex;
std::map <TaskInstID, TaskInstSet> simuls_after_ex;
std::map <TaskInstID, TaskInstSet> unrankeds_after_ex;
+*/
// PrecedenceGraph precedence_graph_;
diff --git a/SA_PlanStrategy.cpp b/SA_PlanStrategy.cpp
index c5d7d97434d..bd6f9d6f269 100644
--- a/SA_PlanStrategy.cpp
+++ b/SA_PlanStrategy.cpp
@@ -142,100 +142,109 @@ bool SA_PlanStrategy::satisfy_open_conds (void)
// If all open conditions have been satisfied, then return true for success.
if (this->open_conds_.empty ())
return this->planner_->full_sched();
+//)
+ if(!(this->planner_->get_working_plan()->get_all_insts().size() > 8)){
+ // Increment step counter.
+ this->cur_step_++;
-// if(!(this->planner_->get_working_plan()->get_all_insts().size() > 8)){
- // Increment step counter.
- this->cur_step_++;
+ // Set decision point and reset sequence number for commands.
+ this->cur_decision_pt_ = SA_PlanStrategy::TASK_DECISION;
+ this->cur_seq_num_ = 1;
- // Set decision point and reset sequence number for commands.
- this->cur_decision_pt_ = SA_PlanStrategy::TASK_DECISION;
- this->cur_seq_num_ = 1;
+ // Variable for preconditions of current task.
+ CondSet preconds;
- // Variable for preconditions of current task.
- CondSet preconds;
+ // Choose an open condition to satisfy.
+ Condition open_cond = this->cond_choice_->choose_cond (this->open_conds_);
- // Choose an open condition to satisfy.
- Condition open_cond = this->cond_choice_->choose_cond (this->open_conds_);
+ // Choose task to satisfy open condition (actually an ordered list of
+ // tasks to try), passing command to planner to be executed next.
+ AddTaskCmd *add_task_cmd = this->satisfy_cond (open_cond);
+ TaskInstSet old_satisfied_insts = this->satisfied_insts;
+ this->satisfied_insts = add_task_cmd->get_satisfied_tasks();
+
+ TaskInstID prev_cur_inst = this->cur_task_inst_;
+ // Try tasks until one yields a complete plan or all have been tried.
+ while (this->planner_->try_next (add_task_cmd->get_id ())) {
+ // Get current task and task instance.
+ this->cur_task_ = add_task_cmd->get_task ();
- // Choose task to satisfy open condition (actually an ordered list of
- // tasks to try), passing command to planner to be executed next.
- AddTaskCmd *add_task_cmd = this->satisfy_cond (open_cond);
+ this->cur_task_inst_ = add_task_cmd->get_task_inst ();
+ // Remove open condition.
+ CommandID rmv_cond_cmd_id = this->rmv_open_cond (open_cond, add_task_cmd->get_satisfied_tasks());
- // Try tasks until one yields a complete plan or all have been tried.
- while (this->planner_->try_next (add_task_cmd->get_id ())) {
- // Get current task and task instance.
- this->cur_task_ = add_task_cmd->get_task ();
+ TaskID stored_task = this->cur_task_;
- TaskInstID prev_cur_inst = this->cur_task_inst_;
+ bool to_fail = false;
- this->cur_task_inst_ = add_task_cmd->get_task_inst ();
- // Remove open condition.
- CommandID rmv_cond_cmd_id = this->rmv_open_cond (open_cond, add_task_cmd->get_satisfied_tasks());
+ // Add preconditions of this task of we didn't reuse the task instance.
+ CommandID add_preconds_cmd_id;
+ if(!add_task_cmd->inst_exists())
+ {
+ preconds = this->planner_->get_unsat_preconds (this->cur_task_);
+ add_preconds_cmd_id =
+ this->add_open_conds (preconds, this->cur_task_inst_);
+ }
- // Add preconditions of this task of we didn't reuse the task instance.
- CommandID add_preconds_cmd_id;
- if(!add_task_cmd->inst_exists())
- {
- preconds = this->planner_->get_unsat_preconds (this->cur_task_);
- add_preconds_cmd_id =
- this->add_open_conds (preconds, this->cur_task_inst_);
- }
- //Move this code to the threat resolution sequence
- // Set decision point and reset sequence number for commands.
- this->cur_decision_pt_ = SA_PlanStrategy::THREAT_DECISION;
- this->cur_seq_num_ = 1;
+ if(this->store_map.should_continue(add_task_cmd->get_id(), add_task_cmd->get_condition(),
+ stored_task, this->open_conds_, this->planner_->get_working_plan()->get_task_insts()))
+ {
+ // Try to satisfy threats and continue recursive planning.
+ if (this->satisfy_everything())
+ return true;
+ this->store_map.undo_binding(add_task_cmd->get_id(), add_task_cmd->get_condition(), stored_task);
+ }else{
+ to_fail = true;
+ bool k = 0;
+ }
+ // else{
+ // this->planner_->undo_command (rmv_cond_cmd_id);
+ // break;
+ // }
- //Deal with threats
- //Actually build the list of threats
- this->planner_->generate_all_threats();
+ std::ostringstream debug_text;
+ debug_text<<" the task instance being deleted is "<<add_task_cmd->get_task_inst()<<std::endl;
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ debug_text.str("");
- // Add causal link threats to open threats.
- bool are_threats = !(this->planner_->get_all_threats().empty ());
- CommandID add_threats_cmd_id;
- if (are_threats)
- add_threats_cmd_id =
- this->add_open_threats (this->planner_->get_all_threats ());
+ // Undo addition of preconditions from this task if we didn't reuse the task instance.
+ if(!add_task_cmd->inst_exists())
+ this->planner_->undo_command (add_preconds_cmd_id);
- // Try to satisfy threats and continue recursive planning.
- if (this->satisfy_everything())
- return true;
- this->cur_task_inst_ = prev_cur_inst;
- SA_POP_DEBUG(SA_POP_DEBUG_NORMAL, "Backtracking from task addition...");
- // Undo addition of causal link threats from this task.
- if (are_threats)
- this->planner_->undo_command (add_threats_cmd_id);
- std::cout<<" the task instance being deleted is "<<add_task_cmd->get_task_inst()<<std::endl;
- // Undo addition of preconditions from this task if we didn't reuse the task instance.
- if(!add_task_cmd->inst_exists())
- this->planner_->undo_command (add_preconds_cmd_id);
+ // Undo removal of open condition.
+ this->planner_->undo_command (rmv_cond_cmd_id);
- // Undo removal of open condition.
- this->planner_->undo_command (rmv_cond_cmd_id);
+ if(to_fail){
+ break;
+ }
+ }
- }
+ this->cur_task_inst_ = prev_cur_inst;
- SA_POP_DEBUG (SA_POP_DEBUG_NORMAL, "Backtracking to previous step...");
- // Undo addition of task.
- this->planner_->undo_command (add_task_cmd->get_id ());
+ SA_POP_DEBUG (SA_POP_DEBUG_NORMAL, "Backtracking to previous step...");
+ // Undo addition of task.
+
+ this->satisfied_insts = old_satisfied_insts;
+ this->planner_->undo_command (add_task_cmd->get_id ());
- // Decrement step.
- this->cur_step_--;
+ // Decrement step.
+ this->cur_step_--;
- // }else{
+ }else{
// std::cout<<"Backing up beccause of iterative deepening"<<std::endl;
- // }
+ }
// No task could satisfy open condition, so return failure.
return false;
@@ -259,20 +268,45 @@ bool SA_PlanStrategy::satisfy_everything(){
assoc_impl_cmd->set_assoc (this->cur_task_inst_, impl_list);
this->planner_->add_command (assoc_impl_cmd);
+ assoc_impl_cmd->set_satisfied_insts(this->satisfied_insts);
+
this->cur_task_inst_ = assoc_impl_cmd->get_task_inst ();
-
while (this->planner_->try_next (assoc_impl_cmd->get_id ()))
{
- ((SA_WorkingPlan*)(this->planner_->get_working_plan()))->
- print_precedence_graph("SA_PlanStrategy::get_next_threat_resolution");
- if(this->get_next_threat_resolution()){
- return true;
- }
- else{
+
+ //Move this code to the threat resolution sequence
+ // Set decision point and reset sequence number for commands.
+ this->cur_decision_pt_ = SA_PlanStrategy::THREAT_DECISION;
+ this->cur_seq_num_ = 1;
+
+
+ //Deal with threats
+
+ //Actually build the list of threats
+ this->planner_->generate_all_threats();
+
+ // Add causal link threats to open threats.
+ bool are_threats = !(this->planner_->get_all_threats().empty ());
+ CommandID add_threats_cmd_id;
+ if (are_threats)
+ add_threats_cmd_id =
+ this->add_open_threats (this->planner_->get_all_threats ());
+
+ // ((SA_WorkingPlan*)(this->planner_->get_working_plan()))->
+ // print_precedence_graph("SA_PlanStrategy::get_next_threat_resolution");
+ if(this->get_next_threat_resolution()){
+ return true;
+ }
+ else{
this->cur_decision_pt_ = SA_PlanStrategy::IMPL_DECISION;
- }
+ }
+
+ SA_POP_DEBUG(SA_POP_DEBUG_NORMAL, "Backtracking from task assoc...");
+ // Undo addition of causal link threats from this task.
+ if (are_threats)
+ this->planner_->undo_command (add_threats_cmd_id);
}
@@ -397,12 +431,14 @@ void SA_PlanStrategy::execute (SA_AddOpenCondsCmd *cmd)
// Undo a command to add open conditions to planning.
void SA_PlanStrategy::undo (SA_AddOpenCondsCmd *cmd)
{
+ std::ostringstream debug_text;
+
// Remove open conditions mapped to the specified task instance.
- std::cout<<"removing open conds mapped to "<<cmd->task_inst_<<std::endl;
+ debug_text<<"removing open conds mapped to "<<cmd->task_inst_<<std::endl;
for (CondSet::iterator cond_iter = cmd->conds_.begin ();
cond_iter != cmd->conds_.end (); cond_iter++)
{
- std::cout<<"checking for "<<cond_iter->id<<std::endl;
+ debug_text<<"checking for "<<cond_iter->id<<std::endl;
for (OpenCondMap::iterator open_iter =
this->open_conds_.lower_bound (*cond_iter);
open_iter != this->open_conds_.upper_bound (*cond_iter);)
@@ -411,11 +447,15 @@ void SA_PlanStrategy::undo (SA_AddOpenCondsCmd *cmd)
open_iter++;
if (prev_iter->second == cmd->task_inst_)
{
- std::cout<<"in planstrat erasing from open_conds_ "<<prev_iter->first.id<<" to "<<prev_iter->second<<std::endl;
+ debug_text<<"in planstrat erasing from open_conds_ "<<prev_iter->first.id<<" to "<<prev_iter->second<<std::endl;
this->open_conds_.erase (prev_iter);
}
}
}
+
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ debug_text.str("");
+
};
// Execute a command to remove open conditions from planning.
@@ -470,14 +510,18 @@ void SA_PlanStrategy::execute (SA_RemoveOpenCondsCmd *cmd)
// Undo a command to remove open conditions from planning.
void SA_PlanStrategy::undo (SA_RemoveOpenCondsCmd *cmd)
{
+
+std::ostringstream debug_text;
// Insert removed open condition to task instance mapping.
for (OpenCondMap::iterator open_iter = cmd->removed_.begin ();
open_iter != cmd->removed_.end (); open_iter++)
{
- std::cout<<"in planstrat undo adding "<<open_iter->first.id<<" to "<<open_iter->second<<std::endl;
+ debug_text<<"in planstrat undo adding "<<open_iter->first.id<<" to "<<open_iter->second<<std::endl;
this->open_conds_.push_front (std::make_pair
(open_iter->first, open_iter->second));
}
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+debug_text.str("");
};
// Execute a command to add causal link threats to planning.
@@ -497,21 +541,30 @@ void SA_PlanStrategy::execute (SA_AddOpenThreatsCmd *cmd)
// Undo a command to add causal link threats to planning.
void SA_PlanStrategy::undo (SA_AddOpenThreatsCmd * cmd)
{
+ std::ostringstream debug_text;
// Remove open conditions mapped to the specified task instance.
- std::cout<<"undoing open threats" <<std::endl;
+ debug_text<<"undoing open threats" <<std::endl;
for (CLThreatSet::iterator cond_iter = cmd->threats_.begin ();
cond_iter != cmd->threats_.end (); cond_iter++)
{
CLThreat threat = *cond_iter;
this->open_threats_.erase (threat);
}
+
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ debug_text.str("");
};
// Execute a command to remove causal link threats from planning.
void SA_PlanStrategy::execute (SA_RemoveOpenThreatsCmd * cmd)
{
+ std::ostringstream debug_text;
// Remove open conditions mapped to the specified task instance.
- std::cout<<"removing open threats" <<std::endl;
+ debug_text<<"removing open threats" <<std::endl;
+
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ debug_text.str("");
+
for (CLThreatSet::iterator cond_iter = cmd->threats_.begin ();
cond_iter != cmd->threats_.end (); cond_iter++)
{
diff --git a/SA_PlanStrategy.h b/SA_PlanStrategy.h
index 9887e6761b8..3b99e8a5a61 100644
--- a/SA_PlanStrategy.h
+++ b/SA_PlanStrategy.h
@@ -222,6 +222,8 @@ namespace SA_POP {
/// Current sequence number for commands in this decision point.
int cur_seq_num_;
+ ///Holds info about which tasks an add task cmd has satisfied
+ TaskInstSet satisfied_insts;
// ************************************************************************
@@ -240,8 +242,8 @@ namespace SA_POP {
/// Scheduling is fourth decision point.
static const int SCHEDULE_DECISION = 4;
-
-
+ StoredConditionEvaluator store_map;
+
// ************************************************************************
// Decision point heuristic strategies.
// ************************************************************************
diff --git a/SA_SchedStrategy.cpp b/SA_SchedStrategy.cpp
index 7e95f7718c4..ca2ad899608 100644
--- a/SA_SchedStrategy.cpp
+++ b/SA_SchedStrategy.cpp
@@ -186,6 +186,9 @@ void SA_SchedStrategy::calculate_levels(TaskInstID task_inst)
ResourceValue Q=this->planner_->get_capacity(rm_iter->first);
// The max and min levels at the consumer
ResourceValue cons_min=Q,cons_max=Q;
+
+ std::ostringstream debug_text;
+
for(TaskInstSet::const_iterator iter=unranked->begin();iter!=unranked->end();iter++)
{
// get the resourse usage by the task instance in the unranked set
@@ -198,16 +201,20 @@ void SA_SchedStrategy::calculate_levels(TaskInstID task_inst)
//The consumer of *iter can be executed before and its producer after the consumer of task_inst
if(start_win.second==NULL_TIME || temp_start.first<start_win.second)
{
- std::cout<<"The consumer of "<<*iter<<" can be executed before and its producer after the consumer of "<<task_inst<<std::endl;
+ debug_text<<"The consumer of "<<*iter<<" can be executed before and its producer after the consumer of "<<task_inst<<std::endl;
cons_min-=temp_rm_iter->second;
}
// The consumer of *iter has to executed before the consumer of task_inst
if(temp_start.second!=NULL_TIME && temp_start.second<start_win.first)
{
- std::cout<<"THe consumer of "<<*iter<<" has to executed before the consumer of "<<task_inst<<std::endl;
+ debug_text<<"THe consumer of "<<*iter<<" has to executed before the consumer of "<<task_inst<<std::endl;
cons_max-=temp_rm_iter->second;
}
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
LevelMap temp;
MinimumLevels::iterator iter1=this->min_cons_levels_.find(rm_iter->first);
// Insert dummy levels if this is a new task instance
@@ -304,7 +311,14 @@ bool SA_SchedStrategy::search(double min_crit)
for(TaskInstSet::iterator iter=all.begin();iter!=all.end();iter++)
{
Criticality crit_cons = this->crit(*iter);
- std::cout<<"Criticality of "<<*iter<<" consumer: "<<crit_cons.second<<std::endl;
+
+ std::ostringstream debug_text;
+
+ debug_text<<"Criticality of "<<*iter<<" consumer: "<<crit_cons.second<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
+
if(crit_cons.second>=max_crit.second)
{
max_crit=crit_cons;
@@ -355,7 +369,12 @@ bool SA_SchedStrategy::search(double min_crit)
///Precedence Link Based Balance Constraint Propogation 5.3.3 (labourie paper)
bool SA_SchedStrategy::prec_balance_prop (TaskInstID task_inst)
{
- std::cout<<"Doing Precedence balance prop for "<<task_inst<<std::endl;
+
+ std::ostringstream debug_text;
+ debug_text<<"Doing Precedence balance prop for "<<task_inst<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
CommandID cur_cmd_id = this->planner_->cur_command_id();
const TaskInstSet *unranked = this->planner_->get_prec_insts(task_inst,UNRANKED);
TimeWindow start_win = this->planner_->get_start_window(task_inst);
@@ -372,7 +391,10 @@ bool SA_SchedStrategy::prec_balance_prop (TaskInstID task_inst)
TimeWindow temp_end = this->planner_->get_end_window(*iter);
if(temp_start.second!=NULL_TIME && temp_start.second<start_win.first)
{
- std::cout<<"The consumer of "<<*iter<<" has to executed before"<<std::endl;
+ debug_text<<"The consumer of "<<*iter<<" has to executed before"<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
if(temp_end.first!=NULL_TIME && (start_win.second==NULL_TIME || temp_end.first<start_win.second)) producers_unranked.insert(*iter);
//The consumer has to be executed before this task instance
ResourceMap temp_rm = this->planner_->get_all_resources(this->planner_->get_task_impl_from_inst(*iter));
@@ -415,7 +437,12 @@ bool SA_SchedStrategy::prec_balance_prop (TaskInstID task_inst)
///Time Based Balance Constraint Propogation 5.3.3 (labourie paper)
bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
{
- std::cout<<"Doing time balance prop for "<<task_inst<<std::endl;
+
+ std::ostringstream debug_text;
+ debug_text<<"Doing time balance prop for "<<task_inst<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
CommandID cur_cmd_id = this->planner_->cur_command_id();
const TaskInstSet *unranked = this->planner_->get_prec_insts(task_inst,UNRANKED);
TimeWindow start_win = this->planner_->get_start_window(task_inst);
@@ -434,7 +461,11 @@ bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
TimeWindow temp_end = this->planner_->get_end_window(*iter);
if(temp_start.second!=NULL_TIME && temp_start.second<start_win.first)
{
- std::cout<<"THe consumer of "<<*iter<<" has to execute before"<<std::endl;
+
+ debug_text<<"THe consumer of "<<*iter<<" has to execute before"<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
//The consumer has to be executed before this task instance
ResourceMap temp_rm = this->planner_->get_all_resources(this->planner_->get_task_impl_from_inst(*iter));
ResourceMap::iterator temp_rm_iter = temp_rm.find(rm_iter->first);
@@ -443,7 +474,11 @@ bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
if(temp_end.first!=NULL_TIME && (start_win.second==NULL_TIME || temp_end.first<start_win.second))
{
// This task instance can be pushed before the task instance
- std::cout<<"Task inst "<<*iter<<" can cause trouble"<<std::endl;
+ debug_text<<"Task inst "<<*iter<<" can cause trouble"<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
+
if(producers_unranked.empty())
producers_unranked.push_front(*iter);
else
@@ -460,15 +495,23 @@ bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
else continue;
}
}
- std::cout<<"The producers_unranked list is: "<<std::endl;
+
+ debug_text<<"The producers_unranked list is: "<<std::endl;
for(std::list<TaskInstID>::iterator iter2=producers_unranked.begin();iter2!=producers_unranked.end();iter2++)
{
- std::cout<<*iter2<<" ";
+ debug_text<<*iter2<<" ";
}
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
if(level_before<0)
{
- std::cout<<"The level_before is negative"<<std::endl;
+ debug_text<<"The level_before is negative"<<std::endl;
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
ResourceValue level_prod=0;
std::list<TaskInstID>::iterator iter2=producers_unranked.begin();
for(;iter2!=producers_unranked.end();iter2++)
@@ -480,7 +523,11 @@ bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
}
if(iter2==producers_unranked.end()) return false;
TimeWindow temp2_end = this->planner_->get_end_window(*iter2);
- std::cout<<"greater than "<<*iter2<<std::endl;
+ debug_text<<"greater than "<<*iter2<<std::endl;
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
if(temp2_end.first>start_win.first)
{
AdjustMinTimesCmd *adj_min_times_cmd = static_cast<AdjustMinTimesCmd *> (this->adj_min_times_cmd_->clone ());
@@ -503,7 +550,10 @@ bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
const TaskInstSet *simul = this->planner_->get_prec_insts(task_inst,SIMUL);
for(TaskInstSet::const_iterator iter=simul->begin();iter!=simul->end();iter++)
{
- std::cout<<"calculating for "<<*iter<<std::endl;
+ debug_text<<"calculating for "<<*iter<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
ResourceMap temp_rm = this->planner_->get_all_resources(this->planner_->get_task_impl_from_inst(*iter));
ResourceMap::iterator temp_rm_iter = temp_rm.find(rm_iter->first);
//This task instance doesn't use this resource
@@ -514,7 +564,10 @@ bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
std::list<TaskInstID> producers_unranked;
for(TaskInstSet::const_iterator iter=unranked->begin();iter!=unranked->end();iter++)
{
- std::cout<<"checking out "<<*iter<<std::endl;
+ debug_text<<"checking out "<<*iter<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
TimeWindow temp_start = this->planner_->get_start_window(*iter);
TimeWindow temp_end = this->planner_->get_end_window(*iter);
if(end_win.first==NULL_TIME ||(temp_start.second!=NULL_TIME && temp_start.second<end_win.first))
@@ -578,7 +631,12 @@ bool SA_SchedStrategy::time_balance_prop (TaskInstID task_inst)
//otherwise, repeat these for this task instance till the windows stop changing and stop in this branch.
bool SA_SchedStrategy::energy_prop (TaskInstID task_inst)
{
- std::cout<<"Doing energy precedence calculations for "<<task_inst<<std::endl;
+ std::ostringstream debug_text;
+
+ debug_text<<"Doing energy precedence calculations for "<<task_inst<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
CommandID cur_cmd_id = this->planner_->cur_command_id();
AdjustMinTimesCmd *adj_min_times_cmd = static_cast<AdjustMinTimesCmd *> (this->adj_min_times_cmd_->clone ());
AdjustMaxTimesCmd *adj_max_times_cmd = static_cast<AdjustMaxTimesCmd *> (this->adj_max_times_cmd_->clone ());
@@ -592,7 +650,7 @@ bool SA_SchedStrategy::energy_prop (TaskInstID task_inst)
{
//Based on all task instances before task_inst
ResourceValue Q = this->planner_->get_capacity(rm_iter->first);
- std::cout<<"The capacity of resource:"<<rm_iter->first<<" is "<<Q<<std::endl;
+ debug_text<<"The capacity of resource:"<<rm_iter->first<<" is "<<Q<<std::endl;
double first_before=-1,first_after=-1,second_before=0,second_after=0;
const TaskInstSet *before = this->planner_->get_prec_insts(task_inst,BEFORE);
const TaskInstSet *after = this->planner_->get_prec_insts(task_inst,AFTER);
@@ -630,7 +688,11 @@ bool SA_SchedStrategy::energy_prop (TaskInstID task_inst)
}
if(first_after!=-1 && max_end>first_after-second_after) max_end=first_after-second_after;
}
- std::cout<<"After calculations for resource "<<rm_iter->first<<" start_min="<<min_start<<" and end_max="<<max_end<<std::endl;
+ debug_text<<"After calculations for resource "<<rm_iter->first<<" start_min="<<min_start<<" and end_max="<<max_end<<std::endl;
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
}
if(min_start!=start_win.first)
{
@@ -693,7 +755,9 @@ bool SA_SchedStrategy::energy_prop (TaskInstID task_inst)
/// Do the uni directional energy precedence propogation in the after direction
bool SA_SchedStrategy::energy_prop_after (TaskInstID task_inst)
{
- std::cout<<"Doing energy precedence after calculations for "<<task_inst<<std::endl;
+ std::ostringstream debug_text;
+
+ debug_text<<"Doing energy precedence after calculations for "<<task_inst<<std::endl;
CommandID cur_cmd_id = this->planner_->cur_command_id();
AdjustMinTimesCmd *adj_min_times_cmd = static_cast<AdjustMinTimesCmd *> (this->adj_min_times_cmd_->clone ());
TimeWindow start_win = this->planner_->get_start_window(task_inst);
@@ -705,7 +769,7 @@ bool SA_SchedStrategy::energy_prop_after (TaskInstID task_inst)
{
//Based on all task instances before task_inst
ResourceValue Q = this->planner_->get_capacity(rm_iter->first);
- std::cout<<"The capacity of resource:"<<rm_iter->first<<" is "<<Q<<std::endl;
+ debug_text<<"The capacity of resource:"<<rm_iter->first<<" is "<<Q<<std::endl;
double first_before=-1,second_before=0;
const TaskInstSet *before = this->planner_->get_prec_insts(task_inst,BEFORE);
if(!before->empty())
@@ -721,7 +785,10 @@ bool SA_SchedStrategy::energy_prop_after (TaskInstID task_inst)
}
if(first_before!=-1 && min_start<first_before+second_before) min_start=first_before+second_before;
}
- std::cout<<"After after calculations for resource "<<rm_iter->first<<" start_min="<<min_start<<std::endl;
+ debug_text<<"After after calculations for resource "<<rm_iter->first<<" start_min="<<min_start<<std::endl;
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
}
if(min_start!=start_win.first)
{
@@ -761,7 +828,9 @@ bool SA_SchedStrategy::energy_prop_after (TaskInstID task_inst)
/// Do the uni directional energy precedence propogation in the after direction
bool SA_SchedStrategy::energy_prop_before (TaskInstID task_inst)
{
- std::cout<<"Doing before energy precedence calculations for "<<task_inst<<std::endl;
+ std::ostringstream debug_text;
+
+ debug_text<<"Doing before energy precedence calculations for "<<task_inst<<std::endl;
CommandID cur_cmd_id = this->planner_->cur_command_id();
AdjustMaxTimesCmd *adj_max_times_cmd = static_cast<AdjustMaxTimesCmd *> (this->adj_max_times_cmd_->clone ());
TimeWindow start_win = this->planner_->get_start_window(task_inst);
@@ -774,7 +843,7 @@ bool SA_SchedStrategy::energy_prop_before (TaskInstID task_inst)
{
//Based on all task instances before task_inst
ResourceValue Q = this->planner_->get_capacity(rm_iter->first);
- std::cout<<"The capacity of resource:"<<rm_iter->first<<" is "<<Q<<std::endl;
+ debug_text<<"The capacity of resource:"<<rm_iter->first<<" is "<<Q<<std::endl;
double first_after=-1,second_after=0;
const TaskInstSet *after = this->planner_->get_prec_insts(task_inst,AFTER);
if(!after->empty() && end_win.second!=NULL_TIME)
@@ -797,7 +866,10 @@ bool SA_SchedStrategy::energy_prop_before (TaskInstID task_inst)
}
if(first_after!=-1 && max_end>first_after-second_after) max_end=first_after-second_after;
}
- std::cout<<"After before calculations for resource "<<rm_iter->first<<" and end_max="<<max_end<<std::endl;
+ debug_text<<"After before calculations for resource "<<rm_iter->first<<" and end_max="<<max_end<<std::endl;
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
}
if(max_end!=end_win.second)
{
diff --git a/SA_WorkingPlan.cpp b/SA_WorkingPlan.cpp
index eb4dd0b8ac5..42ef0ba8544 100644
--- a/SA_WorkingPlan.cpp
+++ b/SA_WorkingPlan.cpp
@@ -389,11 +389,6 @@ void SA_WorkingPlan::generate_all_threats(void)
threat_set.clear();
std::ostringstream debug_text;
-
-
-
-
-
debug_text << "SA_WorkingPlan::generate_all_threats: All Causal Links: " << std::endl;
@@ -416,10 +411,10 @@ void SA_WorkingPlan::generate_all_threats(void)
TaskInstID threat_possibility = iterator->first;
TaskID threat_possibility_taskid = iterator->second;
- debug_text <<" Task (" <<threat_possibility_taskid << ")"<< ": Inst (" <<iterator->first << ")" << std::endl;
+ debug_text <<" Task (" <<threat_possibility_taskid << ")"<< ": Inst (" <<iterator->first << ")" << std::endl;
}
-
- SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ debug_text<<std::endl;
+ SA_POP_DEBUG_STR (SPARTAN, debug_text.str ());
debug_text.str("");
debug_text << "SA_WorkingPlan::generate_all_threats: All Causal Threats: " << std::endl;
@@ -454,33 +449,59 @@ void SA_WorkingPlan::generate_all_threats(void)
if(causal_threatened.first != threat_possibility && causal_threatened.second != threat_possibility)
{
-
+ bool a = false;
+ bool b = false;
+ PrecedenceSet::iterator after_thr_it = (&this->precedence_graph_.find(AFTER)->second)->find(threat_possibility);
+ PrecedenceSet::iterator before_thr_it= (&this->precedence_graph_.find(BEFORE)->second)->find(threat_possibility);
+
+ // if(
+ // after_thr_it != (&this->precedence_graph_.find(AFTER)->second)->end() &&
+ // before_thr_it != (&this->precedence_graph_.find(BEFORE)->second)->end()){
+
+ TaskInstSet after_threat = after_thr_it->second;
+ TaskInstSet before_threat = before_thr_it->second;
+
+ a = after_threat.find(causal_threatened.first) != after_threat.end();
+ b = before_threat.find(causal_threatened.second) != before_threat.end();
+
+ // if(a && b)
+ // bool wat = true;
- CLThreat new_threat;
- new_threat.clink = causal_threatened;
- new_threat.threat = threat_possibility;
+
+ // continue;
-
+ // if( (a && !b)||(!a && b)){
+ // continue;
+ // }
+ // }
- std::pair<CLThreatSet::iterator, bool> asdf = threat_set.insert(new_threat);
+ if(!(a || b))
+ {
+ CLThreat new_threat;
+ new_threat.clink = causal_threatened;
+ new_threat.threat = threat_possibility;
-
+
- TaskID threatened_task1 = this->task_insts_.find(causal_threatened.first)->second;
- if(causal_threatened.second != SA_POP::GOAL_TASK_INST_ID)
- {
- TaskID threatened_task2 = this->task_insts_.find(causal_threatened.second)->second;
- debug_text <<" Causal link from Task ("<< threatened_task1 <<") Inst ("<< causal_threatened.first <<") to Task ("<< threatened_task2 <<") Inst ("<< causal_threatened.second <<") using condition "<<causal_threatened.cond.id<<" threatened by Task ("<< threat_possibility_taskid <<") Inst ("<<threat_possibility<<")" << std::endl;
+ std::pair<CLThreatSet::iterator, bool> asdf = threat_set.insert(new_threat);
- }
- else
- {
- debug_text <<" Causal link from Task ("<< threatened_task1 <<") Inst ("<< causal_threatened.first <<") to Task ( GOAL_TASK )Inst (GOAL_TASK_INST) using condition "<<causal_threatened.cond.id<<" threatened by Task ("<< threat_possibility_taskid <<") Inst ("<<threat_possibility<<")" << std::endl;
- }
+
-
+ TaskID threatened_task1 = this->task_insts_.find(causal_threatened.first)->second;
+ if(causal_threatened.second != SA_POP::GOAL_TASK_INST_ID)
+ {
+ TaskID threatened_task2 = this->task_insts_.find(causal_threatened.second)->second;
+ debug_text <<" Causal link from Task ("<< threatened_task1 <<") Inst ("<< causal_threatened.first <<") to Task ("<< threatened_task2 <<") Inst ("<< causal_threatened.second <<") using condition "<<causal_threatened.cond.id<<" threatened by Task ("<< threat_possibility_taskid <<") Inst ("<<threat_possibility<<")" << std::endl;
+
+ }
+ else
+ {
+ debug_text <<" Causal link from Task ("<< threatened_task1 <<") Inst ("<< causal_threatened.first <<") to Task ( GOAL_TASK )Inst (GOAL_TASK_INST) using condition "<<causal_threatened.cond.id<<" threatened by Task ("<< threat_possibility_taskid <<") Inst ("<<threat_possibility<<")" << std::endl;
+ }
+
+ }
- bool a = true;
+ // bool a = true;
}
}
}
@@ -656,6 +677,8 @@ void SA_WorkingPlan::execute (SA_AddTaskCmd *cmd)
cmd->last_task_choice_ = task_choice;
+
+
if(task_choice.choice == REUSE_INST){
task_inst = task_choice.task_inst_id;
@@ -710,11 +733,13 @@ void SA_WorkingPlan::execute (SA_AddTaskCmd *cmd)
this->causal_links_.insert (std::make_pair (cond, clink));
+ /*
if(clink.second != GOAL_TASK_INST_ID){
this->ordering_links.insert(std::pair<TaskInstID, TaskInstID>(clink.first, clink.second));
this->reverse_ordering_links.insert(std::pair<TaskInstID, TaskInstID>(clink.second, clink.first));
}
+ */
cmd->added_links_.insert(clink);
}
}
@@ -758,7 +783,7 @@ void SA_WorkingPlan::undo (SA_AddTaskCmd *cmd)
this->causal_links_.erase (prev_iter);
cmd->added_links_.erase(iter);
-
+ /*
if(clink.second != GOAL_TASK_INST_ID){
std::pair<SchedulingLinks::iterator, SchedulingLinks::iterator> ret =
ordering_links.equal_range(clink.first);
@@ -780,6 +805,7 @@ void SA_WorkingPlan::undo (SA_AddTaskCmd *cmd)
this->reverse_ordering_links.erase(it);
}
+ */
break;
}
}
@@ -793,24 +819,13 @@ bool SA_WorkingPlan::execute (SA_AssocTaskImplCmd *cmd)
{
-
- //cmd->precedence_graph_ = *this->precedence_graph_;
-
- PrecedenceSet* befores = &this->precedence_graph_.find(BEFORE)->second;
- PrecedenceSet* afters = &this->precedence_graph_.find(AFTER)->second;
- PrecedenceSet* simuls = &this->precedence_graph_.find(SIMUL)->second;
- PrecedenceSet* unrankeds = &this->precedence_graph_.find(UNRANKED)->second;
-
- cmd->befores = *befores;
- cmd->afters = *afters;
- cmd->simuls = *simuls;
- cmd->unrankeds = *unrankeds;
-
// Associate task instance with first implementation in list from command.
if(this->reused_insts_.find(cmd->task_inst_)==this->reused_insts_.end())
{
this->task_impls_.insert (std::make_pair(cmd->task_inst_, cmd->impls_.front ()));
this->durations.insert(std::make_pair(cmd->task_inst_, this->planner_->get_impl(cmd->impls_.front())->get_duration()));
+
+
}
// Update last implementation to this one and remove it from command.
cmd->last_impl_ = cmd->impls_.front ();
@@ -819,27 +834,42 @@ bool SA_WorkingPlan::execute (SA_AssocTaskImplCmd *cmd)
//Ben changed this. undo by returning that stuff
+ PrecedenceSet* befores = &this->precedence_graph_.find(BEFORE)->second;
+
+ PrecedenceSet::iterator find_inst = befores->find(cmd->task_inst_);
+ if(find_inst != befores->end()){
+ TaskInstSet before_task = find_inst->second;
+ for(TaskInstSet::iterator it = cmd->satisfied_insts.begin(); it != cmd->satisfied_insts.end(); it++){
+ if(before_task.find(*it) != before_task.end()){
+ return false;
+ }
+ }
+ }
+ /*
if(is_cycle_in_ordering()){
// cmd->got_to_scheduling = false;
- return false;
+ bool oops = true;
}
+*/
+
+
cmd->got_to_scheduling = true;
bool toReturn = this->init_prec_insert(cmd->task_inst_,cmd);
- cmd->befores_after_ex = *befores;
- cmd->afters_after_ex = *afters;
- cmd->simuls_after_ex = *simuls;
- cmd->unrankeds_after_ex = *unrankeds;
+// cmd->befores_after_ex = *befores;
+// cmd->afters_after_ex = *afters;
+// cmd->simuls_after_ex = *simuls;
+// cmd->unrankeds_after_ex = *unrankeds;
return toReturn;
};
-
+/*
bool SA_WorkingPlan::is_cycle_in_ordering(){
std::ostringstream debug_text;
@@ -881,6 +911,7 @@ bool SA_WorkingPlan::is_cycle_in_ordering(){
return false;
}
+*/
// Undo a command to associate an implementation with a
// task instance in the plan.
@@ -896,13 +927,15 @@ void SA_WorkingPlan::undo (SA_AssocTaskImplCmd *cmd)
if(cmd->got_to_scheduling){
+ /*
if(cmd->afters_after_ex != *afters ||
cmd->befores_after_ex != *befores ||
cmd->simuls_after_ex != *simuls ||
cmd->unrankeds_after_ex != *unrankeds)
{
bool hi = true;
- }
+ }
+ */
this->undo(&cmd->max_adj_cmd);
@@ -921,7 +954,7 @@ void SA_WorkingPlan::undo (SA_AssocTaskImplCmd *cmd)
}
-
+ /*
if(cmd->befores != *befores ||
cmd->afters != *afters ||
cmd->simuls != *simuls ||
@@ -929,6 +962,7 @@ void SA_WorkingPlan::undo (SA_AssocTaskImplCmd *cmd)
{
bool hi = true;
}
+ */
};
@@ -946,27 +980,17 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
Condition condition = cmd->condition;
- this->ordering_links.insert(std::pair<TaskInstID, TaskInstID>(first_task_inst, second_task_inst));
- this->reverse_ordering_links.insert(std::pair<TaskInstID, TaskInstID>(second_task_inst, first_task_inst));
+// this->ordering_links.insert(std::pair<TaskInstID, TaskInstID>(first_task_inst, second_task_inst));
+// this->reverse_ordering_links.insert(std::pair<TaskInstID, TaskInstID>(second_task_inst, first_task_inst));
- PrecedenceSet* befores = &this->precedence_graph_.find(BEFORE)->second;
- PrecedenceSet* afters = &this->precedence_graph_.find(AFTER)->second;
- PrecedenceSet* simuls = &this->precedence_graph_.find(SIMUL)->second;
- PrecedenceSet* unrankeds = &this->precedence_graph_.find(UNRANKED)->second;
- cmd->befores = *befores;
- cmd->afters = *afters;
- cmd->simuls = *simuls;
- cmd->unrankeds = *unrankeds;
// if(cmd->first == 11 && cmd->second == 12){
// bool hi = false;
// }
- if(this->task_insts_.size() > 9){
- return false;
- }
+
if(task_insts_.find(cmd->second)->second == 20){
@@ -990,6 +1014,10 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
return false;
}
+ PrecedenceSet* befores = &this->precedence_graph_.find(BEFORE)->second;
+ PrecedenceSet* afters = &this->precedence_graph_.find(AFTER)->second;
+ PrecedenceSet* simuls = &this->precedence_graph_.find(SIMUL)->second;
+ PrecedenceSet* unrankeds = &this->precedence_graph_.find(UNRANKED)->second;
TaskInstSet *before_A = &befores->find(cmd->first)->second;
@@ -1014,9 +1042,9 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
debug_text.str("");
- if(this->is_cycle_in_ordering()){
- bool this_means_ben_failed = true;
- }
+// if(this->is_cycle_in_ordering()){
+// bool this_means_ben_failed = true;
+// }
return true;
}
@@ -1026,9 +1054,9 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
debug_text << "SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd): Cannot schedule task inst"<<cmd->first<<" before task inst"<<cmd->second<<std::endl;
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
debug_text.str("");
- if(!this->is_cycle_in_ordering()){
- bool this_means_ben_failed = true;
- }
+// if(!this->is_cycle_in_ordering()){
+// bool this_means_ben_failed = true;
+// }
// loop_detected = true;
@@ -1036,14 +1064,18 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
return false;
}else{
- if(this->is_cycle_in_ordering()){
- bool this_means_ben_failed = true;
- }
+// if(this->is_cycle_in_ordering()){
+// bool this_means_ben_failed = true;
+// }
}
cmd->got_to_change_precedences = true;
+ cmd->befores = *befores;
+ cmd->afters = *afters;
+ cmd->simuls = *simuls;
+ cmd->unrankeds = *unrankeds;
TaskInstSet tmp;
@@ -1098,12 +1130,13 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
debug_text.str("");
- print_precedence_graph("SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)");
+// print_precedence_graph("SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)");
return true;
};
+/*
void SA_WorkingPlan::dfs_aux(TaskInstID current, std::stack<TaskInstID>& s, std::map<TaskInstID, bool>& visited, std::map<TaskInstID, bool>& unvisited){
@@ -1145,6 +1178,7 @@ bool SA_WorkingPlan::dfs_aux2(TaskInstID current, std::map<TaskInstID, bool>& vi
return true;
}
+*/
// Undo a command to resolve a causal link threat in the
// plan (with promotion or demotion).
@@ -1159,8 +1193,6 @@ void SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd)
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
debug_text.str("");
-
- print_precedence_graph("SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd)");
}
// if(cmd->first == 11 && cmd->second == 12){
// bool hi = false;
@@ -1207,6 +1239,7 @@ void SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd)
}
+ /*
std::pair<
std::multimap<TaskInstID, TaskInstID >::iterator,
std::multimap<TaskInstID, TaskInstID >::iterator
@@ -1234,6 +1267,7 @@ void SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd)
}
this->reverse_ordering_links.erase(it);
+ */
};
// Execute a command to resolve a scheduling conflict (i.e.
@@ -1241,7 +1275,13 @@ void SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd)
// between two task instances in the plan.
bool SA_WorkingPlan::execute (SA_ResolveSchedOrderCmd *cmd)
{
- std::cout<<"Scheduling "<<cmd->first<<" before "<<cmd->second<<std::endl;
+ std::ostringstream debug_text;
+
+ debug_text<<"Scheduling "<<cmd->first<<" before "<<cmd->second<<std::endl;
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
TaskInstID first_task_inst = cmd->first;
TaskInstID second_task_inst = cmd->second;
TimeWindow first_start,second_start;
@@ -1342,7 +1382,11 @@ void SA_WorkingPlan::undo (SA_ResolveSchedOrderCmd *cmd)
// task instance in the plan.
bool SA_WorkingPlan::execute (SA_AdjustMinTimesCmd *cmd)
{
- std::cout<<"adjusting min time for "<<cmd->task_inst_<<std::endl;
+ std::ostringstream debug_text;
+ debug_text<<"adjusting min time for "<<cmd->task_inst_<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
TimeWindow *start_win = &this->start_window_map_.find(cmd->task_inst_)->second;
TimeWindow *end_win = &this->end_window_map_.find(cmd->task_inst_)->second;
// If this adjustment violated and time constraints, return false.
@@ -1355,7 +1399,7 @@ bool SA_WorkingPlan::execute (SA_AdjustMinTimesCmd *cmd)
TimeWindow ts = this->get_start_window(cmd->task_inst_);
TimeWindow es = this->get_end_window(cmd->task_inst_);
CLSet after_links = this->get_after(cmd->task_inst_);
- if(after_links.empty()) std::cout<<"after links is empty"<<std::endl;
+ if(after_links.empty()) debug_text<<"after links is empty"<<std::endl;
TaskInstSet causal,sched,data;
for(CLSet::iterator iter=after_links.begin();iter!=after_links.end();iter++)
{ if(iter->cond.kind!=DATA) causal.insert(iter->second);
@@ -1364,6 +1408,7 @@ bool SA_WorkingPlan::execute (SA_AdjustMinTimesCmd *cmd)
for(SchedulingLinks::iterator iter=sched_links_.begin();iter!=sched_links_.end();iter++)
if(iter->first==cmd->task_inst_) sched.insert(iter->second);
+
// Propagate this time window change to all the task instances ordered after this task instance
for(TaskInstSet::iterator iter=causal.begin();iter!=causal.end();iter++)
{
@@ -1371,7 +1416,7 @@ bool SA_WorkingPlan::execute (SA_AdjustMinTimesCmd *cmd)
TimeWindow temp_end = this->get_end_window(*iter);
if(end_win->first>temp_start.first)
{
- std::cout<<"adjusting time for causal "<<*iter<<std::endl;
+ debug_text<<"adjusting time for causal "<<*iter<<std::endl;
SA_AdjustMinTimesCmd* temp = static_cast<SA_AdjustMinTimesCmd *> (this->get_AdjustMinTimesCmd());
TimeValue dur = this->durations.find(*iter)->second;
if(dur!=0) temp->set_times(*iter,end_win->first,end_win->first+this->durations.find(*iter)->second);
@@ -1380,8 +1425,10 @@ bool SA_WorkingPlan::execute (SA_AdjustMinTimesCmd *cmd)
}
}
- if(sched.empty()) std::cout<<"sched is empty"<<std::endl;
+ if(sched.empty()) debug_text<<"sched is empty"<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
for(TaskInstSet::iterator iter=sched.begin();iter!=sched.end();iter++)
{
@@ -1399,26 +1446,30 @@ bool SA_WorkingPlan::execute (SA_AdjustMinTimesCmd *cmd)
}
}
+
+
// Do the same change for the task instances simultaneous to this one
for(TaskInstSet::iterator iter=data.begin();iter!=data.end();iter++)
{
TimeWindow temp_start = this->get_start_window(*iter);
if(start_win->first>temp_start.first)
{
- std::cout<<"adjusting time for data "<<*iter<<std::endl;
+ debug_text<<"adjusting time for data "<<*iter<<std::endl;
SA_AdjustMinTimesCmd* temp = static_cast<SA_AdjustMinTimesCmd *> (this->get_AdjustMinTimesCmd());
temp->set_times(*iter,start_win->first,end_win->first);
cmd->min_adjust_cmds.push_back(temp);
}
}
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
for(SA_AdjustMinTimesCmd::MinTimesAdjustList::iterator iter=cmd->min_adjust_cmds.begin();iter!=cmd->min_adjust_cmds.end();iter++)
{
-
if(!this->execute(*iter)) return false;
}
- std::cout<<"the task inst is "<<cmd->task_inst_<<std::endl;
+
+ debug_text<<"the task inst is "<<cmd->task_inst_<<std::endl;
// Check to see whether any task instance should be removed from the unranked set due to this time window change
TaskInstSet *unranked = &this->precedence_graph_.find(UNRANKED)->second.find(cmd->task_inst_)->second;
for(TaskInstSet::iterator iter=unranked->begin();iter!=unranked->end();iter++)
@@ -1436,7 +1487,11 @@ bool SA_WorkingPlan::execute (SA_AdjustMinTimesCmd *cmd)
{
unranked->erase(unranked->find(*iter));
}
- std::cout<<"min times of "<<cmd->task_inst_<<" : "<<cmd->new_start_min<<" "<<cmd->new_end_min<<std::endl;
+ debug_text<<"min times of "<<cmd->task_inst_<<" : "<<cmd->new_start_min<<" "<<cmd->new_end_min<<std::endl;
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
return true;
};
@@ -1477,10 +1532,12 @@ void SA_WorkingPlan::undo (SA_AdjustMinTimesCmd *cmd)
// task instance in the plan.
bool SA_WorkingPlan::execute (SA_AdjustMaxTimesCmd *cmd)
{
- std::cout<<"adjusting max time for "<<cmd->task_inst_<<std::endl;
+ std::ostringstream debug_text;
+
+ debug_text<<"adjusting max time for "<<cmd->task_inst_<<std::endl;
TimeWindow *start_win = &this->start_window_map_.find(cmd->task_inst_)->second;
TimeWindow *end_win = &this->end_window_map_.find(cmd->task_inst_)->second;
- std::cout<<"for "<<cmd->task_inst_<<" "<<cmd->new_end_max<<" "<<end_win->first<<" "<<cmd->new_start_max<<" "<<start_win->first<<std::endl;
+ debug_text<<"for "<<cmd->task_inst_<<" "<<cmd->new_end_max<<" "<<end_win->first<<" "<<cmd->new_start_max<<" "<<start_win->first<<std::endl;
// If this adjustment violated and time constraints, return false.
if((end_win->first==NULL_TIME && cmd->new_end_max!= NULL_TIME) || cmd->new_end_max<end_win->first || cmd->new_start_max<start_win->first) return false;
// Set the new time window
@@ -1507,9 +1564,9 @@ bool SA_WorkingPlan::execute (SA_AdjustMaxTimesCmd *cmd)
}
}
- if(sched.empty()) std::cout<<"msched is empty ("<<cmd->task_inst_<<")"<<std::endl;
+ if(sched.empty()) debug_text<<"msched is empty ("<<cmd->task_inst_<<")"<<std::endl;
else
- std::cout<<"mnot sched is empty ("<<cmd->task_inst_<<")"<<std::endl;
+ debug_text<<"mnot sched is empty ("<<cmd->task_inst_<<")"<<std::endl;
for(TaskInstSet::iterator iter=sched.begin();iter!=sched.end();iter++)
{
@@ -1522,6 +1579,8 @@ bool SA_WorkingPlan::execute (SA_AdjustMaxTimesCmd *cmd)
}
}
+
+
// Do the same change for the task instances simultaneous to this one
for(TaskInstSet::iterator iter=data.begin();iter!=data.end();iter++)
{
@@ -1533,6 +1592,11 @@ bool SA_WorkingPlan::execute (SA_AdjustMaxTimesCmd *cmd)
cmd->max_adjust_cmds.push_back(temp);
}
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
+
for(SA_AdjustMaxTimesCmd::MaxTimesAdjustList::iterator iter=cmd->max_adjust_cmds.begin();iter!=cmd->max_adjust_cmds.end();iter++)
{
if(!this->execute(*iter)) return false;
@@ -1554,7 +1618,10 @@ bool SA_WorkingPlan::execute (SA_AdjustMaxTimesCmd *cmd)
{
unranked->erase(unranked->find(*iter));
}
- std::cout<<"max times for "<<cmd->task_inst_<<" : "<<cmd->new_start_max<<" "<<cmd->new_end_max<<std::endl;
+ debug_text<<"max times for "<<cmd->task_inst_<<" : "<<cmd->new_start_max<<" "<<cmd->new_end_max<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
return true;
};
@@ -1562,7 +1629,11 @@ bool SA_WorkingPlan::execute (SA_AdjustMaxTimesCmd *cmd)
// task instance in the plan.
void SA_WorkingPlan::undo (SA_AdjustMaxTimesCmd *cmd)
{
- std::cout<<"task inst is "<<cmd->task_inst_<<std::endl;
+ std::ostringstream debug_text;
+ debug_text<<"task inst is "<<cmd->task_inst_<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
TimeWindow *start_win = &this->get_start_window(cmd->task_inst_);
TimeWindow *end_win = &this->get_end_window(cmd->task_inst_);
if(start_win->second==cmd->old_start_max && end_win->second==cmd->old_end_max) return;
@@ -1649,7 +1720,11 @@ TimeValue SA_WorkingPlan::get_duration(TaskInstID task_inst)
/// Adds the sched order to the sched_links_ map by putting the first task instance before the second
void SA_WorkingPlan::add_sched_link(TaskInstID first_task_inst, TaskInstID second_task_inst)
{
- std::cout<<"Adding sched link insert"<<std::endl;
+ std::ostringstream debug_text;
+ debug_text<<"Adding sched link insert"<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
this->sched_links_.insert(std::make_pair(first_task_inst,second_task_inst));
}
/// Removes the sched order from the sched_links_ map
@@ -1678,7 +1753,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
this->precedence_graph_.find(SIMUL)->second.insert(std::make_pair(task_inst,temp));
- if(init_start.size() == task_inst){
+ if(init_start.size() <= task_inst){
for(int i = init_start.size(); i < 100+task_inst; i++){
this->init_start.insert(std::make_pair(i,(TimeWindow)std::make_pair(NULL_TIME,NULL_TIME)));
this->init_end.insert(std::make_pair(i,(TimeWindow)std::make_pair(NULL_TIME,NULL_TIME)));
@@ -1689,8 +1764,14 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
TimeWindow win_end = this->init_end.find(task_inst)->second;
TimeWindow start_win = this->get_start_window(task_inst);
TimeWindow end_win = this->get_end_window(task_inst);
- std::cout<<"for "<<task_inst<<win_start.first<<" "<<win_start.second<<" "<<win_end.first<<" "<<win_end.second<<std::endl;
- std::cout<<"for "<<task_inst<<start_win.first<<" "<<start_win.second<<" "<<end_win.first<<" "<<end_win.second<<std::endl;
+
+
+ std::ostringstream debug_text;
+ debug_text<<"for "<<task_inst<<win_start.first<<" "<<win_start.second<<" "<<win_end.first<<" "<<win_end.second<<std::endl;
+ debug_text<<"for "<<task_inst<<start_win.first<<" "<<start_win.second<<" "<<end_win.first<<" "<<end_win.second<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
if(win_start.first!=NULL_TIME)
{
// An initial time constraint is set on the minimum times
@@ -1740,8 +1821,14 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
// No initial time constraint.
cmd->min_adj_cmd.set_times(task_inst,start_win.first,end_win.first);
cmd->max_adj_cmd.set_times(task_inst,start_win.second,end_win.second);
- std::cout<<"for "<<task_inst<<" "<<start_win.first<<" "<<start_win.second<<" "<<end_win.first<<" "<<end_win.second<<std::endl;
- if(!this->execute(&cmd->min_adj_cmd))
+
+ std::ostringstream debug_text;
+ debug_text<<"for "<<task_inst<<" "<<start_win.first<<" "<<start_win.second<<" "<<end_win.first<<" "<<end_win.second<<std::endl;
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
+
+ if(!this->execute(&cmd->min_adj_cmd))
{
this->undo(&cmd->min_adj_cmd);
return false;
@@ -1764,14 +1851,20 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
// If this task instance is not reused, insert all the task instances in it unranked set.
if(unranked->empty() && (this->reused_insts_.find(task_inst)== this->reused_insts_.end()))
{
+ std::ostringstream debug_text;
+
for(PrecedenceSet::iterator iter=this->precedence_graph_.find(BEFORE)->second.begin();iter!=this->precedence_graph_.find(BEFORE)->second.end();iter++)
{
if(iter->first!=task_inst)
{
- std::cout<<"inserting "<<iter->first<<" in unranked of "<<task_inst<<std::endl;
+ debug_text<<"inserting "<<iter->first<<" in unranked of "<<task_inst<<std::endl;
unranked->insert(iter->first);
}
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
if(unranked->empty()) return true;
}
CLSet after_links = this->get_after(task_inst);
@@ -1791,7 +1884,10 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
TaskInstSet *iter_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter)->second;
TaskInstSet *iter_simul = &this->precedence_graph_.find(SIMUL)->second.find(*iter)->second;
if(after->find(*iter)!=after->end()) continue;
- std::cout<<"inserting "<<*iter<<" in after set of "<<task_inst<<std::endl;
+
+
+ std::ostringstream debug_text;
+ debug_text<<"inserting "<<*iter<<" in after set of "<<task_inst<<std::endl;
TaskInstSet temp = *before;
temp.insert(task_inst);
for(TaskInstSet::iterator iter2=simul->begin();iter2!=simul->end();iter2++)
@@ -1805,7 +1901,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
iter2_simul = &this->precedence_graph_.find(SIMUL)->second.find(*iter2)->second;
for(TaskInstSet::iterator iter1=iter_after->begin();iter1!=iter_after->end();iter1++)
{
- std::cout<<*iter1<<" is after "<<*iter<<" so it is after "<<*iter2<<std::endl;
+ debug_text<<*iter1<<" is after "<<*iter<<" so it is after "<<*iter2<<std::endl;
TaskInstSet *iter1_before,*iter1_unranked;
iter1_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter1)->second;
iter1_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter1)->second;
@@ -1818,7 +1914,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
}
for(TaskInstSet::iterator iter1=iter_simul->begin();iter1!=iter_simul->end();iter1++)
{
- std::cout<<*iter1<<" is siml to "<<*iter<<" so it is after "<<*iter2<<std::endl;
+ debug_text<<*iter1<<" is siml to "<<*iter<<" so it is after "<<*iter2<<std::endl;
TaskInstSet *iter1_before,*iter1_unranked;
iter1_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter1)->second;
iter1_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter1)->second;
@@ -1836,19 +1932,25 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
if(iter_unranked->find(*iter2)!=iter_unranked->end()) iter_unranked->erase(*iter2);
if(iter2_unranked->find(*iter)!=iter2_unranked->end()) iter2_unranked->erase(iter2_unranked->find(*iter));
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
}
for(TaskInstSet::iterator iter=data.begin();iter!=data.end();iter++)
{
+ std::ostringstream debug_text;
+
TaskInstSet *iter_after = &this->precedence_graph_.find(AFTER)->second.find(*iter)->second;
TaskInstSet *iter_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter)->second;
TaskInstSet *iter_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter)->second;
TaskInstSet *iter_simul = &this->precedence_graph_.find(SIMUL)->second.find(*iter)->second;
if(simul->find(*iter)!=simul->end()) continue;
- std::cout<<"inserting "<<*iter<<" in simul set of "<<task_inst<<std::endl;
+ debug_text<<"inserting "<<*iter<<" in simul set of "<<task_inst<<std::endl;
TaskInstSet temp = *before;
for(TaskInstSet::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
{
- std::cout<<"iter2 is "<<*iter2<<std::endl;
+ debug_text<<"iter2 is "<<*iter2<<std::endl;
TaskInstSet *iter2_before,*iter2_after,*iter2_simul,*iter2_unranked;
iter2_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter2)->second;
iter2_after = &this->precedence_graph_.find(AFTER)->second.find(*iter2)->second;
@@ -1856,7 +1958,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
iter2_simul = &this->precedence_graph_.find(SIMUL)->second.find(*iter2)->second;
for(TaskInstSet::iterator iter1=iter_after->begin();iter1!=iter_after->end();iter1++)
{
- std::cout<<*iter1<<" is after "<<*iter<<" so it is after "<<*iter2<<std::endl;
+ debug_text<<*iter1<<" is after "<<*iter<<" so it is after "<<*iter2<<std::endl;
TaskInstSet *iter1_before,*iter1_unranked;
iter1_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter1)->second;
iter1_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter1)->second;
@@ -1869,7 +1971,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
}
for(TaskInstSet::iterator iter1=iter_simul->begin();iter1!=iter_simul->end();iter1++)
{
- std::cout<<*iter1<<" is simul to "<<*iter<<" so it is after "<<*iter2<<std::endl;
+ debug_text<<*iter1<<" is simul to "<<*iter<<" so it is after "<<*iter2<<std::endl;
TaskInstSet *iter1_before,*iter1_unranked;
iter1_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter1)->second;
iter1_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter1)->second;
@@ -1886,11 +1988,18 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
iter2_after->insert(*iter);
if(iter_unranked->find(*iter2)!=iter_unranked->end()) iter_unranked->erase(*iter2);
if(iter2_unranked->find(*iter)!=iter2_unranked->end()) iter2_unranked->erase(iter2_unranked->find(*iter));
- }
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+ }
+
+
temp = *simul;
temp.insert(task_inst);
for(TaskInstSet::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
{
+ std::ostringstream debug_text;
+
TaskInstSet *iter2_before,*iter2_after,*iter2_simul,*iter2_unranked;
iter2_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter2)->second;
iter2_after = &this->precedence_graph_.find(AFTER)->second.find(*iter2)->second;
@@ -1898,7 +2007,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
iter2_simul = &this->precedence_graph_.find(SIMUL)->second.find(*iter2)->second;
for(TaskInstSet::iterator iter1=iter_after->begin();iter1!=iter_after->end();iter1++)
{
- std::cout<<*iter1<<" is after "<<*iter<<" so it is after "<<*iter2<<std::endl;
+ debug_text<<*iter1<<" is after "<<*iter<<" so it is after "<<*iter2<<std::endl;
TaskInstSet *iter1_before,*iter1_unranked;
iter1_before = &this->precedence_graph_.find(BEFORE)->second.find(*iter1)->second;
iter1_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter1)->second;
@@ -1911,7 +2020,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
}
for(TaskInstSet::iterator iter1=iter_simul->begin();iter1!=iter_simul->end();iter1++)
{
- std::cout<<*iter1<<" is simul "<<*iter<<" so it is simul "<<*iter2<<std::endl;
+ debug_text<<*iter1<<" is simul "<<*iter<<" so it is simul "<<*iter2<<std::endl;
TaskInstSet *iter1_simul,*iter1_unranked;
iter1_simul = &this->precedence_graph_.find(SIMUL)->second.find(*iter1)->second;
iter1_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter1)->second;
@@ -1927,7 +2036,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
}
for(TaskInstSet::iterator iter1=iter_before->begin();iter1!=iter_before->end();iter1++)
{
- std::cout<<*iter1<<" is before "<<*iter<<" so it is before "<<*iter2<<std::endl;
+ debug_text<<*iter1<<" is before "<<*iter<<" so it is before "<<*iter2<<std::endl;
TaskInstSet *iter1_after,*iter1_unranked;
iter1_after = &this->precedence_graph_.find(AFTER)->second.find(*iter1)->second;
iter1_unranked = &this->precedence_graph_.find(UNRANKED)->second.find(*iter1)->second;
@@ -1938,6 +2047,10 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
if(iter1_unranked->find(*iter2)!=iter1_unranked->end()) iter1_unranked->erase(*iter2);
if(iter2_unranked->find(*iter1)!=iter2_unranked->end()) iter2_unranked->erase(iter2_unranked->find(*iter1));
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
if(iter_simul->find(*iter2)!=iter_simul->end()) continue;
else cmd->simul_insertions.insert(std::make_pair(*iter2,*iter));
iter2_simul->insert(*iter);
@@ -1946,12 +2059,16 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
if(iter2_unranked->find(*iter)!=iter2_unranked->end()) iter2_unranked->erase(iter2_unranked->find(*iter));
}
}
- std::cout<<"for "<<task_inst<<" start window: "<<start_win.first<<"-"<<start_win.second<<" and end window "<<end_win.first<<"-"<<end_win.second<<std::endl;
+
+
+ debug_text<<"for "<<task_inst<<" start window: "<<start_win.first<<"-"<<start_win.second<<" and end window "<<end_win.first<<"-"<<end_win.second<<std::endl;
+
+
for(TaskInstSet::iterator iter = unranked->begin();iter!=unranked->end();iter++)
{
TimeWindow temp_start = this->get_start_window(*iter);
TimeWindow temp_end = this->get_end_window(*iter);
- std::cout<<"checking "<<*iter<<" in all with start window: "<<temp_start.first<<"-"<<temp_start.second<<" and end window "<<temp_end.first<<"-"<<temp_end.second<<std::endl;
+ debug_text<<"checking "<<*iter<<" in all with start window: "<<temp_start.first<<"-"<<temp_start.second<<" and end window "<<temp_end.first<<"-"<<temp_end.second<<std::endl;
if(end_win.second!=NULL_TIME && temp_start.first>end_win.second)
{
after->insert(*iter);
@@ -1966,36 +2083,52 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
{
this->precedence_graph_.find(UNRANKED)->second.find(*iter)->second.insert(task_inst);
}
+
+
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
this->print_prec();
+
for(InstToWinMap::iterator iter=this->start_window_map_.begin();iter!=this->start_window_map_.end();iter++)
{
- std::cout<<"The start window for "<<iter->first<<" is "<<iter->second.first<<" - "<<iter->second.second<<std::endl;
+ debug_text<<"The start window for "<<iter->first<<" is "<<iter->second.first<<" - "<<iter->second.second<<std::endl;
}
for(InstToWinMap::iterator iter=this->end_window_map_.begin();iter!=this->end_window_map_.end();iter++)
{
- std::cout<<"The end window for "<<iter->first<<" is "<<iter->second.first<<" - "<<iter->second.second<<std::endl;
+ debug_text<<"The end window for "<<iter->first<<" is "<<iter->second.first<<" - "<<iter->second.second<<std::endl;
}
+
+ SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
+ debug_text.str("");
+
return true;
};
// Print the precedence graph
void SA_WorkingPlan::print_prec()
{
- std::cout<<"BEFORE : "<<BEFORE<<", AFTER : "<<AFTER<<", SIMUL : "<<SIMUL<<", UNRANKED : "<<UNRANKED<<std::endl;
+ std::ostringstream debug_text;
+
+ debug_text<<"BEFORE : "<<BEFORE<<", AFTER : "<<AFTER<<", SIMUL : "<<SIMUL<<", UNRANKED : "<<UNRANKED<<std::endl;
for(PrecedenceGraph::iterator iter1 = this->precedence_graph_.begin(); iter1 != this->precedence_graph_.end(); iter1++)
{
- std::cout<<"The precedence set "<<iter1->first<<": "<<std::endl;
+ debug_text<<"The precedence set "<<iter1->first<<": "<<std::endl;
for(PrecedenceSet::iterator iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++)
{
- std::cout<<"The task inst set of "<<iter2->first<<" is ";
+ debug_text<<"The task inst set of "<<iter2->first<<" is ";
for(TaskInstSet::iterator iter3 = iter2->second.begin(); iter3 != iter2->second.end(); iter3++)
{
- std::cout<<*iter3<<",";
+ debug_text<<*iter3<<",";
}
- std::cout<<std::endl;
+ debug_text<<std::endl;
}
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
};
// Undo all the updation to the precedence graph due to the chosen task instance
@@ -2005,10 +2138,13 @@ PrecedenceSet *before = &this->precedence_graph_.find(BEFORE)->second;
PrecedenceSet *simul = &this->precedence_graph_.find(SIMUL)->second;
PrecedenceSet *after = &this->precedence_graph_.find(AFTER)->second;
PrecedenceSet *unranked = &this->precedence_graph_.find(UNRANKED)->second;
+
+std::ostringstream debug_text;
+
for(std::set< std::pair<TaskInstID,TaskInstID> >::iterator iter = cmd->causal_insertions.begin();iter!=cmd->causal_insertions.end();iter++)
{
// iter->second has been inserted in the after set of iter->first
- std::cout<<"removing "<<iter->second<<" from after of "<<iter->first<<std::endl;
+ debug_text<<"removing "<<iter->second<<" from after of "<<iter->first<<std::endl;
before->find(iter->second)->second.erase(iter->first);
after->find(iter->first)->second.erase(iter->second);
unranked->find(iter->first)->second.insert(iter->second);
@@ -2017,7 +2153,7 @@ PrecedenceSet *unranked = &this->precedence_graph_.find(UNRANKED)->second;
for(std::set< std::pair<TaskInstID,TaskInstID> >::iterator iter = cmd->simul_insertions.begin();iter!=cmd->simul_insertions.end();iter++)
{
// iter->second has been inserted in the simul set of iter->first
- std::cout<<"removing "<<iter->second<<" from simul of "<<iter->first<<std::endl;
+ debug_text<<"removing "<<iter->second<<" from simul of "<<iter->first<<std::endl;
simul->find(iter->second)->second.erase(iter->first);
simul->find(iter->first)->second.erase(iter->second);
unranked->find(iter->first)->second.insert(iter->second);
@@ -2030,7 +2166,7 @@ PrecedenceSet *unranked = &this->precedence_graph_.find(UNRANKED)->second;
// if(iter->second.second == GOAL_TASK_INST_ID && iter->second.first == task_inst) break;
// if(iter==this->causal_links_.end() || cmd->impls_.size()!=0)
// {
- std::cout<<this->reused_insts_.size()<<std::endl;
+ debug_text<<this->reused_insts_.size()<<std::endl;
if(this->reused_insts_.find(task_inst)==this->reused_insts_.end())
{
before->erase(before->find(task_inst));
@@ -2042,6 +2178,10 @@ PrecedenceSet *unranked = &this->precedence_graph_.find(UNRANKED)->second;
for(PrecedenceSet::iterator iter1 = unranked->begin();iter1!=unranked->end();iter1++)
iter1->second.erase(task_inst);
}
+
+ SA_POP_DEBUG_STR (ANKET, debug_text.str ());
+ debug_text.str("");
+
// }
//std::cout<<"after erasing the precedence graph is "<<std::endl;
//this->print_prec();
diff --git a/SA_WorkingPlan.h b/SA_WorkingPlan.h
index 544d41681e9..299a6c278e7 100644
--- a/SA_WorkingPlan.h
+++ b/SA_WorkingPlan.h
@@ -412,9 +412,11 @@ namespace SA_POP {
SchedulingLinks reverse_ordering_links;
// SA_AssocTaskImplCmd* associate_cmd;
+ /*
bool is_cycle_in_ordering(void);
void dfs_aux(TaskInstID current, std::stack<TaskInstID>& s, std::map<TaskInstID, bool>& visited, std::map<TaskInstID, bool>& unvisited);
bool dfs_aux2(TaskInstID current, std::map<TaskInstID, bool>& visited);
+ */
/// Insert initially task by task in the precedence graph
/**
diff --git a/WorkingPlan.h b/WorkingPlan.h
index 8cad6129149..31f19c14a27 100644
--- a/WorkingPlan.h
+++ b/WorkingPlan.h
@@ -196,6 +196,8 @@ namespace SA_POP {
virtual void generate_all_threats(void) = 0;
+ virtual InstToTaskMap get_task_insts(void) = 0;
+
protected:
/// Pointer to Planner object.
SA_POP::Planner *planner_;