/** * @param f the formula * @param I an interpretation * @return TRUE if it is satisfied, FALSE if it is falsified, UNDEF if one can not answer this question */ int statusFormula(Formula f,Interpretation I) { int nbSat=0; node * p=f.clauses; while (p!=NULL) { if(isSatisfiedClause(*(p->clause),I)==TRUE)nbSat++; else if(isSatisfiedClause(*(p->clause),I)==FALSE)return FALSE; assert(p!=p->next); p=p->next; } if(nbSat==f.nbClauses)return TRUE; return UNDEF; }
int main(){ Formula f; Interpretation I; int clauses=rand()%20; int var=rand()%30; createFormula(&f, clauses, var); generateFullRandomFormula(&f,clauses,var); createAndInitializeInterpretation(&I, f.nbVariables); for (int i = 0; i < f.nbVariables; ++i) { assignVariable(I,i,rand()%2); } int randomValue= rand()%(f.nbClauses); printf("\nstatus of a random clause %d: %d",randomValue,statusClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nsatifcation of a random clause %d : %d",randomValue,isSatisfiedClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nfalsefcation of a random clause %d : %d",randomValue,isFalsifiedClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nUndetermination of a random clause %d : %d",randomValue,isUndefClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nUnit of a random clause %d : %d",randomValue,isUnit(f.clauses[randomValue],I)); printf("\nThe status of the fourmla is %d",statusFormula(f,I)); printf("\nSatification of the fourmla is %d",isSatisfiedFormula(f,I)); printf("\nFalefication of the fourmla is %d",isFalsifiedFormula(f,I)); printf("\nUndetermination of the fourmla is %d",isUndefFormula(f,I)); displayFormula(f,I); }
/** new * gives the status of a clause under a given interpretation if it is staticfied by only one literal or not * @param c the clause * @parm I the interpretation * @parm l the litiral * @return TRUE if it is satisfied uniquely, FALSE if not uniquely satiscfied. */ int isUniquelySat(Clause c , Interpretation I , Literal l) { assert(isSatisfiedClause(c,I)); int status=0; int temp=-1; for (int i = 0; i < c.size; ++i) { if (c.datas[i]!=l) { temp=getValueLiteral(I, c.datas[i]); //printf("value of literal %d: %d\n",c.datas[i], temp); assert(temp!=-1); status=status|| temp; if (status) { return FALSE; } } } status=status||getValueLiteral(I,l); assert(status); return TRUE; }
/** * give the status of a clause under a given interpretation * @param c the clause * @parm I the interpretation * @return TRUE if it is satisfied, FALSE if it is falsified, UNDEF if one can not answer this question */ int statusClause(Clause c,Interpretation I) { if (isUndefClause(c,I)) return UNDEF; else if (isUndefClause(c,I)) return FALSE; else if (isSatisfiedClause(c,I)) return TRUE; else return UNDEF; }
int isUndefClause(Clause c,Interpretation I) { if (!isFalsifiedClause(c,I) && !isSatisfiedClause(c,I)) return TRUE; if (!isFalsifiedClause(c,I) && !isSatisfiedClause(c,I)) return TRUE; else return FALSE; }