Example #1
0
        private Dictionary <string, bool> Solve(List <Clause> clauses, SolverType type)
        {
            Dictionary <string, bool> solution;
            SolverStatus status;

            if (type == SolverType.SAT)
            {
                solution = SolveSAT(clauses, out status);
            }
            else if (type == SolverType.mhs)
            {
                solution = SolveMHS(clauses, out status);
            }
            else if (type == SolverType.MaxSAT)
            {
                solution = SolveMaxSAT(clauses, out status);
            }
            else
            {
                throw new RepairException("Invalid solver type!");
            }

            ClauseLogger.Log(clauses, type, solution);
            if (status == SolverStatus.Unsatisfiable)
            {
                throw new RepairException("The program could not be repaired because of unsatisfiable clauses!");
            }

            return(solution);
        }
Example #2
0
        /// <summary>
        /// Determine the optimized barrier assignments based on the error traces.
        /// </summary>
        /// <param name="errors">The errors.</param>
        /// <param name="solution">The solution obtained so far.</param>
        /// <param name="type">The solver type used.</param>
        /// <returns>The barrier assignments.</returns>
        public Dictionary <string, bool> Optimize(
            List <RepairableError> errors, Dictionary <string, bool> solution, out SolverType type)
        {
            List <Clause> clauses = GenerateClauses(errors);

            Dictionary <string, int> coeffs = new Dictionary <string, int>();

            foreach (Barrier barrier in ProgramMetadata.Barriers.Values)
            {
                coeffs.Add(barrier.Name, barrier.Weight);
            }

            type = SolverType.Optimizer;
            while (true)
            {
                int total_weight = 0;
                foreach (string key in solution.Where(x => x.Value == true).Select(x => x.Key))
                {
                    total_weight += coeffs[key];
                }

                using (Watch watch = new Watch(Measure.Optimization))
                {
                    SolverStatus status;

                    Optimizer optimizer = new Optimizer(clauses, coeffs);
                    Dictionary <string, bool> assignments = optimizer.Solve(--total_weight, out status);

                    if (status == SolverStatus.Unsatisfiable)
                    {
                        ClauseLogger.Log(clauses, type, solution);
                        return(solution);
                    }
                    else
                    {
                        solution = assignments;
                    }
                }
            }
        }