-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatroid.cpp
96 lines (70 loc) · 1.9 KB
/
matroid.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
94
95
#include <vector>
#include <list>
#include <iostream>
#include "basic.h"
#include "field.h"
#include "matroid.h"
#include "gaussian.h"
using namespace std;
Matrix getUniformMatroidRep(int size, int rank) {
Matrix result;
for (int i = 0; i < size; i++) {
vector<Field::Element> current_col{Field::Element(1)};
Field::Element e(i+1);
for (int i = 1; i <= rank-1; i++)
current_col.push_back(current_col[i-1]*e);
result.push_back(current_col);
}
return result;
}
Matrix matroidRepSimpleSum(Matrix && A, Matrix && B) {
int a_x = A[0].size();
int b_x = B[0].size();
vector<Field::Element> zero_end(b_x,Field::Element(0));
for (auto & row : A)
row.insert(row.end(),zero_end.begin(),zero_end.end());
for (auto & row : B) {
vector<Field::Element> new_row(a_x,Field::Element(0));
new_row.insert(new_row.end(),row.begin(),row.end());
A.push_back(new_row);
}
return A;
}
bool operator<(ISet const & A, ISet const & B) {
if (A.size() != B.size())
return A.size() < B.size();
for (int i = 0; i < ((int)A.size()); i++)
if (A[i] != B[i])
return A[i] < B[i];
return false;
}
bool operator==(ISet const & A, ISet const & B) {
if (A.size() != B.size())
return false;
for (int i = 0; i < ((int)A.size()); i++)
if (A[i] != B[i])
return false;
return true;
}
#define ISET_MUL 5501
#define ISET_MOD 1230599
size_t hash<ISet>::operator() (ISet const & iset) const {
size_t result = 0L;
for (int col : iset)
result = (result * ISET_MUL + col) % ISET_MOD;
return result;
}
ISetFamily getMatroidRepSet(Matrix const & matroid, ISetFamily const & family) {
Matrix family_rows;
for (auto set : family) {
Matrix set_rep;
for (auto idx : set)
set_rep.push_back(matroid[idx]);
family_rows.push_back(getAllDets(set_rep));
}
auto rep_set_idx = getSignificantRows(move(family_rows));
ISetFamily result;
for (int idx : rep_set_idx)
result.push_back(family[idx]);
return result;
}