1 #include "polarityassignment.h"
4 void computePolarities(CSolver* This) {
5 for (uint i=0; i < getSizeVectorBoolean(This->constraints); i++) {
6 Boolean* boolean = getVectorBoolean(This->constraints, i);
7 updatePolarity(boolean, P_TRUE);
8 updateMustValue(boolean, BV_MUSTBETRUE);
9 computePolarityAndBooleanValue(boolean);
13 void updatePolarity(Boolean *This, Polarity polarity) {
14 This->polarity |= polarity;
17 void updateMustValue(Boolean *This, BooleanValue value) {
18 This->boolVal |= value;
21 void computePolarityAndBooleanValue(Boolean* This) {
22 switch(GETBOOLEANTYPE(This)){
27 return computePredicatePolarityAndBooleanValue((BooleanPredicate*)This);
29 return computeLogicOpPolarityAndBooleanValue((BooleanLogic*)This);
35 void computePredicatePolarityAndBooleanValue(BooleanPredicate* This){
36 updatePolarity(This->undefStatus, P_BOTHTRUEFALSE);
37 computePolarityAndBooleanValue(This->undefStatus);
40 void computeLogicOpPolarityAndBooleanValue(BooleanLogic* This) {
41 computeLogicOpBooleanValue(This);
42 computeLogicOpPolarity(This);
43 uint size = getSizeArrayBoolean(&This->inputs);
44 for(uint i=0; i<size; i++) {
45 computePolarityAndBooleanValue(getArrayBoolean(&This->inputs, i));
49 Polarity negatePolarity(Polarity This) {
63 BooleanValue negateBooleanValue(BooleanValue This) {
69 return BV_MUSTBEFALSE;
77 void computeLogicOpPolarity(BooleanLogic* This) {
78 Polarity parentpolarity=GETBOOLEANPOLARITY(This);
82 uint size = getSizeArrayBoolean(& This->inputs);
83 for(uint i=0; i<size; i++){
84 Boolean* tmp= getArrayBoolean(&This->inputs, i);
85 updatePolarity(tmp, parentpolarity);
90 Boolean* tmp =getArrayBoolean(&This->inputs, 0);
91 updatePolarity(tmp, negatePolarity(parentpolarity));
95 updatePolarity(getArrayBoolean(&This->inputs, 0), P_BOTHTRUEFALSE);
96 updatePolarity(getArrayBoolean(&This->inputs, 1), P_BOTHTRUEFALSE);
100 Boolean* left = getArrayBoolean(&This->inputs, 0);
101 updatePolarity(left, negatePolarity( parentpolarity));
102 Boolean *right = getArrayBoolean(&This->inputs, 1);
103 updatePolarity(right, parentpolarity);
111 void computeLogicOpBooleanValue(BooleanLogic* This) {
112 BooleanValue parentbv = GETBOOLEANVALUE(This);
115 if (parentbv==BV_MUSTBETRUE || parentbv==BV_UNSAT) {
116 uint size = getSizeArrayBoolean(& This->inputs);
117 for(uint i=0; i<size; i++) {
118 updateMustValue(getArrayBoolean(&This->inputs, i), parentbv);
124 if (parentbv==BV_MUSTBEFALSE || parentbv==BV_UNSAT) {
125 uint size = getSizeArrayBoolean(& This->inputs);
126 for(uint i=0; i<size; i++) {
127 updateMustValue(getArrayBoolean(&This->inputs, i), parentbv);
133 updateMustValue(getArrayBoolean(&This->inputs, 0), negateBooleanValue(parentbv));
136 //implies is really an or with the first term negated
137 if (parentbv==BV_MUSTBEFALSE || parentbv==BV_UNSAT) {
138 uint size = getSizeArrayBoolean(& This->inputs);
139 updateMustValue(getArrayBoolean(&This->inputs, 0), negateBooleanValue(parentbv));
140 updateMustValue(getArrayBoolean(&This->inputs, 1), parentbv);