1 |
gezelter |
1490 |
#include <iostream> |
2 |
|
|
#include <stdlib.h> |
3 |
|
|
|
4 |
tim |
1492 |
#include "brains/Exclude.hpp" |
5 |
gezelter |
1490 |
|
6 |
|
|
|
7 |
tim |
1719 |
namespace oopse { |
8 |
gezelter |
1490 |
|
9 |
tim |
1719 |
Exclude::Exclude() : modified_(false){ |
10 |
gezelter |
1490 |
} |
11 |
|
|
|
12 |
|
|
Exclude::~Exclude() { |
13 |
|
|
} |
14 |
|
|
|
15 |
tim |
1719 |
int* Exclude::getExcludeList(){ |
16 |
gezelter |
1490 |
|
17 |
tim |
1719 |
std::set<std::pair<int, int> >::iterator i; |
18 |
gezelter |
1490 |
|
19 |
tim |
1719 |
if (modified_) { |
20 |
|
|
excludeSet_.clear(); |
21 |
|
|
std::copy(excludeSet_.begin(), excludeSet_.end(), std::back_inserter(excludeSet_.begin())); |
22 |
|
|
modified_ = false; |
23 |
|
|
} else { |
24 |
|
|
return excludeSet_.size() > 0 ? &excludeSet_[0] : NULL; |
25 |
gezelter |
1490 |
} |
26 |
|
|
} |
27 |
|
|
|
28 |
tim |
1719 |
void Exclude::addPair(int i, int j) { |
29 |
gezelter |
1490 |
|
30 |
tim |
1719 |
std::set<std::pair<int, int> >::iterator iter; |
31 |
|
|
iter = findPair(i ,j ); |
32 |
|
|
|
33 |
|
|
if (iter != excludeSet_.end()) { |
34 |
|
|
|
35 |
|
|
if (i == j) { |
36 |
|
|
return; |
37 |
|
|
}else if (i > j) { |
38 |
|
|
std::swap(i, j); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
excludeSet_.insert(make_pair(i, j)); |
42 |
|
|
modified_ = true; |
43 |
gezelter |
1490 |
} |
44 |
|
|
|
45 |
|
|
} |
46 |
|
|
|
47 |
tim |
1719 |
void Exclude::removePair(int i, int j) { |
48 |
|
|
std::set<std::pair<int, int> >::iterator iter; |
49 |
|
|
iter = findPair(i ,j ); |
50 |
|
|
|
51 |
|
|
if (iter != excludeSet_.end()) { |
52 |
|
|
excludeSet_.erase(iter); |
53 |
|
|
modified_ = true; |
54 |
|
|
} |
55 |
gezelter |
1490 |
|
56 |
|
|
} |
57 |
|
|
|
58 |
tim |
1719 |
std::set<std::pair<int, int> >::iterator Exclude::findPair(int i, int j) { |
59 |
gezelter |
1490 |
|
60 |
tim |
1719 |
std::set<std::pair<int, int> >::iterator position; |
61 |
gezelter |
1490 |
|
62 |
|
|
if (i != j) { |
63 |
|
|
if (i < j) |
64 |
tim |
1719 |
position = excludeSet_.find(make_pair(i, j)); |
65 |
gezelter |
1490 |
else |
66 |
tim |
1719 |
position = excludeSet_.find(make_pair(j, i)); |
67 |
gezelter |
1490 |
|
68 |
tim |
1719 |
return excludeSet_.end; |
69 |
gezelter |
1490 |
} else |
70 |
tim |
1719 |
return excludeSet_.end(); |
71 |
gezelter |
1490 |
} |
72 |
|
|
|
73 |
|
|
int Exclude::getSize() { |
74 |
tim |
1719 |
return excludeSet_.size(); |
75 |
gezelter |
1490 |
} |
76 |
tim |
1719 |
|
77 |
|
|
|
78 |
|
|
std::ostream& operator <<(std::ostream& o, Exclude& e){ |
79 |
|
|
std::set<std::pair<int, int> >::iterator i; |
80 |
|
|
int index; |
81 |
|
|
|
82 |
|
|
index = 0; |
83 |
|
|
for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) { |
84 |
|
|
o<< "exclude[" << index << "] i, j: " << (*i).first << " - " << (*i).second << "\n"; |
85 |
|
|
index++; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
return o; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
|
92 |
|
|
} |