.. _program_listing_file_src_popf_RPGBuilder.h: Program Listing for File RPGBuilder.h ===================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/popf/RPGBuilder.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /************************************************************************ * Copyright 2010, Strathclyde Planning Group, * Department of Computer and Information Sciences, * University of Strathclyde, Glasgow, UK * http://planning.cis.strath.ac.uk/ * * Andrew Coles, Amanda Coles - Code for POPF * Maria Fox, Richard Howey and Derek Long - Code from VAL * Stephen Cresswell - PDDL Parser * * This file is part of the planner POPF. * * POPF is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * POPF is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with POPF. If not, see . * ************************************************************************/ #ifndef __RPGBUILDER #define __RPGBUILDER #include #include #include #include #include using std::vector; using std::list; using std::set; using std::map; #include "minimalstate.h" #include "instantiation.h" #include "ptree.h" #include #include #include using namespace Inst; namespace Planner { class RPGHeuristic; class StartEvent; struct EpsilonComp { bool operator()(const double & a, const double & b) const { if (fabs(b - a) < 0.0005) return false; return (a < b); } }; class MinimalState; struct ActionFluentModification { int act; VAL::time_spec ts; bool openEnd; double change; int howManyTimes; bool assignment; ActionFluentModification(const int & a, const VAL::time_spec & startOrEnd, const bool & oe, const double & incr, const int & shots, const bool & ass) : act(a), ts(startOrEnd), openEnd(oe), change(incr), howManyTimes(shots), assignment(ass) {}; }; class ActionSegment { public: static int tilLimit; instantiatedOp* first; VAL::time_spec second; int divisionID; set needToFinish; ActionSegment() : first(0), second(VAL::E_OVER_ALL), divisionID(-1) { } ActionSegment(instantiatedOp* const f, const VAL::time_spec & s, const int & d, const set & n) : first(f), second(s), divisionID(d), needToFinish(n) { assert(second != VAL::E_AT || divisionID <= tilLimit); } ActionSegment(const ActionSegment & o) : first(o.first), second(o.second), divisionID(o.divisionID), needToFinish(o.needToFinish) { } virtual ~ActionSegment() { } }; struct InvData; class RPGBuilder { public: enum math_op { NE_ADD, NE_SUBTRACT, NE_MULTIPLY, NE_DIVIDE, NE_CONSTANT, NE_FLUENT, NE_VIOLATION}; static bool doSkipAnalysis; struct Operand { math_op numericOp; int fluentValue; double constantValue; string isviolated; Operand(const math_op & o) : numericOp(o), fluentValue(-1), constantValue(NAN) {}; Operand(const int & f) : numericOp(NE_FLUENT), fluentValue(f), constantValue(NAN) {}; Operand(const double & c) : numericOp(NE_CONSTANT), fluentValue(-1), constantValue(c) {}; Operand(const string & s) : numericOp(NE_VIOLATION), fluentValue(-1), constantValue(NAN), isviolated(s) {}; }; static double calculateRHS(const list & formula, vector & fluents); static pair constRHS(const list & formula); class NumericEffect { public: int fluentIndex; VAL::assign_op op; // how to update given fluent index (add to it, assign to it, etc.) list formula; // formula in postfix notation NumericEffect(const VAL::assign_op & opIn, const int & fIn, VAL::expression * formulaIn, VAL::FastEnvironment * f, VAL::TypeChecker * t = 0); double applyEffect(vector & fluents) const; void display(ostream & o) const; }; class NumericPrecondition { public: VAL::comparison_op op; // how to compare given fluent index to calculated RHS list LHSformula; // formula for LHS in postfix notation list RHSformula; // formula for RHS postfix notation bool valid; bool polarity; // false = it needs to be negated NumericPrecondition(const VAL::comparison_op & opIn, VAL::expression * LHSformulaIn, VAL::expression * RHSformulaIn, VAL::FastEnvironment * f, VAL::TypeChecker * t = 0, const bool negated = false); bool isSatisfied(vector & fluents) const; void display(ostream & o) const; double evaluateRHS(vector & fluentTable) const; pair constRHS() const; }; class ArtificialVariable { public: int ID; int size; vector weights; vector fluents; double constant; double maxNeed; ArtificialVariable() : ID(-1), size(0), constant(0.0), maxNeed(-DBL_MAX) {}; ArtificialVariable(const int & id, const int & s, const vector & w, const vector & f, const double & d, const double & maxIn) : ID(id), size(s), weights(w), fluents(f), constant(d), maxNeed(maxIn) {}; double evaluate(const vector & fluentTable) { double toReturn = constant; for (int i = 0; i < size; ++i) { if (fluents[i] < 0) { return std::numeric_limits::signaling_NaN(); } toReturn += weights[i] * fluentTable[fluents[i]]; } return toReturn; }; double evaluateWCalculate(const vector & fluentTable, const int & pneCount); double evaluateWCalculate(const vector & minFluentTable, const vector & maxFluentTable, const int & pneCount); bool operator <(const ArtificialVariable & v) const; void display(ostream & o) const; void updateMax(const double & m) { if (m > maxNeed) maxNeed = m; } }; class RPGNumericPrecondition { public: int ID; int LHSVariable; double LHSConstant; VAL::comparison_op op; int RHSVariable; double RHSConstant; RPGNumericPrecondition() : ID(-1), LHSVariable(-1), LHSConstant(0.0), op(VAL::E_GREATEQ), RHSVariable(-1), RHSConstant(0.0) {}; RPGNumericPrecondition(const int & i, const int & lv, const double & lw, const VAL::comparison_op & o, const double & rw) : ID(i), LHSVariable(lv), LHSConstant(lw), op(o), RHSVariable(-1), RHSConstant(rw) {}; bool isSatisfied(vector & maxFluents) const { if (LHSVariable < 0) return false; const double lv = maxFluents[LHSVariable]; if (lv == std::numeric_limits::signaling_NaN()) return false; if (op == VAL::E_GREATER) { return (lv > RHSConstant); } else { return (lv >= RHSConstant); } }; bool isSatisfiedWCalculate(const vector & maxFluents) const; bool isSatisfiedWCalculate(const vector & minFluents, const vector & maxFluents) const; bool operator <(const RPGNumericPrecondition & r) const; void display(ostream & o) const; }; class RPGNumericEffect { public: int ID; int fluentIndex; bool isAssignment; // if it's an assignmentOp - assume it's a += otherwise vector weights; vector variables; double constant; int size; RPGNumericEffect() : ID(-1), fluentIndex(-1), isAssignment(false), constant(NAN), size(-1) {}; RPGNumericEffect(const int & idIn, const int & fluent, const bool & ass, const vector & weightsIn, const vector & vars, const int & s, const double & con) : ID(idIn), fluentIndex(fluent), isAssignment(ass), weights(weightsIn), variables(vars), constant(con), size(s) {}; double evaluate(const vector & maxFluents, const double & minDur, const double & maxDur) const { double toReturn = constant; for (int i = 0; i < size; ++i) { if (variables[i] >= 0) { const double val = maxFluents[variables[i]]; if (val == DBL_MAX) return DBL_MAX; if (val == -DBL_MAX) return -DBL_MAX; toReturn += weights[i] * val; } else if (variables[i] == -3) { double lw = weights[i]; double toUse = maxDur; if (lw < 0) { lw *= -1.0; toUse = -minDur; } if (toUse == DBL_MAX) return DBL_MAX; if (toUse == -DBL_MAX) return -DBL_MAX; toReturn += lw * toUse; } else { assert(false); } } return toReturn; }; pair applyEffectMinMax(const vector & minFluents, const vector & maxFluents, const double & minDur, const double & maxDur); bool operator <(const RPGNumericEffect & e) const; void display(ostream & o) const; }; class DurationExpr { public: vector weights; vector variables; VAL::comparison_op op; double constant; DurationExpr() : weights(), variables(), constant(0.0) {}; DurationExpr(const double & d) : weights(0), variables(0), constant(d) {} ; double minOf(const vector & minVars, const vector & maxVars); double maxOf(const vector & minVars, const vector & maxVars); }; class RPGDuration { public: list fixed; list min; list max; // LPDuration() : fixed(0), min(0), max(0) {}; RPGDuration(list & eq, list & low, list & high) : fixed(eq), min(low), max(high) {}; const list & operator[](const int & i) const { switch (i) { case 0: return fixed; case 1: return min; case 2: return max; } assert(false); } }; class FakeTILAction { public: const double duration; list addEffects; list delEffects; void mergeIn(const LiteralSet & adds, const LiteralSet & dels) { { LiteralSet::iterator lsItr = adds.begin(); const LiteralSet::iterator lsEnd = adds.end(); for (; lsItr != lsEnd; ++lsItr) { addEffects.push_back(*lsItr); } } { LiteralSet::iterator lsItr = dels.begin(); const LiteralSet::iterator lsEnd = dels.end(); for (; lsItr != lsEnd; ++lsItr) { delEffects.push_back(*lsItr); } } } FakeTILAction(const double & dur, const LiteralSet & adds, const LiteralSet & dels) : duration(dur) { mergeIn(adds, dels); } }; class KShotFormula { public: KShotFormula() {}; virtual int getLimit(const MinimalState & s) const = 0; virtual int getOptimisticLimit(const MinimalState & s) const = 0; virtual ~KShotFormula() {}; }; class UnlimitedKShotFormula : public KShotFormula { public: UnlimitedKShotFormula() : KShotFormula() {}; virtual int getLimit(const MinimalState &) const { return INT_MAX; }; virtual int getOptimisticLimit(const MinimalState &) const { return INT_MAX; }; }; class OneShotKShotFormula : public KShotFormula { private: list watchedLiterals; public: OneShotKShotFormula(list & toWatch) : KShotFormula(), watchedLiterals(toWatch) {}; virtual int getLimit(const MinimalState & s) const; virtual int getOptimisticLimit(const MinimalState & s) const; }; struct ShotCalculator { int variable; double greaterThan; double decreaseBy; ShotCalculator(const int & v, const double & g, const double & d) : variable(v), greaterThan(g), decreaseBy(d) {}; }; class KShotKShotFormula : public KShotFormula { private: list formulae; public: KShotKShotFormula(list & c) : KShotFormula(), formulae(c) {}; virtual int getLimit(const MinimalState & s) const; virtual int getOptimisticLimit(const MinimalState & s) const; }; class LinearEffects { public: struct EffectExpression { vector weights; vector variables; double constant; EffectExpression(const double & g) : weights(0), variables(0), constant(g) {}; }; // vector durations; vector vars; vector > effects; // double totalDuration; int divisions; }; class Metric { public: bool minimise; list weights; list variables; Metric(const bool & m) : minimise(m) {}; }; static Metric * theMetric; static set metricVars; struct Constraint { string name; VAL::constraint_sort cons; list goal; list trigger; list goalNum; list triggerNum; list goalRPGNum; list triggerRPGNum; double deadline; double from; double cost; bool neverTrue; Constraint() : deadline(0.0), from(0.0), cost(0.0), neverTrue(false) {}; Constraint(const string & n) : name(n), deadline(0.0), from(0.0), cost(0.0), neverTrue(false) {}; }; class ConditionalEffect { private: list > propositionalConditions; list > numericPreconditions; list > numericEffects; list > propositionalAddEffects; list > propositionalDeleteEffects; public: ConditionalEffect() { } void addCondition(Literal * const l, const VAL::time_spec & t) { propositionalConditions.push_back(make_pair(l, t)); } void addCondition(const int & p, const VAL::time_spec & t) { numericPreconditions.push_back(make_pair(p, t)); } void addNumericEffect(const int & p, const VAL::time_spec & t) { numericEffects.push_back(make_pair(p, t)); } void addAddEffect(Literal * const l, const VAL::time_spec & t) { propositionalAddEffects.push_back(make_pair(l, t)); } void addDeleteEffect(Literal * const l, const VAL::time_spec & t) { propositionalDeleteEffects.push_back(make_pair(l, t)); } const list > & getPropositionalConditions() const { return propositionalConditions; } const list > & getNumericPreconditions() const { return numericPreconditions; } const list > & getNumericEffects() const { return numericEffects; } const list > & getPropositionalAddEffects() const { return propositionalAddEffects; } const list > & getPropositionalDeleteEffects() const { return propositionalDeleteEffects; } }; class NoDuplicatePair { protected: list * first; LiteralSet * second; public: NoDuplicatePair() : first((list*)0), second((LiteralSet*)0) { } NoDuplicatePair(list * const listIn, LiteralSet* const setIn) : first(listIn), second(setIn) { } void push_back(Literal* const toAdd) { if (second->insert(toAdd).second) { first->push_back(toAdd); } } Literal* back() const { return first->back(); } bool operator!() const { return (!first); } template void insert(T itr, const T & itrEnd) { for (; itr != itrEnd; ++itr) { push_back(*itr); } }; }; class ProtoConditionalEffect { public: list startPrec; LiteralSet startPrecSet; list inv; LiteralSet invSet; list endPrec; LiteralSet endPrecSet; list startNegPrec; LiteralSet startNegPrecSet; list negInv; LiteralSet negInvSet; list endNegPrec; LiteralSet endNegPrecSet; list startPrecNumeric; list invNumeric; list endPrecNumeric; list startAddEff; LiteralSet startAddEffSet; list startDelEff; LiteralSet startDelEffSet; list startNumericEff; list endAddEff; LiteralSet endAddEffSet; list endDelEff; LiteralSet endDelEffSet; list endNumericEff; }; private: static bool RPGdebug; static bool problemIsNotTemporal; // static vector > > actionsToNegativeNumericEffects; // static vector > > negativeNumericEffectsToActions; static vector > > preconditionsToActions; static vector > > negativePreconditionsToActions; static list > preconditionlessActions; static list > onlyNumericPreconditionActions; static vector > actionsToStartPreconditions; static vector > actionsToInvariants; static vector > actionsToEndPreconditions; static vector > actionsToStartNegativePreconditions; static vector > actionsToNegativeInvariants; static vector > actionsToEndNegativePreconditions; static vector actionsToEndOneShots; static vector > actionsToStartEffects; static vector > actionsToStartNegativeEffects; static vector > actionsToEndEffects; static vector > actionsToEndNegativeEffects; static vector > > effectsToActions; static vector > > negativeEffectsToActions; static vector actionsToMinDurations; static vector actionsToMaxDurations; static vector > fixedDurationExpressions; static vector > minDurationExpressions; static vector > maxDurationExpressions; static vector startEndSkip; // one for each instantiated action; within that - one for each point along the action, minus the last // entry [a][0] specifies duration between a0 and a1 static vector > rpgDurationExpressions; static vector nonTemporalDuration; static vector linearDiscretisation; static vector > actionsToRawConditionalEffects; static vector > actionsToStartNumericPreconditions; static vector > actionsToNumericInvariants; static vector > actionsToEndNumericPreconditions; static vector > actionsToStartNumericEffects; static vector > actionsToEndNumericEffects; static vector > actionsToRPGNumericStartPreconditions; static vector > actionsToRPGNumericInvariants; static vector > actionsToRPGNumericEndPreconditions; static vector > actionsToRPGNumericStartEffects; static vector > actionsToRPGNumericEndEffects; static vector > actionsToConditionalEffects; // static vector > > numericPreconditionsToActions; // static vector > > actionsToNumericPreconditions; static vector initialUnsatisfiedStartPreconditions; static vector initialUnsatisfiedInvariants; static vector initialUnsatisfiedEndPreconditions; static vector achievedInLayer; static vector achievedInLayerReset; static vector > achievedBy; static vector > achievedByReset; static vector negativeAchievedInLayer; static vector negativeAchievedInLayerReset; static vector > negativeAchievedBy; static vector > negativeAchievedByReset; static vector numericAchievedInLayer; static vector numericAchievedInLayerReset; static vector numericAchievedBy; static vector numericAchievedByReset; // static vector increasedInLayer; // static vector > increasedBy; // static vector > increasedReset; static vector instantiatedOps; static vector literals; static vector pnes; static vector > staticLiterals; static vector rpgNumericPreconditions; static vector rpgNumericEffects; static vector > > rpgNumericEffectsToActions; static vector > > rpgNumericPreconditionsToActions; static vector rpgArtificialVariables; static vector > rpgVariableDependencies; static vector > rpgArtificialVariablesToPreconditions; static vector > rpgNegativeVariablesToPreconditions; static vector > rpgPositiveVariablesToPreconditions; static vector initialUnsatisfiedNumericStartPreconditions; static vector initialUnsatisfiedNumericInvariants; static vector initialUnsatisfiedNumericEndPreconditions; static vector > > processedPreconditionsToActions; static vector > > processedNegativePreconditionsToActions; static vector > actionsToProcessedStartPreconditions; static vector > actionsToProcessedStartNegativePreconditions; static vector initialUnsatisfiedProcessedStartPreconditions; static vector > realVariablesToRPGEffects; static vector > > processedRPGNumericPreconditionsToActions; static vector > actionsToProcessedStartNumericPreconditions; static list literalGoals; static list literalGoalDeadlines; static list numericGoals; static list numericGoalDeadlines; static list > numericRPGGoals; static vector preferences; static map prefNameToID; static vector constraints; static vector > actionsToProcessedStartRPGNumericPreconditions; static vector initialUnsatisfiedProcessedStartNumericPreconditions; static vector > mentionedInFluentInvariants; static list timedInitialLiterals; static vector timedInitialLiteralsVector; static list optimisationTimedInitialLiterals; static vector optimisationTimedInitialLiteralsVector; static vector allTimedInitialLiteralsVector; static map > tilsThatAddFact; static map > tilsThatDeleteFact; static vector kShotFormulae; static vector selfMutexes; static vector oneShotLiterals; static vector maxNeeded; static map uninterestingnessCriteria; static void buildRPGNumericPreconditions(); static void buildRPGNumericEffects(); // static void simplify(pair, list > & s); // static void makeOneSided(pair, list > & LHSvariable, pair, list > & RHSvariable, const int & negOffset); // static void makeWeightedSum(list & formula, pair, list > & result); static void processPreconditions(set & artificialVariableSet, map > > & rpgNumericPreconditionSet, list & currPreList, list & destList, int & toIncrement, const int & negOffset, const int & offset, int & precCount, int & avCount, vector & localMaxNeed, const int & i, const VAL::time_spec & passTimeSpec); static void buildDurations(vector > & d, vector > & e, vector > & f); static bool pushInvariantBackThroughStartEffects(const RPGNumericPrecondition & pre, list & startEffs, InvData & commonData, pair & preResult, pair & avResult); static void handleNumericInvariants(); static void findSelfMutexes(); static void oneShotInferForTILs(); static void kshotInferForAction(const int & i, MinimalState & refState, LiteralSet & maybeOneShotLiteral, vector & initialFluents, const int & fluentCount); static void doSomeUsefulMetricRPGInference(); static void checkConditionalNumericEffectsAreOnlyOnMetricTrackingVariables(); static void separateOptimisationTILs(); static void findUninterestingnessCriteria(); static DurationExpr * buildDE(NumericPrecondition * d); static list buildDEList(list & d); static LinearEffects * buildLE(const int & i); static bool considerAndFilter(LiteralSet & initialState, LiteralSet & revisit, const int & operatorID); static void postFilterUnreachableActions(); static void buildMetric(VAL::metric_spec*); static void buildThePropositionalBitOfConditionalEffects(); static void findStaticLiterals(); static void pruneStaticPreconditions(list & toPrune, int & toDec); static void pruneStaticPreconditions(); class CommonRegressionData; static void postFilterIrrelevantActions(); static void findActionTimestampLowerBounds(); static void pruneIrrelevant(const int & operatorID); static void findCompressionSafeActions(); static RPGHeuristic * globalHeuristic; public: static bool canSkipToEnd(const int & i) { return startEndSkip[i]; }; static pair & isStatic(Literal* l); static void simplify(pair, list > & s); static void makeOneSided(pair, list > & LHSvariable, pair, list > & RHSvariable, const int & negOffset); static void makeWeightedSum(list & formula, pair, list > & result); static const vector & getNonTemporalDurationToPrint() { return nonTemporalDuration; } static const vector & getAllTimedInitialLiterals() { return allTimedInitialLiteralsVector; } static vector > & getFixedDEs() { return fixedDurationExpressions; } static vector > & getMinDEs() { return minDurationExpressions; } static vector > & getMaxDEs() { return maxDurationExpressions; } static vector & getRPGDEs(const int & a) { return rpgDurationExpressions[a]; } static vector & getLinearDiscretisation() { return linearDiscretisation; } static vector > & getStartPreNumerics() { return actionsToRPGNumericStartPreconditions; } static vector > & getInvariantNumerics() { return actionsToRPGNumericInvariants; } static vector > & getEndPreNumerics() { return actionsToRPGNumericEndPreconditions; } static vector > & getStartEffNumerics() { return actionsToRPGNumericStartEffects; } static vector > & getEndEffNumerics() { return actionsToRPGNumericEndEffects; } static const vector > & getActionsToConditionalEffects() { return actionsToConditionalEffects; } static vector > & getStartPropositionAdds() { return actionsToStartEffects; } static vector > & getStartPropositionDeletes() { return actionsToStartNegativeEffects; } static vector > & getEndPropositionAdds() { return actionsToEndEffects; }; static vector > & getEndPropositionDeletes() { return actionsToEndNegativeEffects; }; static vector > & getProcessedStartPropositionalPreconditions() { return actionsToProcessedStartPreconditions; }; static vector > & getStartPropositionalPreconditions() { return actionsToStartPreconditions; }; static vector > & getStartNegativePropositionalPreconditions() { return actionsToStartNegativePreconditions; }; static vector > & getInvariantPropositionalPreconditions() { return actionsToInvariants; }; static vector > & getInvariantNegativePropositionalPreconditions() { return actionsToNegativeInvariants; }; static vector > & getEndPropositionalPreconditions() { return actionsToEndPreconditions; }; static vector > & getEndNegativePropositionalPreconditions() { return actionsToEndNegativePreconditions; }; static vector > & getProcessedStartNegativePropositionalPreconditions() { return actionsToProcessedStartNegativePreconditions; }; static vector & getNumericPreTable() { return rpgNumericPreconditions; } static vector & getNumericEff() { return rpgNumericEffects; } static const vector > > & getRpgNumericEffectsToActions() { return rpgNumericEffectsToActions; } static const vector & getArtificialVariableTable() { return rpgArtificialVariables; } static vector > > & getPresToActions() { return processedPreconditionsToActions; } static vector > > & getRawPresToActions() { return preconditionsToActions; }; static const vector & rogueActions; static vector realRogueActions; static bool sortedExpansion; static bool fullFFHelpfulActions; static bool modifiedRPG; static bool noSelfOverlaps; static bool doTemporalAnalysis; static void initialise(); static bool nonTemporalProblem() { return problemIsNotTemporal; }; static list & getLiteralGoals() { return literalGoals; }; static RPGHeuristic * generateRPGHeuristic(); static RPGHeuristic * getHeuristic() { return globalHeuristic; } static void getInitialState(LiteralSet & initialState, vector & initialFluents); static void getNonStaticInitialState(LiteralSet & initialState, vector & initialFluents); static instantiatedOp* getInstantiatedOp(const int & i) { return instantiatedOps[i]; }; static Literal* getLiteral(const int & i) { return literals[i]; }; static list & getTILs() { return timedInitialLiterals; }; static list > & getEffectsToActions(const int & i) { return effectsToActions[i]; }; static vector & getTILVec() { return timedInitialLiteralsVector; }; static void getEffects(instantiatedOp* op, const bool & start, list & add, list & del, list & numeric); static void getPrecInv(instantiatedOp* op, const bool & start, list & precs, list & inv, list & numericPrec, list & numericInv); // static void getCollapsedAction(instantiatedOp* op, list & pre, list & add, list & del, list & numericPre, list & numericEff); static Metric * getMetric() { return theMetric; } static list & getMentioned(const int & i) { return mentionedInFluentInvariants[i]; }; static bool stepNeedsToHaveFinished(const ActionSegment & act, const MinimalState & s, set & dest); static double getOpMinDuration(instantiatedOp* op, const int & div); static double getOpMinDuration(const int & op, const int & div); static double getOpMaxDuration(instantiatedOp* op, const int & div); static double getOpMaxDuration(const int & op, const int & div); static pair getOpDuration(instantiatedOp* op, const int & div, const vector & minFluents, const vector & maxFluents); static pair getOpDuration(const int & op, const int & div, const vector & minFluents, const vector & maxFluents); static PNE* getPNE(const int & i) { return pnes[i]; }; static int getPNECount() { return pnes.size(); }; static int getAVCount() { return rpgArtificialVariables.size(); }; static ArtificialVariable & getArtificialVariable(const int & i) { return rpgArtificialVariables[i - (2 * getPNECount())]; }; static list & getVariableDependencies(const int & i) { return rpgVariableDependencies[i]; }; static list & affectsRPGNumericPreconditions(int i) { static const int off = getPNECount(); if (i < off) { return rpgPositiveVariablesToPreconditions[i]; }; i -= off; if (i < off) { return rpgNegativeVariablesToPreconditions[i]; } i -= off; return rpgArtificialVariablesToPreconditions[i]; } static int howManyTimes(const int & actID, const MinimalState & e) { return kShotFormulae[actID]->getLimit(e); }; static int howManyTimesOptimistic(const int & actID, const MinimalState & e) { return kShotFormulae[actID]->getOptimisticLimit(e); }; static bool literalIsOneShot(const int & lID) { return oneShotLiterals[lID]; }; static bool isSelfMutex(const int & actID) { return selfMutexes[actID]; }; static list > & getNumericRPGGoals() { return numericRPGGoals; }; static list & getNumericGoals() { return numericGoals; }; static bool isInteresting(const int & act, const map & facts, const map > & started); static LiteralSet & getEndOneShots(const int & i) { return actionsToEndOneShots[i]; }; }; class RPGHeuristic { private: class Private; Private * const d; public: static bool hAddCostPropagation; static bool blindSearch; static bool ignoreNumbers; static bool makeCTSEffectsInstantaneous; static void setGuidance(const char * config); static set emptyIntList; RPGHeuristic(const bool & b, vector > * atse, vector > * atee, vector > > * eta, vector > * atsne, vector > * atene, vector > > * neta, vector > > * pta, vector > * atsp, vector > * ati, vector > * atep, vector > * atnuse, vector > * atnuee, vector > * atrnuse, vector > * atrnuee, vector > * atnusp, vector > * atnui, vector > * atnuep, vector > * atpnuep, vector * iusp, vector * iuip, vector * iuep, vector * ail, vector * ailr, vector > * ab, vector > * abr, vector * nail, vector * nailr, vector * nab, vector * nabr, vector * iunsp, vector * iuni, vector * iunep, vector * rnp, vector * rne, vector > > * ppta, vector > > * nppta, vector > * atpsp, vector * iupsp, vector * iupsnp, list > * pla, list > * onpa); ~RPGHeuristic(); static vector & getEarliestForStarts(); static vector & getEarliestForEnds(); int getRelaxedPlan(const MinimalState & theState, const vector & minTimestamps, const double & stateTS, list & helpfulActions, list > > & relaxedPlan, double & finalPlanMakespanEstimate, map > > * justApplied = 0, double tilFrom = 0.001); void findApplicableActions(const MinimalState & theState, const double & stateTime, list & applicableActions); void filterApplicableActions(const MinimalState & theState, const double & stateTime, list & applicableActions); bool testApplicability(const MinimalState & theState, const double & stateTime, const ActionSegment & actID, bool fail = false, bool ignoreDeletes = false); list & getDeleteEffects(const int & i, const VAL::time_spec & t); list & getAddEffects(const int & i, const VAL::time_spec & t); list & getPreconditions(const int & i, const VAL::time_spec & t); list & getInvariants(const int & i); list & getNumericEffects(const int & i, const VAL::time_spec & t); RPGBuilder::RPGNumericEffect & getRPGNE(const int & i); list * makePlan(list & steps); instantiatedOp* getOp(const int & i); double earliestTILForAction(const int & i, const bool & isStart); static double & getDeadlineRelevancyStart(const int & i); static double & getDeadlineRelevancyEnd(const int & i); void doFullExpansion(MinimalState & refState); }; ostream & operator <<(ostream & o, const RPGBuilder::NumericPrecondition & p); ostream & operator <<(ostream & o, const RPGBuilder::NumericEffect & p); ostream & operator <<(ostream & o, const RPGBuilder::RPGNumericPrecondition & p); ostream & operator <<(ostream & o, const RPGBuilder::ArtificialVariable & p); ostream & operator <<(ostream & o, const RPGBuilder::RPGNumericEffect & p); enum whereAreWe { PARSE_UNKNOWN, PARSE_PRECONDITION, PARSE_EFFECT, PARSE_DURATION, PARSE_GOAL, PARSE_INITIAL, PARSE_CONDITIONALEFFECT, PARSE_CONTINUOUSEFFECT, PARSE_METRIC, PARSE_DERIVATION_RULE, PARSE_CONSTRAINTS }; extern whereAreWe WhereAreWeNow; void validatePNE(PNE * c); void validateLiteral(Literal * l); void postmortem_noNestedWhens(); void postmortem_noADL(); void postmortem_nonLinearCTS(const string & actName, const string & worksOutAs); void postmortem_noQuadratic(const string & theOp); void postmortem_noTimeSpecifierOnAPropPrecondition(const string & actname, const string & effect); void postmortem_fixedAndNotTimeSpecifiers(const string & actname, const bool & multipleEquals); void postmortem_noTimeSpecifierOnAPropEffect(const string & actname, const string & effect); void postmortem_noTimeSpecifierOnInstantNumericEffect(const string & actname, const string & effect, const string & suggested, const bool & isAssign); void postmortem_wrongNumberOfFluentArguments(const string & actname, const bool & haveActName, const whereAreWe & w, const string & predname, const string & lit, const int & givenArgs, const set & realargs); void postmortem_wrongNumberOfPredicateArguments(const string & actname, const bool & haveActName, const whereAreWe & w, const string & predname, const string & lit, const int & givenargs, const set & realargs); void postmortem_mathsError(const string & description, const string & help, const whereAreWe & w); void postmortem_noConstraints(const bool unsupportedPref = false, const char * n = 0); void postmortem_isViolatedNotExist(const string & s); void postmortem_fatalConstraint(const string & whichOne); }; #endif // kate: indent-mode cstyle; space-indent on; indent-width 4; replace-tabs on;