14
14
15
15
public class DimacsFileGenerator {
16
16
17
- final static int WITHOUT_SB = 0 ;
18
- final static int BFS_SB = 1 ;
19
- final static int CLIQUE_SB = 2 ;
17
+ enum SBStrategy {
18
+ WITHOUT_SB , BFS_SB , CLIQUE_SB ;
19
+ }
20
+
21
+ // Exception??
22
+
23
+ public SBStrategy getSBStrategyByNum (int num ) {
24
+ switch (num ) {
25
+ case 0 :
26
+ return SBStrategy .WITHOUT_SB ;
27
+ case 2 :
28
+ return SBStrategy .CLIQUE_SB ;
29
+ default :
30
+ return SBStrategy .BFS_SB ;
31
+ }
32
+ }
20
33
21
34
private APTA apta ;
22
35
private ConsistencyGraph cg ;
23
36
private int colors ;
24
37
private int maxVar ;
25
38
private int vertices ;
26
- private PrintWriter pwDF ;
27
39
private Set <String > alphabet ;
28
40
private int [][] x ;
29
41
private Map <String , Integer >[][] y ;
@@ -36,37 +48,23 @@ public class DimacsFileGenerator {
36
48
private String tmpFile = "tmp" ;
37
49
private String dimacsFile ;
38
50
private int countClauses = 0 ;
39
- private int SB ;
51
+ private SBStrategy SB ;
40
52
private int noisyP ;
41
53
private int noisySize ;
42
54
private Set <Integer > acceptableClique ;
43
55
private Set <Integer > rejectableClique ;
44
56
private int color = 0 ;
45
57
private Set <Integer > ends ;
58
+
46
59
47
- public DimacsFileGenerator (APTA apta , ConsistencyGraph cg , int colors ,
48
- int SB ) throws IOException {
49
- init (apta , cg , colors , SB , 0 , "dimacsFile.cnf" );
50
- }
51
-
52
- public DimacsFileGenerator (APTA apta , ConsistencyGraph cg , int colors ,
53
- int SB , int noisyP ) throws IOException {
54
- init (apta , cg , colors , SB , noisyP , "dimacsFile.cnf" );
55
- }
56
-
57
- public DimacsFileGenerator (APTA apta , ConsistencyGraph cg , int colors ,
60
+ public DimacsFileGenerator (APTA apta , ConsistencyGraph cg , int noisyP , int colors ,
58
61
int SB , String dimacsFile ) throws IOException {
59
- init (apta , cg , colors , SB , 0 , dimacsFile );
60
- }
61
-
62
- public DimacsFileGenerator (APTA apta , ConsistencyGraph cg , int colors ,
63
- int SB , int noisyP , String dimacsFile ) throws IOException {
64
- init (apta , cg , colors , SB , noisyP , dimacsFile );
62
+ init (apta , cg , colors , getSBStrategyByNum (SB ), noisyP , dimacsFile );
65
63
}
66
64
67
65
@ SuppressWarnings ("unchecked" )
68
- private void init (APTA apta , ConsistencyGraph cg , int colors , int SB ,
69
- int noisyP , String dimacsFile ) throws IOException {
66
+ private void init (APTA apta , ConsistencyGraph cg , int colors ,
67
+ SBStrategy SB , int noisyP , String dimacsFile ) throws IOException {
70
68
this .apta = apta ;
71
69
this .cg = cg ;
72
70
this .colors = colors ;
@@ -75,10 +73,9 @@ private void init(APTA apta, ConsistencyGraph cg, int colors, int SB,
75
73
this .maxVar = 1 ;
76
74
this .vertices = apta .getSize ();
77
75
this .dimacsFile = dimacsFile ;
78
- this .pwDF = new PrintWriter (dimacsFile );
79
76
this .alphabet = apta .getAlphabet ();
80
77
this .ends = new HashSet <>();
81
-
78
+
82
79
this .x = new int [vertices ][colors ];
83
80
this .y = new HashMap [colors ][colors ];
84
81
this .z = new int [colors ];
@@ -100,7 +97,7 @@ private void init(APTA apta, ConsistencyGraph cg, int colors, int SB,
100
97
}
101
98
}
102
99
103
- if (SB == BFS_SB ) {
100
+ if (SB == SBStrategy . BFS_SB ) {
104
101
this .e = new int [colors ][colors ];
105
102
this .p = new int [colors ][colors ];
106
103
for (int i = 0 ; i < colors ; i ++) {
@@ -127,7 +124,7 @@ private void init(APTA apta, ConsistencyGraph cg, int colors, int SB,
127
124
}
128
125
}
129
126
130
- if (SB == CLIQUE_SB ) {
127
+ if (SB == SBStrategy . CLIQUE_SB ) {
131
128
int maxDegree = 0 ;
132
129
int maxV = -1 ;
133
130
acceptableClique = new HashSet <>();
@@ -178,7 +175,7 @@ private void init(APTA apta, ConsistencyGraph cg, int colors, int SB,
178
175
if (noisyP > 0 ) {
179
176
ends .addAll (apta .getAcceptableNodes ());
180
177
ends .addAll (apta .getRejectableNodes ());
181
-
178
+
182
179
noisySize = ends .size () * this .noisyP / 100 ;
183
180
n = new int [noisySize ][vertices ];
184
181
f = new int [vertices ];
@@ -197,9 +194,12 @@ private void init(APTA apta, ConsistencyGraph cg, int colors, int SB,
197
194
198
195
public String generateFile () throws IOException {
199
196
197
+
200
198
File tmp = new File (tmpFile );
201
199
PrintWriter tmpPW = new PrintWriter (tmp );
202
200
Buffer buffer = new Buffer (tmpPW );
201
+
202
+ PrintWriter pwDF = new PrintWriter (dimacsFile );
203
203
204
204
printOneAtLeast (buffer );
205
205
printOneAtMost (buffer );
@@ -208,13 +208,13 @@ public String generateFile() throws IOException {
208
208
printParrentRelationAtLeastOneColor (buffer );
209
209
printParrentRelationForces (buffer );
210
210
211
- if (SB == BFS_SB ) {
211
+ if (SB == SBStrategy . BFS_SB ) {
212
212
// root has 0 color
213
213
buffer .addClause (x [0 ][0 ]);
214
214
printSBPEdgeExist (buffer );
215
215
printSBPMinimalSymbol (buffer );
216
216
printSBPParent (buffer );
217
- // printSBPChildrenOrder(buffer);
217
+ // printSBPChildrenOrder(buffer);
218
218
if (apta .getAlphaSize () == 2 ) {
219
219
printSBPOrderByChildrenSymbolForSizeTwo (buffer );
220
220
} else {
@@ -223,7 +223,7 @@ public String generateFile() throws IOException {
223
223
printSBPOrderInLayer (buffer );
224
224
printSBPParentExist (buffer );
225
225
}
226
- if (SB == CLIQUE_SB ) {
226
+ if (SB == SBStrategy . CLIQUE_SB ) {
227
227
printAcceptableCliqueSB (buffer );
228
228
printRejectableCliqueSB (buffer );
229
229
}
@@ -234,7 +234,7 @@ public String generateFile() throws IOException {
234
234
printNoisyOrdered (buffer );
235
235
printFProxy (buffer );
236
236
printAccVertDiffColorRejNoisy (buffer );
237
-
237
+
238
238
} else {
239
239
printAccVertDiffColorRej (buffer );
240
240
printConflictsFromCG (buffer );
@@ -480,17 +480,17 @@ private void printSBPParent(Buffer buffer) {
480
480
buffer .flush ();
481
481
}
482
482
483
- // p_{i,j} and !p_{i+1,j} => !p_{i+q, j}
484
- private void printSBPChildrenOrder (Buffer buffer ) {
485
- for (int i = 1 ; i < colors ; i ++) {
486
- for (int j = 0 ; j < i ; j ++) {
487
- for (int k = i + 2 ; k < colors ; k ++) {
488
- buffer .addClause (-p [i ][j ], p [i + 1 ][j ], -p [k ][j ]);
489
- }
490
- }
491
- }
492
- buffer .flush ();
493
- }
483
+ // // p_{i,j} and !p_{i+1,j} => !p_{i+q, j}
484
+ // private void printSBPChildrenOrder(Buffer buffer) {
485
+ // for (int i = 1; i < colors; i++) {
486
+ // for (int j = 0; j < i; j++) {
487
+ // for (int k = i + 2; k < colors; k++) {
488
+ // buffer.addClause(-p[i][j], p[i + 1][j], -p[k][j]);
489
+ // }
490
+ // }
491
+ // }
492
+ // buffer.flush();
493
+ // }
494
494
495
495
// if alphabet size greater then 2
496
496
// p_{i,j} and p_{i+1,j} and m_{j,i,c_k} => !m_{j,i+1,c_(k-q)}
@@ -513,7 +513,7 @@ private void printSBPOrderByChildrenSymbol(Buffer buffer) {
513
513
}
514
514
515
515
// if alphabet size equal to 2
516
- // p_{i,j} and p_{i+1,j} => y_{j, i, 0} and y_{j, i + 1, 1}
516
+ // p_{i,j} and p_{i+1,j} => y_{j, i, 0} and y_{j, i + 1, 1}
517
517
private void printSBPOrderByChildrenSymbolForSizeTwo (Buffer buffer ) {
518
518
for (int i = 1 ; i < colors - 1 ; i ++) {
519
519
for (int j = 0 ; j < i ; j ++) {
@@ -524,7 +524,6 @@ private void printSBPOrderByChildrenSymbolForSizeTwo(Buffer buffer) {
524
524
buffer .flush ();
525
525
}
526
526
527
-
528
527
// p_{i,j} => !p_{i+1,j-q}
529
528
private void printSBPOrderInLayer (Buffer buffer ) {
530
529
for (int i = 1 ; i < colors - 1 ; i ++) {
0 commit comments