public void Solve_MultipleResults() { ExactCover exactCover = new ExactCover(); var input = new byte[, ] { { 1, 0, 1, 0 }, { 1, 0, 1, 0 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 1 }, }; var results = exactCover.GetAllSolutions(input); Assert.AreEqual(2, results.Count); var result1 = results[0]; Assert.AreEqual(2, result1.Count); Assert.True(result1.Contains(0)); Assert.True(result1.Contains(1)); var result2 = results[1]; Assert.AreEqual(2, result2.Count); Assert.True(result2.Contains(2)); Assert.True(result2.Contains(3)); }
public void Solve_NoResults()//Because empty column cannot be satisfied { ExactCover exactCover = new ExactCover(); var input = new byte[, ] { { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 1 }, { 0, 0, 0, 1, 1, 0 }, { 1, 1, 1, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0 }, { 0, 0, 0, 1, 1, 0 }, { 1, 0, 1, 0, 1, 1 }, }; var results = exactCover.GetAllSolutions(input); Assert.AreEqual(0, results.Count); }
public void CheckMultipleSolutions_False() { ExactCover exactCover = new ExactCover(); var input = new byte[, ] { { 1, 0, 1, 0 }, { 1, 0, 1, 0 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 0, 1, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 1 }, }; var result = exactCover.MoreThanOneSolution(input); Assert.False(result); }
public void GetFirstSolution() { ExactCover exactCover = new ExactCover(); var input = new byte[, ] { { 1, 0, 1, 0 }, { 1, 0, 1, 0 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 1 }, }; var result = exactCover.GetFirstSolution(input); Assert.True(result.Contains(0)); Assert.True(result.Contains(1)); }
public void Solve_RowAllZero() { ExactCover exactCover = new ExactCover(); var input = new byte[, ] { { 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 1 }, { 0, 0, 0, 1, 1, 0 }, { 0, 1, 1, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0 }, { 0, 0, 0, 1, 1, 0 }, { 0, 0, 1, 0, 1, 1 }, }; var results = exactCover.GetAllSolutions(input); Assert.AreEqual(1, results.Count); var result = results[0]; Assert.AreEqual(3, result.Count); Assert.True(result.Contains(1)); Assert.True(result.Contains(3)); Assert.True(result.Contains(5)); }
private static void Cover1() { ExactCover ec = new ExactCover( 8 ); ec.Add( new int[] { 1, 0, 0, 0, 0, 0, 0, 0 }, "0" ); ec.Add( new int[] { 0, 1, 0, 0, 0, 0, 0, 0 }, "1" ); ec.Add( new int[] { 0, 0, 1, 0, 0, 0, 0, 0 }, "2" ); ec.Add( new int[] { 0, 0, 0, 1, 0, 0, 0, 0 }, "3" ); ec.Add( new int[] { 0, 0, 0, 0, 1, 0, 0, 0 }, "4" ); ec.Add( new int[] { 0, 0, 0, 0, 0, 1, 0, 0 }, "5" ); ec.Add( new int[] { 0, 0, 0, 0, 0, 0, 1, 0 }, "6" ); ec.Add( new int[] { 0, 0, 0, 0, 0, 0, 0, 1 }, "7" ); ec.Add( new int[] { 1, 1, 0, 0, 0, 0, 0, 0 }, "8" ); ec.Add( new int[] { 0, 1, 1, 0, 0, 0, 0, 0 }, "9" ); ec.Add( new int[] { 0, 0, 1, 1, 0, 0, 0, 0 }, "10" ); ec.Add( new int[] { 0, 0, 0, 1, 1, 0, 0, 0 }, "11" ); ec.Add( new int[] { 0, 0, 0, 0, 1, 1, 0, 0 }, "12" ); ec.Add( new int[] { 0, 0, 0, 0, 0, 1, 1, 0 }, "13" ); ec.Add( new int[] { 0, 0, 0, 0, 0, 0, 1, 1 }, "14" ); ec.Add( new int[] { 1, 1, 1, 1, 0, 0, 0, 0 }, "15" ); ec.Add( new int[] { 0, 0, 0, 0, 1, 1, 1, 1 }, "16" ); Cover cover = new Cover( ec.Solver, 8, ec.List ); Cover.Search goal = new Cover.Search( cover ); ec.Solver.Solve( goal ); ec.Solver.Out.WriteLine( cover.Index.Domain.Cardinality.ToString() + "\t" + cover.Index.ToString() ); while( ec.Solver.Next() ) { ec.Solver.Out.WriteLine( cover.Index.Domain.Cardinality.ToString() + "\t" + cover.Index.ToString() ); } ec.Solver.PrintInformation(); }