-
Notifications
You must be signed in to change notification settings - Fork 1
/
Compare.h
63 lines (52 loc) · 1.17 KB
/
Compare.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
//
// Created by Stepan Dergachev on 07.07.18.
//
#ifndef ASEARCH_COMPARE_H
#define ASEARCH_COMPARE_H
#include "node.h"
#include <cmath>
#include <limits>
#include "gl_const.h"
static bool isEqual(double left, double right)
{
return std::fabs(left - right) < D_EPS;
}
static bool gMaxCompare(const Node &lhs, const Node &rhs)
{
if (isEqual(lhs.F, rhs.F))
{
if (isEqual(lhs.g, rhs.g))
{
return lhs.i < rhs.i || lhs.i == rhs.i && lhs.j < rhs.j;
}
else
{
return lhs.g - rhs.g > D_EPS;
}
}
return lhs.F - rhs.F < D_EPS;
}
static bool gMinCompare(const Node &lhs, const Node &rhs)
{
if (isEqual(lhs.F, rhs.F))
{
if (isEqual(lhs.g, rhs.g))
{
return lhs.i < rhs.i || lhs.i == rhs.i && lhs.j < rhs.j;
}
else
{
return lhs.g - rhs.g < D_EPS;
}
}
return lhs.F - rhs.F < D_EPS;
}
static bool inline gMaxComparePQ(const Node &lhs, const Node &rhs)
{
return !gMaxCompare(lhs, rhs);
}
static bool inline gMinComparePQ(const Node &lhs, const Node &rhs)
{
return !gMinCompare(lhs, rhs);
}
#endif //ASEARCH_COMPARE_H