-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.h
More file actions
89 lines (71 loc) · 2 KB
/
Model.h
File metadata and controls
89 lines (71 loc) · 2 KB
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
#ifndef BUTTERFLY_MODEL_H
#define BUTTERFLY_MODEL_H
#include <iostream>
#include <vector>
#include <unordered_map>
#include <fstream>
#include <cmath>
#include <cassert>
#include <algorithm>
using namespace std;
struct Edge {
int u, v;
double weight;
double pr;
};
struct Butterfly {
int u1, u2, v1, v2;
double weight;
double pr_u1_v1, pr_u1_v2, pr_u2_v1, pr_u2_v2;
double pr;
int combined_weight;
bool operator==(const Butterfly &b) const {
return //weight == b.weight &&
u1 == b.u1 && u2 == b.u2 &&
v1 == b.v1 && v2 == b.v2;
}
struct HashFunction {
size_t operator()(const Butterfly &b) const {
// size_t h1 = hash<double>()(b.weight);
size_t h2 = hash<int>()(b.u1) << 1;
size_t h3 = hash<int>()(b.u2) << 3;
size_t h4 = hash<int>()(b.v1) << 5;
size_t h5 = hash<int>()(b.v2) << 9;
return h2 ^ h3 ^ h4 ^ h5;
}
};
};
struct Angle {
int u, v, w;
double weight;
double pr_u_v, pr_v_w;
double pr;
int combined_weight;
};
struct hash_pair {
template<class T1, class T2>
size_t operator()(const pair<T1, T2> &p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
class Model {
public:
int num_l, num_r;
int num_e;
vector<int> node_l, node_r, node;
vector<vector<Edge>> neighbor;
vector<vector<Edge>> sampling_neighbor;
static unordered_map<int, int> is_left;
vector<int> priority;
unordered_map<Butterfly, double, Butterfly::HashFunction> result;
void PrintResult(double coe = 1.0);
int monte_carlo_iteration = 20000;
int DEBUG = 0;
ifstream fin;
ofstream fout;
static Angle EdgeToAngle(Edge e1, Edge e2);
static Butterfly AngleToButterfly(const Angle &a1, const Angle &a2);
};
#endif //BUTTERFLY_MODEL_H