All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
NavGraphConformerSolver.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Routes.h"
7 #include "MortonKey.h"
8 #include "tr1.h"
9 #include "SolverConfig.h"
10 #include "NavGraphConnectionCache.h"
11 #include "SearchNodePriorityComparer.h"
12 #include <vector>
13 #include <queue>
14 
15 namespace Eegeo
16 {
17  namespace Routes
18  {
19  namespace Fitting
20  {
21  namespace NavGraphConforming
22  {
24  {
25  public:
26  NavGraphConformerSolver(const SolverConfig& config, SolverNodeAllocator& allocator, const Streaming::MortonKey& key, const std::vector<const CandidateSet*>& candidateSets);
27  virtual ~NavGraphConformerSolver();
28 
29  virtual bool TrySolve(std::vector<const Candidate*>& solution);
30 
31 
32 
33  private:
34  typedef std::vector<Candidate*> TCandidatesInner;
35  typedef std::vector<const CandidateSet*> TCandidatesOuter;
36 
37  SolverNode* CreateNeighbour(SolverNode* parent, const Candidate* nextCandidate);
38 
39  void BuildSolutionOutput(SolverNode* goalNode, std::vector<const Candidate*>& solutionSelectedCandidates);
40 
41  float GetH(const Candidate& candidate) const;
42 
43  void CreateDuplicatedCandidates(const std::vector<const CandidateSet*>& originalCandidates, std::vector<const CandidateSet*>& out_duplicatedCandidates, std::vector<int>& out_candidatesToOriginalCandidates) const;
44 
45  void DestroyDuplicatedCandidates(std::vector<const CandidateSet*>& duplicatedCandidates) const;
46 
47  bool PassesPreconditions() const;
48 
49  int CountUniqueRoads(const std::vector<Candidate*>& inner) const;
50 
51  bool TryPrecalcCandidatesH();
52 
53  void OpenNeighbours(SolverNode* node);
54 
55  bool IsGoal(const SolverNode& node) const;
56 
57  bool HasNonContiguousRoadSequence(const SolverNode& lastNode) const;
58 
59  bool IsValidConnection(const SolverNode& nodeA, const SolverNode& nodeB);
60 
61  bool CalculateIsValidConnection(const SolverNode& nodeA, const SolverNode& nodeB);
62 
63  bool IsValidCandidateExtension(const SolverNode& node);
64 
65  float CalcEdgeTraversalCost(const Candidate& candidateA, const Candidate& candidateB);
66 
67  void Reset();
68 
69  const TCandidatesOuter& m_originalCandidates;
70 
71  const Streaming::MortonKey m_key;
72 
73  std::vector<int> m_candidatesToOriginalCandidates;
74 
75  std::vector<float> m_candidatesH;
76  TCandidatesOuter m_candidates;
77 
78  typedef Eegeo::unordered_set<const Candidate*>::type TClosedSet;
79  TClosedSet m_closedSet;
80 
81  typedef Eegeo::unordered_map<const Candidate*, SolverNode*>::type TCandidateToOpen;
82  TCandidateToOpen m_candidateToOpenNodes;
83 
84  typedef std::priority_queue<SolverNode*, std::deque<SolverNode*>, SearchNodePriorityComparer> TOpenSet;
85  TOpenSet m_openSet;
86 
87  const SolverConfig m_config;
88 
89  SolverNodeAllocator& m_nodeAllocator;
90 
91  NavGraphConnectionCache m_connectionCache;
92 
93  int m_trivialCalls;
94  int m_cachedCalls;
95  int m_uncachedCalls;
96  };
97  }
98  }
99  }
100 }