diff --git a/Makefile.am b/Makefile.am index 1c01d25..fb717b1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,7 +27,7 @@ mypop_SOURCES = VALfiles/DebugWriteController.cpp VALfiles/FastEnvironment.cpp \ SAS/dtg_graph.cpp SAS/property_space.cpp SAS/relaxed_reachability_analyst.cpp \ SAS/recursive_function.cpp \ action_manager.cpp bindings_propagator.cpp \ - formula.cpp logging.cpp mypop.cpp parser_utils.cpp \ + formula.cpp mypop.cpp parser_utils.cpp \ plan.cpp plan_bindings.cpp plan_flaws.cpp plan_orderings.cpp planner.cpp \ predicate_manager.cpp relaxed_planning_graph.cpp simple_flaw_selector.cpp term_manager.cpp \ type_manager.cpp diff --git a/SAS/transition.cpp b/SAS/transition.cpp index 9dc0da8..fa92de0 100644 --- a/SAS/transition.cpp +++ b/SAS/transition.cpp @@ -918,11 +918,11 @@ Transition* Transition::createTransition(const std::vector& enabler const std::vector* invariable_term = property_space_invariables[&property_space]; if (invariable_term == NULL) { - #ifdef ENABLE_MYPOP_SAS_TRANSITION_COMMENTS +#ifdef ENABLE_MYPOP_SAS_TRANSITION_COMMENTS std::cout << "Could not find the invariable term of "; bounded_atom->print(std::cout, bindings); std::cout << "[" << from_node.getIndex(*bounded_atom) << "]" << std::endl; - #endif +#endif continue; } diff --git a/action_manager.cpp b/action_manager.cpp index 9d99593..f5a06d2 100644 --- a/action_manager.cpp +++ b/action_manager.cpp @@ -4,10 +4,11 @@ #include "predicate_manager.h" #include "formula.h" #include "parser_utils.h" -#include "logging.h" #include "plan_bindings.h" #include "plan.h" +///#define MYPOP_ACTION_MANAGER_COMMENTS + namespace MyPOP { /************************* @@ -134,10 +135,9 @@ ActionManager::ActionManager(const TypeManager& type_manager, TermManager& term_ ActionManager::~ActionManager() { - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "[Destructor] ActionManager" << std::endl; - } +#ifdef MYPOP_ACTION_MANAGER_COMMENTS + std::cout << "[Destructor] ActionManager" << std::endl; +#endif } void ActionManager::processActions(const VAL::operator_list& operators) @@ -209,12 +209,11 @@ void ActionManager::processActions(const VAL::operator_list& operators) void ActionManager::getAchievingActions(std::vector >& actions, const Atom& atom) const { - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Find all the actions which can achieve "; - atom.print(std::cout); - std::cout << std::endl; - } +#ifdef MYPOP_ACTION_MANAGER_COMMENTS + std::cout << "Find all the actions which can achieve "; + atom.print(std::cout); + std::cout << std::endl; +#endif // Create a list of all action which have the same predicate. for (unsigned int i = 0; i < highest_id_; i++) diff --git a/formula.cpp b/formula.cpp index ecf8c85..826cc43 100644 --- a/formula.cpp +++ b/formula.cpp @@ -1,12 +1,13 @@ #include "formula.h" #include "term_manager.h" -#include "logging.h" #include "plan.h" #include "pointers.h" #include "plan_flaws.h" #include "plan_bindings.h" #include "predicate_manager.h" +///#define MYPOP_FORMULA_COMMENTS + namespace MyPOP { // Instantiate default formulea for true and false. @@ -56,10 +57,9 @@ Atom::Atom(const Predicate& predicate, const std::vector& terms, bo Atom::~Atom() { - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << predicate_ << " is deleted!" << std::endl; - } +#ifdef MYPOP_FORMULA_COMMENTS + std::cout << predicate_ << " is deleted!" << std::endl; +#endif delete terms_; } diff --git a/landmarks.cpp b/landmarks.cpp index 05ce17b..a09fd7a 100644 --- a/landmarks.cpp +++ b/landmarks.cpp @@ -23,6 +23,8 @@ #include "SAS/transition.h" //#include "SAS/reachability.h" +///#define MYPOP_LANDMARKS_COMMENTS + namespace MyPOP { namespace LANDMARKS { @@ -53,13 +55,12 @@ bool LandmarkOrderings::addOrdering(const Ordering& ordering) biggest_step_id_ = max_step_id; } - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Highest index " << biggest_step_id_ << std::endl; - std::cout << "Ordering size" << orderings_.size() << std::endl; - std::cout << "before id " << ordering.before_id() << std::endl; - std::cout << "after id " << ordering.after_id() << std::endl; - } +#ifdef MYPOP_LANDMARKS_COMMENTS + std::cout << "Highest index " << biggest_step_id_ << std::endl; + std::cout << "Ordering size" << orderings_.size() << std::endl; + std::cout << "before id " << ordering.before_id() << std::endl; + std::cout << "after id " << ordering.after_id() << std::endl; +#endif // Having extended the bitset. We continue by imposing the actual ordering constraint. (*orderings_[ordering.after_id()])[ordering.before_id()] = false; diff --git a/logging.cpp b/logging.cpp deleted file mode 100644 index 38cdb4a..0000000 --- a/logging.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -#include "logging.h" - -namespace MyPOP { - -namespace Logging { - -LogLevel verbosity = INFO; - -void setLogLevel(int log_level) -{ - switch (log_level) - { - case 0: - verbosity = DEBUG; - break; - case 1: - verbosity = INFO; - break; - case 2: - verbosity = WARNING; - break; - case 3: - verbosity = ERROR; - break; - default: - std::cout << "Unknown debug level " << log_level << std::endl; - assert(false); - } -} - -}; - -}; diff --git a/logging.h b/logging.h deleted file mode 100644 index 44c9468..0000000 --- a/logging.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MYPOP_LOGGING -#define MYPOP_LOGGING - -/** - * This class takes care of the logging of messages. We declare 4 levels of logging: - * DEBUG: These include messages one is only interested while debugging the application. - * INFO: Messages which are shown when one is interested in why decisions are made. - * WARNING: Messages which are shown indicating there is a potential problem. - * ERROR: Messages which are shown when a fatal error occured. The program should terminate - * after encountering an error message. - */ -namespace MyPOP { - -namespace Logging { - -enum LogLevel { DEBUG, INFO, WARNING, ERROR }; -const std::string LogLevelString[4] = { "DEBUG", "INFO", "WARNING", "ERROR" }; - -extern LogLevel verbosity; -void setLogLevel(int log_level); - -}; - -}; - -#endif diff --git a/manager.h b/manager.h index d6ab7a3..0c50576 100644 --- a/manager.h +++ b/manager.h @@ -3,7 +3,7 @@ #include -#include "logging.h" +///#define MYPOP_MANAGER_COMMENTS namespace MyPOP { @@ -49,10 +49,9 @@ class Manager { // Destroy all the stored objects. virtual ~Manager() { - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "[Destructor] Manager" << std::endl; - } +#ifdef MYPOP_MANAGER_COMMENTS + std::cout << "[Destructor] Manager" << std::endl; +#endif for (unsigned int i = 0; i < objects_.size(); i++) delete objects_[i]; diff --git a/mypop.cpp b/mypop.cpp index 028a01e..c0a78aa 100644 --- a/mypop.cpp +++ b/mypop.cpp @@ -5,8 +5,6 @@ #include #include -#include "logging.h" - #include "VALfiles/ptree.h" #include "VALfiles/TIM.h" #include "VALfiles/ToFunction.h" @@ -30,6 +28,8 @@ #include "relaxed_planning_graph.h" //#include "action_graph.h" +///#define MYPOP_COMMENTS + extern int yyparse(); extern int yydebug; @@ -55,33 +55,16 @@ int main(int argc,char * argv[]) { // The first line is the debug level. - if (argc != 4) + if (argc != 3) { - std::cout << "Usage: mypop ." << std::endl; - exit(0); + std::cout << "Usage: mypop ." << std::endl; + exit(1); } struct itimerval timer = { { 1000000, 900000 }, { 1000000, 900000 } }; setitimer ( ITIMER_PROF, &timer, NULL ); - int log_level = -1; - std::string log_level_str(argv[1]); - std::stringstream in(log_level_str); - in >> log_level; - - // Set the log level: - if (log_level < Logging::DEBUG || log_level > Logging::ERROR) - { - std::cout << "The log level should be between " << Logging::DEBUG << "(DEBUG) and " << Logging::ERROR << "(ERROR)." << std::endl; - exit(0); - } - Logging::setLogLevel(log_level); - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "Logging level set to " << Logging::LogLevelString[Logging::verbosity] << std::endl; - } - - TIM::performTIMAnalysis(&argv[2]); + TIM::performTIMAnalysis(&argv[1]); for_each(TA->pbegin(),TA->pend(), ptrwriter(cout,"\n")); for_each(TA->abegin(),TA->aend(), ptrwriter(cout,"\n")); @@ -188,34 +171,30 @@ int main(int argc,char * argv[]) // Create the initial step, which is a custom action with the atoms of the initial state as its effects. Action* initial_action = new Action("Initial action", Formula::TRUE, initial_action_variables, initial_effects); - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Print initial action" << std::endl; - std::cout << *initial_action << std::endl; - } +#ifdef MYPOP_COMMENTS + std::cout << "Print initial action" << std::endl; + std::cout << *initial_action << std::endl; +#endif // Create the goal, which is a custom action with the goal atoms as preconditions. - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Create goal action" << std::endl; - } +#ifdef MYPOP_COMMENTS + std::cout << "Create goal action" << std::endl; +#endif std::vector* goal_action_variables = new std::vector(); std::vector* goal_action_effects = new std::vector(); Action* goal_action = new Action("Goal action", *goal, goal_action_variables, goal_action_effects); - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Print goal action" << std::endl; - std::cout << *goal_action << std::endl; - } +#ifdef MYPOP_COMMENTS + std::cout << "Print goal action" << std::endl; + std::cout << *goal_action << std::endl; +#endif plan->makeInitialPlan(*initial_action, *goal_action); - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Initial plan" << *plan << std::endl; - } +#ifdef MYPOP_COMMENTS + std::cout << "Initial plan" << *plan << std::endl; +#endif assert (plan->getSteps().size() == 2); diff --git a/parser_utils.cpp b/parser_utils.cpp index dc15046..dde1fa2 100644 --- a/parser_utils.cpp +++ b/parser_utils.cpp @@ -5,7 +5,8 @@ #include "term_manager.h" #include "predicate_manager.h" #include "formula.h" -#include "logging.h" + +///#define MYPOP_PARSER_UTILS_COMMENTS namespace MyPOP { @@ -38,10 +39,7 @@ const Formula* Utility::convertGoal(const TermManager& term_manager, const Predi return con; } - if (Logging::verbosity <= Logging::ERROR) - { - std::cout << "Unsupported goal detected, quiting!" << std::endl; - } + std::cout << "Unsupported goal detected, quiting!" << std::endl; assert (false); } diff --git a/plan.cpp b/plan.cpp index a528c97..502a910 100644 --- a/plan.cpp +++ b/plan.cpp @@ -9,9 +9,10 @@ #include "plan_orderings.h" #include "formula.h" #include "plan_flaws.h" -#include "logging.h" #include "exceptions.h" +///#define MYPOP_PLAN_COMMENTS + namespace MyPOP { int Plan::plan_counter_ = -1; @@ -196,10 +197,9 @@ bool Plan::createCausalLink(StepPtr from_step, const Atom& supporting_effect, co if (!can_unify) { - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "Could not be unified :(" << std::endl; - } +#ifdef MYPOP_PLAN_COMMENTS + std::cout << "Could not be unified :(" << std::endl; +#endif return false; } @@ -250,10 +250,9 @@ bool Plan::isThreat(const Unsafe& unsafe) const if (!orderings_->canBeOrderedBefore((*step).getStepId(), StepTime::dummy_step_time, (*to_step).getStepId(), StepTime::dummy_step_time) || !orderings_->canBeOrderedAfter((*step).getStepId(), StepTime::dummy_step_time, (*from_step).getStepId(), StepTime::dummy_step_time)) { - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Ordering cannot be imposed for the step to be a threat!" << unsafe << std::endl; - } +#ifdef MYPOP_PLAN_COMMENTS + std::cout << "Ordering cannot be imposed for the step to be a threat!" << unsafe << std::endl; +#endif return false; } @@ -281,20 +280,18 @@ void Plan::checkThreat(StepPtr step, LinkPtr link) StepPtr to_step = (*link).getToStep(); const Atom& condition = (*link).getCondition(); - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Check treat by " << step->getStepId() << " to " << *link << std::endl; - } +#ifdef MYPOP_PLAN_COMMENTS + std::cout << "Check treat by " << step->getStepId() << " to " << *link << std::endl; +#endif // First of all check if this step could potentially interfere. I.e. it can be ordered before the // step related to the open condition or after the step which satisfies it. if (!orderings_->canBeOrderedBefore((*step).getStepId(), StepTime::dummy_step_time, (*to_step).getStepId(), StepTime::dummy_step_time) || !orderings_->canBeOrderedAfter((*step).getStepId(), StepTime::dummy_step_time, (*from_step).getStepId(), StepTime::dummy_step_time)) { - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Ordering cannot be imposed for the step to be a threat!" << *link << std::endl; - } +#ifdef MYPOP_PLAN_COMMENTS + std::cout << "Ordering cannot be imposed for the step to be a threat!" << *link << std::endl; +#endif return; } @@ -312,17 +309,18 @@ void Plan::checkThreat(StepPtr step, LinkPtr link) // Found a new unsafe! UnsafePtr unsafe(new Unsafe(step, *effect, link)); - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Found an unsafe relation: " << *unsafe << std::endl; - } +#ifdef MYPOP_PLAN_COMMENTS + std::cout << "Found an unsafe relation: " << *unsafe << std::endl; +#endif unsafes_.push_back(unsafe); } - else if (Logging::verbosity <= Logging::DEBUG) +#ifdef MYPOP_PLAN_COMMENTS + else { std::cout << "Does not affect!" << *link << std::endl; } +#endif } } diff --git a/plan_bindings.cpp b/plan_bindings.cpp index 8d82531..86ceb95 100644 --- a/plan_bindings.cpp +++ b/plan_bindings.cpp @@ -5,7 +5,6 @@ #include "term_manager.h" #include "predicate_manager.h" #include "plan.h" -#include "logging.h" #include "formula.h" #include "exceptions.h" #include "bindings_propagator.h" diff --git a/plan_orderings.cpp b/plan_orderings.cpp index 950b768..a9623ed 100644 --- a/plan_orderings.cpp +++ b/plan_orderings.cpp @@ -1,10 +1,11 @@ #include "plan_orderings.h" #include "plan.h" -#include "logging.h" #include +///#define MYPOP_PLAN_ORDERINGS_COMMENTS + namespace MyPOP { StepTime StepTime::dummy_step_time = StepTime(); @@ -97,13 +98,12 @@ bool BinaryOrderings::addOrdering(const Ordering& ordering) biggest_step_id_ = max_step_id; } - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Highest index " << biggest_step_id_ << std::endl; - std::cout << "Ordering size" << orderings_.size() << std::endl; - std::cout << "before id " << ordering.before_id() << std::endl; - std::cout << "after id " << ordering.after_id() << std::endl; - } +#ifdef MYPOP_PLAN_ORDERINGS_COMMENTS + std::cout << "Highest index " << biggest_step_id_ << std::endl; + std::cout << "Ordering size" << orderings_.size() << std::endl; + std::cout << "before id " << ordering.before_id() << std::endl; + std::cout << "after id " << ordering.after_id() << std::endl; +#endif // Having extended the bitset. We continue by imposing the actual ordering constraint. (*orderings_[ordering.after_id()])[ordering.before_id()] = false; diff --git a/planner.cpp b/planner.cpp index 7c17b44..7ac46aa 100644 --- a/planner.cpp +++ b/planner.cpp @@ -19,7 +19,9 @@ #include "action_manager.h" #include "predicate_manager.h" #include "plan_bindings.h" -#include "logging.h" + + +///#define MYPOP_PLANNER_COMMENTS namespace MyPOP { @@ -42,10 +44,9 @@ Planner::~Planner() { const Plan* plan = plans_.top(); delete plan; - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Delete plan!" << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "Delete plan!" << std::endl; +#endif plans_.pop(); } } @@ -56,11 +57,9 @@ const Plan* Planner::getSolution() while (!plans_.empty()) { const Plan* current_plan = plans_.top(); - if (Logging::verbosity <= Logging::INFO) - { - std::cout << Logging::verbosity << " v.s. " << Logging::INFO << std::endl; - std::cout << "*** Current plan:" << std::endl << *current_plan << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "*** Current plan:" << std::endl << *current_plan << std::endl; +#endif plans_.pop(); // If there are no more flaws to work on, return the plan! @@ -78,21 +77,19 @@ const Plan* Planner::getSolution() // Get all the refinements on this plan and put them into the queue. std::vector refinements; flaw.handleFlaw(refinements, *this, *current_plan); - if (Logging::verbosity <= Logging::INFO) +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "Possible refinements:" << std::endl; + for (std::vector::const_iterator ci = refinements.begin(); ci != refinements.end(); ci++) { - std::cout << "Possible refinements:" << std::endl; - for (std::vector::const_iterator ci = refinements.begin(); ci != refinements.end(); ci++) - { - std::cout << **ci << std::endl; - } + std::cout << **ci << std::endl; } +#endif if (refinements.size() == 0) { - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "Dead end..." << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "Dead end..." << std::endl; +#endif ++dead_ends_; } @@ -267,10 +264,7 @@ bool Planner::promote(std::vector& refinements, const Plan& plan, c void Planner::handleMutex(std::vector& refinement, const Plan& plan, const Mutex& mutex) { - if (Logging::verbosity <= Logging::ERROR) - { - std::cout << "Function not yet implemented!" << std::endl; - } + std::cout << "Function not yet implemented!" << std::endl; assert(false); } @@ -287,13 +281,12 @@ void Planner::handleUnsafe(std::vector& refinements, const Plan& pl // The effect. //const Atom& effect = unsafe.getEffect(); - if (Logging::verbosity <= Logging::INFO) - { - std::cout << unsafe << std::endl; - //std::cout << "Refine unsafe: " << *threatening_step << " -> " << *threatened_step << " Effect: "; - //effect.print(std::cout); - //std::cout << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << unsafe << std::endl; + //std::cout << "Refine unsafe: " << *threatening_step << " -> " << *threatened_step << " Effect: "; + //effect.print(std::cout); + //std::cout << std::endl; +#endif // Check if this unsafe is still valid, it might already been solved due to other orderings // and separations constraints added to the plan in an attempt to resolve other unsafes as well. @@ -320,31 +313,28 @@ void Planner::handleOpenCondition(std::vector& refinements, const P StepPtr step = oc.getStep(); const Atom& atom = oc.getAtom(); - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "Refine [" << step->getStepId() << "] "; - atom.print(std::cout); - std::cout << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "Refine [" << step->getStepId() << "] "; + atom.print(std::cout); + std::cout << std::endl; +#endif // Find all actions which can achieve the asked atom. std::vector > actions; action_manager_->getAchievingActions(actions, atom); - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "--- Possible achievers: " << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "--- Possible achievers: " << std::endl; +#endif for (std::vector >::const_iterator ci = actions.begin(); ci != actions.end(); ci++) { const Action* achieving_action = (*ci).first; const Atom* achieving_action_effect = (*ci).second; - if (Logging::verbosity <= Logging::INFO) - { - std::cout << *achieving_action << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << *achieving_action << std::endl; +#endif // The new step to be added. Plan* new_plan = new Plan(plan); @@ -353,27 +343,24 @@ void Planner::handleOpenCondition(std::vector& refinements, const P // Create a causal link. if (!new_plan->createCausalLink(new_step, *achieving_action_effect, oc, true)) { - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "Could not be impose causal link :(" << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "Could not be impose causal link :(" << std::endl; +#endif delete new_plan; continue; } - if (Logging::verbosity <= Logging::INFO) - { - std::cout << *new_plan << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << *new_plan << std::endl; +#endif refinements.push_back(new_plan); } // Next check if we can reuse any of the actions from the plan. const std::vector& steps = plan.getSteps(); - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "--- Possible actions to reuse: " << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "--- Possible actions to reuse: " << std::endl; +#endif for (std::vector::const_iterator ci = steps.begin(); ci != steps.end(); ci++) { StepPtr existing_step = *ci; @@ -381,19 +368,17 @@ void Planner::handleOpenCondition(std::vector& refinements, const P // Check if the step can be ordered before the step we want to support. if (!plan.getOrderings().canBeOrderedBefore((*existing_step).getStepId(), StepTime::dummy_step_time, (*step).getStepId(), StepTime::dummy_step_time)) { - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "We cannot order " << *existing_step << " before " << *step << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "We cannot order " << *existing_step << " before " << *step << std::endl; +#endif continue; } // Get the action. const Action& action = (*existing_step).getAction(); - if (Logging::verbosity <= Logging::INFO) - { - std::cout << action << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << action << std::endl; +#endif // Check if any of the effects can satisfy the open condition. std::vector achieving_effects; @@ -408,18 +393,16 @@ void Planner::handleOpenCondition(std::vector& refinements, const P Plan* new_plan = new Plan(plan); if (!new_plan->createCausalLink(existing_step, *achieving_effect, oc, false)) { - if (Logging::verbosity <= Logging::INFO) - { - std::cout << "Could not be impose causal link :(" << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << "Could not be impose causal link :(" << std::endl; +#endif delete new_plan; continue; } - if (Logging::verbosity <= Logging::INFO) - { - std::cout << *new_plan << std::endl; - } +#ifdef MYPOP_PLANNER_COMMENTS + std::cout << *new_plan << std::endl; +#endif refinements.push_back(new_plan); } } diff --git a/predicate_manager.cpp b/predicate_manager.cpp index bfa4b52..127c6d0 100644 --- a/predicate_manager.cpp +++ b/predicate_manager.cpp @@ -6,6 +6,8 @@ #include "type_manager.h" #include "formula.h" +///#define MYPOP_PREDICATE_COMMENTS + namespace MyPOP { //Predicate::Predicate(const std::string& name) @@ -151,7 +153,9 @@ void PredicateManager::processPredicates(const VAL::pred_decl_list& predicates) predicate_map_[std::make_pair(predicate_name, *types)] = predicate; addManagableObject(predicate); -// std::cout << "Predicate: " << *predicate << std::endl; +#ifdef MYPOP_PREDICATE_COMMENTS + std::cout << "Predicate: " << *predicate << std::endl; +#endif // Find the most generalised types. std::vector* general_types = NULL; @@ -166,7 +170,9 @@ void PredicateManager::processPredicates(const VAL::pred_decl_list& predicates) general_types = (*type_ci).second; } - //std::cout << "Find super types for: " << predicate_name << std::endl; +#ifdef MYPOP_PREDICATE_COMMENTS + std::cout << "Find super types for: " << predicate_name << std::endl; +#endif if (general_types->size() == 0) @@ -182,43 +188,67 @@ void PredicateManager::processPredicates(const VAL::pred_decl_list& predicates) { for (unsigned int i = 0; i < types->size(); i++) { - //std::cout << "Check " << i << "th type" << std::endl; const Type* current_type = (*types)[i]; - //std::cout << *current_type << std::endl; - //std::cout << " v.s. current general type: " << std::endl; - //std::cout << *(*general_types)[i] << std::endl; +#ifdef MYPOP_PREDICATE_COMMENTS + std::cout << "Check " << i << "th type" << std::endl; + std::cout << *current_type << std::endl; + std::cout << " v.s. current general type: " << std::endl; + std::cout << *(*general_types)[i] << std::endl; +#endif if ((*general_types)[i]->isSubtypeOf(*current_type)) { - //std::cout << "- " << *(*general_types)[i] << " is a subtype of " << *current_type << std::endl; +#ifdef MYPOP_PREDICATE_COMMENTS + std::cout << "- " << *(*general_types)[i] << " is a subtype of " << *current_type << std::endl; +#endif (*general_types)[i] = current_type; } else if ((*general_types)[i] != current_type && !current_type->isSubtypeOf(*(*general_types)[i])) { // If this type is not the same nor the subtype, we must find for the supertype both are members of. const Type* super_type = (*general_types)[i]->getSupertype(); + + ///std::cout << "The super type of the general type " << *(*general_types)[i] << " is " << *super_type << std::endl; + while (super_type != NULL && !current_type->isSubtypeOf(*super_type) && current_type != super_type) { - //std::cout << "- " << "Is: " << *super_type << " a super type of " << *current_type << "?" << std::endl; +#ifdef MYPOP_PREDICATE_COMMENTS + std::cout << "- " << "Is: " << *super_type << " a super type of " << *current_type << "?" << std::endl; +#endif super_type = super_type->getSupertype(); - +#ifdef MYPOP_PREDICATE_COMMENTS + if (super_type != NULL) + { + std::cout << "- New super type: " << *super_type << std::endl; + } + else + { + std::cout << "- No supertype found!" << std::endl; + } +#endif } assert (super_type != NULL); - //std::cout << "- " << "Super type!!!" << *super_type << std::endl; +#ifdef MYPOP_PREDICATE_COMMENTS + std::cout << "- " << "Super type!!!" << *super_type << std::endl; +#endif (*general_types)[i] = super_type; } else { - //std::cout << "- The same." << std::endl; +#ifdef MYPOP_PREDICATE_COMMENTS + std::cout << "- The same." << std::endl; +#endif } } } - //if (getGeneralPredicate(predicate_name) != NULL) - //{ - // std::cout << "Generalised types for predicate: " << *predicate << ": " << *getGeneralPredicate(predicate_name) << std::endl; - //} +#ifdef MYPOP_PREDICATE_COMMENTS + if (getGeneralPredicate(predicate_name) != NULL) + { + std::cout << "Generalised types for predicate: " << *predicate << ": " << *getGeneralPredicate(predicate_name) << std::endl; + } +#endif } } diff --git a/term_manager.cpp b/term_manager.cpp index 775564a..cf01ddc 100644 --- a/term_manager.cpp +++ b/term_manager.cpp @@ -1,8 +1,9 @@ #include "term_manager.h" #include "type_manager.h" -#include "logging.h" #include "plan_bindings.h" +///#define MYPOP_TERM_MANAGER_COMMENTS + namespace MyPOP { /************************* @@ -387,11 +388,6 @@ void TermManager::processActionVariables(const VAL::operator_list& operators) const Type* type = type_manager_->getType(parameter->type->getName()); Variable* var = new Variable(*type, parameter->getName()); addTerm(*parameter, *var); - - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "!!!!!" << *var << std::endl; - } } } } diff --git a/type_manager.cpp b/type_manager.cpp index 7235824..56972dd 100644 --- a/type_manager.cpp +++ b/type_manager.cpp @@ -5,9 +5,9 @@ #include "VALfiles/ptree.h" #include "type_manager.h" -#include "logging.h" #include "term_manager.h" +///#define MYPOP_TYPE_COMMENTS namespace MyPOP { @@ -141,40 +141,124 @@ void TypeManager::processTypes(const VAL::pddl_type_list& types) } // Show the results. - if (Logging::verbosity <= Logging::DEBUG) +#ifdef MYPOP_TYPE_COMMENTS + for (unsigned int i = 0; i < highest_id_; i++) + { + std::cout << *objects_[i] << std::endl; + + for (unsigned int j = 0; j < highest_id_; j++) { + if (objects_[i]->isSubtypeOf(*objects_[j])) + std::cout << "SUBTYPE OF: " << *objects_[j] << std::endl; + if (objects_[i]->isSupertypeOf(*objects_[j])) + std::cout << "SUPERTYPE OF: " << *objects_[j] << std::endl; + if (objects_[i]->isCompatible(*objects_[j])) + std::cout << "COMPATIBLE WITH: " << *objects_[j] << std::endl; + } + } +#endif +} + +bool TypeManager::containsSuperTypes(const VAL::pddl_type& type, VAL::pddl_type_list& other_types, bool* closed_list) const +{ +#ifdef MYPOP_TYPE_COMMENTS + std::cout << "Check if the type : " << type.getName() << " contains the following types: "; + for (VAL::pddl_type_list::const_iterator ci = other_types.begin(); ci != other_types.end(); ci++) { - for (unsigned int i = 0; i < highest_id_; i++) + const VAL::pddl_type* other_type = *ci; + std::cout << other_type->getName(); +/// if (ci != other_types.end() - 1) { - std::cout << *objects_[i] << std::endl; + std::cout << ", "; + } + } + std::cout << std::endl; +#endif - for (unsigned int j = 0; j < highest_id_; j++) { - if (objects_[i]->isSubtypeOf(*objects_[j])) - std::cout << "SUBTYPE OF: " << *objects_[j] << std::endl; - if (objects_[i]->isSupertypeOf(*objects_[j])) - std::cout << "SUPERTYPE OF: " << *objects_[j] << std::endl; - if (objects_[i]->isCompatible(*objects_[j])) - std::cout << "COMPATIBLE WITH: " << *objects_[j] << std::endl; + unsigned int counter = 0; + for (VAL::pddl_type_list::const_iterator ci = other_types.begin(); ci != other_types.end(); ci++) + { + const VAL::pddl_type* other_type = *ci; + if (other_type->getName() == type.getName()) + { + closed_list[counter] = true; + } + + const VAL::pddl_type* parent_type = type.type; + if (parent_type != NULL) + { + if (containsSuperTypes(*parent_type, other_types, closed_list)) + { + return true; } } + else + { + const VAL::pddl_type_list* parent_list = type.either_types; + if (parent_list != NULL) + { + for (VAL::pddl_type_list::const_iterator ci = parent_list->begin(); ci != parent_list->end(); ci++) + { + if (containsSuperTypes(**ci, other_types, closed_list)) + { + return true; + } + } + } + } + ++counter; } + + // Check if all types have been found. + bool done = true; + for (unsigned int i = 0; i < other_types.size(); i++) + { + if (!closed_list[i]) + { + done = false; + break; + } + } + if (done) return true; + else return false; } Type* TypeManager::processType(const VAL::pddl_type& type) { - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << type.getName() << "..." << std::endl; - } +#ifdef MYPOP_TYPE_COMMENTS + std::cout << type.getName() << "..." << std::endl; + + type.write(std::cout); +#endif const VAL::pddl_type* parent = type.type; Type* parent_type = NULL; + + // If a type has multiple supertypes, we assert that both have a common supertype. + // The parent pointer will be assigned to the most specific of the two. + if (parent == NULL) + { + VAL::pddl_type_list* parent_list = type.either_types; + + if (parent_list != NULL) + { + for (std::list::const_iterator ci = parent_list->begin(); ci != parent_list->end(); ci++) + { + const VAL::pddl_type* current_type = *ci; + bool closed_list[parent_list->size()]; + if (containsSuperTypes(*current_type, *parent_list, &closed_list[0])) + { + parent = current_type; + break; + } + } + } + } // If the type has a supertype, process this one first. if (parent != NULL) { - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << type.getName() << " has " << parent->getName() << " as a parent!" << std::endl; - } +#ifdef MYPOP_TYPE_COMMENTS + std::cout << type.getName() << " has " << parent->getName() << " as a parent!" << std::endl; +#endif // Check if the parent has already been constructed. std::map::const_iterator parent_ci = types_mapping_.find(parent->getName()); @@ -192,16 +276,16 @@ Type* TypeManager::processType(const VAL::pddl_type& type) assert (parent_type != NULL); } - else if (Logging::verbosity <= Logging::DEBUG) +#ifdef MYPOP_TYPE_COMMENTS + else { std::cout << type.getName() << " has no parents." << std::endl; } +#endif - - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Process " << type.getName() << std::endl; - } +#ifdef MYPOP_TYPE_COMMENTS + std::cout << "Process " << type.getName() << std::endl; +#endif // Create a new type with the given name if it hasn't already been created. std::map::const_iterator type_ci = types_mapping_.find(type.getName()); @@ -227,10 +311,9 @@ Type* TypeManager::processType(const VAL::pddl_type& type) new_type = (*type_ci).second; } - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << "Done! Return type: " << type.getName() << std::endl; - } +#ifdef MYPOP_TYPE_COMMENTS + std::cout << "Done! Return type: " << type.getName() << std::endl; +#endif return new_type; } @@ -252,10 +335,9 @@ void TypeManager::processObjects(TermManager& term_manager, const VAL::const_sym // Add the object as a term. term_manager.addTerm(*pddl_object, *object); - if (Logging::verbosity <= Logging::DEBUG) - { - std::cout << *object << std::endl; - } +#ifdef MYPOP_TYPE_COMMENTS + std::cout << *object << std::endl; +#endif } } diff --git a/type_manager.h b/type_manager.h index 0c43512..4bd17ed 100644 --- a/type_manager.h +++ b/type_manager.h @@ -112,6 +112,8 @@ class TypeManager : public Manager { void mapObjectToType(const Object& object, const Type& type); private: + + bool containsSuperTypes(const VAL::pddl_type& type, VAL::pddl_type_list& other_types, bool* closed_list) const; // During construction of the types keep track of the indexing from the // pddl type to TypeID. This allows us to instantiate all the types in a // single iteration.