summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbpodgursky <bpodgursky@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2009-07-10 22:28:58 +0000
committerbpodgursky <bpodgursky@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2009-07-10 22:28:58 +0000
commite5a42ed6f8d9c1b08b633281b99aadb4b2071ee4 (patch)
tree18ddf25d3840160ae85094d098981b1bd98f7123
parent9857490a7e33385e8738a57ca1ae8eeaa365ed15 (diff)
downloadATCD-e5a42ed6f8d9c1b08b633281b99aadb4b2071ee4.tar.gz
Fri Jul 10 22:27:30 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
-rw-r--r--ChangeLog14
-rw-r--r--SA_POP_Types.h4
-rw-r--r--SA_PlanCommands.cpp20
-rw-r--r--SA_PlanCommands.h6
-rw-r--r--SA_PlanHeuristics.cpp47
-rw-r--r--SA_PlanStrategy.cpp40
-rw-r--r--SA_WorkingPlan.cpp317
7 files changed, 180 insertions, 268 deletions
diff --git a/ChangeLog b/ChangeLog
index 67f6f4892a8..01b659e1857 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Fri Jul 10 22:27:30 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
+
+ * SA_POP_Types.h:
+ * SA_PlanCommands.h:
+ * SA_PlanCommands.cpp:
+ * SA_PlanHeuristics.cpp:
+ * 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.
+
Wed Jul 8 22:17:52 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
* SA_POP_Types.h:
@@ -7,7 +19,7 @@ Wed Jul 8 22:17:52 UTC 2009 Ben Podgursky <bpodgursky@gmail.com>
* SA_WorkingPlan.h:
* SA_WorkingPlan.cpp:
- Debugging output improved.
+ Debugging output improved.
Wed Jul 8 01:13:05 UTC 2009 Daniel L.C. Mack <daniel.l.mack@vanderbilt.edu>
diff --git a/SA_POP_Types.h b/SA_POP_Types.h
index 3bb2ab35f77..ca25b37aac8 100644
--- a/SA_POP_Types.h
+++ b/SA_POP_Types.h
@@ -181,13 +181,13 @@ namespace SA_POP {
TaskInstID last_instance;
void note_instance(TaskInstID instance){
- if (last_instance > instance){
+ if (last_instance < instance){
this->last_instance = instance;
}
}
bool operator<(const SortTaskByTime & s) {
- return this->last_instance < s.last_instance;
+ return this->last_instance > s.last_instance;
}
bool operator!=(const SortTaskByTime & s) {
return this->last_instance != s.last_instance;
diff --git a/SA_PlanCommands.cpp b/SA_PlanCommands.cpp
index 78aa0b62aea..6f2b22764b4 100644
--- a/SA_PlanCommands.cpp
+++ b/SA_PlanCommands.cpp
@@ -180,10 +180,14 @@ PlanCommand *SA_AddTaskCmd::clone (void)
// Execute next option for this command.
bool SA_AddTaskCmd::execute_next (void)
{
+
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, this->get_log_text ());
+
this->undo();
+
+
bool isInitial = false;
if (this->tasks_.empty())
@@ -194,7 +198,6 @@ bool SA_AddTaskCmd::execute_next (void)
isInitial = true;
}
*/
-
this->working_plan_->execute (this);
this->num_tries_++;
@@ -207,8 +210,6 @@ void SA_AddTaskCmd::undo (void)
if (this->last_task_ == SA_POP::NULL_TASK_ID)
return;
-
-
this->working_plan_->undo (this);
if (this->tasks_.empty ()) {
@@ -315,14 +316,20 @@ bool SA_AssocTaskImplCmd::execute_next (void)
{
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, this->get_log_text ());
+ if(get_id().step == 12 && get_id().decision_pt == 2 && get_id().seq_num == 1){
+ bool k = true;
+ }
+
this->undo();
got_to_scheduling = false;
+
if (this->impls_.empty ()){
return false;
}
+
this->num_tries_++;
return this->working_plan_->execute (this);
//return true;
@@ -711,10 +718,12 @@ PlanCommand *SA_ResolveCLThreatCmd::clone (void)
bool SA_ResolveCLThreatCmd::execute_next (void)
{
bool goodOption = true;
- got_to_change_precedences = false;
+
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, this->get_log_text ());
if(choices == 0)
{
+ got_to_change_precedences = false;
+
//Add this next line to execute function
this->working_plan_->add_sched_link(this->threat.threat,this->threat.clink.first);
choices++;
@@ -736,6 +745,8 @@ bool SA_ResolveCLThreatCmd::execute_next (void)
{
this->undo();
+ got_to_change_precedences = false;
+
//Add this next line to execute function
this->working_plan_->add_sched_link(this->threat.clink.second, this->threat.threat);
choices++;
@@ -758,7 +769,6 @@ bool SA_ResolveCLThreatCmd::execute_next (void)
}
else
{
- // this->undo();
return false;
}
diff --git a/SA_PlanCommands.h b/SA_PlanCommands.h
index cce56c20656..2bef292181b 100644
--- a/SA_PlanCommands.h
+++ b/SA_PlanCommands.h
@@ -371,6 +371,12 @@ namespace SA_POP {
std::map <TaskInstID, TaskInstSet> afters;
std::map <TaskInstID, TaskInstSet> simuls;
std::map <TaskInstID, TaskInstSet> unrankeds;
+
+ std::map <TaskInstID, TaskInstSet> befores_after_ex;
+ 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_PlanHeuristics.cpp b/SA_PlanHeuristics.cpp
index 61c70128ed1..79a213e00c6 100644
--- a/SA_PlanHeuristics.cpp
+++ b/SA_PlanHeuristics.cpp
@@ -71,13 +71,18 @@ SA_TaskStrategy::~SA_TaskStrategy (void)
TaskChoiceList SA_TaskStrategy::choose_task_fair (Condition open_cond)
{
- TaskSet tasks = this->planner_->get_satisfying_tasks (open_cond);
- /*
- if(this->planner_->init_added){
- tasks.erase(20);
- }
- */
+ TaskSet tasks;
+
+ // if(this->planner_->get_working_plan()->get_all_insts().size() > 8){
+
+// TaskChoiceList s;
+ // s.clear();
+// return s;
+ // }
+
+ tasks = this->planner_->get_satisfying_tasks (open_cond);
+
// Add tasks to map with EU (to sort).
std::multimap<EUCalc, TaskID> task_map;
@@ -118,6 +123,10 @@ TaskChoiceList SA_TaskStrategy::choose_task_fair (Condition open_cond)
task_choice.task_inst_id = -2;
task_list.push_back(task_choice);
+
+
+
+
}else{
SortTaskByTime to_sort;
@@ -136,7 +145,9 @@ TaskChoiceList SA_TaskStrategy::choose_task_fair (Condition open_cond)
to_sort.note_instance(it->second);
}
- tasks_with_existing_instances.push_back(to_sort);
+ if(!(iter->second == 20 && this->planner_->init_added)){
+ tasks_with_existing_instances.push_back(to_sort);
+ }
}
}
@@ -145,32 +156,14 @@ TaskChoiceList SA_TaskStrategy::choose_task_fair (Condition open_cond)
for(std::vector<SortTaskByTime>::iterator it = tasks_with_existing_instances.begin(); it != tasks_with_existing_instances.end(); it++){
-
- if(it->task_id== 20 && this->planner_->init_added){
- continue;
- }
+
TaskChoice task_choice;
task_choice.choice = NEW_INST;
task_choice.task_id = it->task_id;
task_choice.task_inst_id = -2;
-
- }
-
- /*
-
- for(std::multimap<TaskID, TaskInstID>::iterator it = tasks_to_insts.lower_bound(iter->second); it != tasks_to_insts.upper_bound(iter->second);
- it++){
-
- TaskChoice task_choice;
- task_choice.choice = REUSE_INST;
- task_choice.task_id = it->first;
- task_choice.task_inst_id = it->second;
-
task_list.push_back(task_choice);
- }
- */
-
+ }
return task_list;
diff --git a/SA_PlanStrategy.cpp b/SA_PlanStrategy.cpp
index 4a8be2434f6..c5d7d97434d 100644
--- a/SA_PlanStrategy.cpp
+++ b/SA_PlanStrategy.cpp
@@ -19,6 +19,7 @@
#include "Planner.h"
#include "PlanHeuristics.h"
#include "PlanCommands.h"
+#include "SA_WorkingPlan.h"
#include <fstream>
using namespace SA_POP;
@@ -142,7 +143,7 @@ bool SA_PlanStrategy::satisfy_open_conds (void)
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_++;
@@ -156,6 +157,12 @@ bool SA_PlanStrategy::satisfy_open_conds (void)
// 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);
@@ -164,6 +171,9 @@ bool SA_PlanStrategy::satisfy_open_conds (void)
while (this->planner_->try_next (add_task_cmd->get_id ())) {
// Get current task and task instance.
this->cur_task_ = add_task_cmd->get_task ();
+
+ TaskInstID prev_cur_inst = this->cur_task_inst_;
+
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());
@@ -198,7 +208,7 @@ bool SA_PlanStrategy::satisfy_open_conds (void)
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.
@@ -218,9 +228,15 @@ bool SA_PlanStrategy::satisfy_open_conds (void)
// Undo addition of task.
this->planner_->undo_command (add_task_cmd->get_id ());
+
+
// Decrement step.
this->cur_step_--;
+ // }else{
+// std::cout<<"Backing up beccause of iterative deepening"<<std::endl;
+ // }
+
// No task could satisfy open condition, so return failure.
return false;
};
@@ -235,9 +251,7 @@ bool SA_PlanStrategy::satisfy_everything(){
TaskImplList impl_list;
// Choose a task implementation.
-
-// if(this->planner_->get_working_plan()->get_task_impl_from_inst(this->cur_task_inst_)== NULL_TASK_IMPL_ID){
- assoc_impl_cmd =
+ assoc_impl_cmd =
static_cast<AssocTaskImplCmd *> (this->assoc_impl_cmd_->clone ());
if(!this->planner_->inst_exists(this->cur_task_inst_)) impl_list = this->impl_choice_->choose_impl (this->cur_task_inst_);
else impl_list.push_back(this->planner_->get_impl_id(this->cur_task_inst_));
@@ -250,7 +264,8 @@ bool SA_PlanStrategy::satisfy_everything(){
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;
}
@@ -266,16 +281,7 @@ bool SA_PlanStrategy::satisfy_everything(){
planner_->undo_command(assoc_impl_cmd->get_id());
-// }else{
-// if(this->get_next_threat_resolution()){
- // return true;
- // }
-// else{
-
- this->cur_decision_pt_ = SA_PlanStrategy::IMPL_DECISION;
-// }
-// }
-
+ this->cur_decision_pt_ = SA_PlanStrategy::IMPL_DECISION;
return false;
}
@@ -312,6 +318,8 @@ bool SA_PlanStrategy::get_next_threat_resolution(){
//this->open_threats_.erase(threat);
+
+
this->cur_decision_pt_ = SA_PlanStrategy::THREAT_DECISION;
// this->cur_seq_num_ = 1;
diff --git a/SA_WorkingPlan.cpp b/SA_WorkingPlan.cpp
index 84667249ee1..eb4dd0b8ac5 100644
--- a/SA_WorkingPlan.cpp
+++ b/SA_WorkingPlan.cpp
@@ -647,6 +647,8 @@ AdjustMaxTimesCmd *SA_WorkingPlan::get_AdjustMaxTimesCmd (void)
void SA_WorkingPlan::execute (SA_AddTaskCmd *cmd)
{
+// if(cmd->id_.step == 13 && cmd->id_.decision_pt == 1 && cmd->id_.seq_num == 1 && cmd->task_choice == 20)
+
TaskChoice task_choice = cmd->tasks_.front();
TaskID task = task_choice.task_id;
TaskInstID task_inst;
@@ -656,8 +658,8 @@ void SA_WorkingPlan::execute (SA_AddTaskCmd *cmd)
if(task_choice.choice == REUSE_INST){
- task_inst = task_choice.task_inst_id;
- this->reused_insts_.insert(task_inst);
+ task_inst = task_choice.task_inst_id;
+ this->reused_insts_.insert(task_inst);
cmd->tasks_.pop_front();
}
else if(task_choice.choice == NEW_INST){
@@ -667,8 +669,9 @@ void SA_WorkingPlan::execute (SA_AddTaskCmd *cmd)
throw "Reached SA_WorkingPlan::execute (SA_AddTaskCmd *cmd) for Special Initial Action after it was already existing instance tried";
}
- if(task == 20)
+ if(task == 20){
this->planner_->init_added = true;
+ }
task_inst = this->get_next_inst_id ();
// Add task instance.
@@ -678,53 +681,6 @@ void SA_WorkingPlan::execute (SA_AddTaskCmd *cmd)
}
-/*
-
- // Get task ID, condition, and instance ID.
- TaskID task = cmd->tasks_.front ();
-
-
-
- Condition cond = cmd->cond_;
- TaskInstID task_inst;
- //bool hadInsts = false;
-
- // If trying a new task (i.e., not still trying task instances for same task), get existing task instances for that task from working plan.
- if(cmd->last_task_ != task)
- {
- // Get existing task instances for current task.
- for(InstToTaskMap::iterator iter = this->task_insts_.begin(); iter!=this->task_insts_.end();iter++)
- if(iter->second==cmd->tasks_.front())
- {
- //hadInsts = true;
- cmd->used_task_insts_.insert(iter->first);
- }
- }
-
-
- // If there are no/no-more existing task instances to try, create new task instance.
- if(cmd->used_task_insts_.empty())
- {
- if(task == 20 && this->planner_->init_added)
- {
- throw "Reached SA_WorkingPlan::execute (SA_AddTaskCmd *cmd) for Special Initial Action after it was already existing instance tried";
- }
-
- if(task == 20)
- this->planner_->init_added = true;
-
-
- }
- else
- {
- // Reuse the task instance
- task_inst = *cmd->used_task_insts_.begin();
- this->reused_insts_.insert(task_inst);
-
- // NOTE: task instance removed from existing task instances to try in undo.
- }
-
-*/
std::ostringstream debug_text;
debug_text << "SA_WorkingPlan::execute (SA_AddTaskCmd *cmd): Adding task (" << task << ") instance (" << task_inst << ") for condition (" << cond.id << ").";
@@ -768,81 +724,22 @@ void SA_WorkingPlan::execute (SA_AddTaskCmd *cmd)
cmd->last_task_inst_ = task_inst;
};
-//void note_ordering_link(TaskInstID first, TaskInstID second){
-
-// std::pair<CountedSchedulingLinks::iterator, CountedSchedulingLinks::iterator>
-// find_pair = ordering_links.equal_range(first);
-
-// CountedSchedulingLinks::iterator find_it;
-
-// for(find_it = find_pair.first; find_it != find_pair.second; find_it++){
-// if(find_it->second.first == second){
-/// break;
-// }
-// }
-
-// if(find_it == find_pair.second){
-// ordering_links.insert(std::pair<TaskInstID, std::pair<TaskInstID, int> >(first, std::pair<TaskInstID, int>(second, 1)));
-// reverse_ordering_links.insert(std::pair<TaskInstID, std::pair<TaskInstID, int> >(second, std::pair<TaskInstID, int>(first, 1)));
-// }else{
-
- // int prev_count = find_it->second.second;
-
- // ordering_links.insert(std::pair<TaskInstID, std::pair<TaskInstID, int> >(first, std::pair<TaskInstID, int>(second, prev_count+1)));
- // reverse_ordering_links.insert(std::pair<TaskInstID, std::pair<TaskInstID, int> >(second, std::pair<TaskInstID, int>(first, prev_count+1)));
-
-// }
-
-//}
-
-//void decrement_ordering_link(TaskInstID first, TaskInstID second){
-
-// std::pair<CountedSchedulingLinks::iterator, CountedSchedulingLinks::iterator>
-// find_pair = ordering_links.equal_range(first);
-
-// CountedSchedulingLinks::iterator find_it;
-
-// for(find_it = find_pair.
-
-//}
-
void SA_WorkingPlan::undo (SA_AddTaskCmd *cmd)
{
+
- if(cmd->last_task_ == 20)
- {
- planner_->init_added = false;
- }
if(cmd->last_task_choice_.choice == NEW_INST){
+ if(cmd->last_task_ == 20){
+ planner_->init_added = false;
+ }
+
this->task_insts_.erase (this->task_insts_.find(cmd->last_task_inst_));
}else{
this->reused_insts_.erase(this->reused_insts_.find(cmd->last_task_inst_));
}
-/*
- if(cmd->last_task_ == 20)
- {
- planner_->init_added = false;
- }
-
- if(cmd->used_task_insts_.empty())
- {
- // Remove task instance.
- this->task_insts_.erase (this->task_insts_.find(cmd->last_task_inst_));
- }
- else {
- // Remove the task instance from the set of reusable task instances
- cmd->used_task_insts_.erase(cmd->used_task_insts_.begin());
- this->reused_insts_.erase(this->reused_insts_.find(cmd->last_task_inst_));
- }
-*/
-
-
-
-
- // Remove causal links.
for (SA_WorkingPlan::CondToCLinksMap::iterator cl_iter =
this->causal_links_.lower_bound (cmd->cond_);
cl_iter != this->causal_links_.upper_bound (cmd->cond_);)
@@ -894,6 +791,9 @@ void SA_WorkingPlan::undo (SA_AddTaskCmd *cmd)
// task instance in the plan.
bool SA_WorkingPlan::execute (SA_AssocTaskImplCmd *cmd)
{
+
+
+
//cmd->precedence_graph_ = *this->precedence_graph_;
PrecedenceSet* befores = &this->precedence_graph_.find(BEFORE)->second;
@@ -926,42 +826,17 @@ bool SA_WorkingPlan::execute (SA_AssocTaskImplCmd *cmd)
return false;
}
-/*
-
- std::map<TaskInstID, bool> un_visited_map;
- std::map<TaskInstID, bool> visited_map;
- std::stack<TaskInstID> s;
-
- for(InstToTaskMap::iterator it = this->task_insts_.begin(); it != this->task_insts_.end(); it++){
- un_visited_map.insert(std::pair<TaskInstID, bool>(it->first, true));
-
- }
-
- int total_num = un_visited_map.size();
- while(!(s.size()== total_num)){
-
- std::map<TaskInstID, bool>::iterator some_it = un_visited_map.begin();
- TaskInstID next = some_it->first;
- dfs_aux(next, s, visited_map, un_visited_map);
- }
-
- visited_map.clear();
-
cmd->got_to_scheduling = true;
+
+ bool toReturn = this->init_prec_insert(cmd->task_inst_,cmd);
- while(!s.empty()){
- TaskInstID next = s.top();
- s.pop();
+ cmd->befores_after_ex = *befores;
+ cmd->afters_after_ex = *afters;
+ cmd->simuls_after_ex = *simuls;
+ cmd->unrankeds_after_ex = *unrankeds;
- if(!dfs_aux2(next, visited_map)){
- cmd->got_to_scheduling = false;
- return false;
- }
- }
-*/
+ return toReturn;
- cmd->got_to_scheduling = true;
- return this->init_prec_insert(cmd->task_inst_,cmd);
};
@@ -1012,7 +887,24 @@ bool SA_WorkingPlan::is_cycle_in_ordering(){
void SA_WorkingPlan::undo (SA_AssocTaskImplCmd *cmd)
{
// Undo the time window adjustments and the precedence graph updations.
+
+ 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;
+
+
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);
this->undo(&cmd->min_adj_cmd);
this->prec_erase(cmd->task_inst_,cmd);
@@ -1028,10 +920,7 @@ void SA_WorkingPlan::undo (SA_AssocTaskImplCmd *cmd)
this->task_impls_.erase (cmd->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;
+
if(cmd->befores != *befores ||
cmd->afters != *afters ||
@@ -1052,16 +941,32 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
std::ostringstream debug_text;
- TaskInstID first_task_inst = cmd->first;
- TaskInstID second_task_inst = cmd->second;
- Condition condition = cmd->condition;
+ TaskInstID first_task_inst = cmd->first;
+ TaskInstID second_task_inst = cmd->second;
+ 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));
+ 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){
@@ -1078,13 +983,14 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
debug_text.str("");
+ if(cmd->second == 12){
+ bool a = true;
+ }
+
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;
TaskInstSet *after_A = &afters->find(cmd->first)->second;
@@ -1097,6 +1003,9 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
TaskInstSet *unranked_B = &unrankeds->find(cmd->second)->second;
+
+
+
if(before_B->find(cmd->first) != before_B->end()){
//Don't need to resolve
@@ -1123,7 +1032,7 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
// loop_detected = true;
- cmd->got_to_change_precedences = false;
+// cmd->got_to_change_precedences = false;
return false;
}else{
@@ -1135,10 +1044,7 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
cmd->got_to_change_precedences = true;
- cmd->befores = *befores;
- cmd->afters = *afters;
- cmd->simuls = *simuls;
- cmd->unrankeds = *unrankeds;
+
TaskInstSet tmp;
@@ -1149,16 +1055,20 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
for(TaskInstSet::iterator it = before_A->begin(); it != before_A->end(); it++){
- /*
- if(after_B->find(*it) != after_B->end()){
- loop_detected = true;
- }
- */
before_B->insert(*it);
unranked_B->erase(*it);
afters->find(*it)->second.insert(cmd->second);
unrankeds->find(*it)->second.erase(cmd->second);
+
+
+ for(TaskInstSet::iterator it2 = after_B->begin(); it2 != after_B->end(); it2++){
+ befores->find(*it2)->second.insert(*it);
+ unrankeds->find(*it2)->second.erase(*it);
+
+ afters->find(*it)->second.insert(*it2);
+ unrankeds->find(*it)->second.erase(*it2);
+ }
}
after_A->insert(cmd->second);
@@ -1166,39 +1076,23 @@ bool SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd)
for(TaskInstSet::iterator it = after_B->begin(); it != after_B->end(); it++){
- /*
- if(before_A->find(*it) != before_A->end()){
- loop_detected = true;
- }
- */
after_A->insert(*it);
unranked_A->erase(*it);
befores->find(*it)->second.insert(cmd->first);
unrankeds->find(*it)->second.erase(cmd->first);
- }
- // if(loop_detected){
+ /*
+ for(TaskInstSet::iterator it2 = before_A->begin(); it2 != before_A->end(); it2++){
+ afters->find(*it2)->second.insert(*it);
+ unrankeds->find(*it2)->second.erase(*it);
- // 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;
+ befores->find(*it)->second.insert(*it2);
+ unrankeds->find(*it)->second.erase(*it2);
}
-*/
-
- // return false;
- // }
-
- /*
- if(is_cycle_in_ordering()){
- bool this_means_ben_failed = true;
+ */
}
- */
debug_text << "SA_WorkingPlan::execute (SA_ResolveCLThreatCmd * cmd): Now scheduling task "<<cmd->first<<" before "<<cmd->second<<std::endl;
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
@@ -1260,7 +1154,17 @@ void SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd)
std::ostringstream debug_text;
debug_text << "SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd): Undoing scheduling task "<<cmd->first<<" before "<<cmd->second<<std::endl;
-
+ if(!cmd->got_to_change_precedences){
+ debug_text <<" no changes to the precedence graph to undo"<<std::endl;
+
+ 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;
+// }
SA_POP_DEBUG_STR (SA_POP_DEBUG_NORMAL, debug_text.str ());
debug_text.str("");
@@ -1330,31 +1234,6 @@ void SA_WorkingPlan::undo (SA_ResolveCLThreatCmd * cmd)
}
this->reverse_ordering_links.erase(it);
-
-
- /*
-
- for(std::list<SA_ResolveCLThreatCmd*>::reverse_iterator iter=cmd->cmds_.rbegin();iter!=cmd->cmds_.rend();iter++)
- this->undo(*iter);
-
- TaskInstID first_task_inst = cmd->first;
- TaskInstID second_task_inst = cmd->second;
-
- PrecedenceSet *before = &this->precedence_graph_.find(BEFORE)->second;
- PrecedenceSet *after = &this->precedence_graph_.find(AFTER)->second;
- PrecedenceSet *unranked = &this->precedence_graph_.find(UNRANKED)->second;
-
- before->find(second_task_inst)->second.erase(before->find(second_task_inst)->second.find(first_task_inst));
- after->find(first_task_inst)->second.erase(after->find(first_task_inst)->second.find(second_task_inst));
- unranked->find(first_task_inst)->second.insert(second_task_inst);
- unranked->find(second_task_inst)->second.insert(first_task_inst);
- if(cmd->adj_max_times_cmd_ != NULL) {
- this->undo(cmd->adj_max_times_cmd_);
- }
- if(cmd->adj_min_times_cmd_ != NULL)this->undo(cmd->adj_min_times_cmd_);
-
-
- */
};
// Execute a command to resolve a scheduling conflict (i.e.
@@ -1788,6 +1667,10 @@ void SA_WorkingPlan::remove_sched_link(TaskInstID first_task_inst, TaskInstID se
// Update the precedence graph by inserting the task instance.
bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd *cmd)
{
+
+ if(cmd->get_id().step == 12 && cmd->get_id().decision_pt== 2 && cmd->get_id().seq_num == 1 && task_inst == 3)
+ bool yep = true;
+
TaskInstSet temp;
this->precedence_graph_.find(BEFORE)->second.insert(std::make_pair(task_inst,temp));
this->precedence_graph_.find(AFTER)->second.insert(std::make_pair(task_inst,temp));
@@ -1879,7 +1762,7 @@ bool SA_WorkingPlan::init_prec_insert(TaskInstID task_inst, SA_AssocTaskImplCmd
unranked = &this->precedence_graph_.find(UNRANKED)->second.find(task_inst)->second;
simul = &this->precedence_graph_.find(SIMUL)->second.find(task_inst)->second;
// If this task instance is not reused, insert all the task instances in it unranked set.
- if(unranked->empty())
+ if(unranked->empty() && (this->reused_insts_.find(task_inst)== this->reused_insts_.end()))
{
for(PrecedenceSet::iterator iter=this->precedence_graph_.find(BEFORE)->second.begin();iter!=this->precedence_graph_.find(BEFORE)->second.end();iter++)
{