-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOVctSet.cpp
96 lines (82 loc) · 1.77 KB
/
OVctSet.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Created by Stepan Dergachev on 08.07.18.
//
#include "OVctSet.h"
OVctSet::OVctSet() : IOpenContainer()
{
dupl = false;
vsminindex = 0;
VctSt.resize(0);
}
OVctSet::OVctSet(bool breakingties, bool allowduplicates, int mapheight) : IOpenContainer(breakingties)
{
dupl = allowduplicates;
vsminindex = 0;
if(this->breakingties)
{
this->compare = &gMaxCompare;
}
else
{
this->compare = &gMinCompare;
}
VctSt.resize(mapheight);
for(int i = 0; i < VctSt.size(); i++)
{
VctSt[i]= std::set<Node, bool(*)(const Node&, const Node&)>(compare);
}
}
OVctSet::OVctSet(OVctSet const &a) : IOpenContainer(a)
{
this->dupl = a.dupl;
this->vsminindex = a.vsminindex;
this->VctSt = a.VctSt;
}
OVctSet::~OVctSet()
{
for(auto it = VctSt.begin(); it != VctSt.end(); ++it)
{
it->clear();
}
}
void OVctSet::Add(Node elem)
{
if(!dupl)
{
auto a = std::find(VctSt[elem.i].begin(), VctSt[elem.i].end(), elem);
if (a != VctSt[elem.i].end())
{
if (a->F > elem.F)
{
VctSt[elem.i].erase(a);
size -= 1;
} else
{
return;
}
}
}
if(VctSt[elem.i].insert(elem).second)
{
size += 1;
}
return;
}
Node OVctSet::GetOptimal()
{
Node currOpt;
for (int i = 0; i < VctSt.size(); i++)
{
if (VctSt[i].size() && this->compare(*VctSt[i].begin(), currOpt))
{
vsminindex = i;
currOpt.F = VctSt[i].begin()->F;
currOpt.g = VctSt[i].begin()->g;
}
}
auto a = VctSt[vsminindex].begin();
Node result = *a;
VctSt[vsminindex].erase(a);
size -= 1;
return result;
}