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