private static void NotAllTheSame() { //for every field, there should not be another field with all 4 properties the same. for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int i2 = 0; i2 < 4; i2++) { for (int j2 = 0; j2 < 4; j2++) { if (i != i2 || j != j2) { //so we create one and for all properties for these two fields List <CNFify.Term> AllProperties = new List <CNFify.Term>(); for (int k = 0; k < 4; k++) { var thisSquare = board[i, j, k]; var otherSquare = board[i2, j2, k]; var Equal = CNFify.equal(thisSquare, otherSquare); AllProperties.Add(Equal); } AllPropositions.Add(NotAllEqual(AllProperties)); } } } } } }
static void Main(string[] args) { initBoard(); //loop over the number of properties //every property should not be equal for all row, column and diagonal for (int k = 0; k < 4; k++) { GenerateRowRules(k); GenerateColumnRules(k); GenerateDiagonalRules(k); } //add the rules that not all stones should be the same NotAllTheSame(); //combine all rules FSharpList <CNFify.Term> FSharpAllPropositions = ListModule.OfSeq(AllPropositions); CNFify.Term all = CNFify.createAndClauseFromList(FSharpAllPropositions); var dimacs = CNFify.makeDimacs(all); using (System.IO.StreamWriter file = new System.IO.StreamWriter("..\\..\\..\\Minisat\\input")) { file.WriteLine(dimacs); } }
public void SimpleDeMorgan() { // ! (q ∧ r) ----> !q ∨ !r var T = CNFify.Term.NewNot(CNFify.Term.NewAnd(q, r)); var result = CNFify.normalize(T); var expected = CNFify.Term.NewOr(CNFify.Term.NewNot(q), CNFify.Term.NewNot(r)); Assert.AreEqual(expected, result); }
public void InnerDistribution() { // a ∧ (p ∨ (q ∧ r)) ----> a ∧ (q ∨ p) ∧ (r ∨ p) var T = CNFify.Term.NewAnd(a, CNFify.Term.NewOr(p, CNFify.Term.NewAnd(q, r))); var result = CNFify.normalize(T); var expected = CNFify.Term.NewAnd(a, CNFify.Term.NewAnd(CNFify.Term.NewOr(p, q), CNFify.Term.NewOr(p, r))); Assert.AreEqual(expected, result); }
public void SimpleEquality() { // (a <=> b) ----> (a ∨ !b) ∧ (b ∨ !a) var T = CNFify.equal(a, b); var result = CNFify.normalize(T); var expected = CNFify.Term.NewAnd( CNFify.Term.NewOr(CNFify.Term.NewNot(a), b), CNFify.Term.NewOr(CNFify.Term.NewNot(b), a) ); Assert.AreEqual(expected, result); }
private static CNFify.Term NotAllEqual(List <CNFify.Term> input) { //we now have a list of all squares that should not be equal, make a //not - and combi of them: // voor in de slides: gekut met types kan wel wat beter Microsoft //eerste poging ipv ListModule.OfSeq was: (Microsoft.FSharp.Collections.FSharpList<CNFify.Term>)AllAnds; CNFify.Term NotAllSame = CNFify.Term.NewNot( CNFify.createAndClauseFromList(ListModule.OfSeq(input)) ); return(NotAllSame); }
public void SimpleRemoveNotBImp() { // !(a <=> b) ----> (a ∨ b) ∧ (!b ∨ !a) var T = CNFify.Term.NewNot(CNFify.equal(a, b)); var result = CNFify.normalize(T); var expected = CNFify.Term.NewAnd( CNFify.Term.NewOr(b, a), CNFify.Term.NewOr(CNFify.Term.NewNot(a), CNFify.Term.NewNot(b)) ); Assert.AreEqual(expected, result); }
private static void GenerateRowRules(int k) { //loop over all rows for (int i = 0; i < 4; i++) { List <CNFify.Term> AllEqualities = new List <CNFify.Term>(); //loop over the number of columns for (int j = 0; j < 3; j++) { var thisSquare = board[i, j, k]; var neighbourSquare = board[i, j + 1, k]; //these two should not be equal, //the not is added at the upper level, here //we just spec the equality var Equal = CNFify.equal(thisSquare, neighbourSquare); AllEqualities.Add(Equal); } AllPropositions.Add(NotAllEqual(AllEqualities)); } }
private static void GenerateDiagonalRules(int k) { List <CNFify.Term> Diagonal1Equalities = new List <CNFify.Term>(); List <CNFify.Term> Diagonal2Equalities = new List <CNFify.Term>(); //step through the four diagonal cells for (int i = 0; i < 3; i++) { //one diagonal var thisSquare = board[i, i, k]; var neighbourSquare = board[i + 1, i + 1, k]; //these two should not be equal, //the not is added at the upper level, here //we just spec the biimplication var Equal = CNFify.equal(thisSquare, neighbourSquare); Diagonal1Equalities.Add(Equal); //the other diagonal var thisSquare2 = board[i, 3 - i, k]; var neighbourSquare2 = board[i + 1, 3 - (i + 1), k]; //these two should not be equal, //the not is added at the upper level, here //we just spec the equality var Equal2 = CNFify.equal(thisSquare, neighbourSquare); Diagonal2Equalities.Add(Equal2); } AllPropositions.Add(NotAllEqual(Diagonal1Equalities)); AllPropositions.Add(NotAllEqual(Diagonal2Equalities)); }