From 20726f2bc109ce6bd1af1683a3e6640e27e87625 Mon Sep 17 00:00:00 2001 From: jkinnebrew Date: Tue, 12 Jan 2010 03:14:11 +0000 Subject: Tue Jan 12 03:11:44 UTC 2010 John S. Kinnebrew --- SA_POP/C2W/C2W_Demo.cpp | 445 ++++++++++++--------- SA_POP/C2W/C2W_Demo.mpc | 14 +- SA_POP/ChangeLog | 22 + SA_POP/Standalone/SA_POP_Demo.cpp | 100 ++++- SA_POP/UserInput/InputCL.h | 4 +- .../EU_Performance/Exp_Core/Exp_EU_Builder.cpp | 22 +- .../EU_Performance/Exp_Core/Exp_EU_Builder.h | 19 +- SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp | 348 +++++++++------- SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc | 20 +- SA_POP/experiments/EU_Performance/UserInput.cpp | 33 -- SA_POP/experiments/EU_Performance/UserInput.h | 42 -- 11 files changed, 624 insertions(+), 445 deletions(-) delete mode 100644 SA_POP/experiments/EU_Performance/UserInput.cpp delete mode 100644 SA_POP/experiments/EU_Performance/UserInput.h diff --git a/SA_POP/C2W/C2W_Demo.cpp b/SA_POP/C2W/C2W_Demo.cpp index d4beaab5d9d..9fcffccfa72 100644 --- a/SA_POP/C2W/C2W_Demo.cpp +++ b/SA_POP/C2W/C2W_Demo.cpp @@ -20,17 +20,51 @@ #include #include +#include +#include + #include "SA_POP_Types.h" #include "SA_Builder.h" -#include "UserInput.h" #include "TaskMapFileIn.h" #include "SANet/SANetFileIn.h" #include "LogScreenOut.h" #include "LogGraphOut.h" //#include "SA_POP_Utils.h" -#include -#include +#include "InputCL.h" + +// Additional SA-POP DEFAULT values for use in demo. +namespace SA_POP { + namespace Default { + const SA_POP::CondID CondIDMin = 1; + const SA_POP::CondID CondIDMax = 999999; + const SA_POP::Utility GoalUtilMin = -1000; + const SA_POP::Utility GoalUtilMax = 1000; + const SA_POP::Probability CondProbMin = 0.0; + const SA_POP::Probability CondProbMax = 1.0; + const size_t NumGoalsMin = 1; + const size_t NumGoalsMax = 10; + const size_t NumKnownCondsMin = 0; + const size_t NumKnownCondsMax = 100; + }; /* SA_POP::Default namespace */ +}; /* SA_POP namespace */ + +// Additional SANet DEFAULT values for use in demo. +namespace SANet { + namespace Default { + const size_t SA_MAX_STEPS = 1000; + }; /* SANet::Default namespace */ +}; /* SANet namespace */ + + +// Additional UI DEFAULT values for use in demo. +namespace UserInterface { + namespace C2W { + /// An enumerated type for user input in run loop. + enum NextKind {EFFECT, CONDITION, EXIT, INVALID}; + }; /* UserInterface::Testing namespace */ +}; /* UserInterface namespace */ + //Commands to run in the thread unsigned long WINAPI ThirdThread(PVOID pvParam) @@ -92,84 +126,49 @@ int main (int argc, char* argv[]) SA_POP::SA_Builder builder; SANet::SANetFileIn sanet_in; SA_POP::TaskMapFileIn tm_in; + SA_POP::Planner *planner = 0; + SA_POP::LogGraphOut graph_out (std::cout, false); + + UserInterface::InputCL user_input; std::string sanet_filename = ""; std::string tm_filename = ""; - std::vector * kconds = new std::vector; - std::vector toCheck; - std::map condMap; + size_t max_steps = SANet::Default::SA_MAX_STEPS; -/* - SA_POP::ListMultiMap intList; - - intList.insert(std::make_pair(1,2)); - intList.insert(std::make_pair(5,6)); - intList.insert(std::make_pair(5,7)); - - for (SA_POP::ListMultiMap::iterator list_iter = intList.lower_bound (5);list_iter != intList.upper_bound (5);list_iter++) - { - std::cout << list_iter->second << std::endl; - } + std::vector track_conds; + std::vector kconds; + std::map condMap; - for (SA_POP::ListMultiMap::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) - { - std::cout << list_iter->first << " FOR JOHN " <second << std::endl; - } - intList.erase(intList.lower_bound (5), intList.upper_bound (5)); - - for (SA_POP::ListMultiMap::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) - { - std::cout << list_iter->first << " FOR JOHN " <second << std::endl; - } - - intList.push_front(std::make_pair(9,9)); - intList.push_front(std::make_pair(8,8)); - intList.push_back(std::make_pair(7,7)); - - std::cout << "Front: " <::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) - { - std::cout << list_iter->first << " FOR JOHN " <second << std::endl; - } - std::cout << "Front: " <::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) - { - std::cout << list_iter->first << " FOR JOHN " <second << std::endl; + // Get filenames from user. + UserInterface::Question sanet_file_ques ("Task Network file:"); + if (user_input.ask (sanet_file_ques)) + sanet_filename = sanet_file_ques.get_answer (); + else { + std::cerr << "No Task Network filename provided." << std::endl; + throw "No Task Network filename provided."; } - intList.push_back(std::make_pair(7,7)); - std::cout << "Front: " <::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) - { - std::cout << list_iter->first << " FOR JOHN " <second << std::endl; + UserInterface::Question tm_file_ques ("Task Map file:"); + if (user_input.ask (tm_file_ques)) + tm_filename = tm_file_ques.get_answer (); + else { + std::cerr << "No Task Map filename provided." << std::endl; + throw "No Task Map filename provided."; } -*/ - - // Get filenames from user. - std::cout << "Task Network file: "; -// sanet_filename = "../examples/output1.xml"; -// sanet_filename = "../examples/SPACE.san.xml"; -// sanet_filename = "../examples/test_graph1.san.xml"; - std::cin >> sanet_filename; - std::cout << "Task Map file: "; -// tm_filename = "../examples/SPACE.tm.xml"; -// tm_filename = "../examples/test_graph.tm.xml"; - std::cin >> tm_filename; + + // Build task network and task map. + try { + sanet_in.build_net (sanet_filename, &builder); + tm_in.build_task_map (tm_filename, &builder); + } catch (std::string e) { + std::cerr << "ERROR while building task network and task map from files:"; + std::cerr << std::endl; + std::cerr << e; + } catch (...) { + std::cerr << "UNKNOWN ERROR while building task network and task map from files." << std::endl; + } + // Create empty goal. SA_POP::Goal goal; goal.goal_id = "UserSpecifiedGoal ID"; goal.name = "User specified goal"; @@ -178,71 +177,91 @@ int main (int argc, char* argv[]) goal.goal_conds.clear (); goal.start_window = std::make_pair (0, 0); - // Get goal(s). - int goal_num = 0; - std::cout << "Number of goals to find: "; - std::cin >> goal_num; - for(int g = 0; g < goal_num; g++) + + // Get number of goal conditions. + size_t num_goals = 0; + UserInterface::QuestionInt num_goals_ques ("Number of goal conditions:", SA_POP::Default::NumGoalsMin, SA_POP::Default::NumGoalsMax); + if (user_input.ask (num_goals_ques)) + num_goals = num_goals_ques.get_answer_int (); + else { + std::cerr << "Invalid number of goals provided." << std::endl; + throw "Invalid number of goals provided."; + } + + // Get condition ID and utility for each goal condition. + for(size_t g = 0; g < num_goals; g++) { - SA_POP::CondID goal_id; - SA_POP::Utility goal_util; - std::cout << "Goal condition ID: "; - std::cin >> goal_id; - std::cout << "Goal utility: "; - std::cin >> goal_util; - goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); + SA_POP::CondID goal_id = 0; + SA_POP::Utility goal_util = 0; + UserInterface::QuestionInt goal_id_ques ("Goal condition ID:", SA_POP::Default::CondIDMin, SA_POP::Default::CondIDMax); + if (user_input.ask (goal_id_ques)) + goal_id = goal_id_ques.get_answer_int (); + else { + std::cerr << "No valid goal condition ID provided." << std::endl; + throw "No valid goal condition ID provided."; + } + UserInterface::QuestionInt goal_util_ques ("Goal utility:", SA_POP::Default::GoalUtilMin, SA_POP::Default::GoalUtilMax); + if (user_input.ask (goal_util_ques)) + goal_util = goal_util_ques.get_answer_int (); + else { + std::cerr << "No valid goal condition utility provided." << std::endl; + throw "No valid goal condition utility provided."; + } + goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); } - try { - - - sanet_in.build_net (sanet_filename, &builder); - tm_in.build_task_map (tm_filename, &builder); + // Get SA-POP Planner. + planner = builder.get_planner (); + // Get number of initial conditions to set (different from probability value in initial network from XML). + size_t num_known_conds = 0; + UserInterface::QuestionInt num_known_conds_ques ("Number of intial conditions to set:", SA_POP::Default::NumKnownCondsMin, SA_POP::Default::NumKnownCondsMax); + if (user_input.ask (num_known_conds_ques)) + num_known_conds = num_known_conds_ques.get_answer_int (); - } - - catch (std::string e) { - std::cerr << "ERROR while building task network and task map from files:"; - std::cerr << std::endl; - std::cerr << e; - } catch (...) { - std::cerr << "UNKNOWN ERROR while building task network and task map from files." << std::endl; - } + // Set initial conditions. + for(size_t k = 0; k < num_known_conds; k++) + { + SA_POP::CondID cond_id = 0; + SA_POP::Probability cond_prob = 0; + UserInterface::QuestionInt cond_id_ques ("Initial condition ID:", SA_POP::Default::CondIDMin, SA_POP::Default::CondIDMax); + if (user_input.ask (cond_id_ques)) + cond_id = cond_id_ques.get_answer_int (); + else + break; - SA_POP::Planner *planner = 0; - SA_POP::LogGraphOut graph_out (std::cout, false); - - +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP +// TO DO: CREATE QuestionRange template class to replace QuestionInt and use one with a type of double for condition probability. + UserInterface::QuestionInt cond_prob_ques ("Initial condition probability (of true):", SA_POP::Default::CondProbMin, SA_POP::Default::CondProbMin); + if (user_input.ask (cond_prob_ques)) + cond_prob = cond_prob_ques.get_answer_int (); + else + break; +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP - // try { - planner = builder.get_planner (); + // Update condition to provided value. + planner->update_cond_val (cond_id, cond_prob); - //Set any probabilities not listed in the XML - int knownconds = 0; + // Add condition to known conditions list. + kconds.push_back(cond_id); + } - std::cout << "How many conditions do we know? "; - std::cin >> knownconds; + // Get maximum steps of spreading activation from user. + UserInterface::QuestionInt steps_ques("Max steps to run (10000 step limit): ", 0, 10000); + if (user_input.ask (steps_ques)) + max_steps = steps_ques.get_answer_int (); - for(int k = 0; k < knownconds; k++) - { - int cid = 0; - std::cout << "Enter the Condition ID you know:"; - std::cin >> cid; - SA_POP::CondID ccid = SA_POP::CondID(cid); - SANet::Probability newprob = SANet::Probability(1); - planner->update_cond_val(ccid, 1); - kconds->push_back(ccid); - - } + - int track = 0; + // Get number of conditions to track. + int track = 0; //Conditions to be potentially displayed std::cout << "How many conditions to track? "; std::cin >> track; + // Get conditions to track. for(int t = 0; t < track; t++) { int cid = 0; @@ -250,80 +269,73 @@ int main (int argc, char* argv[]) std::cin >> cid; SA_POP::CondID ccid = SA_POP::CondID(cid); condMap.insert(std::make_pair(ccid, 1)); - toCheck.push_back(ccid); + track_conds.push_back(ccid); } - //Configure the OutAdapters to use - SA_POP::LogScreenOut screen_out (std::cout); - graph_out.addTracking(toCheck); - planner->add_out_adapter (&graph_out); - //SA_POP::SchemaOut s_out (std::cout, *kconds); - //planner->add_out_adapter (&s_out); - //planner->add_out_adapter (&screen_out); + //Configure the OutAdapters to use + SA_POP::LogScreenOut screen_out (std::cout); + graph_out.addTracking(track_conds); + planner->add_out_adapter (&graph_out); + //SA_POP::SchemaOut s_out (std::cout, kconds); + //planner->add_out_adapter (&s_out); + //planner->add_out_adapter (&screen_out); - planner->plan (SA_POP::Default::SA_MAX_STEPS, goal); - SA_POP::Plan plan = planner->get_plan (); - SA_POP::Utility plan_eu = planner->calc_plan_eu (plan); + planner->plan (max_steps, goal); + SA_POP::Plan plan = planner->get_plan (); + SA_POP::Utility plan_eu = planner->calc_plan_eu (plan); + std::cout << "Expected utility of generated plan: " << plan_eu << std::endl; + + + UserInterface::QuestionChoice ques_next ("Negate an (E)ffect, change an external (C)ondition, or e(X)it:", UserInterface::C2W::INVALID, false); + ques_next.add_mapping ("E", UserInterface::C2W::EFFECT); + ques_next.add_mapping ("Effect", UserInterface::C2W::EFFECT); + ques_next.add_mapping ("C", UserInterface::C2W::CONDITION); + ques_next.add_mapping ("Condition", UserInterface::C2W::CONDITION); + ques_next.add_mapping ("X", UserInterface::C2W::EXIT); + ques_next.add_mapping ("Exit", UserInterface::C2W::EXIT); - std::cout << "Expected utility of generated plan: " << plan_eu << std::endl; - //} - /* - catch (std::string e) { - std::cerr << "ERROR while planning:" << std::endl; - std::cerr << e; - delete planner; - } catch (...) { - std::cerr << "UNKNOWN ERROR while planning." << std::endl; - delete planner; - } - */ - bool stop = false; while(!stop) { - - std::string step; - std::cout << "Would you like to advance to the next time step? (Y or N): "; - displayConds(planner, toCheck, &condMap); - std::cin >> step; - if(step == "Y" || step == "y") + displayConds(planner, track_conds, &condMap); + + UserInterface::QuestionBool adv_ques ("Advance to next time step? [(Y)es or (N)o]:", false); + user_input.ask (adv_ques); + if (adv_ques.get_answer_bool ()) { graph_out.moveStep(); - planner->plan (100, goal); + planner->plan (max_steps, goal); } else { - std::string eff; - std::cout << "Would you like to negate an effect, change an external condition, or stop? (E or C or S): "; - std::cin >>eff; - if(eff == "E" || eff == "e") - { + UserInterface::C2W::NextKind next_val = UserInterface::C2W::INVALID; + user_input.ask (ques_next); + next_val = ques_next.get_answer_val (); + + switch (next_val) + { + case UserInterface::C2W::EFFECT: SA_POP::TaskID curTask; SA_POP::CondID curEff; std::cout << "Enter the Task ID: "; std::cin >> curTask; std::cout << "Enter the Condition ID: "; std::cin >> curEff; - /* - SA_POP::SA_Builder rebuilder; - sanet_in.build_net (sanet_filename, &rebuilder); - tm_in.build_task_map (tm_filename, &rebuilder); - planner = rebuilder.get_planner (); - planner->add_out_adapter (&graph_out); - */ + for(std::map::iterator cIter = condMap.begin(); cIter != condMap.end(); cIter++) { planner->update_cond_val((*cIter).first, (*cIter).second); } planner->update_effect(curTask, curEff, -1); - //planner->plan(100, goal); - planner->replan(100, goal); - } - else if(eff == "C" || eff == "c") - { + planner->replan(max_steps, goal); + + break; + + case UserInterface::C2W::CONDITION: + { SA_POP::CondID envi; SA_POP::Probability newprob; std::cout << "Enter the Condition ID: "; @@ -332,44 +344,99 @@ int main (int argc, char* argv[]) std::cin >> newprob; std::map::iterator cmp = condMap.find(envi); if(cmp != condMap.end()) - { (*cmp).second = newprob; - } - /* - SA_POP::SA_Builder rebuilder; - sanet_in.build_net (sanet_filename, &rebuilder); - tm_in.build_task_map (tm_filename, &rebuilder); - planner = rebuilder.get_planner (); - planner->add_out_adapter (&graph_out); -*/ + for(std::map::iterator cIter = condMap.begin(); cIter != condMap.end(); cIter++) { planner->update_cond_val((*cIter).first, (*cIter).second); } - //planner->plan (100, goal); - planner->replan(100, goal); - } - else - { + planner->replan(max_steps, goal); + } + break; + + case UserInterface::C2W::EXIT: + case UserInterface::C2W::INVALID: + default: stop = true; - } + break; + } } } delete planner; -//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP - std::cout << "Enter any character to end program: "; - char temp_; - std::cin>>temp_; -//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + // Wait for user to end program. +// UserInterface::Question end_ques ("Enter any character to end program:"); +// user_input.ask (end_ques); _CrtDumpMemoryLeaks(); return 0; -} +}; +int test_listmultimap (void) +{ + SA_POP::ListMultiMap intList; + + intList.insert(std::make_pair(1,2)); + intList.insert(std::make_pair(5,6)); + intList.insert(std::make_pair(5,7)); + + for (SA_POP::ListMultiMap::iterator list_iter = intList.lower_bound (5);list_iter != intList.upper_bound (5);list_iter++) + { + std::cout << list_iter->second << std::endl; + } + + for (SA_POP::ListMultiMap::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) + { + std::cout << list_iter->first << " FOR JOHN " <second << std::endl; + } + + intList.erase(intList.lower_bound (5), intList.upper_bound (5)); + + for (SA_POP::ListMultiMap::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) + { + std::cout << list_iter->first << " FOR JOHN " <second << std::endl; + } + + intList.push_front(std::make_pair(9,9)); + intList.push_front(std::make_pair(8,8)); + intList.push_back(std::make_pair(7,7)); + + std::cout << "Front: " <::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) + { + std::cout << list_iter->first << " FOR JOHN " <second << std::endl; + } + std::cout << "Front: " <::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) + { + std::cout << list_iter->first << " FOR JOHN " <second << std::endl; + } + intList.push_back(std::make_pair(7,7)); + std::cout << "Front: " <::iterator list_iter = intList.begin();list_iter != intList.end();list_iter++) + { + std::cout << list_iter->first << " FOR JOHN " <second << std::endl; + } + + return 0; +}; diff --git a/SA_POP/C2W/C2W_Demo.mpc b/SA_POP/C2W/C2W_Demo.mpc index 389682f9982..cd2caf82e45 100644 --- a/SA_POP/C2W/C2W_Demo.mpc +++ b/SA_POP/C2W/C2W_Demo.mpc @@ -1,17 +1,19 @@ project(C2W_Demo) : xerces, aceexe, sapop_core_standalone { exename = C2W_Demo + includes += $(SAPOP_ROOT)/UserInput + + Header_Files { + $(SAPOP_ROOT)/UserInput/InputCL.h + $(SAPOP_ROOT)/UserInput/Question.h + } + Source_Files { C2W_Demo.cpp - UserInput.cpp - } - Inline_Files { + $(SAPOP_ROOT)/UserInput/InputCL.cpp } - Header_Files { - UserInput.h - } Documentation_Files { readme.txt diff --git a/SA_POP/ChangeLog b/SA_POP/ChangeLog index d37921220b4..63c32c21323 100644 --- a/SA_POP/ChangeLog +++ b/SA_POP/ChangeLog @@ -1,3 +1,25 @@ +Tue Jan 12 03:11:44 UTC 2010 John S. Kinnebrew + + * C2W/C2W_Demo.mpc: + * C2W/C2W_Demo.cpp: + * Standalone/SA_POP_Demo.cpp: + * UserInput/InputCL.h: + + User interface enhancements. + + * experiments/EU_Performance/UserInput.h: + * experiments/EU_Performance/UserInput.cpp: + + Removed unused files. + + * experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h: + * experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp: + * experiments/EU_Performance/SAPOP_Exp_EU.cpp: + * experiments/EU_Performance/SAPOP_Exp_EU.mpc: + + Continuing work on EU experiment. + + Fri Jan 8 20:59:42 UTC 2010 John S. Kinnebrew * Planner.h: diff --git a/SA_POP/Standalone/SA_POP_Demo.cpp b/SA_POP/Standalone/SA_POP_Demo.cpp index f80dc34699b..8b4cb44fec1 100644 --- a/SA_POP/Standalone/SA_POP_Demo.cpp +++ b/SA_POP/Standalone/SA_POP_Demo.cpp @@ -46,22 +46,27 @@ int main (int argc, char* argv[]) SANet::SANetFileIn sanet_in; SA_POP::TaskMapFileIn tm_in; SA_POP::Planner *planner = 0; - UserInterface::InputCL user_input; + UserInterface::InputCL user_input; std::string sanet_filename = ""; std::string tm_filename = ""; - SA_POP::CondID goal_id = 0; - SA_POP::Utility goal_util = 0; size_t max_steps = SANet::Default::SA_MAX_STEPS; - // Get filenames from user. UserInterface::Question sanet_file_ques ("Task Network file:"); if (user_input.ask (sanet_file_ques)) sanet_filename = sanet_file_ques.get_answer (); + else { + std::cerr << "No Task Network filename provided." << std::endl; + throw "No Task Network filename provided."; + } UserInterface::Question tm_file_ques ("Task Map file:"); if (user_input.ask (tm_file_ques)) tm_filename = tm_file_ques.get_answer (); + else { + std::cerr << "No Task Map filename provided." << std::endl; + throw "No Task Map filename provided."; + } // Build task network and task map. @@ -76,9 +81,7 @@ int main (int argc, char* argv[]) std::cerr << "UNKNOWN ERROR while building task network and task map from files." << std::endl; } - - - // Create goal. + // Create empty goal. SA_POP::Goal goal; goal.goal_id = "UserSpecifiedGoal ID"; goal.name = "User specified goal"; @@ -87,30 +90,85 @@ int main (int argc, char* argv[]) goal.goal_conds.clear (); goal.start_window = std::make_pair (0, 0); - // Get goal condition and utility from user. - UserInterface::QuestionInt goal_id_ques ("Goal condition ID:", SA_POP::Default::CondIDMin, SA_POP::Default::CondIDMax); - if (user_input.ask (goal_id_ques)) - goal_id = goal_id_ques.get_answer_int (); - UserInterface::QuestionInt goal_util_ques ("Goal utility:", SA_POP::Default::GoalUtilMin, SA_POP::Default::GoalUtilMax); - if (user_input.ask (goal_util_ques)) - goal_util = goal_util_ques.get_answer_int (); - goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); + // Get number of goal conditions. + size_t num_goals = 0; + UserInterface::QuestionInt num_goals_ques ("Number of goal conditions:", SA_POP::Default::NumGoalsMin, SA_POP::Default::NumGoalsMax); + if (user_input.ask (num_goals_ques)) + num_goals = num_goals_ques.get_answer_int (); + else { + std::cerr << "Invalid number of goals provided." << std::endl; + throw "Invalid number of goals provided."; + } + + // Get condition ID and utility for each goal condition. + for(size_t g = 0; g < num_goals; g++) + { + SA_POP::CondID goal_id = 0; + SA_POP::Utility goal_util = 0; + UserInterface::QuestionInt goal_id_ques ("Goal condition ID:", SA_POP::Default::CondIDMin, SA_POP::Default::CondIDMax); + if (user_input.ask (goal_id_ques)) + goal_id = goal_id_ques.get_answer_int (); + else { + std::cerr << "No valid goal condition ID provided." << std::endl; + throw "No valid goal condition ID provided."; + } + UserInterface::QuestionInt goal_util_ques ("Goal utility:", SA_POP::Default::GoalUtilMin, SA_POP::Default::GoalUtilMax); + if (user_input.ask (goal_util_ques)) + goal_util = goal_util_ques.get_answer_int (); + else { + std::cerr << "No valid goal condition utility provided." << std::endl; + throw "No valid goal condition utility provided."; + } + goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); + } + + // Get SA-POP Planner. + planner = builder.get_planner (); + + // Get number of initial conditions to set (different from probability value in initial network from XML). + size_t num_known_conds = 0; + UserInterface::QuestionInt num_known_conds_ques ("Number of intial conditions to set:", SA_POP::Default::NumKnownCondsMin, SA_POP::Default::NumKnownCondsMax); + if (user_input.ask (num_known_conds_ques)) + num_known_conds = num_known_conds_ques.get_answer_int (); + + // Set initial conditions. + for(size_t k = 0; k < num_known_conds; k++) + { + SA_POP::CondID cond_id = 0; + SA_POP::Probability cond_prob = 0; + + UserInterface::QuestionInt cond_id_ques ("Initial condition ID:", SA_POP::Default::CondIDMin, SA_POP::Default::CondIDMax); + if (user_input.ask (cond_id_ques)) + cond_id = cond_id_ques.get_answer_int (); + else + break; + +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP +// TO DO: CREATE QuestionRange template class to replace QuestionInt and use one with a type of double for condition probability. + UserInterface::QuestionInt cond_prob_ques ("Initial condition probability (of true):", SA_POP::Default::CondProbMin, SA_POP::Default::CondProbMin); + if (user_input.ask (cond_prob_ques)) + cond_prob = cond_prob_ques.get_answer_int (); + else + break; +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + + // Update condition to provided value. + planner->update_cond_val (cond_id, cond_prob); + } // Get maximum steps of spreading activation from user. UserInterface::QuestionInt steps_ques("Max steps to run (10000 step limit): ", 0, 10000); if (user_input.ask (steps_ques)) max_steps = steps_ques.get_answer_int (); - + // Add screen output adapter. + SA_POP::LogScreenOut screen_out (std::cout); + planner->add_out_adapter (&screen_out); + // Run SA-POP. try { - planner = builder.get_planner (); - - SA_POP::LogScreenOut screen_out (std::cout); - planner->add_out_adapter (&screen_out); - planner->plan (max_steps, goal); } catch (std::string e) { std::cerr << "ERROR while planning:" << std::endl; diff --git a/SA_POP/UserInput/InputCL.h b/SA_POP/UserInput/InputCL.h index 2656c967b6d..0d16b084e71 100644 --- a/SA_POP/UserInput/InputCL.h +++ b/SA_POP/UserInput/InputCL.h @@ -81,7 +81,9 @@ namespace UserInterface { - +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP +// TO DO: CREATE QuestionRange template class to replace QuestionInt. +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP /** * @class QuestionInt diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp index 70adb1b7377..34328291ce8 100644 --- a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp +++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.cpp @@ -6,7 +6,7 @@ * @file Exp_EU_Builder.cpp * * This file contains the implementation of the Exp_EU_Builder concrete class, - * which implements a Builder creating SA_Planner and associated + * which implements a Builder creating Exp_EU_Planner and associated * objects for planning with spreading activation networks and scheduling * with the "roadblock" scheduler (Exp_EU_SchedStrategy). * @@ -20,7 +20,9 @@ //#include "SA_Builder.h" #include "Exp_EU_Builder.h" -#include "Planner.h" +//#include "Planner.h" +#include "Exp_EU_Planner.h" + #include "SANet/SANet.h" #include "SA_PlanHeuristics.h" #include "SA_PlanStrategy.h" @@ -35,8 +37,9 @@ using namespace SA_POP; // Constructor. Exp_EU_Builder::Exp_EU_Builder (void) +: exp_eu_planner_ (0) { - // Nothing to do. + // All other initialization handled by SA_Builder base class constructor. }; // Destructor. @@ -53,7 +56,9 @@ void Exp_EU_Builder::init (void) this->is_init_ = true; // Create objects. - this->planner_ = new Planner (); + this->exp_eu_planner_ = new Exp_EU_Planner (); + this->planner_ = this->exp_eu_planner_; + this->sanet_ = new SANet::Network (); this->cond_choice_ = new SA_CondStrategy (this->planner_); this->task_choice_ = new SA_TaskStrategy (this->planner_); @@ -84,3 +89,12 @@ void Exp_EU_Builder::init (void) this->working_plan_, this->task_map_); }; + +// Get Exp_EU_Planner object. +Exp_EU_Planner *Exp_EU_Builder::get_exp_eu_planner (void) +{ + if (!this->is_init_) + this->init (); + return this->exp_eu_planner_; +}; + diff --git a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h index dd5abd51391..663df80df5e 100644 --- a/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h +++ b/SA_POP/experiments/EU_Performance/Exp_Core/Exp_EU_Builder.h @@ -6,7 +6,7 @@ * @file Exp_EU_Builder.h * * This file contains the definition of the Exp_EU_Builder concrete class, - * which implements a Builder creating SA_Planner and associated + * which implements a Builder creating Exp_EU_Planner and associated * objects for planning with spreading activation networks and scheduling * with the "roadblock" scheduler (Exp_EU_SchedStrategy). * @@ -26,7 +26,9 @@ //#include "Builder.h" #include "SA_Builder.h" -#include "Planner.h" +//#include "Planner.h" +#include "Exp_EU_Planner.h" + #include "SANet/SANet.h" #include "SA_PlanHeuristics.h" #include "SA_PlanStrategy.h" @@ -44,9 +46,9 @@ namespace SA_POP { /** * @class Exp_EU_Builder * - * @brief Builder concrete class for creating SA_Planner and + * @brief Builder concrete class for creating Exp_EU_Planner and * associated objects for planning with spreading activation networks - * and scheduling with the "roadblock" scheduler (Exp_EU_SchedStrategy). + * and scheduling with the "roadblock" scheduler (Exp_EU_SchedStrategy). */ class Exp_EU_Builder : public SA_Builder { public: @@ -56,7 +58,16 @@ namespace SA_POP { /// Destructor. virtual ~Exp_EU_Builder (void); + /// Get Exp_EU_Planner object. + /** + * @return Pointer to the configured planner object. + */ + virtual Exp_EU_Planner *get_exp_eu_planner (void); + protected: + /// Planner object to centralize/mediate planning (as Exp_EU_Planner pointer). + Exp_EU_Planner *exp_eu_planner_; + /// Create SA-POP objects. virtual void init (void); }; diff --git a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp index 257e989d3d0..107af895733 100644 --- a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp +++ b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.cpp @@ -3,11 +3,10 @@ //============================================================================= /** - * @file SA_POP_Demo.cpp + * @file SAPOP_Exp_EU.cpp * - * This file contains the main() function for the SA-POP demo. - * 11/19/08 Added the ability for multiple goals - dmack - * 11/25/08 Added the use of the LogGraph Out Adapter for Visual purposes - dmack + * This file contains the main() function for the SA-POP Expected Utility + * experiment. * * @author John S. Kinnebrew * @author Daniel L.C. Mack @@ -20,17 +19,53 @@ #include #include +#include +#include + #include "SA_POP_Types.h" #include "Exp_Core/Exp_EU_Builder.h" -#include "UserInput.h" +#include "Exp_Core/Exp_EU_Planner.h" #include "TaskMapFileIn.h" #include "SANet/SANetFileIn.h" #include "LogScreenOut.h" #include "LogGraphOut.h" //#include "SA_POP_Utils.h" -#include -#include +#include "InputCL.h" + +// Additional SA-POP DEFAULT values for use in demo. +namespace SA_POP { + namespace Default { + const SA_POP::CondID CondIDMin = 1; + const SA_POP::CondID CondIDMax = 999999; + const SA_POP::Utility GoalUtilMin = -1000; + const SA_POP::Utility GoalUtilMax = 1000; + const SA_POP::Probability CondProbMin = 0.0; + const SA_POP::Probability CondProbMax = 1.0; + const size_t NumGoalsMin = 1; + const size_t NumGoalsMax = 10; + const size_t NumKnownCondsMin = 0; + const size_t NumKnownCondsMax = 100; + }; /* SA_POP::Default namespace */ +}; /* SA_POP namespace */ + +// Additional SANet DEFAULT values for use in demo. +namespace SANet { + namespace Default { + const size_t SA_MAX_STEPS = 1000; + }; /* SANet::Default namespace */ +}; /* SANet namespace */ + + +// Additional UI DEFAULT values for use in demo. +namespace UserInterface { + namespace ExpEU { + /// An enumerated type for user input in run loop. + enum NextKind {EFFECT, CONDITION, EXIT, INVALID}; + }; /* UserInterface::Testing namespace */ +}; /* UserInterface namespace */ + + //Commands to run in the thread unsigned long WINAPI ThirdThread(PVOID pvParam) @@ -38,7 +73,7 @@ unsigned long WINAPI ThirdThread(PVOID pvParam) system("dot -Tgif cond.dot -o conds.gif"); //system("conds.gif"); return 0; -} +}; //for displaying conditions void displayConds(SA_POP::Planner *plans, std::vector checks, std::map *cMap) @@ -85,28 +120,61 @@ void displayConds(SA_POP::Planner *plans, std::vector checks, std 0, &dwThreadId); CloseHandle(tThread); -} +}; + + + + + + int main (int argc, char* argv[]) { SA_POP::Exp_EU_Builder builder; SANet::SANetFileIn sanet_in; SA_POP::TaskMapFileIn tm_in; + SA_POP::Exp_EU_Planner *planner = 0; + SA_POP::LogGraphOut graph_out (std::cout, false); + + UserInterface::InputCL user_input; std::string sanet_filename = ""; std::string tm_filename = ""; - std::vector * kconds = new std::vector; - std::vector toCheck; - std::map condMap; + size_t max_steps = SANet::Default::SA_MAX_STEPS; + + std::vector track_conds; + std::vector kconds; + std::map condMap; // Get filenames from user. - std::cout << "Task Network file: "; -// sanet_filename = "../../examples/simple/simple.san.xml"; - std::cin >> sanet_filename; + UserInterface::Question sanet_file_ques ("Task Network file:"); + if (user_input.ask (sanet_file_ques)) + sanet_filename = sanet_file_ques.get_answer (); + else { + std::cerr << "No Task Network filename provided." << std::endl; + throw "No Task Network filename provided."; + } + UserInterface::Question tm_file_ques ("Task Map file:"); + if (user_input.ask (tm_file_ques)) + tm_filename = tm_file_ques.get_answer (); + else { + std::cerr << "No Task Map filename provided." << std::endl; + throw "No Task Map filename provided."; + } - std::cout << "Task Map file: "; -// tm_filename = "../../examples/simple/simple.tm.xml"; - std::cin >> tm_filename; + + // Build task network and task map. + try { + sanet_in.build_net (sanet_filename, &builder); + tm_in.build_task_map (tm_filename, &builder); + } catch (std::string e) { + std::cerr << "ERROR while building task network and task map from files:"; + std::cerr << std::endl; + std::cerr << e; + } catch (...) { + std::cerr << "UNKNOWN ERROR while building task network and task map from files." << std::endl; + } + // Create empty goal. SA_POP::Goal goal; goal.goal_id = "UserSpecifiedGoal ID"; goal.name = "User specified goal"; @@ -115,71 +183,91 @@ int main (int argc, char* argv[]) goal.goal_conds.clear (); goal.start_window = std::make_pair (0, 0); - // Get goal(s). - int goal_num = 0; - std::cout << "Number of goals to find: "; - std::cin >> goal_num; - for(int g = 0; g < goal_num; g++) + + // Get number of goal conditions. + size_t num_goals = 0; + UserInterface::QuestionInt num_goals_ques ("Number of goal conditions:", SA_POP::Default::NumGoalsMin, SA_POP::Default::NumGoalsMax); + if (user_input.ask (num_goals_ques)) + num_goals = num_goals_ques.get_answer_int (); + else { + std::cerr << "Invalid number of goals provided." << std::endl; + throw "Invalid number of goals provided."; + } + + // Get condition ID and utility for each goal condition. + for(size_t g = 0; g < num_goals; g++) { - SA_POP::CondID goal_id; - SA_POP::Utility goal_util; - std::cout << "Goal condition ID: "; - std::cin >> goal_id; - std::cout << "Goal utility: "; - std::cin >> goal_util; - goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); + SA_POP::CondID goal_id = 0; + SA_POP::Utility goal_util = 0; + UserInterface::QuestionInt goal_id_ques ("Goal condition ID:", SA_POP::Default::CondIDMin, SA_POP::Default::CondIDMax); + if (user_input.ask (goal_id_ques)) + goal_id = goal_id_ques.get_answer_int (); + else { + std::cerr << "No valid goal condition ID provided." << std::endl; + throw "No valid goal condition ID provided."; + } + UserInterface::QuestionInt goal_util_ques ("Goal utility:", SA_POP::Default::GoalUtilMin, SA_POP::Default::GoalUtilMax); + if (user_input.ask (goal_util_ques)) + goal_util = goal_util_ques.get_answer_int (); + else { + std::cerr << "No valid goal condition utility provided." << std::endl; + throw "No valid goal condition utility provided."; + } + goal.goal_conds.insert (std::make_pair (goal_id, goal_util)); } - try { - - - sanet_in.build_net (sanet_filename, &builder); - tm_in.build_task_map (tm_filename, &builder); + // Get SA-POP Planner. + planner = builder.get_exp_eu_planner (); + // Get number of initial conditions to set (different from probability value in initial network from XML). + size_t num_known_conds = 0; + UserInterface::QuestionInt num_known_conds_ques ("Number of intial conditions to set:", SA_POP::Default::NumKnownCondsMin, SA_POP::Default::NumKnownCondsMax); + if (user_input.ask (num_known_conds_ques)) + num_known_conds = num_known_conds_ques.get_answer_int (); - } - - catch (std::string e) { - std::cerr << "ERROR while building task network and task map from files:"; - std::cerr << std::endl; - std::cerr << e; - } catch (...) { - std::cerr << "UNKNOWN ERROR while building task network and task map from files." << std::endl; - } - + // Set initial conditions. + for(size_t k = 0; k < num_known_conds; k++) + { + SA_POP::CondID cond_id = 0; + SA_POP::Probability cond_prob = 0; - SA_POP::Planner *planner = 0; - SA_POP::LogGraphOut graph_out (std::cout, false); - + UserInterface::QuestionInt cond_id_ques ("Initial condition ID:", SA_POP::Default::CondIDMin, SA_POP::Default::CondIDMax); + if (user_input.ask (cond_id_ques)) + cond_id = cond_id_ques.get_answer_int (); + else + break; +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP +// TO DO: CREATE QuestionRange template class to replace QuestionInt and use one with a type of double for condition probability. + UserInterface::QuestionInt cond_prob_ques ("Initial condition probability (of true):", SA_POP::Default::CondProbMin, SA_POP::Default::CondProbMin); + if (user_input.ask (cond_prob_ques)) + cond_prob = cond_prob_ques.get_answer_int (); + else + break; +//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP - // try { - planner = builder.get_planner (); + // Update condition to provided value. + planner->update_cond_val (cond_id, cond_prob); - //Set any probabilities not listed in the XML - int knownconds = 0; + // Add condition to known conditions list. + kconds.push_back(cond_id); + } - std::cout << "How many conditions do we know? "; - std::cin >> knownconds; + // Get maximum steps of spreading activation from user. + UserInterface::QuestionInt steps_ques("Max steps to run (10000 step limit): ", 0, 10000); + if (user_input.ask (steps_ques)) + max_steps = steps_ques.get_answer_int (); - for(int k = 0; k < knownconds; k++) - { - int cid = 0; - std::cout << "Enter the Condition ID you know:"; - std::cin >> cid; - SA_POP::CondID ccid = SA_POP::CondID(cid); - SANet::Probability newprob = SANet::Probability(1); - planner->update_cond_val(ccid, 1); - kconds->push_back(ccid); - - } + - int track = 0; + // Get number of conditions to track. + int track = 0; //Conditions to be potentially displayed std::cout << "How many conditions to track? "; std::cin >> track; + // Get conditions to track. for(int t = 0; t < track; t++) { int cid = 0; @@ -187,77 +275,73 @@ int main (int argc, char* argv[]) std::cin >> cid; SA_POP::CondID ccid = SA_POP::CondID(cid); condMap.insert(std::make_pair(ccid, 1)); - toCheck.push_back(ccid); + track_conds.push_back(ccid); } - //Configure the OutAdapters to use - SA_POP::LogScreenOut screen_out (std::cout); - graph_out.addTracking(toCheck); - planner->add_out_adapter (&graph_out); - //SA_POP::SchemaOut s_out (std::cout, *kconds); - //planner->add_out_adapter (&s_out); - //planner->add_out_adapter (&screen_out); - - planner->plan (15, goal); - planner->calculate_plan_utility(15); - - //} - /* - catch (std::string e) { - std::cerr << "ERROR while planning:" << std::endl; - std::cerr << e; - delete planner; - } catch (...) { - std::cerr << "UNKNOWN ERROR while planning." << std::endl; - delete planner; - } - */ - + //Configure the OutAdapters to use + SA_POP::LogScreenOut screen_out (std::cout); + graph_out.addTracking(track_conds); + planner->add_out_adapter (&graph_out); + //SA_POP::SchemaOut s_out (std::cout, kconds); + //planner->add_out_adapter (&s_out); + planner->add_out_adapter (&screen_out); + + planner->plan (max_steps, goal); + SA_POP::Plan plan = planner->get_plan (); + SA_POP::Utility plan_eu = planner->calc_plan_eu (plan); + std::cout << "Expected utility of generated plan: " << plan_eu << std::endl; + + + UserInterface::QuestionChoice ques_next ("Negate an (E)ffect, change an external (C)ondition, or e(X)it:", UserInterface::ExpEU::INVALID, false); + ques_next.add_mapping ("E", UserInterface::ExpEU::EFFECT); + ques_next.add_mapping ("Effect", UserInterface::ExpEU::EFFECT); + ques_next.add_mapping ("C", UserInterface::ExpEU::CONDITION); + ques_next.add_mapping ("Condition", UserInterface::ExpEU::CONDITION); + ques_next.add_mapping ("X", UserInterface::ExpEU::EXIT); + ques_next.add_mapping ("Exit", UserInterface::ExpEU::EXIT); + + bool stop = false; while(!stop) { - - std::string step; - std::cout << "Would you like to advance to the next time step? (Y or N): "; - displayConds(planner, toCheck, &condMap); - std::cin >> step; - if(step == "Y" || step == "y") + displayConds(planner, track_conds, &condMap); + + UserInterface::QuestionBool adv_ques ("Advance to next time step? [(Y)es or (N)o]:", false); + user_input.ask (adv_ques); + if (adv_ques.get_answer_bool ()) { graph_out.moveStep(); - planner->plan (100, goal); + planner->plan (max_steps, goal); } else { - std::string eff; - std::cout << "Would you like to negate an effect, change an external condition, or stop? (E or C or S): "; - std::cin >>eff; - if(eff == "E" || eff == "e") - { + UserInterface::ExpEU::NextKind next_val = UserInterface::ExpEU::INVALID; + user_input.ask (ques_next); + next_val = ques_next.get_answer_val (); + + switch (next_val) + { + case UserInterface::ExpEU::EFFECT: SA_POP::TaskID curTask; SA_POP::CondID curEff; std::cout << "Enter the Task ID: "; std::cin >> curTask; std::cout << "Enter the Condition ID: "; std::cin >> curEff; - /* - SA_POP::SA_Builder rebuilder; - sanet_in.build_net (sanet_filename, &rebuilder); - tm_in.build_task_map (tm_filename, &rebuilder); - planner = rebuilder.get_planner (); - planner->add_out_adapter (&graph_out); - */ + for(std::map::iterator cIter = condMap.begin(); cIter != condMap.end(); cIter++) { planner->update_cond_val((*cIter).first, (*cIter).second); } planner->update_effect(curTask, curEff, -1); - //planner->plan(100, goal); - planner->replan(100, goal); - } - else if(eff == "C" || eff == "c") - { + planner->replan(max_steps, goal); + + break; + + case UserInterface::ExpEU::CONDITION: + { SA_POP::CondID envi; SA_POP::Probability newprob; std::cout << "Enter the Condition ID: "; @@ -266,44 +350,36 @@ int main (int argc, char* argv[]) std::cin >> newprob; std::map::iterator cmp = condMap.find(envi); if(cmp != condMap.end()) - { (*cmp).second = newprob; - } - /* - SA_POP::SA_Builder rebuilder; - sanet_in.build_net (sanet_filename, &rebuilder); - tm_in.build_task_map (tm_filename, &rebuilder); - planner = rebuilder.get_planner (); - planner->add_out_adapter (&graph_out); -*/ + for(std::map::iterator cIter = condMap.begin(); cIter != condMap.end(); cIter++) { planner->update_cond_val((*cIter).first, (*cIter).second); } - //planner->plan (100, goal); - planner->replan(100, goal); - } - else - { + planner->replan(max_steps, goal); + } + break; + + case UserInterface::ExpEU::EXIT: + case UserInterface::ExpEU::INVALID: + default: stop = true; - } + break; + } } } delete planner; -//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP - std::cout << "Enter any character to end program: "; - char temp_; - std::cin>>temp_; -//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP + // Wait for user to end program. +// UserInterface::Question end_ques ("Enter any character to end program:"); +// user_input.ask (end_ques); _CrtDumpMemoryLeaks(); return 0; -} - +}; diff --git a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc index 5ae4ee81b6e..b49247fc495 100644 --- a/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc +++ b/SA_POP/experiments/EU_Performance/SAPOP_Exp_EU.mpc @@ -1,21 +1,21 @@ project(SAPOP_Exp_EU) : xerces, aceexe, sapop_xml { exename = SAPOP_Exp_EU - includes += $(SAPOP_ROOT) + includes += $(SAPOP_ROOT) + includes += $(SAPOP_ROOT)/UserInput - macros = SA_POP_HAS_ACE ACE_AS_STATIC_LIBS + macros = SA_POP_HAS_ACE ACE_AS_STATIC_LIBS - Source_Files { - SAPOP_Exp_EU.cpp - UserInput.cpp + Header_Files { + $(SAPOP_ROOT)/UserInput/InputCL.h + $(SAPOP_ROOT)/UserInput/Question.h } - Inline_Files { - } + Source_Files { + SAPOP_Exp_EU.cpp - Header_Files { - UserInput.h + $(SAPOP_ROOT)/UserInput/InputCL.cpp } Documentation_Files { @@ -28,6 +28,7 @@ project(SAPOP_Exp_EU) : xerces, aceexe, sapop_xml { Header_Files { Exp_Core/Exp_EU_Builder.h Exp_Core/Exp_EU_SchedStrategy.h + Exp_Core/Exp_EU_Planner.h $(SAPOP_ROOT)/SA_POP_Types.h @@ -74,6 +75,7 @@ project(SAPOP_Exp_EU) : xerces, aceexe, sapop_xml { Source_Files { Exp_Core/Exp_EU_Builder.cpp Exp_Core/Exp_EU_SchedStrategy.cpp + Exp_Core/Exp_EU_Planner.cpp $(SAPOP_ROOT)/SA_POP_Exceptions.cpp diff --git a/SA_POP/experiments/EU_Performance/UserInput.cpp b/SA_POP/experiments/EU_Performance/UserInput.cpp deleted file mode 100644 index a216b91cbff..00000000000 --- a/SA_POP/experiments/EU_Performance/UserInput.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// -*- C++ -*- -// $Id$ - -//============================================================================= -/** - * @file UserInput.cpp - * - * This file contains the UserInput class implementation for the input adapter - * that provides a user interface for testing SA-POP. - * - * @author John S. Kinnebrew - */ -//============================================================================= - -#include "SA_POP_Types.h" -#include "UserInput.h" -#include "Builder.h" -#include "Planner.h" - - -using namespace SA_POP; - -// Constructor. -UserInput::UserInput (void) -{ - //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP -}; - -// Destructor. -UserInput::~UserInput (void) -{ - //****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP -}; diff --git a/SA_POP/experiments/EU_Performance/UserInput.h b/SA_POP/experiments/EU_Performance/UserInput.h deleted file mode 100644 index b1b2b52111c..00000000000 --- a/SA_POP/experiments/EU_Performance/UserInput.h +++ /dev/null @@ -1,42 +0,0 @@ -// -*- C++ -*- -// $Id$ - -//============================================================================= -/** - * @file UserInput.h - * - * This file contains the UserInput class definition for the input adapter - * that provides a user interface for testing SA-POP. - * - * @author John S. Kinnebrew - */ -//============================================================================= - -#ifndef SA_POP_USER_INPUT_H_ -#define SA_POP_USER_INPUT_H_ - -#include "SA_POP_Types.h" -#include "UserInput.h" -#include "Builder.h" -#include "Planner.h" - - -namespace SA_POP { - - /** - * @class UserInput - * - * @brief Input adapter that provides a user interface for testing SA-POP. - */ - class UserInput { - public: - /// Constructor. - UserInput (void); - - /// Destructor. - virtual ~UserInput (void); - }; - -}; /* SA_POP namespace */ - -#endif /* SA_POP_USER_INPUT_H_ */ -- cgit v1.2.1