-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.h
65 lines (53 loc) · 1.44 KB
/
search.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#ifndef _SEARCH_H_
#define _SEARCH_H_
#include <boost/shared_ptr.hpp>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include "position.h"
struct Vertex;
typedef boost::shared_ptr<Vertex> VertexPtr;
struct Vertex {
Vertex();
Vertex( const Position& position_, int cost_, int h_, int heuristic_, const VertexPtr& parent_);
Position position;
int cost;
int h;
int heuristic;
VertexPtr parent;
};
class PoolCompare {
public:
bool operator()( const VertexPtr& operand1, const VertexPtr& operand2) const;
};
class VertexPool {
public:
typedef std::set<VertexPtr, PoolCompare> Pool;
VertexPtr Find( const Position& position);
void Insert( const VertexPtr& vertex);
private:
Pool pool_;
};
class OpenedSetCompare {
public:
bool operator()( const VertexPtr& operand1, const VertexPtr& operand2) const;
};
class OpenedSet {
public:
typedef std::set<VertexPtr, OpenedSetCompare> Set;
bool FindAndErase( const VertexPtr& vertex);
void Insert( const VertexPtr& vertex);
VertexPtr ExtractMin();
bool Empty();
private:
Set set_;
};
class AStarSearcher {
public:
std::vector<Position> Search( const Position& source, const Position& goal, long long limit, std::string& error_msg);
std::pair<bool, VertexPtr> SideSearch( OpenedSet& opened_set, VertexPool& pool, Position& goal, VertexPool& check);
const static int ITERATION_COUNT;
};
#endif /* _SEARCH_H_ */