forked from Gullesnuffs/MaxCutInapproximability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gadget.h
39 lines (31 loc) · 947 Bytes
/
gadget.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
#pragma once
#include <cassert>
#include <map>
#include "config.h"
#include "edge.h"
template <typename T>
struct Gadget {
std::map<Edge, T> weight;
//T totalWeight;
public:
Gadget(std::map<Edge, T> weight) : weight(weight) {
//totalWeight = 0;
//for (const auto& it : weight) {
// totalWeight += it.second;
//}
}
T getWeight(const Edge& edge) const {
auto it = weight.find(edge);
assert(it != weight.end());
return it->second;
}
//T getTotalWeight() const { return totalWeight; }
bool operator==(const Gadget& other) { return weight == other.weight; }
};
template<typename T>
std::ostream &operator<<(std::ostream &os, Gadget<T> const &gadget) {
os << "Gadget of size " << gadget.weight.size() << std::endl;
for (auto [e, w] : gadget.weight)
os << "Gadget contains weight " << w << " with representative edge " << e.a.getIndex() << " " << e.b.getIndex() << std::endl;
return os;
}