diff options
-rw-r--r-- | SA_POP/PlanHeuristics.h | 1 | ||||
-rw-r--r-- | SA_POP/SA_PlanHeuristics.cpp | 69 | ||||
-rw-r--r-- | SA_POP/SA_PlanHeuristics.h | 1 | ||||
-rw-r--r-- | SA_POP/SA_PlanStrategy.cpp | 2 | ||||
-rw-r--r-- | SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp | 6 | ||||
-rwxr-xr-x | SA_POP/utils/SANetGenerator/Net_Complete.py | 13 | ||||
-rwxr-xr-x | SA_POP/utils/SANetGenerator/Rand_Params.py | 24 | ||||
-rwxr-xr-x | SA_POP/utils/SANetGenerator/Rand_Skeletons.py | 96 |
8 files changed, 166 insertions, 46 deletions
diff --git a/SA_POP/PlanHeuristics.h b/SA_POP/PlanHeuristics.h index 9a2875eb3f2..79d1810ff76 100644 --- a/SA_POP/PlanHeuristics.h +++ b/SA_POP/PlanHeuristics.h @@ -93,6 +93,7 @@ namespace SA_POP { virtual TaskChoiceList choose_task_once(Condition open_cond) = 0; + virtual TaskChoiceList choose_task_once_optimistic (Condition open_cond) = 0; protected: /// Pointer to Planner object. diff --git a/SA_POP/SA_PlanHeuristics.cpp b/SA_POP/SA_PlanHeuristics.cpp index db2e8119f97..9696672f50d 100644 --- a/SA_POP/SA_PlanHeuristics.cpp +++ b/SA_POP/SA_PlanHeuristics.cpp @@ -319,6 +319,75 @@ TaskChoiceList SA_TaskStrategy::choose_task_once(Condition open_cond){ return task_list; } +TaskChoiceList SA_TaskStrategy::choose_task_once_optimistic(Condition open_cond){ + TaskSet tasks = this->planner_->get_satisfying_tasks (open_cond); + + // Add tasks to map with EU (to sort). + std::multimap<EUCalc, TaskID> task_map; + task_map.clear (); + for (TaskSet::iterator iter = tasks.begin (); iter != tasks.end (); iter++) + { + task_map.insert (std::make_pair ( + this->planner_->get_task_sa_eu (*iter), *iter)); + } + + std::multimap<TaskID, TaskInstID> tasks_to_insts; + + SA_WorkingPlan* working_plan = (SA_WorkingPlan*)this->planner_->get_working_plan(); + + InstToTaskMap inst_task_map = working_plan->get_task_insts(); + + for(InstToTaskMap::iterator it = inst_task_map.begin(); + it != inst_task_map.end(); it++){ + tasks_to_insts.insert(std::pair<TaskID, TaskInstID>(it->second, it->first)); + } + + // Add tasks to list in reverse order of map (highest EU first). + TaskChoiceList task_list; + task_list.clear (); + +//*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP***** + // WE NEED TO PUT A THRESHOLD ON PROBABILITY OF TRUE/FALSE INSTEAD OF COMPARING A DOUBLE TO A BOOL. + //If init can handle it, put it on here first + if(this->planner_->get_cond_val(open_cond.id) == open_cond.value){ +//*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP*****TEMP***** + TaskChoice init_choice; + init_choice.choice = REUSE_INST; + init_choice.task_id = INIT_TASK_ID; + init_choice.task_inst_id = INIT_TASK_INST_ID; + + task_list.push_back(init_choice); + }else{ + + for (std::multimap<EUCalc, TaskID>::reverse_iterator iter = task_map.rbegin (); + iter != task_map.rend (); iter++) + { + + 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); + } + + if(tasks_to_insts.find(iter->second) == tasks_to_insts.end()) + { + TaskChoice task_choice; + task_choice.choice = NEW_INST; + task_choice.task_id = iter->second; + task_choice.task_inst_id = -2; + + task_list.push_back(task_choice); + } + } + } + + return task_list; +} // Choose the (ordering of) task(s) to satisfy an open condition. diff --git a/SA_POP/SA_PlanHeuristics.h b/SA_POP/SA_PlanHeuristics.h index 28892fcac96..4d778f55d90 100644 --- a/SA_POP/SA_PlanHeuristics.h +++ b/SA_POP/SA_PlanHeuristics.h @@ -87,6 +87,7 @@ namespace SA_POP { virtual TaskChoiceList choose_task_once(Condition open_cond); + virtual TaskChoiceList choose_task_once_optimistic (Condition open_cond); }; /** diff --git a/SA_POP/SA_PlanStrategy.cpp b/SA_POP/SA_PlanStrategy.cpp index 1d0c1baf884..303f526fb48 100644 --- a/SA_POP/SA_PlanStrategy.cpp +++ b/SA_POP/SA_PlanStrategy.cpp @@ -579,7 +579,7 @@ AddTaskCmd *SA_PlanStrategy::satisfy_cond (Condition open_cond) // Get add task command. AddTaskCmd *add_task_cmd = static_cast<AddTaskCmd *> (this->add_task_cmd_->clone ()); - TaskChoiceList task_list = this->task_choice_->choose_task_once (open_cond); + TaskChoiceList task_list = this->task_choice_->choose_task_once_optimistic (open_cond); add_task_cmd->set_id (this->get_next_cmd_id ()); add_task_cmd->set_tasks (task_list); diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp index 3fab1d73cf3..d06575988b2 100644 --- a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp +++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Planner.cpp @@ -474,6 +474,12 @@ SA_POP::Goal Exp_EU_Planner::exp_init (SA_POP::Exp_EU_Trial_Params params) } } + //TEMP I really need to see cond values for a run -- Ben + std::cout<<std::endl; + for(SA_POP::CondSet::iterator cond_iter = conds.begin(); cond_iter != conds.end(); cond_iter++){ + std::cout<<"Value of "<<(*cond_iter).id<<" = "<<this->sanet_->get_cond_val((*cond_iter).id)<<std::endl; + } + std::cout<<std::endl; return goal; }; diff --git a/SA_POP/utils/SANetGenerator/Net_Complete.py b/SA_POP/utils/SANetGenerator/Net_Complete.py index 09bc5362d6a..c6665b80cfe 100755 --- a/SA_POP/utils/SANetGenerator/Net_Complete.py +++ b/SA_POP/utils/SANetGenerator/Net_Complete.py @@ -58,7 +58,16 @@ for each in conds: ofile.write("\"" + each +"\" [ style=filled, color = grey];\n") for edge in SANet.edges(): - ofile.write("\"" + edge[0] + "\" -> \"" + edge[1] + "\";\n") + if edge[0] in ParamInfo[3]: + elinks = ParamInfo[3][edge[0]] + weight = 0 + for link in elinks: + if link[0] == edge[1]: + weight = link[1] + break + ofile.write("\"" + edge[0] + "\" -> \"" + edge[1] + "\"[label=\"" + str(weight) + "\"];\n") + else: + ofile.write("\"" + edge[0] + "\" -> \"" + edge[1] + "\";\n") ofile.write("}\n") ofile.close() @@ -104,7 +113,7 @@ tfile.write("\n\n\t") for each in tasks: tfile.write("\n\t<taskImpl>\n\t\t<implID>" + each + "_1" + "</implID>\n\t\t<param>\n\t\t\t<paramID></paramID>\n\t\t\t<kind></kind>\n\t\t\t<value></value>\n\t\t</param>\n\t</taskImpl>\n" ) -tfile.write("\n\t<resource>\n\t\t<resourceID>Dack</resourceID>\n\t\t<kind>DISCRETE</kind>\n\t\t<capacity>1</capacity>\n\t</resource>\n") +tfile.write("\n\t<resource>\n\t\t<resourceID>Dack</resourceID>\n\t\t<kind>DISCRETE</kind>\n\t\t<capacity>1000</capacity>\n\t</resource>\n") for each in tasks: tfile.write("\n\t<taskToImpl>\n\t\t<taskID>" + str(ttonum[each]) + "</taskID>\n\t\t<implID>" + each + "_1" + "</implID>\n\t\t<duration>1</duration>\n\t</taskToImpl>\n") diff --git a/SA_POP/utils/SANetGenerator/Rand_Params.py b/SA_POP/utils/SANetGenerator/Rand_Params.py index 5efad373c31..23a24489a4a 100755 --- a/SA_POP/utils/SANetGenerator/Rand_Params.py +++ b/SA_POP/utils/SANetGenerator/Rand_Params.py @@ -22,10 +22,30 @@ def flatGen(SANet, tasks, conds): effects = SANet.successors(each) effLinks[each] = [] effAr = effLinks[each] + for eff in effects: + assigned = 0 #uses uniform for the time being - weight = rand.uniform(0,2) - 1 - #a tuple for efficient look up + edges = SANet.edges(eff) + #print eff + #print edges + #for edge in edges: + # #print eff + # if edge[1] == each: + # #print edge + # assigned = 1 + # weight = rand.uniform(-.8,-1) + # #print weight + # break + + if assigned == 0: + #dire = rand.uniform(0,2) - 1 + + #if dire >= 0: + weight = rand.uniform(.8,1) + #else: + # weight = rand.uniform(-.8,-1) + #a tuple for efficient look up lnk = (eff, weight) effAr.append(lnk) diff --git a/SA_POP/utils/SANetGenerator/Rand_Skeletons.py b/SA_POP/utils/SANetGenerator/Rand_Skeletons.py index 76b1ea05932..14f200e4b28 100755 --- a/SA_POP/utils/SANetGenerator/Rand_Skeletons.py +++ b/SA_POP/utils/SANetGenerator/Rand_Skeletons.py @@ -19,57 +19,71 @@ def erdosGen(SANet, tasks, conds, inDegree, outDegree): ctask = "" ccond = "" found = 0 - while found == 0: + #while found == 0: #Choose Task - ctask = tasks[rand.randrange(len(tasks))] + ctask = tasks[rand.randrange(len(tasks))] #Choose Cond - ccond = conds[rand.randrange(len(conds))] - key = ctask + "," + ccond + ccond = conds[rand.randrange(len(conds))] + key = ctask + "," + ccond #if already been used as either an effect or precondition - if key in pairs: - found = 0 - else: + # if key in pairs: + # found = 0 + # else: #valid pair for random pairing - found = 1 - pairs[key] = 1 + + #choose direction EfforPre = rand.randrange(2) - #If 0 then it's a precondition link - if EfforPre == 0 and haltIn == 0: - SANet.add_edge(ccond, ctask) - if ctask in inD: - inD[ctask] += 1 - else: - inD[ctask] = 1 - elif haltOut == 0: - #otherwise it's an effect - SANet.add_edge(ctask, ccond) - if ctask in outD: - outD[ctask] += 1 - else: - outD[ctask] = 1 + #if EfforPre == 0: + edges = SANet.edges(ccond) + for each in edges: + if each[1] == ctask: + found = 1 + break + #else: + edges = SANet.edges(ctask) + for each in edges: + if each[1] == ccond: + found = 1 + break + + if found == 0: + #If 0 then it's a precondition link + if EfforPre == 0 and haltIn == 0: + SANet.add_edge(ccond, ctask) + if ctask in inD: + inD[ctask] += 1 + else: + inD[ctask] = 1 + elif haltOut == 0: + #otherwise it's an effect + SANet.add_edge(ctask, ccond) + if ctask in outD: + outD[ctask] += 1 + else: + outD[ctask] = 1 - #Check for Stopping Conditions - totalIn = 0.0 - totalOut = 0.0 - for each in tasks: - if each in inD: - totalIn += inD[each] - if each in outD: - totalOut += outD[each] - avgIn = totalIn/len(tasks) - avgOut = totalOut/len(tasks) + #Check for Stopping Conditions + totalIn = 0.0 + totalOut = 0.0 + for each in tasks: + if each in inD: + totalIn += inD[each] + if each in outD: + totalOut += outD[each] + avgIn = totalIn/len(tasks) + avgOut = totalOut/len(tasks) - if avgIn >= inDegree: - haltIn = 1 - if avgOut >= outDegree: - haltOut = 1 - if haltIn == 1 and haltOut == 1: - print avgIn - print avgOut - haltGen = 1 + if avgIn >= inDegree: + haltIn = 1 + if avgOut >= outDegree: + haltOut = 1 + if haltIn == 1 and haltOut == 1: + print avgIn + print avgOut + haltGen = 1 return SANet
\ No newline at end of file |