private void CalculateAppearances() { for (int i = 0; i < variables.List.Count; i++) { appearances.Add(new VariableAppearance(i, 0)); } foreach (var clause in clauses.List) { foreach (int var in clause) { int index = SatSolver.GetVar(var); appearances[index].Count++; } } appearances = appearances.OrderBy(o => - o.Variable).ToList(); }
private void InitVarCounts() { varCount.Clear(); for (int c = 0; c < clauses.List.Count; c++) { if (clauses.List[c] == null) { continue; } int len = clauses.List[c].Count; if (len < 2) { continue; } foreach (int variable in clauses.List[c]) { Key key = new Key(len, SatSolver.GetVar(variable)); if (variables[key.Variable] != 0) { continue; } if (varCount.ContainsKey(key)) { varCount[key]++; } else { varCount.Add(key, 1); } } } }
public UnitClause(int value) { this.Value = value; this.Index = SatSolver.GetVar(value); }
private static void SolveSatInstance(string instance) { //if (instance.Contains("bmc")) { // Console.WriteLine("Skippped: " + instance); // return; //} string instanceName = Path.GetFileName(instance); SatSolver solver = GetSolver(); solver.LoadProblem(instance); //solver.PrintState(); bool res = false; bool finished = false; Stopwatch watch = new Stopwatch(); long passed = 0; var cancel = new CancellationTokenSource(); Thread solveThread = new Thread(() => { res = solver.SolveImplementation(); finished = true; cancel.Cancel(); passed = watch.ElapsedMilliseconds; }); solveThread.Priority = ThreadPriority.Highest; watch.Start(); solveThread.Start(); while (watch.ElapsedMilliseconds < 120000) { Thread.Sleep(250); if (finished) { break; } } watch.Stop(); solveThread.Abort(); if (!finished) { Console.WriteLine($"Cancelled by timeout: \"{instanceName}\""); solveThread.Abort(); Console.WriteLine(); return; } string sat = res ? "SATISFIABLE" : "UNSATISFIABLE"; Console.WriteLine($"Solved problem \"{instanceName}\" in {passed} ms, result: {sat}"); PrintList(solver.GetVariableAssignments); solver.Clear(); Console.WriteLine(); }