Go to the documentation of this file.00001 #include <actasp/reasoners/FilteringReasoner.h>
00002
00003 #include <actasp/FilteringQueryGenerator.h>
00004
00005 #include <vector>
00006 #include <sstream>
00007 #include <boost/graph/graph_concepts.hpp>
00008
00009
00010 using namespace std;
00011
00012 namespace actasp {
00013
00014
00015 FilteringReasoner::FilteringReasoner(FilteringQueryGenerator *actualReasoner,unsigned int max_n,const ActionSet& allActions) :
00016 Reasoner(actualReasoner,max_n,allActions),
00017 clingo(actualReasoner) {}
00018
00019
00020 GraphPolicy *FilteringReasoner::computePolicy(const std::vector<actasp::AspRule>& goal, double suboptimality) const throw (std::logic_error) {
00021
00022 GraphPolicy *p = new GraphPolicy(allActions);
00023 computePolicyHelper(goal,suboptimality,p);
00024 return p;
00025 }
00026
00027
00028 struct AnswerSetStateComparator {
00029 bool operator()(const AnswerSet &first, const AnswerSet& second) const {
00030 return first.getFluentsAtTime(0).size() < second.getFluentsAtTime(0).size();
00031 }
00032
00033 };
00034
00035
00036
00037
00038
00039
00040 AnswerSet FilteringReasoner::filterState(const std::vector<actasp::AnswerSet>& plans, const std::vector<actasp::AspRule>& goals) {
00041
00042
00043 if (plans.empty() || goals.empty()) {
00044 return AnswerSet();
00045 }
00046
00047
00048 AnswerSet currentState = Reasoner::currentStateQuery(vector<AspRule>());
00049
00050 set<AspFluent> result;
00051
00052 std::vector<actasp::AnswerSet>::const_iterator planIt = plans.begin();
00053 for (; planIt != plans.end(); ++planIt) {
00054
00055 std::list<actasp::AnswerSet> listResult = clingo->filteringQuery(currentState,*planIt,goals);
00056 if (!listResult.empty()) {
00057 std::list<actasp::AnswerSet>::const_iterator best = min_element(listResult.begin(), listResult.end(),AnswerSetStateComparator());
00058 set<AspFluent> statezero = best->getFluentsAtTime(0);
00059 set<AspFluent>::const_iterator statezeroIt = statezero.begin();
00060 for (;statezeroIt != statezero.end(); ++statezeroIt) {
00061 result.insert(*statezeroIt);
00062 }
00063 }
00064
00065 }
00066
00067 return AnswerSet(result.begin(), result.end());
00068
00069 }
00070
00071 }