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