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 package org.sat4j.tools;
29
30 import org.sat4j.core.VecInt;
31 import org.sat4j.specs.ContradictionException;
32 import org.sat4j.specs.ISolver;
33 import org.sat4j.specs.IVecInt;
34
35
36
37
38
39
40
41
42
43
44 public class ExtendedDimacsArrayReader extends DimacsArrayReader {
45
46 public static final int FALSE = 1;
47
48 public static final int TRUE = 2;
49
50 public static final int NOT = 3;
51
52 public static final int AND = 4;
53
54 public static final int NAND = 5;
55
56 public static final int OR = 6;
57
58 public static final int NOR = 7;
59
60 public static final int XOR = 8;
61
62 public static final int XNOR = 9;
63
64 public static final int IMPLIES = 10;
65
66 public static final int IFF = 11;
67
68 public static final int IFTHENELSE = 12;
69
70 public static final int ATLEAST = 13;
71
72 public static final int ATMOST = 14;
73
74 public static final int COUNT = 15;
75
76 private static final long serialVersionUID = 1L;
77
78 private final GateTranslator gater;
79
80 public ExtendedDimacsArrayReader(ISolver solver) {
81 super(solver);
82 gater = new GateTranslator(solver);
83 }
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 @Override
100 protected boolean handleConstr(int gateType, int output, int[] inputs)
101 throws ContradictionException {
102 IVecInt literals;
103 switch (gateType) {
104 case FALSE:
105 assert inputs.length == 0;
106 gater.gateFalse(output);
107 break;
108 case TRUE:
109 assert inputs.length == 0;
110 gater.gateTrue(output);
111 break;
112 case OR:
113 literals = new VecInt(inputs);
114 gater.or(output, literals);
115 break;
116 case NOT:
117 assert inputs.length == 1;
118 gater.not(output, inputs[0]);
119 break;
120 case AND:
121 literals = new VecInt(inputs);
122 gater.and(output, literals);
123 break;
124 case XOR:
125 literals = new VecInt(inputs);
126 gater.xor(output, literals);
127 break;
128 case IFF:
129 literals = new VecInt(inputs);
130 gater.iff(output, literals);
131 break;
132 case IFTHENELSE:
133 assert inputs.length == 3;
134 gater.ite(output, inputs[0], inputs[1], inputs[2]);
135 break;
136 default:
137 throw new UnsupportedOperationException("Gate type " + gateType
138 + " not handled yet");
139 }
140 return true;
141 }
142 }