static void Main(string[] args) { AdjacentMap wichtelAdjazentMap = GetWichtelAdjazentMap(); Dictionary <String, Variable> variableStore = new Dictionary <string, Variable>(); Formula wichtel3Sat = IndependentSetReducer.ReduceTo3Sat(wichtelAdjazentMap, variableStore); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var satisfiableInfo = new SatResolver().IsSatisfiable(wichtel3Sat); stopwatch.Stop(); Console.WriteLine($"{Console.Out.NewLine}Time elapsed: {stopwatch.Elapsed}"); bool[] maxSatisfiebleAssignment = SatUtil.GetMaxSatisfiebleAssignment(satisfiableInfo.SatisfiableAssignments); if (satisfiableInfo.IsSatisfiable && maxSatisfiebleAssignment.Count(a => a) > 0) { Console.WriteLine("\nResolved Wichtel Independet Set!"); for (int i = 0; i < satisfiableInfo.VariableList.Count; i++) { Console.WriteLine("Wichtel {0}: {1}", satisfiableInfo.VariableList[i].Name, maxSatisfiebleAssignment[i]); } } else { Console.WriteLine("\nCould not resolve Wichtel Independet Set!"); } Console.ReadLine(); }
static void Main(string[] args) { var formula = ReduceTuringMachineToSat(GetPalindromTuringMachineInfo()); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var satisfiableInfo = new SatResolver().IsSatisfiable(formula); stopwatch.Stop(); Console.WriteLine($"{Console.Out.NewLine}Time elapsed: {stopwatch.Elapsed}"); bool[] maxSatisfiebleAssignment = SatUtil.GetMaxSatisfiebleAssignment(satisfiableInfo.SatisfiableAssignments); if (satisfiableInfo.IsSatisfiable && maxSatisfiebleAssignment.Count(a => a) > 0) { Console.WriteLine("\nFor the turing machine exists a calculation!"); } else { Console.WriteLine("\nFor the turing machine does not exists a calculation!"); } }
static void Main(string[] args) { Variable arya = new Variable("Arya"); Variable brandon = new Variable("Brandon"); Variable cersei = new Variable("Cersei"); Variable dany = new Variable("Dany"); Variable eddard = new Variable("Eddard"); Variable gilly = new Variable("Gilly"); Variable jon = new Variable("Jon"); Variable melisandre = new Variable("Melisandre"); Variable rob = new Variable("Rob"); Variable sansa = new Variable("Sansa"); Operator and = new Operator(Operator.Types.And); Operator or = new Operator(Operator.Types.Or); Operator not = new Operator(Operator.Types.Not); var dinnerPartyProblem = new Formula() { new Bracket() { not, arya, or, not, brandon }, and, new Bracket() { not, arya, or, not, cersei }, and, new Bracket() { not, arya, or, not, gilly }, and, new Bracket() { not, brandon, or, not, arya }, and, new Bracket() { not, brandon, or, not, jon }, and, new Bracket() { not, brandon, or, not, melisandre }, and, new Bracket() { not, cersei, or, not, arya }, and, new Bracket() { not, cersei, or, not, dany }, and, new Bracket() { not, cersei, or, not, rob }, and, new Bracket() { not, dany, or, not, cersei }, and, new Bracket() { not, dany, or, not, eddard }, and, new Bracket() { not, dany, or, not, melisandre }, and, new Bracket() { not, eddard, or, not, dany }, and, new Bracket() { not, eddard, or, not, gilly }, and, new Bracket() { not, eddard, or, not, jon }, and, new Bracket() { not, gilly, or, not, arya }, and, new Bracket() { not, gilly, or, not, eddard }, and, new Bracket() { not, gilly, or, not, sansa }, and, new Bracket() { not, jon, or, not, brandon }, and, new Bracket() { not, jon, or, not, eddard }, and, new Bracket() { not, jon, or, not, rob }, and, new Bracket() { not, melisandre, or, not, brandon }, and, new Bracket() { not, melisandre, or, not, dany }, and, new Bracket() { not, melisandre, or, not, sansa }, and, new Bracket() { not, rob, or, not, cersei }, and, new Bracket() { not, rob, or, not, jon }, and, new Bracket() { not, rob, or, not, sansa }, and, new Bracket() { not, sansa, or, not, gilly }, and, new Bracket() { not, sansa, or, not, melisandre }, and, new Bracket() { not, sansa, or, not, rob } }; var satResolver = new SatResolver(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var satisfiableInfo = satResolver.IsSatisfiable(dinnerPartyProblem); stopwatch.Stop(); Console.WriteLine($"{Console.Out.NewLine}Time elapsed: {stopwatch.Elapsed}"); bool[] maxSatisfiebleAssignment = SatUtil.GetMaxSatisfiebleAssignment(satisfiableInfo.SatisfiableAssignments); if (satisfiableInfo.IsSatisfiable && maxSatisfiebleAssignment.Count(a => a) > 0) { Console.WriteLine("\nThe dinner party problem is satisfiable!"); for (int i = 0; i < satisfiableInfo.VariableList.Count; i++) { Console.WriteLine("{0}:{1}", satisfiableInfo.VariableList[i].Name, maxSatisfiebleAssignment[i]); } } else { Console.WriteLine("\nThe dinner party problem is not satisfiable!"); } Console.ReadLine(); }
private static void Main(string[] args) { var graph = new AdjacentMap() { { "A", new List <string>() { "B", "F", "C", "E" } }, { "B", new List <string>() { "A", "C", "D", "F" } }, { "C", new List <string>() { "B", "D", "A", "E" } }, { "D", new List <string>() { "C", "E", "B", "F" } }, { "E", new List <string>() { "D", "F", "C", "A" } }, { "F", new List <string>() { "E", "A", "B", "D" } } }; Formula formula = ThreeColoringReducer.ReduceTo3Sat(graph); Console.WriteLine("Formula:"); Console.WriteLine(formula); var satResolver = new SatResolver(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var satisfiableInfo = satResolver.IsSatisfiable(formula); stopwatch.Stop(); Console.WriteLine($"{Console.Out.NewLine}Time elapsed: {stopwatch.Elapsed}"); bool[] maxSatisfiebleAssignment = SatUtil.GetMaxSatisfiebleAssignment(satisfiableInfo.SatisfiableAssignments); if (satisfiableInfo.IsSatisfiable && maxSatisfiebleAssignment.Count(a => a) > 0) { Console.WriteLine("\nThe graph is 3-colorable!"); for (int i = 0; i < satisfiableInfo.VariableList.Count; i++) { var nodeColorInfo = satisfiableInfo.VariableList[i].Name .Split("|", StringSplitOptions.RemoveEmptyEntries); Console.WriteLine("Node {0}|{1}:{2}", nodeColorInfo[0], nodeColorInfo[1], maxSatisfiebleAssignment[i]); } } else { Console.WriteLine("\nThe graph is not 3-colorable!"); } Console.Out.Flush(); Console.ReadLine(); }