コード例 #1
0
ファイル: ValidatorAPI.cpp プロジェクト: KCL-Planning/ROSPlan
void executePlan (std::stringstream& plan_to_validate, TypeChecker & tc, const DerivationRules * derivRules, double tolerance, bool lengthDefault, bool giveAdvice)
{
	Ranking rnk;
	Ranking rnkInv;
	vector<string> failed;
	vector<string> queries;

	std::string name = "The master plan";

	plan * the_plan = getPlan (plan_to_validate, tc, failed, name);
	if (the_plan == 0) return;

	plan * copythe_plan = new plan (*the_plan);
	plan * planNoTimedLits = new plan();
	vector<plan_step *> timedInitialLiteralActions = getTimedInitialLiteralActions();
	double deadLine = 101;

	//add timed initial literals to the plan from the problem spec
	for (vector<plan_step *>::iterator ps = timedInitialLiteralActions.begin(); ps != timedInitialLiteralActions.end(); ++ps)
	{
		the_plan->push_back (*ps);
	};

	//add actions that are not to be moved to the timed intitial literals otherwise to the plan to be repaired
	//i.e. pretend these actions are timed initial literals
	for (pc_list<plan_step*>::const_iterator i = copythe_plan->begin(); i != copythe_plan->end(); ++i)
	{
		planNoTimedLits->push_back (*i);
	};

	copythe_plan->clear(); delete copythe_plan;

	PlanRepair pr (timedInitialLiteralActions, deadLine, derivRules, tolerance, tc, an_analysis.the_domain->ops,
	               an_analysis.the_problem->initial_state,
	               the_plan, planNoTimedLits, an_analysis.the_problem->metric, lengthDefault,
	               an_analysis.the_domain->isDurative(), an_analysis.the_problem->the_goal, current_analysis);

	if (Verbose)
		pr.getValidator().displayPlan();



	try
	{

		if (pr.getValidator().execute())
		{
			if (!Silent) cout << "Plan executed successfully - checking goal\n";

			if (pr.getValidator().checkGoal (an_analysis.the_problem->the_goal))

			{
				if (! (pr.getValidator().hasInvariantWarnings()))
				{
					rnk[pr.getValidator().finalValue() ].push_back (name);
					if (!Silent) *report << "Plan valid\n";
					if (!Silent) *report << "Final value: " << pr.getValidator().finalValue() << "\n";
				}
				else
				{
					rnkInv[pr.getValidator().finalValue() ].push_back (name);
					if (!Silent) *report << "Plan valid (subject to further invariant checks)\n";
					if (!Silent) *report << "Final value: " << pr.getValidator().finalValue();
				};
				if (Verbose)
				{
					pr.getValidator().reportViolations();
				};
			}
			else
			{
				failed.push_back (name);
				*report << "Goal not satisfied\n";

				*report << "Plan invalid\n";
				++errorCount;
			};

		}
		else
		{
			failed.push_back (name);
			++errorCount;
			if (ContinueAnyway)
			{
				cout << "\nPlan failed to execute - checking goal\n";

				if (!pr.getValidator().checkGoal (an_analysis.the_problem->the_goal)) *report << "\nGoal not satisfied\n";

			}

			else *report << "\nPlan failed to execute\n";


		};

		if (pr.getValidator().hasInvariantWarnings())
		{
			cout << "\n\n";
			*report << "This plan has the following further condition(s) to check:";
			cout << "\n\n";

			pr.getValidator().displayInvariantWarnings();
		};
	}
	catch (exception & e)
	{
		cout << "Error occurred in validation attempt:\n  " << e.what() << "\n";
		queries.push_back (name);

	};

	//display error report and plan repair advice
	if (giveAdvice && (Verbose || ErrorReport))
	{
		pr.firstPlanAdvice();
	};

	planNoTimedLits->clear(); delete planNoTimedLits;
	delete the_plan;

	if (!rnk.empty())
	{
		if (!Silent) cout << "\nSuccessful plans:";


		if (an_analysis.the_problem->metric &&
		    an_analysis.the_problem->metric->opt == E_MINIMIZE)
		{
			if (!Silent) for_each (rnk.begin(), rnk.end(), showList());

		}
		else
		{
			if (!Silent) for_each (rnk.rbegin(), rnk.rend(), showList());
		};



		*report << "\n";
	};

	if (!rnkInv.empty())
	{
		if (!Silent) cout << "\nSuccessful Plans Subject To Further Invariant Checks:";


		if (an_analysis.the_problem->metric &&
		    an_analysis.the_problem->metric->opt == E_MINIMIZE)
		{
			for_each (rnkInv.begin(), rnkInv.end(), showList());
		}
		else
		{
			for_each (rnkInv.rbegin(), rnkInv.rend(), showList());
		};



		*report << "\n";
	};

	if (!failed.empty())
	{
		cout << "\n\nFailed plans:\n ";
		copy (failed.begin(), failed.end(), ostream_iterator<string> (cout, " "));
		*report << "\n";
	};

	if (!queries.empty())
	{
		cout << "\n\nQueries (validator failed):\n ";
		copy (queries.begin(), queries.end(), ostream_iterator<string> (cout, " "));
		*report << "\n";
	};

};
コード例 #2
0
ファイル: PlanRec.cpp プロジェクト: Dunes/janitor
//execute all the plans in the usual manner without robustness checking
void executePlans(int & argc,char * argv[],int & argcount,TypeChecker & tc,const DerivationRules * derivRules,double tolerance,bool lengthDefault,bool giveAdvice)
{
  Ranking rnk;
  Ranking rnkInv;
  vector<string> failed;
  vector<string> queries;

	while(argcount < argc)
	{       
      string name(argv[argcount]);

      plan * the_plan = getPlan(argc,argv,argcount,tc,failed,name);
      if(the_plan == 0) continue;     

      plan * copythe_plan = new plan(*the_plan);
      plan * planNoTimedLits = new plan();
      vector<plan_step *> timedInitialLiteralActions = getTimedInitialLiteralActions();
      double deadLine = 101;

        //add timed initial literals to the plan from the problem spec
       for(vector<plan_step *>::iterator ps = timedInitialLiteralActions.begin(); ps != timedInitialLiteralActions.end(); ++ps)
       {
          the_plan->push_back(*ps);
       };

       //add actions that are not to be moved to the timed intitial literals otherwise to the plan to be repaired
       //i.e. pretend these actions are timed initial literals
       for(pc_list<plan_step*>::const_iterator i = copythe_plan->begin(); i != copythe_plan->end(); ++i)
       {
              planNoTimedLits->push_back(*i);
       };

       copythe_plan->clear(); delete copythe_plan;
       
       PlanRepair pr(timedInitialLiteralActions,deadLine,derivRules,tolerance,tc,current_analysis->the_domain->ops,
	    			current_analysis->the_problem->initial_state,
	    			the_plan,planNoTimedLits,current_analysis->the_problem->metric,lengthDefault,
	    			current_analysis->the_domain->isDurative(),current_analysis->the_problem->the_goal,current_analysis);

		PlanExecutionTracker pet(State(&(pr.getValidator()),current_analysis->the_problem->initial_state),&(pr.getValidator()));
		State::addObserver(&pet);
			
		if(LaTeX)
		{
			latex.LaTeXPlanReport(&(pr.getValidator()),the_plan);
		}
		else if(Verbose)
			pr.getValidator().displayPlan();



	    bool showGraphs = false;


	    try {

		    if(pr.getValidator().execute())
		    {
		    	if(LaTeX)
		    		*report << "Plan executed successfully - checking goal\\\\\n";
		    	else
		    		if(!Silent) cout << "Plan executed successfully - checking goal\n";

		    	if(pr.getValidator().checkGoal(current_analysis->the_problem->the_goal))

		    	{
		    		if(!(pr.getValidator().hasInvariantWarnings()))
		    		{
		    			rnk[pr.getValidator().finalValue()].push_back(name);
		    			if(!Silent && !LaTeX) *report << "Plan valid\n";
		    			if(LaTeX) *report << "\\\\\n";
		    			if(!Silent && !LaTeX) *report << "Final value: " << pr.getValidator().finalValue() << "\n";
		    		}
		    		else
		    		{
						rnkInv[pr.getValidator().finalValue()].push_back(name);
		    			if(!Silent && !LaTeX) *report << "Plan valid (subject to further invariant checks)\n";
		    			if(LaTeX) *report << "\\\\\n";
		    			if(!Silent && !LaTeX) *report << "Final value: " << pr.getValidator().finalValue();
		          };
		          	if(Verbose)
		          	{
		          		pr.getValidator().reportViolations();
		          	};
		    	}
		    	else
		    	{
		    		failed.push_back(name);
		    		*report << "Goal not satisfied\n";

		    		if(LaTeX) *report << "\\\\\n";
		    		*report << "Plan invalid\n";
				++errorCount;
			};

		    }
		    else
		    {
		    	failed.push_back(name);
			++errorCount;
         		    	if(ContinueAnyway)
                  {
                     if(LaTeX) *report << "\nPlan failed to execute - checking goal\\\\\n";
                     else cout << "\nPlan failed to execute - checking goal\n";

                     if(!pr.getValidator().checkGoal(current_analysis->the_problem->the_goal)) *report << "\nGoal not satisfied\n";

         		    }

                 else *report << "\nPlan failed to execute\n";


        };

              if(pr.getValidator().hasInvariantWarnings())
              {
						if(LaTeX)
							*report << "\\\\\n\\\\\n";
						else
							cout << "\n\n";


		    			*report << "This plan has the following further condition(s) to check:";

						if(LaTeX)
							*report << "\\\\\n\\\\\n";
						else
							cout << "\n\n";

						pr.getValidator().displayInvariantWarnings();
		    		};

		    if(pr.getValidator().graphsToShow()) showGraphs = true;
		    cout << pet;
		}
		catch(exception & e)
		{
			if(LaTeX)
			{
				*report << "\\error \\\\\n";
				*report << "\\end{tabbing}\n";
				*report << "Error occurred in validation attempt:\\\\\n  " << e.what() << "\n";
			}
			else
				cout << "Error occurred in validation attempt:\n  " << e.what() << "\n";

			queries.push_back(name);

		};

    //display error report and plan repair advice
      if(giveAdvice && (Verbose || ErrorReport))
     {
            pr.firstPlanAdvice();
      };

      //display LaTeX graphs of PNEs
    		if(LaTeX && showGraphs)
		{
			latex.LaTeXGraphs(&(pr.getValidator()));
		};

    //display gantt chart of plan
		if(LaTeX)
		{
			latex.LaTeXGantt(&(pr.getValidator()));

		};

    planNoTimedLits->clear(); delete planNoTimedLits;
    delete the_plan;
	};

	if(!rnk.empty())
	{
		if(LaTeX)
		{
			*report << "\\section{Successful Plans}\n";


		}
		else
			if(!Silent) cout << "\nSuccessful plans:";


		if(current_analysis->the_problem->metric &&
				current_analysis->the_problem->metric->opt == E_MINIMIZE)
		{
			if(LaTeX)
			{
				*report << "\\begin{tabbing}\n";
				*report << "{\\bf Value} \\qquad \\= {\\bf Plan}\\\\[0.8ex]\n";
			};


			if(!Silent && !LaTeX) for_each(rnk.begin(),rnk.end(),showList());

			if(LaTeX) *report << "\\end{tabbing}\n";

		}
		else
		{
			if(LaTeX)
			{
				*report << "\\begin{tabbing}\n";
				*report << "{\\bf Value} \\qquad \\= {\\bf Plan}\\\\[0.8ex]\n";
			};


			if(!Silent && !LaTeX) for_each(rnk.rbegin(),rnk.rend(),showList());



			if(LaTeX) *report << "\\end{tabbing}\n";
		};



		*report << "\n";
	};

	if(!rnkInv.empty())
	{
		if(LaTeX)
		{
			*report << "\\section{Successful Plans Subject To Further Checks}\n";

		}
		else

			if(!Silent) cout << "\nSuccessful Plans Subject To Further Invariant Checks:";


		if(current_analysis->the_problem->metric &&
				current_analysis->the_problem->metric->opt == E_MINIMIZE)
		{
			if(LaTeX)
			{
				*report << "\\begin{tabbing}\n";
				*report << "{\\bf Value} \\qquad \\= {\\bf Plan}\\\\[0.8ex]\n";
			};

			for_each(rnkInv.begin(),rnkInv.end(),showList());

			if(LaTeX) *report << "\\end{tabbing}\n";
		}
		else
		{
			if(LaTeX)
			{
				*report << "\\begin{tabbing}\n";
				*report << "{\\bf Value} \\qquad \\= {\\bf Plan}\\\\[0.8ex]\n";
			};

			for_each(rnkInv.rbegin(),rnkInv.rend(),showList());

			if(LaTeX) *report << "\\end{tabbing}\n";
		};



		*report << "\n";
	};

	if(!failed.empty())
	{
		if(LaTeX)
		{
			*report << "\\section{Failed Plans}\n";

		}
		else
			cout << "\n\nFailed plans:\n ";

		if(LaTeX)
			displayFailedLaTeXList(failed);
		else
			copy(failed.begin(),failed.end(),ostream_iterator<string>(cout," "));



		*report << "\n";
	};

	if(!queries.empty())
	{
		if(LaTeX)
		{
			*report << "\\section{Queries (validator failed)}\n";

		}
		else
			cout << "\n\nQueries (validator failed):\n ";

		if(LaTeX)
			displayFailedLaTeXList(queries);
		else
			copy(queries.begin(),queries.end(),ostream_iterator<string>(cout," "));



		*report << "\n";
	};

};