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); }
/// <summary> /// Populates the metadata. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="useAxioms">Use axioms for instrumentation instead of variable assignments.</param> public static void PopulateMetadata(string filePath, bool useAxioms) { Program program = BoogieUtilities.ReadFile(filePath); PopulateLocations(filePath.Replace(".cbpl", ".loc")); PopulateBarriers(program, useAxioms); PopulateLoopInformation(program); ClauseLogger.LogWeights(); Logger.Log($"GridLevelBarriers;{Barriers.Values.Where(x => x.GridLevel).Count()}"); Logger.Log($"LoopBarriers;{Barriers.Values.Where(x => x.LoopDepth > 0).Count()}"); }
/// <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; } } } }