예제 #1
0
        public static void Reset()
        {
            //Debug.WriteLine("SAT Reset IN!");
            instance = null;
            ConstraintSystemSolver newSolver = ConstraintSystemSolver.Instance;

            wireTermsDictionary.Clear();
            //Debug.WriteLine("SAT Reset OUT!");
        }
예제 #2
0
        /// <summary>
        ///  If true its a diagnosis
        //   If false its a conflict
        /// </summary>
        /// <param name="observation"></param>
        /// <param name="posibleConflict"></param>
        /// <returns></returns>
        public bool CheckConsistensy(Observation observation, List <Gate> posibleConflict)
        {
            lock (Locker)
            {
                //Debug.WriteLine("SAT CheckConsistensy IN!");

                // Set broken gates
                foreach (Gate gate in posibleConflict)
                {
                    gate.IsNotHealthy = true;
                }

                /*
                 * // Add input constrain
                 * List<Wire> allInputWires = observation.TheModel.Input;
                 * foreach (Wire wire in allInputWires)
                 * {
                 * Solver.AddConstraints(wire.GetTerm());
                 * }
                 *
                 *
                 * // Add output constrain
                 * List<Wire> allOutputWires = observation.TheModel.Output;
                 * foreach (Wire wire in allOutputWires)
                 * {
                 * Solver.AddConstraints(wire.GetTerm());
                 * }
                 */

                // Add components constrain
                List <Gate> allSystemGates = observation.TheModel.Components;
                foreach (Gate gate in allSystemGates)
                {
                    gate.AddConstaint();
                }


                ConstraintSolverSolution solution;
                try
                {
                    solution = Solver.Solve();
                }
                catch (Exception)
                {
                    Reset();
                    solution = Solver.Solve();
                }



                // If true its a diagnosis
                // If false its a conflict
                bool explainOutput = solution.HasFoundSolution;

                if (!explainOutput)
                {
                    Debug.WriteLine("SAT Doesn't found a solution. The new node is N-O-T a diagnosis!");
                }

                //Reset
                instance = null;
                Solver.ResetSolver();
                ConstraintSystemSolver newSolver = ConstraintSystemSolver.Instance;
                wireTermsDictionary.Clear();

                //Revert broken
                foreach (Gate gate in posibleConflict)
                {
                    gate.IsNotHealthy = false;
                }

                //Debug.WriteLine("SAT CheckConsistensy OUT!");
                return(explainOutput);
            }
        }