KrisLibrary  1.0.0
MCRPlannerGoalSet.h
1 #ifndef MCR_PLANNER_GOAL_SET_H
2 #define MCR_PLANNER_GOAL_SET_H
3 
4 #include "MotionPlanner.h"
5 #include "CSpace.h"
6 #include <KrisLibrary/utils/Subset.h>
7 
8 
31 {
32  public:
33  struct Milestone {
34  Config q;
35  int mode;
36  };
37  struct Edge {
38  EdgePlannerPtr e;
39  int mode;
40  };
42 
43  struct Mode {
44  Subset subset; //subset covered by this mode
45  std::vector<int> roadmapNodes;
46  std::vector<Subset> pathCovers; //minimal covers leading from the start to this mode
47  Real minCost;
48  };
49  struct Transition {
50  std::vector<std::pair<int,int> > connections;
51  };
53 
54  MCRPlannerGoalSet(CSpace* space);
55  void Init(const Config& start,CSet* goal);
57  void Expand(Real maxExplanationCost,std::vector<int>& newNodes);
58  void Expand2(Real maxExplanationCost,std::vector<int>& newNodes);
60  void Plan(int initialLimit,const std::vector<int>& expansionSchedule,std::vector<int>& bestPath,Subset& cover);
62  void BuildRoadmap(Real maxExplanationCost,RoadmapPlanner& prm);
67  bool CoveragePath(int s,int t,const Subset& cover,std::vector<int>& path,Subset& pathCover);
69  bool GreedyPath(int s,int t,std::vector<int>& path,Subset& pathCover);
71  bool OptimalPath(int s,int t,std::vector<int>& path,Subset& pathCover);
73  bool GreedyPath(std::vector<int>& path,Subset& pathCover);
75  bool OptimalPath(std::vector<int>& path,Subset& pathCover);
76 
77  //helpers
78  Real Cost(const Subset& s) const;
79  int AddNode(const Config& q,int parent=-1);
80  int AddNode(const Config& q,const Subset& subset,int parent=-1);
81  bool AddEdge(int i,int j,int depth=0);
82  int AddEdge(int i,const Config& q,Real maxExplanationCost); //returns index of q
83  void AddEdgeRaw(int i,int j);
84  int ExtendToward(int i,const Config& qdest,Real maxExplanationCost);
85  void KNN(const Config& q,int k,std::vector<int>& neighbors,std::vector<Real>& distances);
86  void KNN(const Config& q,Real maxExplanationCost,int k,std::vector<int>& neighbors,std::vector<Real>& distances);
87  void UpdatePathsGreedy();
88  void UpdatePathsComplete();
89  void UpdatePathsGreedy2(int nstart=-1);
90  void UpdatePathsComplete2(int nstart=-1);
91  //returns true if a path from mode a to mode b can improve the explanation
92  //at b
93  bool CanImproveConnectivity(const Mode& ma,const Mode& mb,Real maxExplanationCost);
94  //updates the minCost member of m
95  void UpdateMinCost(Mode& m);
96  //fast checking of whether the cost of the local constraints at q exceed the
97  //given limit
98  bool ExceedsCostLimit(const Config& q,Real limit,Subset& violations);
99  //fast checking of whether the cost of the local constraints violated on
100  //the edge ab exceed the given limit
101  bool ExceedsCostLimit(const Config& a,const Config& b,Real limit,Subset& violations);
102 
104  void GetCover(const std::vector<int>& path,Subset& cover) const;
106  Real GetLength(const std::vector<int>& path) const;
108  void GetMilestonePath(const std::vector<int>& path,MilestonePath& mpath) const;
109 
110  Config start;
111  CSpace* space;
112  CSet* goalSet;
113  Optimization::NonlinearProgram* goalNumeric;
114  std::vector<int> goalNodes; //a list of goal nodes in roadmap
115 
116  //weighted explanation
117  std::vector<Real> obstacleWeights;
118 
119  //settings for RRT* like expansion
120  int numConnections;
121  Real connectThreshold,expandDistance,goalConnectThreshold;
122  Real goalBiasProbability; //probability of expanding toward the goal
123  bool bidirectional; //not functional yet
124 
125  //settings for path update
134 
135  Roadmap roadmap;
136  ModeGraph modeGraph;
137 
138  //planning statistics
139  int numExpands,numRefinementAttempts,numRefinementSuccesses,numExplorationAttempts,
140  numEdgeChecks,numConfigChecks,
141  numUpdatePaths,numUpdatePathsIterations;
142  double timeNearestNeighbors,timeRefine,timeExplore,timeUpdatePaths,timeOverhead;
143 };
144 
145 #endif
int updatePathsMax
For complete planning, keep at most this number of covers.
Definition: MCRPlannerGoalSet.h:133
bool OptimalPath(int s, int t, std::vector< int > &path, Subset &pathCover)
An optimal search.
Definition: MCRPlannerGoalSet.cpp:1724
bool updatePathsDynamic
Definition: MCRPlannerGoalSet.h:131
Definition: MCRPlannerGoalSet.h:49
bool updatePathsComplete
Definition: MCRPlannerGoalSet.h:128
void Expand(Real maxExplanationCost, std::vector< int > &newNodes)
Performs one iteration of planning given a limit on the explanation size.
Definition: MCRPlannerGoalSet.cpp:990
Vector Config
an alias for Vector
Definition: RobotKinematics3D.h:14
Motion planning configuration space base class. The configuration space implements an interpolation s...
Definition: CSpace.h:39
bool GreedyPath(int s, int t, std::vector< int > &path, Subset &pathCover)
A greedy heuristic that performs smallest cover given predecessor.
Definition: MCRPlannerGoalSet.cpp:1702
A sequence of locally planned paths between milestones.
Definition: planning/Path.h:18
Definition: MCRPlannerGoalSet.h:33
Real GetLength(const std::vector< int > &path) const
Computes the length of the path.
void BuildCCGraph(Graph::UndirectedGraph< Subset, int > &G)
Definition: MCRPlannerGoalSet.cpp:1449
Definition: MCRPlannerGoalSet.h:37
Definition: MCRPlannerGoalSet.h:43
void GetMilestonePath(const std::vector< int > &path, MilestonePath &mpath) const
Returns the MilestonePath.
Definition: MCRPlannerGoalSet.cpp:1788
A base roadmap planner class.
Definition: MotionPlanner.h:24
bool CoveragePath(int s, int t, const Subset &cover, std::vector< int > &path, Subset &pathCover)
A search that finds a path subject to a coverage constraint.
Definition: MCRPlannerGoalSet.cpp:1502
void Plan(int initialLimit, const std::vector< int > &expansionSchedule, std::vector< int > &bestPath, Subset &cover)
Performs bottom-up planning according to a given limit expansion schedule.
Definition: MCRPlannerGoalSet.cpp:1318
void GetCover(const std::vector< int > &path, Subset &cover) const
Computes the cover of the path.
A finite subset of numbered items with convenient operators for union, intersection, difference, etc.
Definition: Subset.h:13
A planner that minimizes the the number of violated constraints using a RRT-like strategy.
Definition: MCRPlannerGoalSet.h:30
A structure defining a nonlinear program.
Definition: NonlinearProgram.h:22
A subset of a CSpace, which establishes a constraint for a configuration must meet. Mathematically, this is a set S which imposes the constraint [q in S].
Definition: CSet.h:20
void BuildRoadmap(Real maxExplanationCost, RoadmapPlanner &prm)
Outputs the graph with the given explanation limit.
Definition: MCRPlannerGoalSet.cpp:1414