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);
13 updatePolarity(b, P_TRUE);
20 void updatePolarity(Boolean *This, Polarity polarity) {
21 This->polarity = (Polarity) (This->polarity | polarity);
24 void updateMustValue(Boolean *This, BooleanValue value) {
25 This->boolVal = (BooleanValue) (This->boolVal | value);
28 void computePolarity(Boolean *This) {
34 return computePredicatePolarity((BooleanPredicate *)This);
36 return computeLogicOpPolarity((BooleanLogic *)This);
42 void computePredicatePolarity(BooleanPredicate *This) {
43 if (This->undefStatus) {
44 updatePolarity(This->undefStatus.getBoolean(), P_BOTHTRUEFALSE);
45 computePolarity(This->undefStatus.getBoolean());
49 void computeLogicOpPolarity(BooleanLogic *This) {
50 computeLogicOpPolarityChildren(This);
51 uint size = This->inputs.getSize();
52 for (uint i = 0; i < size; i++) {
53 computePolarity(This->inputs.get(i).getBoolean());
57 Polarity negatePolarity(Polarity This) {
71 BooleanValue negateBooleanValue(BooleanValue This) {
77 return BV_MUSTBEFALSE;
85 void computeLogicOpPolarityChildren(BooleanLogic *This) {
86 Polarity parentpolarity = This->polarity;
89 uint size = This->inputs.getSize();
90 for (uint i = 0; i < size; i++) {
91 BooleanEdge tmp = This->inputs.get(i);
92 Boolean *btmp = tmp.getBoolean();
93 updatePolarity(btmp, tmp.isNegated() ? negatePolarity(parentpolarity) : parentpolarity);
98 updatePolarity(This->inputs.get(0).getBoolean(), P_BOTHTRUEFALSE);
99 updatePolarity(This->inputs.get(1).getBoolean(), P_BOTHTRUEFALSE);