Пример #1
0
        public static void Main( )
        {
            var problem = new Problem3Sat(4, 5);

            problem.AddClause(new[] { 1, -2, 3 });
            problem.AddClause(new[] { -1, -4, 2 });
            problem.AddClause(new[] { 4, -2, -3 });
            problem.AddClause(new[] { 2, -3, 1 });
            problem.AddClause(new[] { 1, -3, 4 });

            var graph = new Graph(problem);

            problem.Solution = graph.SolveIdset( );
            Console.WriteLine(problem);

            Console.ReadLine( );
        }
Пример #2
0
        public Graph(Problem3Sat problem)
        {
            Clauses = new List <Clause> (problem.K);
            foreach (var clause in problem.Clauses)
            {
                Clauses.Add(new Clause(clause));
            }

            foreach (var clause in Clauses)
            {
                foreach (var node in clause.Nodes)
                {
                    node.AddNeighbours(
                        Clauses
                        .Where(x => x.Contains(node.Complement))
                        .Select(x => x.GetNode(node.Complement))
                        );
                }
            }
        }