-
Notifications
You must be signed in to change notification settings - Fork 2
/
MaxSAT_Partition.h
151 lines (117 loc) · 4.41 KB
/
MaxSAT_Partition.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*!
* \author Vasco Manquinho - [email protected]
*
* @section LICENSE
*
* Open-WBO, Copyright (c) 2013-2017, Ruben Martins, Vasco Manquinho, Ines Lynce
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#ifndef MAXSAT_PARTITION_H
#define MAXSAT_PARTITION_H
#include "MaxSAT.h"
#include "graph/Graph.h"
#include "graph/Graph_Communities.h"
#include <gmpxx.h>
using NSPACE::Var;
namespace openwbo {
enum graphType_ { VIG_GRAPH = 0, CVIG_GRAPH = 1, RES_GRAPH = 2 };
typedef struct {
vec<int> vars;
vec<int> sclauses;
vec<int> hclauses;
} Partition;
class MaxSAT_Partition : public MaxSAT {
public:
MaxSAT_Partition();
~MaxSAT_Partition();
void split(int mode, int graphType = RES_GRAPH); // Default Value
// Set number of Random Partitions
void setRandomPartitions(int n) { _nRandomPartitions = n; }
int getRandomPartitions() { return _nRandomPartitions; }
// Set random seed
void setRandomSeed(int n) { _randomSeed = n; }
int getRandomSeed() { return _randomSeed; }
double getModularity() { return _gc.getModularity(); }
int nPartitions() { return _nPartitions; }
int varPartition(Var v) { return _graphMappingVar[v]; }
int hardClausePartition(int index) { return _graphMappingHard[index]; }
int softClausePartition(int index) {
if (index >= maxsat_formula->nSoft())
return 0;
else
return _graphMappingSoft[index];
}
int nPartitionVars(int index) { return _partitions[index].vars.size(); }
int nPartitionSoft(int index) { return _partitions[index].sclauses.size(); }
int nPartitionHard(int index) { return _partitions[index].hclauses.size(); }
const vec<int> &communityVars(int index) { return _partitions[index].vars; }
const vec<int> &communitySoft(int index) {
return _partitions[index].sclauses;
}
const vec<int> &communityHard(int index) {
return _partitions[index].hclauses;
}
const vec<int> &adjacentPartitions(int index) {
return _gc.adjCommunities(index);
}
const vec<double> &adjacentPartitionWeights(int index) {
return _gc.adjCommunityWeights(index);
}
mpq_class *computeSparsity() {
mpq_class *h_val_pointer = new mpq_class("0", 10);
for (int i = 0; i < nPartitions(); ++i) {
*h_val_pointer += adjacentPartitions(i).size();
}
*h_val_pointer /= nPartitions() * nPartitions();
return h_val_pointer;
}
int nVertexes() { return _graph->nVertexes(); }
int nEdges() { return _graph->nEdges(); }
protected:
void init();
void splitRandom();
void buildPartitions(int graphType);
void buildSinglePartition();
void buildVIGPartitions();
void buildCVIGPartitions();
void buildRESPartitions();
Graph *buildGraph(bool weighted, int graphType);
Graph *buildVIGGraph(bool weighted);
Graph *buildCVIGGraph(bool weighted);
Graph *buildRESGraph(bool weighted);
int unassignedLiterals(vec<Lit> &sc);
bool isUnsatisfied(vec<Lit> &sc);
int markUnassignedLiterals(vec<Lit> &c, int *markedLits, bool v);
void printClause(vec<Lit> &sc);
protected:
Solver *_solver;
vec<int> _graphMappingVar;
vec<int> _graphMappingHard;
vec<int> _graphMappingSoft;
int _randomSeed;
int _nRandomPartitions;
int _nPartitions;
vec<Partition> _partitions;
Graph *_graph;
Graph_Communities _gc;
};
} // namespace openwbo
#endif // MAXSAT_PARTITION_H