1 #include "polarityassignment.h"
4 void computePolarities(CSolver *This) {
5 SetIteratorBooleanEdge *iterator = This->getConstraints();
6 while (iterator->hasNext()) {
7 BooleanEdge boolean = iterator->next();
8 Boolean *b = boolean.getBoolean();
9 bool isNegated = boolean.isNegated();
11 updatePolarity(b, P_FALSE);
12 updateMustValue(b, BV_MUSTBEFALSE);
14 updatePolarity(b, P_TRUE);
15 updateMustValue(b, BV_MUSTBETRUE);
17 computePolarityAndBooleanValue(b);
22 void updatePolarity(Boolean *This, Polarity polarity) {
23 This->polarity = (Polarity) (This->polarity | polarity);
26 void updateMustValue(Boolean *This, BooleanValue value) {
27 This->boolVal = (BooleanValue) (This->boolVal | value);
30 void computePolarityAndBooleanValue(Boolean *This) {
36 return computePredicatePolarityAndBooleanValue((BooleanPredicate *)This);
38 return computeLogicOpPolarityAndBooleanValue((BooleanLogic *)This);
44 void computePredicatePolarityAndBooleanValue(BooleanPredicate *This) {
45 if (This->undefStatus) {
46 updatePolarity(This->undefStatus.getBoolean(), P_BOTHTRUEFALSE);
47 computePolarityAndBooleanValue(This->undefStatus.getBoolean());
51 void computeLogicOpPolarityAndBooleanValue(BooleanLogic *This) {
52 computeLogicOpBooleanValue(This);
53 computeLogicOpPolarity(This);
54 uint size = This->inputs.getSize();
55 for (uint i = 0; i < size; i++) {
56 computePolarityAndBooleanValue(This->inputs.get(i).getBoolean());
60 Polarity negatePolarity(Polarity This) {
74 BooleanValue negateBooleanValue(BooleanValue This) {
80 return BV_MUSTBEFALSE;
88 void computeLogicOpPolarity(BooleanLogic *This) {
89 Polarity parentpolarity = This->polarity;
92 uint size = This->inputs.getSize();
93 for (uint i = 0; i < size; i++) {
94 BooleanEdge tmp = This->inputs.get(i);
95 Boolean *btmp = tmp.getBoolean();
96 updatePolarity(btmp, tmp.isNegated() ? negatePolarity(parentpolarity) : parentpolarity);
101 updatePolarity(This->inputs.get(0).getBoolean(), P_BOTHTRUEFALSE);
102 updatePolarity(This->inputs.get(1).getBoolean(), P_BOTHTRUEFALSE);
110 void computeLogicOpBooleanValue(BooleanLogic *This) {
111 BooleanValue parentbv = This->boolVal;
114 if (parentbv == BV_MUSTBETRUE || parentbv == BV_UNSAT) {
115 uint size = This->inputs.getSize();
116 for (uint i = 0; i < size; i++) {
117 BooleanEdge be=This->inputs.get(i);
118 updateMustValue(be.getBoolean(), be.isNegated()?negateBooleanValue(parentbv):parentbv);