I'm doing a SAT Solver (mainly the DPLL or Partial DPLL) and I have the method for Unit Propogation. Basically what it does is that it checks whether there are any standalone literals, and removes that literal, and any instance found in the other clauses. Any Example would be
(x) (x,y) (w,z)
the Unit Propogation would be 'x' and when performing the unit prop it would leave only (w,z)
In this method I have several nested foreach
loops and List<literals>
<literals>
is a custom made class which has 2 variables hasNegation
(bool) and char literalCharacter
The Coding is below, and will explain from below
foreach (clauses c1 in listOfClauses)
{
if (c1.listOfLiterals.Count == 1)
{
literals l1 = c1.listOfLiterals[0];
solved.Add(l1);
foreach (clauses c2 in listOfClauses)
{
List<literals> tempList = new List<literals>();
foreach (literals l2 in listOfLiterals)
{
if (l2.solveDPLL(l1))
{
removable.Add(c2);
}
else
{
if (c2.listOfLiterals.Count == 1)
{
UNSAT = true;
return false;
}
else
{
if (l1.solveDPLL(l2))
{
tempList.Add(l2);
}
}
}
c2.listOfLiterals.RemoveAll(tempList); //obviously giving error
}
}
}
}
return true;
}
I have 2 List <literals>
which are templist
and listOfLiterals
where the LATTER is the "parent"
I am tryign to remove the entries of listOfLiterals
that match with tempList
and I use c2.listOfLiterals.RemoveAll(tempList);
obviously will output an error as it is not a Delegate.
I've searched a lot,even on stackoverflow, but every one of them compares either to an ID or an integer. In my case, since I'm just comparing 2 Lists
, how can I do the delegate so that, the entries that are the same in both listOfLiterals and tempList are removed from listOfLiterals?
Many thanks
EDIT:
Literals Class
public class literals
{
public char literalCharacter { get; set; }
public bool negation { get; set; }
public literals(char lc, bool neg )
{
literalCharacter = lc;
negation = neg;
}
public bool solveDPLL (literals lit)
{
return ((Object.Equals(literalCharacter, lit.literalCharacter) && (negation == lit.negation)));
}
public String toString()
{
return literalCharacter + " : " + !negation;
}
}