diff --git a/kissat-inc/makefile b/kissat-inc/makefile index 37626dd..8e4ab81 100644 --- a/kissat-inc/makefile +++ b/kissat-inc/makefile @@ -1,17 +1,17 @@ all: - $(MAKE) -C "/pub/netdisk1/qianyh/Light/kissat-inc/build" + $(MAKE) -C "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" kissat: - $(MAKE) -C "/pub/netdisk1/qianyh/Light/kissat-inc/build" kissat + $(MAKE) -C "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" kissat tissat: - $(MAKE) -C "/pub/netdisk1/qianyh/Light/kissat-inc/build" tissat + $(MAKE) -C "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" tissat clean: - rm -f "/pub/netdisk1/qianyh/Light/kissat-inc"/makefile - -$(MAKE) -C "/pub/netdisk1/qianyh/Light/kissat-inc/build" clean - rm -rf "/pub/netdisk1/qianyh/Light/kissat-inc/build" + rm -f "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc"/makefile + -$(MAKE) -C "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" clean + rm -rf "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" coverage: - $(MAKE) -C "/pub/netdisk1/qianyh/Light/kissat-inc/build" coverage + $(MAKE) -C "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" coverage indent: - $(MAKE) -C "/pub/netdisk1/qianyh/Light/kissat-inc/build" indent + $(MAKE) -C "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" indent test: - $(MAKE) -C "/pub/netdisk1/qianyh/Light/kissat-inc/build" test + $(MAKE) -C "/home/chenzh/solvers/cloud-nobug/cloud-sat/kissat-inc/build" test .PHONY: all clean coverage indent kissat test tissat diff --git a/lstech_maple/LICENSE b/lstech_maple/LICENSE deleted file mode 100755 index d5ecee5..0000000 --- a/lstech_maple/LICENSE +++ /dev/null @@ -1,38 +0,0 @@ - -/*************************************************************************************** -MIT LICENSE - -lstech_maple, Relaxed_newTech -- Copyright (c) 2019-2021, Shaowei Cai, Xindi Zhang. -Reference: Shaowei Cai, Xindi Zhang: Deep Cooperation of CDCL and Local Search for SAT. -Xindi Zhang, Shaowei Cai: Relaxed Backtracking with Rephasing. - -MapleLCMDistChronoBT-DL, based on MapleLCMDistChronoBT -- Copyright (c) 2019, Stepan Kochemazov, Oleg Zaikin, Victor Kondratiev, Alexander Semenov: The solver was augmented with heuristic that moves duplicate learnt clauses into the core/tier2 tiers depending on a number of parameters. - -MapleLCMDistChronoBT, based on Maple_LCM_Dist -- Copyright (c) 2018, Alexander Nadel, Vadim Ryvchin: "Chronological Backtracking" in SAT-2018, pp. 111-121. - -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. - -Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh - -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - Copyright (c) 2007-2010, Niklas Sorensson - - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ \ No newline at end of file diff --git a/lstech_maple/README b/lstech_maple/README deleted file mode 100755 index 910d1b8..0000000 --- a/lstech_maple/README +++ /dev/null @@ -1,32 +0,0 @@ -How to build: - use the command "./starexec_build" - -How to use: - In the "bin" directory, - use the command "./lstech_maple " - e,g. ./lstech_maple ./simple_v3_c2.cnf - -The format of CNF: - the CNF format includes lines of 3-lines: - p-line: start with "p cnf ", followed by the number of variables and clauses. - c-line: comment lines. - clause-line: a clause can be represented by a series of numbers end with 0. - - For example: - c simple_v3_c2.cnf - c - p cnf 3 2 - 1 -3 0 - 2 3 -1 0 - - The details can be found in "https://people.sc.fsu.edu/~jburkardt/data/cnf/cnf.html" - -The output format: - c-line: comment lines - s-line: show the result of this call, SATISFIABLE UNSATISFIABLE or UNKNOWN. - v-line: show the model if SAT - - For example: - c result of simple_v3_c2.cnf - s SATISFIABLE - v 1 -2 3 0 \ No newline at end of file diff --git a/lstech_maple/bin/lstech_maple b/lstech_maple/bin/lstech_maple deleted file mode 100755 index 884d3f3..0000000 Binary files a/lstech_maple/bin/lstech_maple and /dev/null differ diff --git a/lstech_maple/lstech/.vscode/settings.json b/lstech_maple/lstech/.vscode/settings.json deleted file mode 100755 index b6f8178..0000000 --- a/lstech_maple/lstech/.vscode/settings.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "files.associations": { - "ostream": "cpp", - "iosfwd": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "array": "cpp", - "atomic": "cpp", - "*.tcc": "cpp", - "chrono": "cpp", - "cstdint": "cpp", - "deque": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "map": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "set": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/lstech_maple/lstech/core/Solver.cc b/lstech_maple/lstech/core/Solver.cc deleted file mode 100755 index f572ebe..0000000 --- a/lstech_maple/lstech/core/Solver.cc +++ /dev/null @@ -1,2831 +0,0 @@ -/***************************************************************************************[Solver.cc] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - Copyright (c) 2007-2010, Niklas Sorensson - -Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh - -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. - -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - -MapleLCMDistChronoBT, based on Maple_LCM_Dist -- Copyright (c), Alexander Nadel, Vadim Ryvchin: "Chronological Backtracking" in SAT-2018, pp. 111-121. - -MapleLCMDistChronoBT-DL, based on MapleLCMDistChronoBT -- Copyright (c), Stepan Kochemazov, Oleg Zaikin, Victor Kondratiev, Alexander Semenov: The solver was augmented with heuristic that moves duplicate learnt clauses into the core/tier2 tiers depending on a number of parameters. - -lstech, Relaxed_newTech -- Copyright (c) 2019-2021, Xindi Zhang, Shaowei Cai -Reference: Shaowei Cai, Xindi Zhang: Deep Cooperation of CDCL and Local Search for SAT. -Xindi Zhang, Shaowei Cai: Relaxed Backtracking with Rephasing. - - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#include -#include -#include -#include -#include - -#include "mtl/Sort.h" -#include "core/Solver.h" -#include "utils/ccnr.h" -#include "utils/System.h" -using namespace Minisat; - -//#define PRINT_OUT - -#ifdef BIN_DRUP -int Solver::buf_len = 0; -unsigned char Solver::drup_buf[2 * 1024 * 1024]; -unsigned char* Solver::buf_ptr = drup_buf; -#endif - - -//================================================================================================= -// Options: - - -static const char* _cat = "CORE"; - -static DoubleOption opt_step_size (_cat, "step-size", "Initial step size", 0.40, DoubleRange(0, false, 1, false)); -static DoubleOption opt_step_size_dec (_cat, "step-size-dec","Step size decrement", 0.000001, DoubleRange(0, false, 1, false)); -static DoubleOption opt_min_step_size (_cat, "min-step-size","Minimal step size", 0.06, DoubleRange(0, false, 1, false)); -static DoubleOption opt_var_decay (_cat, "var-decay", "The variable activity decay factor", 0.80, DoubleRange(0, false, 1, false)); -static DoubleOption opt_clause_decay (_cat, "cla-decay", "The clause activity decay factor", 0.999, DoubleRange(0, false, 1, false)); -static DoubleOption opt_random_var_freq (_cat, "rnd-freq", "The frequency with which the decision heuristic tries to choose a random variable", 0, DoubleRange(0, true, 1, true)); -static DoubleOption opt_random_seed (_cat, "rnd-seed", "Used by the random variable selection", 91648253, DoubleRange(0, false, HUGE_VAL, false)); -static IntOption opt_ccmin_mode (_cat, "ccmin-mode", "Controls conflict clause minimization (0=none, 1=basic, 2=deep)", 2, IntRange(0, 2)); -static IntOption opt_phase_saving (_cat, "phase-saving", "Controls the level of phase saving (0=none, 1=limited, 2=full)", 2, IntRange(0, 2)); -static BoolOption opt_rnd_init_act (_cat, "rnd-init", "Randomize the initial activity", false); -static IntOption opt_restart_first (_cat, "rfirst", "The base restart interval", 100, IntRange(1, INT32_MAX)); -static DoubleOption opt_restart_inc (_cat, "rinc", "Restart interval increase factor", 2, DoubleRange(1, false, HUGE_VAL, false)); -static DoubleOption opt_garbage_frac (_cat, "gc-frac", "The fraction of wasted memory allowed before a garbage collection is triggered", 0.20, DoubleRange(0, false, HUGE_VAL, false)); -static IntOption opt_chrono (_cat, "chrono", "Controls if to perform chrono backtrack", 100, IntRange(-1, INT32_MAX)); -static IntOption opt_conf_to_chrono (_cat, "confl-to-chrono", "Controls number of conflicts to perform chrono backtrack", 4000, IntRange(-1, INT32_MAX)); - -static IntOption opt_max_lbd_dup ("DUP-LEARNTS", "lbd-limit", "specifies the maximum lbd of learnts to be screened for duplicates.", 14, IntRange(0, INT32_MAX)); -static IntOption opt_min_dupl_app ("DUP-LEARNTS", "min-dup-app", "specifies the minimum number of learnts to be included into db.", 2, IntRange(2, INT32_MAX)); -static IntOption opt_dupl_db_init_size ("DUP-LEARNTS", "dupdb-init", "specifies the initial maximal duplicates DB size.", 1000000, IntRange(1, INT32_MAX)); - - -//================================================================================================= -// Constructor/Destructor: - - -Solver::Solver() : - - // Parameters (user settable): - // - worker_index (-1) - , worker_number (-1) - , worker_seed (-1) - , drup_file (NULL) - , verbosity (0) - , step_size (opt_step_size) - , step_size_dec (opt_step_size_dec) - , min_step_size (opt_min_step_size) - , timer (5000) - , var_decay (opt_var_decay) - , clause_decay (opt_clause_decay) - , random_var_freq (opt_random_var_freq) - , random_seed (opt_random_seed) - , VSIDS (false) - , ccmin_mode (opt_ccmin_mode) - , phase_saving (opt_phase_saving) - , rnd_pol (false) - , rnd_init_act (opt_rnd_init_act) - , garbage_frac (opt_garbage_frac) - , restart_first (opt_restart_first) - , restart_inc (opt_restart_inc) - - - , min_number_of_learnts_copies(opt_min_dupl_app) - , max_lbd_dup(opt_max_lbd_dup) - , dupl_db_init_size(opt_dupl_db_init_size) - - // Parameters (the rest): - // - , learntsize_factor((double)1/(double)3), learntsize_inc(1.1) - - // Parameters (experimental): - // - , learntsize_adjust_start_confl (100) - , learntsize_adjust_inc (1.5) - - // Statistics: (formerly in 'SolverStats') - // - , solves(0), starts(0), decisions(0), rnd_decisions(0), propagations(0), conflicts(0), conflicts_VSIDS(0) - , dec_vars(0), clauses_literals(0), learnts_literals(0), max_literals(0), tot_literals(0) - , chrono_backtrack(0), non_chrono_backtrack(0) - - , ok (true) - , cla_inc (1) - , var_inc (1) - , watches_bin (WatcherDeleted(ca)) - , watches (WatcherDeleted(ca)) - , qhead (0) - , simpDB_assigns (-1) - , simpDB_props (0) - , order_heap_CHB (VarOrderLt(activity_CHB)) - , order_heap_VSIDS (VarOrderLt(activity_VSIDS)) - , progress_estimate (0) - , remove_satisfied (true) - - , core_lbd_cut (2) - , global_lbd_sum (0) - , lbd_queue (50) - , next_T2_reduce (10000) - , next_L_reduce (15000) - , confl_to_chrono (opt_conf_to_chrono) - , chrono (opt_chrono) - - , counter (0) - - // Resource constraints: - // - , conflict_budget (-1) - , propagation_budget (-1) - , asynch_interrupt (false) - - // simplfiy - , nbSimplifyAll(0) - , s_propagations(0) - - // simplifyAll adjust occasion - , curSimplify(1) - , nbconfbeforesimplify(1000) - , incSimplify(1000) - -{} - - -Solver::~Solver() -{ -} - - -// simplify All -// -CRef Solver::simplePropagate() -{ - CRef confl = CRef_Undef; - int num_props = 0; - watches.cleanAll(); - watches_bin.cleanAll(); - while (qhead < trail.size()) - { - Lit p = trail[qhead++]; // 'p' is enqueued fact to propagate. - vec& ws = watches[p]; - Watcher *i, *j, *end; - num_props++; - - - // First, Propagate binary clauses - vec& wbin = watches_bin[p]; - - for (int k = 0; kblocker; - if (value(blocker) == l_True) - { - *j++ = *i++; continue; - } - - // Make sure the false literal is data[1]: - CRef cr = i->cref; - Clause& c = ca[cr]; - Lit false_lit = ~p; - if (c[0] == false_lit) - c[0] = c[1], c[1] = false_lit; - assert(c[1] == false_lit); - // i++; - - // If 0th watch is true, then clause is already satisfied. - // However, 0th watch is not the blocker, make it blocker using a new watcher w - // why not simply do i->blocker=first in this case? - Lit first = c[0]; - // Watcher w = Watcher(cr, first); - if (first != blocker && value(first) == l_True) - { - i->blocker = first; - *j++ = *i++; continue; - } - - // Look for new watch: - //if (incremental) - //{ // ----------------- INCREMENTAL MODE - // int choosenPos = -1; - // for (int k = 2; k < c.size(); k++) - // { - // if (value(c[k]) != l_False) - // { - // if (decisionLevel()>assumptions.size()) - // { - // choosenPos = k; - // break; - // } - // else - // { - // choosenPos = k; - - // if (value(c[k]) == l_True || !isSelector(var(c[k]))) { - // break; - // } - // } - - // } - // } - // if (choosenPos != -1) - // { - // // watcher i is abandonned using i++, because cr watches now ~c[k] instead of p - // // the blocker is first in the watcher. However, - // // the blocker in the corresponding watcher in ~first is not c[1] - // Watcher w = Watcher(cr, first); i++; - // c[1] = c[choosenPos]; c[choosenPos] = false_lit; - // watches[~c[1]].push(w); - // goto NextClause; - // } - //} - else - { // ----------------- DEFAULT MODE (NOT INCREMENTAL) - for (int k = 2; k < c.size(); k++) - { - - if (value(c[k]) != l_False) - { - // watcher i is abandonned using i++, because cr watches now ~c[k] instead of p - // the blocker is first in the watcher. However, - // the blocker in the corresponding watcher in ~first is not c[1] - Watcher w = Watcher(cr, first); i++; - c[1] = c[k]; c[k] = false_lit; - watches[~c[1]].push(w); - goto NextClause; - } - } - } - - // Did not find watch -- clause is unit under assignment: - i->blocker = first; - *j++ = *i++; - if (value(first) == l_False) - { - confl = cr; - qhead = trail.size(); - // Copy the remaining watches: - while (i < end) - *j++ = *i++; - } - else - { - simpleUncheckEnqueue(first, cr); - } -NextClause:; - } - ws.shrink(i - j); - } - - s_propagations += num_props; - - return confl; -} - -void Solver::simpleUncheckEnqueue(Lit p, CRef from){ - assert(value(p) == l_Undef); - assigns[var(p)] = lbool(!sign(p)); // this makes a lbool object whose value is sign(p) - vardata[var(p)].reason = from; - trail.push_(p); -} - -void Solver::cancelUntilTrailRecord() -{ - for (int c = trail.size() - 1; c >= trailRecord; c--) - { - Var x = var(trail[c]); - assigns[x] = l_Undef; - - } - qhead = trailRecord; - trail.shrink(trail.size() - trailRecord); - -} - -void Solver::litsEnqueue(int cutP, Clause& c) -{ - for (int i = cutP; i < c.size(); i++) - { - simpleUncheckEnqueue(~c[i]); - } -} - -bool Solver::removed(CRef cr) { - return ca[cr].mark() == 1; -} - -void Solver::simpleAnalyze(CRef confl, vec& out_learnt, vec& reason_clause, bool True_confl) -{ - int pathC = 0; - Lit p = lit_Undef; - int index = trail.size() - 1; - - do{ - if (confl != CRef_Undef){ - reason_clause.push(confl); - Clause& c = ca[confl]; - // Special case for binary clauses - // The first one has to be SAT - if (p != lit_Undef && c.size() == 2 && value(c[0]) == l_False) { - - assert(value(c[1]) == l_True); - Lit tmp = c[0]; - c[0] = c[1], c[1] = tmp; - } - // if True_confl==true, then choose p begin with the 1th index of c; - for (int j = (p == lit_Undef && True_confl == false) ? 0 : 1; j < c.size(); j++){ - Lit q = c[j]; - if (!seen[var(q)]){ - seen[var(q)] = 1; - pathC++; - } - } - } - else if (confl == CRef_Undef){ - out_learnt.push(~p); - } - // if not break, while() will come to the index of trail blow 0, and fatal error occur; - if (pathC == 0) break; - // Select next clause to look at: - while (!seen[var(trail[index--])]); - // if the reason cr from the 0-level assigned var, we must break avoid move forth further; - // but attention that maybe seen[x]=1 and never be clear. However makes no matter; - if (trailRecord > index + 1) break; - p = trail[index + 1]; - confl = reason(var(p)); - seen[var(p)] = 0; - pathC--; - - } while (pathC >= 0); -} - -void Solver::simplifyLearnt(Clause& c) -{ - //// - original_length_record += c.size(); - - trailRecord = trail.size();// record the start pointer - - vec falseLit; - falseLit.clear(); - - //sort(&c[0], c.size(), VarOrderLevelLt(vardata)); - - bool True_confl = false; - int beforeSize, afterSize; - beforeSize = c.size(); - int i, j; - CRef confl; - - for (i = 0, j = 0; i < c.size(); i++){ - if (value(c[i]) == l_Undef){ - //printf("///@@@ uncheckedEnqueue:index = %d. l_Undef\n", i); - simpleUncheckEnqueue(~c[i]); - c[j++] = c[i]; - confl = simplePropagate(); - if (confl != CRef_Undef){ - break; - } - } - else{ - if (value(c[i]) == l_True){ - //printf("///@@@ uncheckedEnqueue:index = %d. l_True\n", i); - c[j++] = c[i]; - True_confl = true; - confl = reason(var(c[i])); - break; - } - else{ - //printf("///@@@ uncheckedEnqueue:index = %d. l_False\n", i); - falseLit.push(c[i]); - } - } - } - c.shrink(c.size() - j); - afterSize = c.size(); - //printf("\nbefore : %d, after : %d ", beforeSize, afterSize); - - - if (confl != CRef_Undef || True_confl == true){ - simp_learnt_clause.clear(); - simp_reason_clause.clear(); - if (True_confl == true){ - simp_learnt_clause.push(c.last()); - } - simpleAnalyze(confl, simp_learnt_clause, simp_reason_clause, True_confl); - - if (simp_learnt_clause.size() < c.size()){ - for (i = 0; i < simp_learnt_clause.size(); i++){ - c[i] = simp_learnt_clause[i]; - } - c.shrink(c.size() - i); - } - } - - cancelUntilTrailRecord(); - - //// - simplified_length_record += c.size(); - -} - -bool Solver::simplifyLearnt_x(vec& learnts_x) -{ - int beforeSize, afterSize; - int learnts_x_size_before = learnts_x.size(); - - int ci, cj, li, lj; - bool sat, false_lit; - unsigned int nblevels; - //// - //printf("learnts_x size : %d\n", learnts_x.size()); - - //// - int nbSimplified = 0; - int nbSimplifing = 0; - - for (ci = 0, cj = 0; ci < learnts_x.size(); ci++){ - CRef cr = learnts_x[ci]; - Clause& c = ca[cr]; - - if (removed(cr)) continue; - else if (c.simplified()){ - learnts_x[cj++] = learnts_x[ci]; - //// - nbSimplified++; - } - else{ - //// - nbSimplifing++; - sat = false_lit = false; - for (int i = 0; i < c.size(); i++){ - if (value(c[i]) == l_True){ - sat = true; - break; - } - else if (value(c[i]) == l_False){ - false_lit = true; - } - } - if (sat){ - removeClause(cr); - } - else{ - detachClause(cr, true); - - if (false_lit){ - for (li = lj = 0; li < c.size(); li++){ - if (value(c[li]) != l_False){ - c[lj++] = c[li]; - } - } - c.shrink(li - lj); - } - - beforeSize = c.size(); - assert(c.size() > 1); - // simplify a learnt clause c - simplifyLearnt(c); - assert(c.size() > 0); - afterSize = c.size(); - - //printf("beforeSize: %2d, afterSize: %2d\n", beforeSize, afterSize); - - if (c.size() == 1){ - // when unit clause occur, enqueue and propagate - uncheckedEnqueue(c[0]); - if (propagate() != CRef_Undef){ - ok = false; - return false; - } - // delete the clause memory in logic - c.mark(1); - ca.free(cr); - } - else{ - attachClause(cr); - learnts_x[cj++] = learnts_x[ci]; - - nblevels = computeLBD(c); - if (nblevels < c.lbd()){ - //printf("lbd-before: %d, lbd-after: %d\n", c.lbd(), nblevels); - c.set_lbd(nblevels); - } - if (c.mark() != CORE){ - if (c.lbd() <= core_lbd_cut){ - //if (c.mark() == LOCAL) local_learnts_dirty = true; - //else tier2_learnts_dirty = true; - cj--; - learnts_core.push(cr); - c.mark(CORE); - } - else if (c.mark() == LOCAL && c.lbd() <= 6){ - //local_learnts_dirty = true; - cj--; - learnts_tier2.push(cr); - c.mark(TIER2); - } - } - - c.setSimplified(true); - } - } - } - } - learnts_x.shrink(ci - cj); - - // printf("c nbLearnts_x %d / %d, nbSimplified: %d, nbSimplifing: %d\n", - // learnts_x_size_before, learnts_x.size(), nbSimplified, nbSimplifing); - - return true; -} - -bool Solver::simplifyLearnt_core() -{ - int beforeSize, afterSize; - int learnts_core_size_before = learnts_core.size(); - - int ci, cj, li, lj; - bool sat, false_lit; - unsigned int nblevels; - //// - //printf("learnts_x size : %d\n", learnts_x.size()); - - //// - int nbSimplified = 0; - int nbSimplifing = 0; - - for (ci = 0, cj = 0; ci < learnts_core.size(); ci++){ - CRef cr = learnts_core[ci]; - Clause& c = ca[cr]; - - if (removed(cr)) continue; - else if (c.simplified()){ - learnts_core[cj++] = learnts_core[ci]; - //// - nbSimplified++; - } - else{ - int saved_size=c.size(); - // if (drup_file){ - // add_oc.clear(); - // for (int i = 0; i < c.size(); i++) add_oc.push(c[i]); } - //// - nbSimplifing++; - sat = false_lit = false; - for (int i = 0; i < c.size(); i++){ - if (value(c[i]) == l_True){ - sat = true; - break; - } - else if (value(c[i]) == l_False){ - false_lit = true; - } - } - if (sat){ - removeClause(cr); - } - else{ - detachClause(cr, true); - - if (false_lit){ - for (li = lj = 0; li < c.size(); li++){ - if (value(c[li]) != l_False){ - c[lj++] = c[li]; - } - } - c.shrink(li - lj); - } - - beforeSize = c.size(); - assert(c.size() > 1); - // simplify a learnt clause c - simplifyLearnt(c); - assert(c.size() > 0); - afterSize = c.size(); - - if(drup_file && saved_size !=c.size()){ -#ifdef BIN_DRUP - binDRUP('a', c , drup_file); - // binDRUP('d', add_oc, drup_file); -#else - for (int i = 0; i < c.size(); i++) - fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1)); - fprintf(drup_file, "0\n"); - - // fprintf(drup_file, "d "); - // for (int i = 0; i < add_oc.size(); i++) - // fprintf(drup_file, "%i ", (var(add_oc[i]) + 1) * (-2 * sign(add_oc[i]) + 1)); - // fprintf(drup_file, "0\n"); -#endif - } - - //printf("beforeSize: %2d, afterSize: %2d\n", beforeSize, afterSize); - - if (c.size() == 1){ - // when unit clause occur, enqueue and propagate - uncheckedEnqueue(c[0]); - if (propagate() != CRef_Undef){ - ok = false; - return false; - } - // delete the clause memory in logic - c.mark(1); - ca.free(cr); -//#ifdef BIN_DRUP -// binDRUP('d', c, drup_file); -//#else -// fprintf(drup_file, "d "); -// for (int i = 0; i < c.size(); i++) -// fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1)); -// fprintf(drup_file, "0\n"); -//#endif - } - else{ - attachClause(cr); - learnts_core[cj++] = learnts_core[ci]; - - nblevels = computeLBD(c); - if (nblevels < c.lbd()){ - //printf("lbd-before: %d, lbd-after: %d\n", c.lbd(), nblevels); - c.set_lbd(nblevels); - } - - c.setSimplified(true); - } - } - } - } - learnts_core.shrink(ci - cj); - - // printf("c nbLearnts_core %d / %d, nbSimplified: %d, nbSimplifing: %d\n", - // learnts_core_size_before, learnts_core.size(), nbSimplified, nbSimplifing); - - return true; - -} - - -int Solver::is_duplicate(std::vector&c){ - auto time_point_0 = std::chrono::high_resolution_clock::now(); - dupl_db_size++; - int res = 0; - - int sz = c.size(); - std::vector tmp(c); - sort(tmp.begin(),tmp.end()); - - uint64_t hash = 0; - - for (int i =0; i> 2); - } - - int32_t head = tmp[0]; - auto it0 = ht.find(head); - if (it0 != ht.end()){ - auto it1=ht[head].find(sz); - if (it1 != ht[head].end()){ - auto it2 = ht[head][sz].find(hash); - if (it2 != ht[head][sz].end()){ - it2->second++; - res = it2->second; - } - else{ - ht[head][sz][hash]=1; - } - } - else{ - ht[head][sz][hash]=1; - } - }else{ - ht[head][sz][hash]=1; - } - auto time_point_1 = std::chrono::high_resolution_clock::now(); - duptime += std::chrono::duration_cast(time_point_1-time_point_0); - return res; -} - -bool Solver::simplifyLearnt_tier2() -{ - int beforeSize, afterSize; - int learnts_tier2_size_before = learnts_tier2.size(); - - int ci, cj, li, lj; - bool sat, false_lit; - unsigned int nblevels; - //// - //printf("learnts_x size : %d\n", learnts_x.size()); - - //// - int nbSimplified = 0; - int nbSimplifing = 0; - - for (ci = 0, cj = 0; ci < learnts_tier2.size(); ci++){ - CRef cr = learnts_tier2[ci]; - Clause& c = ca[cr]; - - if (removed(cr)) continue; - else if (c.simplified()){ - learnts_tier2[cj++] = learnts_tier2[ci]; - //// - nbSimplified++; - } - else{ - int saved_size=c.size(); - // if (drup_file){ - // add_oc.clear(); - // for (int i = 0; i < c.size(); i++) add_oc.push(c[i]); } - //// - nbSimplifing++; - sat = false_lit = false; - for (int i = 0; i < c.size(); i++){ - if (value(c[i]) == l_True){ - sat = true; - break; - } - else if (value(c[i]) == l_False){ - false_lit = true; - } - } - if (sat){ - removeClause(cr); - } - else{ - detachClause(cr, true); - - if (false_lit){ - for (li = lj = 0; li < c.size(); li++){ - if (value(c[li]) != l_False){ - c[lj++] = c[li]; - } - } - c.shrink(li - lj); - } - - beforeSize = c.size(); - assert(c.size() > 1); - // simplify a learnt clause c - simplifyLearnt(c); - assert(c.size() > 0); - afterSize = c.size(); - - if(drup_file && saved_size!=c.size()){ - -#ifdef BIN_DRUP - binDRUP('a', c , drup_file); - // binDRUP('d', add_oc, drup_file); -#else - for (int i = 0; i < c.size(); i++) - fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1)); - fprintf(drup_file, "0\n"); - - // fprintf(drup_file, "d "); - // for (int i = 0; i < add_oc.size(); i++) - // fprintf(drup_file, "%i ", (var(add_oc[i]) + 1) * (-2 * sign(add_oc[i]) + 1)); - // fprintf(drup_file, "0\n"); -#endif - } - - //printf("beforeSize: %2d, afterSize: %2d\n", beforeSize, afterSize); - - if (c.size() == 1){ - // when unit clause occur, enqueue and propagate - uncheckedEnqueue(c[0]); - if (propagate() != CRef_Undef){ - ok = false; - return false; - } - // delete the clause memory in logic - c.mark(1); - ca.free(cr); -//#ifdef BIN_DRUP -// binDRUP('d', c, drup_file); -//#else -// fprintf(drup_file, "d "); -// for (int i = 0; i < c.size(); i++) -// fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1)); -// fprintf(drup_file, "0\n"); -//#endif - } - else{ - - - nblevels = computeLBD(c); - if (nblevels < c.lbd()){ - //printf("lbd-before: %d, lbd-after: %d\n", c.lbd(), nblevels); - c.set_lbd(nblevels); - } - //duplicate learnts - int id = 0; - - std::vector tmp; - for (int i = 0; i < c.size(); i++) - tmp.push_back(c[i].x); - id = is_duplicate(tmp); - - - //duplicate learnts - - if (id < min_number_of_learnts_copies+2){ - attachClause(cr); - learnts_tier2[cj++] = learnts_tier2[ci]; - if (id == min_number_of_learnts_copies+1){ - duplicates_added_minimization++; - } - if ((c.lbd() <= core_lbd_cut)||(id == min_number_of_learnts_copies+1)){ - //if (id == min_number_of_learnts_copies+1){ - cj--; - learnts_core.push(cr); - c.mark(CORE); - } - - c.setSimplified(true); - } - } - } - } - } - learnts_tier2.shrink(ci - cj); - - // printf("c nbLearnts_tier2 %d / %d, nbSimplified: %d, nbSimplifing: %d\n", - // learnts_tier2_size_before, learnts_tier2.size(), nbSimplified, nbSimplifing); - - return true; - -} - -bool Solver::simplifyAll() -{ - //// - simplified_length_record = original_length_record = 0; - - if (!ok || propagate() != CRef_Undef) - return ok = false; - - //// cleanLearnts(also can delete these code), here just for analyzing - //if (local_learnts_dirty) cleanLearnts(learnts_local, LOCAL); - //if (tier2_learnts_dirty) cleanLearnts(learnts_tier2, TIER2); - //local_learnts_dirty = tier2_learnts_dirty = false; - - if (!simplifyLearnt_core()) return ok = false; - if (!simplifyLearnt_tier2()) return ok = false; - //if (!simplifyLearnt_x(learnts_local)) return ok = false; - - checkGarbage(); - - //// - // printf("c size_reduce_ratio : %4.2f%%\n", - // original_length_record == 0 ? 0 : (original_length_record - simplified_length_record) * 100 / (double)original_length_record); - - return true; -} -//================================================================================================= -// Minor methods: - - -// Creates a new SAT variable in the solver. If 'decision' is cleared, variable will not be -// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result). -// - -Var Solver::newVar(bool sign, bool dvar) -{ - int v = nVars(); - // printf("%d %d %d\n", v, sign, dvar); - watches_bin.init(mkLit(v, false)); - watches_bin.init(mkLit(v, true )); - watches .init(mkLit(v, false)); - watches .init(mkLit(v, true )); - assigns .push(l_Undef); - vardata .push(mkVarData(CRef_Undef, 0)); - activity_CHB .push(0); - activity_VSIDS.push(rnd_init_act ? drand(random_seed) * 0.00001 : 0); - - picked.push(0); - conflicted.push(0); - almost_conflicted.push(0); -#ifdef ANTI_EXPLORATION - canceled.push(0); -#endif - seen .push(0); - seen2 .push(0); - polarity .push(sign); - decision .push(); - trail .capacity(v+1); - setDecisionVar(v, dvar); - - return v; -} - - -bool Solver::addClause_(vec& ps) -{ - assert(decisionLevel() == 0); - if (!ok) return false; - - // Check if clause is satisfied and remove false/duplicate literals: - sort(ps); - Lit p; int i, j; - - if (drup_file){ - add_oc.clear(); - for (int i = 0; i < ps.size(); i++) add_oc.push(ps[i]); } - - for (i = j = 0, p = lit_Undef; i < ps.size(); i++) - if (value(ps[i]) == l_True || ps[i] == ~p) - return true; - else if (value(ps[i]) != l_False && ps[i] != p) - ps[j++] = p = ps[i]; - ps.shrink(i - j); - - if (drup_file && i != j){ -#ifdef BIN_DRUP - binDRUP('a', ps, drup_file); - binDRUP('d', add_oc, drup_file); -#else - for (int i = 0; i < ps.size(); i++) - fprintf(drup_file, "%i ", (var(ps[i]) + 1) * (-2 * sign(ps[i]) + 1)); - fprintf(drup_file, "0\n"); - - fprintf(drup_file, "d "); - for (int i = 0; i < add_oc.size(); i++) - fprintf(drup_file, "%i ", (var(add_oc[i]) + 1) * (-2 * sign(add_oc[i]) + 1)); - fprintf(drup_file, "0\n"); -#endif - } - - if (ps.size() == 0) - return ok = false; - else if (ps.size() == 1){ - uncheckedEnqueue(ps[0]); - return ok = (propagate() == CRef_Undef); - }else{ - CRef cr = ca.alloc(ps, false); - clauses.push(cr); - attachClause(cr); - } - - return true; -} - -bool Solver::importClauses() { - assert(decisionLevel() == 0); - - if (cbkImportClause == NULL) - return true; - int lbd, k, l; - bool alreadySat; - while (cbkImportClause(issuer, &lbd, importedClause)) { - // fflush(stdout); - alreadySat = false; - // Simplify clause before add - for (k = l = 0; k < importedClause.size(); k++) { - if (value(importedClause[k]) == l_True) { - alreadySat = true; - break; - } else if (value(importedClause[k]) == l_Undef) { - importedClause[l++] = importedClause[k]; - } - } - importedClause.shrink(k - l); - - if (alreadySat) { - importedClause.clear(); - continue; - } - - if (importedClause.size() == 0) { - return false; - } else if (importedClause.size() == 1) { - uncheckedEnqueue(importedClause[0]); - } else { - CRef cr = ca.alloc(importedClause, true); - lbd = importedClause.size(); - ca[cr].set_lbd(lbd); - if (lbd <= core_lbd_cut) { - learnts_core.push(cr); - ca[cr].mark(CORE); - } else if (lbd <= 6) { - learnts_tier2.push(cr); - ca[cr].mark(TIER2); - ca[cr].touched() = conflicts; - } else { - learnts_local.push(cr); - claBumpActivity(ca[cr]); - } - attachClause(cr); - } - importedClause.clear(); - } - - return true; -} - -void Solver::attachClause(CRef cr) { - const Clause& c = ca[cr]; - assert(c.size() > 1); - OccLists, WatcherDeleted>& ws = c.size() == 2 ? watches_bin : watches; - ws[~c[0]].push(Watcher(cr, c[1])); - ws[~c[1]].push(Watcher(cr, c[0])); - if (c.learnt()) learnts_literals += c.size(); - else clauses_literals += c.size(); } - - -void Solver::detachClause(CRef cr, bool strict) { - const Clause& c = ca[cr]; - assert(c.size() > 1); - OccLists, WatcherDeleted>& ws = c.size() == 2 ? watches_bin : watches; - - if (strict){ - remove(ws[~c[0]], Watcher(cr, c[1])); - remove(ws[~c[1]], Watcher(cr, c[0])); - }else{ - // Lazy detaching: (NOTE! Must clean all watcher lists before garbage collecting this clause) - ws.smudge(~c[0]); - ws.smudge(~c[1]); - } - - if (c.learnt()) learnts_literals -= c.size(); - else clauses_literals -= c.size(); } - - -void Solver::removeClause(CRef cr) { - Clause& c = ca[cr]; - - if (drup_file){ - if (c.mark() != 1){ -#ifdef BIN_DRUP - binDRUP('d', c, drup_file); -#else - fprintf(drup_file, "d "); - for (int i = 0; i < c.size(); i++) - fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1)); - fprintf(drup_file, "0\n"); -#endif - }else - printf("c Bug. I don't expect this to happen.\n"); - } - - detachClause(cr); - // Don't leave pointers to free'd memory! - if (locked(c)){ - Lit implied = c.size() != 2 ? c[0] : (value(c[0]) == l_True ? c[0] : c[1]); - vardata[var(implied)].reason = CRef_Undef; } - c.mark(1); - ca.free(cr); -} - - -bool Solver::satisfied(const Clause& c) const { - for (int i = 0; i < c.size(); i++) - if (value(c[i]) == l_True) - return true; - return false; } - - -// Revert to the state at given level (keeping all assignment at 'level' but not beyond). -// -void Solver::cancelUntil(int bLevel) { - - if (decisionLevel() > bLevel){ -#ifdef PRINT_OUT - std::cout << "bt " << bLevel << "\n"; -#endif - add_tmp.clear(); - for (int c = trail.size()-1; c >= trail_lim[bLevel]; c--) - { - Var x = var(trail[c]); - - if (level(x) <= bLevel) - { - add_tmp.push(trail[c]); - } - else - { - if (!VSIDS){ - uint32_t age = conflicts - picked[x]; - if (age > 0){ - double adjusted_reward = ((double) (conflicted[x] + almost_conflicted[x])) / ((double) age); - double old_activity = activity_CHB[x]; - activity_CHB[x] = step_size * adjusted_reward + ((1 - step_size) * old_activity); - if (order_heap_CHB.inHeap(x)){ - if (activity_CHB[x] > old_activity) - order_heap_CHB.decrease(x); - else - order_heap_CHB.increase(x); - } - } -#ifdef ANTI_EXPLORATION - canceled[x] = conflicts; -#endif - } - - assigns [x] = l_Undef; -#ifdef PRINT_OUT - std::cout << "undo " << x << "\n"; -#endif - if (phase_saving > 1 || (phase_saving == 1) && c > trail_lim.last()){ - polarity[x] = sign(trail[c]); - } - insertVarOrder(x); - } - } - qhead = trail_lim[bLevel]; - trail.shrink(trail.size() - trail_lim[bLevel]); - trail_lim.shrink(trail_lim.size() - bLevel); - for (int nLitId = add_tmp.size() - 1; nLitId >= 0; --nLitId) - { - trail.push_(add_tmp[nLitId]); - } - - add_tmp.clear(); - } } - - -//================================================================================================= -// Major methods: - - -Lit Solver::pickBranchLit() -{ - Var next = var_Undef; - // Heap& order_heap = VSIDS ? order_heap_VSIDS : order_heap_CHB; - Heap& order_heap = ((!VSIDS)? order_heap_CHB:order_heap_VSIDS); - - // Random decision: - /*if (drand(random_seed) < random_var_freq && !order_heap.empty()){ - next = order_heap[irand(random_seed,order_heap.size())]; - if (value(next) == l_Undef && decision[next]) - rnd_decisions++; }*/ - - // Activity based decision: - while (next == var_Undef || value(next) != l_Undef || !decision[next]) - if (order_heap.empty()) - return lit_Undef; - else{ -#ifdef ANTI_EXPLORATION - if (!VSIDS){ - Var v = order_heap_CHB[0]; - uint32_t age = conflicts - canceled[v]; - while (age > 0){ - double decay = pow(0.95, age); - activity_CHB[v] *= decay; - if (order_heap_CHB.inHeap(v)) - order_heap_CHB.increase(v); - canceled[v] = conflicts; - v = order_heap_CHB[0]; - age = conflicts - canceled[v]; - } - } -#endif - next = order_heap.removeMin(); - } - - return mkLit(next, polarity[next]); - - -} - -inline Solver::ConflictData Solver::FindConflictLevel(CRef cind) -{ - ConflictData data; - Clause& conflCls = ca[cind]; - data.nHighestLevel = level(var(conflCls[0])); - if (data.nHighestLevel == decisionLevel() && level(var(conflCls[1])) == decisionLevel()) - { - return data; - } - - int highestId = 0; - data.bOnlyOneLitFromHighest = true; - // find the largest decision level in the clause - for (int nLitId = 1; nLitId < conflCls.size(); ++nLitId) - { - int nLevel = level(var(conflCls[nLitId])); - if (nLevel > data.nHighestLevel) - { - highestId = nLitId; - data.nHighestLevel = nLevel; - data.bOnlyOneLitFromHighest = true; - } - else if (nLevel == data.nHighestLevel && data.bOnlyOneLitFromHighest == true) - { - data.bOnlyOneLitFromHighest = false; - } - } - - if (highestId != 0) - { - std::swap(conflCls[0], conflCls[highestId]); - if (highestId > 1) - { - OccLists, WatcherDeleted>& ws = conflCls.size() == 2 ? watches_bin : watches; - //ws.smudge(~conflCls[highestId]); - remove(ws[~conflCls[highestId]], Watcher(cind, conflCls[1])); - ws[~conflCls[0]].push(Watcher(cind, conflCls[1])); - } - } - - return data; -} - - -/*_________________________________________________________________________________________________ -| -| analyze : (confl : Clause*) (out_learnt : vec&) (out_btlevel : int&) -> [void] -| -| Description: -| Analyze conflict and produce a reason clause. -| -| Pre-conditions: -| * 'out_learnt' is assumed to be cleared. -| * Current decision level must be greater than root level. -| -| Post-conditions: -| * 'out_learnt[0]' is the asserting literal at level 'out_btlevel'. -| * If out_learnt.size() > 1 then 'out_learnt[1]' has the greatest decision level of the -| rest of literals. There may be others from the same level though. -| -|________________________________________________________________________________________________@*/ -void Solver::analyze(CRef confl, vec& out_learnt, int& out_btlevel, int& out_lbd) -{ - int pathC = 0; - Lit p = lit_Undef; - - // Generate conflict clause: - // - out_learnt.push(); // (leave room for the asserting literal) - int index = trail.size() - 1; - int nDecisionLevel = level(var(ca[confl][0])); - assert(nDecisionLevel == level(var(ca[confl][0]))); - - do{ - assert(confl != CRef_Undef); // (otherwise should be UIP) - Clause& c = ca[confl]; - - // For binary clauses, we don't rearrange literals in propagate(), so check and make sure the first is an implied lit. - if (p != lit_Undef && c.size() == 2 && value(c[0]) == l_False){ - assert(value(c[1]) == l_True); - Lit tmp = c[0]; - c[0] = c[1], c[1] = tmp; } - - // Update LBD if improved. - if (c.learnt() && c.mark() != CORE){ - int lbd = computeLBD(c); - if (lbd < c.lbd()){ - if (c.lbd() <= 30) c.removable(false); // Protect once from reduction. - c.set_lbd(lbd); - if (lbd <= core_lbd_cut){ - learnts_core.push(confl); - c.mark(CORE); - }else if (lbd <= 6 && c.mark() == LOCAL){ - // Bug: 'cr' may already be in 'learnts_tier2', e.g., if 'cr' was demoted from TIER2 - // to LOCAL previously and if that 'cr' is not cleaned from 'learnts_tier2' yet. - learnts_tier2.push(confl); - c.mark(TIER2); } - } - - if (c.mark() == TIER2) - c.touched() = conflicts; - else if (c.mark() == LOCAL) - claBumpActivity(c); - } - - for (int j = (p == lit_Undef) ? 0 : 1; j < c.size(); j++){ - Lit q = c[j]; - - if (!seen[var(q)] && level(var(q)) > 0){ - if (VSIDS){ - varBumpActivity(var(q), .5); - add_tmp.push(q); - }else - conflicted[var(q)]++; - seen[var(q)] = 1; - if (level(var(q)) >= nDecisionLevel){ - pathC++; - }else - out_learnt.push(q); - } - } - - // Select next clause to look at: - do { - while (!seen[var(trail[index--])]); - p = trail[index+1]; - } while (level(var(p)) < nDecisionLevel); - - confl = reason(var(p)); - seen[var(p)] = 0; - pathC--; - - }while (pathC > 0); - out_learnt[0] = ~p; - - // Simplify conflict clause: - // - int i, j; - out_learnt.copyTo(analyze_toclear); - if (ccmin_mode == 2){ - uint32_t abstract_level = 0; - for (i = 1; i < out_learnt.size(); i++) - abstract_level |= abstractLevel(var(out_learnt[i])); // (maintain an abstraction of levels involved in conflict) - - for (i = j = 1; i < out_learnt.size(); i++) - if (reason(var(out_learnt[i])) == CRef_Undef || !litRedundant(out_learnt[i], abstract_level)) - out_learnt[j++] = out_learnt[i]; - - }else if (ccmin_mode == 1){ - for (i = j = 1; i < out_learnt.size(); i++){ - Var x = var(out_learnt[i]); - - if (reason(x) == CRef_Undef) - out_learnt[j++] = out_learnt[i]; - else{ - Clause& c = ca[reason(var(out_learnt[i]))]; - for (int k = c.size() == 2 ? 0 : 1; k < c.size(); k++) - if (!seen[var(c[k])] && level(var(c[k])) > 0){ - out_learnt[j++] = out_learnt[i]; - break; } - } - } - }else - i = j = out_learnt.size(); - - max_literals += out_learnt.size(); - out_learnt.shrink(i - j); - tot_literals += out_learnt.size(); - - out_lbd = computeLBD(out_learnt); - if (out_lbd <= 6 && out_learnt.size() <= 30) // Try further minimization? - if (binResMinimize(out_learnt)) - out_lbd = computeLBD(out_learnt); // Recompute LBD if minimized. - - // Find correct backtrack level: - // - if (out_learnt.size() == 1) - out_btlevel = 0; - else{ - int max_i = 1; - // Find the first literal assigned at the next-highest level: - for (int i = 2; i < out_learnt.size(); i++) - if (level(var(out_learnt[i])) > level(var(out_learnt[max_i]))) - max_i = i; - // Swap-in this literal at index 1: - Lit p = out_learnt[max_i]; - out_learnt[max_i] = out_learnt[1]; - out_learnt[1] = p; - out_btlevel = level(var(p)); - } - - if (VSIDS){ - for (int i = 0; i < add_tmp.size(); i++){ - Var v = var(add_tmp[i]); - if (level(v) >= out_btlevel - 1) - varBumpActivity(v, 1); - } - add_tmp.clear(); - }else{ - seen[var(p)] = true; - for(int i = out_learnt.size() - 1; i >= 0; i--){ - Var v = var(out_learnt[i]); - CRef rea = reason(v); - if (rea != CRef_Undef){ - const Clause& reaC = ca[rea]; - for (int i = 0; i < reaC.size(); i++){ - Lit l = reaC[i]; - if (!seen[var(l)]){ - seen[var(l)] = true; - almost_conflicted[var(l)]++; - analyze_toclear.push(l); } } } } } - - for (int j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0; // ('seen[]' is now cleared) -} - - -// Try further learnt clause minimization by means of binary clause resolution. -bool Solver::binResMinimize(vec& out_learnt) -{ - // Preparation: remember which false variables we have in 'out_learnt'. - counter++; - for (int i = 1; i < out_learnt.size(); i++) - seen2[var(out_learnt[i])] = counter; - - // Get the list of binary clauses containing 'out_learnt[0]'. - const vec& ws = watches_bin[~out_learnt[0]]; - - int to_remove = 0; - for (int i = 0; i < ws.size(); i++){ - Lit the_other = ws[i].blocker; - // Does 'the_other' appear negatively in 'out_learnt'? - if (seen2[var(the_other)] == counter && value(the_other) == l_True){ - to_remove++; - seen2[var(the_other)] = counter - 1; // Remember to remove this variable. - } - } - - // Shrink. - if (to_remove > 0){ - int last = out_learnt.size() - 1; - for (int i = 1; i < out_learnt.size() - to_remove; i++) - if (seen2[var(out_learnt[i])] != counter) - out_learnt[i--] = out_learnt[last--]; - out_learnt.shrink(to_remove); - } - return to_remove != 0; -} - - -// Check if 'p' can be removed. 'abstract_levels' is used to abort early if the algorithm is -// visiting literals at levels that cannot be removed later. -bool Solver::litRedundant(Lit p, uint32_t abstract_levels) -{ - analyze_stack.clear(); analyze_stack.push(p); - int top = analyze_toclear.size(); - while (analyze_stack.size() > 0){ - assert(reason(var(analyze_stack.last())) != CRef_Undef); - Clause& c = ca[reason(var(analyze_stack.last()))]; analyze_stack.pop(); - - // Special handling for binary clauses like in 'analyze()'. - if (c.size() == 2 && value(c[0]) == l_False){ - assert(value(c[1]) == l_True); - Lit tmp = c[0]; - c[0] = c[1], c[1] = tmp; } - - for (int i = 1; i < c.size(); i++){ - Lit p = c[i]; - if (!seen[var(p)] && level(var(p)) > 0){ - if (reason(var(p)) != CRef_Undef && (abstractLevel(var(p)) & abstract_levels) != 0){ - seen[var(p)] = 1; - analyze_stack.push(p); - analyze_toclear.push(p); - }else{ - for (int j = top; j < analyze_toclear.size(); j++) - seen[var(analyze_toclear[j])] = 0; - analyze_toclear.shrink(analyze_toclear.size() - top); - return false; - } - } - } - } - - return true; -} - - -/*_________________________________________________________________________________________________ -| -| analyzeFinal : (p : Lit) -> [void] -| -| Description: -| Specialized analysis procedure to express the final conflict in terms of assumptions. -| Calculates the (possibly empty) set of assumptions that led to the assignment of 'p', and -| stores the result in 'out_conflict'. -|________________________________________________________________________________________________@*/ -void Solver::analyzeFinal(Lit p, vec& out_conflict) -{ - out_conflict.clear(); - out_conflict.push(p); - - if (decisionLevel() == 0) - return; - - seen[var(p)] = 1; - - for (int i = trail.size()-1; i >= trail_lim[0]; i--){ - Var x = var(trail[i]); - if (seen[x]){ - if (reason(x) == CRef_Undef){ - assert(level(x) > 0); - out_conflict.push(~trail[i]); - }else{ - Clause& c = ca[reason(x)]; - for (int j = c.size() == 2 ? 0 : 1; j < c.size(); j++) - if (level(var(c[j])) > 0) - seen[var(c[j])] = 1; - } - seen[x] = 0; - } - } - - seen[var(p)] = 0; -} - - -void Solver::uncheckedEnqueue(Lit p, int level, CRef from) -{ - assert(value(p) == l_Undef); - Var x = var(p); - if (!VSIDS){ - picked[x] = conflicts; - conflicted[x] = 0; - almost_conflicted[x] = 0; -#ifdef ANTI_EXPLORATION - uint32_t age = conflicts - canceled[var(p)]; - if (age > 0){ - double decay = pow(0.95, age); - activity_CHB[var(p)] *= decay; - if (order_heap_CHB.inHeap(var(p))) - order_heap_CHB.increase(var(p)); - } -#endif - } - - assigns[x] = lbool(!sign(p)); - vardata[x] = mkVarData(from, level); - trail.push_(p); -} - - -/*_________________________________________________________________________________________________ -| -| propagate : [void] -> [Clause*] -| -| Description: -| Propagates all enqueued facts. If a conflict arises, the conflicting clause is returned, -| otherwise CRef_Undef. -| -| Post-conditions: -| * the propagation queue is empty, even if there was a conflict. -|________________________________________________________________________________________________@*/ -CRef Solver::propagate() -{ - CRef confl = CRef_Undef; - int num_props = 0; - watches.cleanAll(); - watches_bin.cleanAll(); - - while (qhead < trail.size()){ - Lit p = trail[qhead++]; // 'p' is enqueued fact to propagate. - int currLevel = level(var(p)); - vec& ws = watches[p]; - Watcher *i, *j, *end; - num_props++; - - vec& ws_bin = watches_bin[p]; // Propagate binary clauses first. - for (int k = 0; k < ws_bin.size(); k++){ - Lit the_other = ws_bin[k].blocker; - if (value(the_other) == l_False){ - confl = ws_bin[k].cref; -#ifdef LOOSE_PROP_STAT - return confl; -#else - goto ExitProp; -#endif - }else if(value(the_other) == l_Undef) - { - uncheckedEnqueue(the_other, currLevel, ws_bin[k].cref); -#ifdef PRINT_OUT - std::cout << "i " << the_other << " l " << currLevel << "\n"; -#endif - } - } - - for (i = j = (Watcher*)ws, end = i + ws.size(); i != end;){ - // Try to avoid inspecting the clause: - Lit blocker = i->blocker; - if (value(blocker) == l_True){ - *j++ = *i++; continue; } - - // Make sure the false literal is data[1]: - CRef cr = i->cref; - Clause& c = ca[cr]; - Lit false_lit = ~p; - if (c[0] == false_lit) - c[0] = c[1], c[1] = false_lit; - assert(c[1] == false_lit); - i++; - - // If 0th watch is true, then clause is already satisfied. - Lit first = c[0]; - Watcher w = Watcher(cr, first); - if (first != blocker && value(first) == l_True){ - *j++ = w; continue; } - - // Look for new watch: - for (int k = 2; k < c.size(); k++) - if (value(c[k]) != l_False){ - c[1] = c[k]; c[k] = false_lit; - watches[~c[1]].push(w); - goto NextClause; } - - // Did not find watch -- clause is unit under assignment: - *j++ = w; - if (value(first) == l_False){ - confl = cr; - qhead = trail.size(); - // Copy the remaining watches: - while (i < end) - *j++ = *i++; - }else - { - if (currLevel == decisionLevel()) - { - uncheckedEnqueue(first, currLevel, cr); -#ifdef PRINT_OUT - std::cout << "i " << first << " l " << currLevel << "\n"; -#endif - } - else - { - int nMaxLevel = currLevel; - int nMaxInd = 1; - // pass over all the literals in the clause and find the one with the biggest level - for (int nInd = 2; nInd < c.size(); ++nInd) - { - int nLevel = level(var(c[nInd])); - if (nLevel > nMaxLevel) - { - nMaxLevel = nLevel; - nMaxInd = nInd; - } - } - - if (nMaxInd != 1) - { - std::swap(c[1], c[nMaxInd]); - *j--; // undo last watch - watches[~c[1]].push(w); - } - - uncheckedEnqueue(first, nMaxLevel, cr); -#ifdef PRINT_OUT - std::cout << "i " << first << " l " << nMaxLevel << "\n"; -#endif - } - } - -NextClause:; - } - ws.shrink(i - j); - } - -ExitProp:; - propagations += num_props; - simpDB_props -= num_props; - - return confl; -} - - -/*_________________________________________________________________________________________________ -| -| reduceDB : () -> [void] -| -| Description: -| Remove half of the learnt clauses, minus the clauses locked by the current assignment. Locked -| clauses are clauses that are reason to some assignment. Binary clauses are never removed. -|________________________________________________________________________________________________@*/ -struct reduceDB_lt { - ClauseAllocator& ca; - reduceDB_lt(ClauseAllocator& ca_) : ca(ca_) {} - bool operator () (CRef x, CRef y) const { return ca[x].activity() < ca[y].activity(); } -}; -void Solver::reduceDB() -{ - int i, j; - //if (local_learnts_dirty) cleanLearnts(learnts_local, LOCAL); - //local_learnts_dirty = false; - - sort(learnts_local, reduceDB_lt(ca)); - - int limit = learnts_local.size() / 2; - for (i = j = 0; i < learnts_local.size(); i++){ - Clause& c = ca[learnts_local[i]]; - if (c.mark() == LOCAL) - if (c.removable() && !locked(c) && i < limit) - removeClause(learnts_local[i]); - else{ - if (!c.removable()) limit++; - c.removable(true); - learnts_local[j++] = learnts_local[i]; } - } - learnts_local.shrink(i - j); - - checkGarbage(); -} -void Solver::reduceDB_Tier2() -{ - int i, j; - for (i = j = 0; i < learnts_tier2.size(); i++){ - Clause& c = ca[learnts_tier2[i]]; - if (c.mark() == TIER2) - if (!locked(c) && c.touched() + 30000 < conflicts){ - learnts_local.push(learnts_tier2[i]); - c.mark(LOCAL); - //c.removable(true); - c.activity() = 0; - claBumpActivity(c); - }else - learnts_tier2[j++] = learnts_tier2[i]; - } - learnts_tier2.shrink(i - j); -} - - -void Solver::removeSatisfied(vec& cs) -{ - int i, j; - for (i = j = 0; i < cs.size(); i++){ - Clause& c = ca[cs[i]]; - if (satisfied(c)) - removeClause(cs[i]); - else - cs[j++] = cs[i]; - } - cs.shrink(i - j); -} - -void Solver::safeRemoveSatisfied(vec& cs, unsigned valid_mark) -{ - int i, j; - for (i = j = 0; i < cs.size(); i++){ - Clause& c = ca[cs[i]]; - if (c.mark() == valid_mark) - if (satisfied(c)) - removeClause(cs[i]); - else - cs[j++] = cs[i]; - } - cs.shrink(i - j); -} - -void Solver::rebuildOrderHeap() -{ - vec vs; - for (Var v = 0; v < nVars(); v++) - if (decision[v] && value(v) == l_Undef) - vs.push(v); - - order_heap_CHB .build(vs); - order_heap_VSIDS.build(vs); -} - - -/*_________________________________________________________________________________________________ -| -| simplify : [void] -> [bool] -| -| Description: -| Simplify the clause database according to the current top-level assigment. Currently, the only -| thing done here is the removal of satisfied clauses, but more things can be put here. -|________________________________________________________________________________________________@*/ -bool Solver::simplify() -{ - assert(decisionLevel() == 0); - - if (!ok || propagate() != CRef_Undef) - return ok = false; - - if (nAssigns() == simpDB_assigns || (simpDB_props > 0)) - return true; - - // Remove satisfied clauses: - removeSatisfied(learnts_core); // Should clean core first. - safeRemoveSatisfied(learnts_tier2, TIER2); - safeRemoveSatisfied(learnts_local, LOCAL); - if (remove_satisfied) // Can be turned off. - removeSatisfied(clauses); - checkGarbage(); - rebuildOrderHeap(); - - simpDB_assigns = nAssigns(); - simpDB_props = clauses_literals + learnts_literals; // (shouldn't depend on stats really, but it will do for now) - - return true; -} - -/*_________________________________________________________________________________________________ -| -| search : (nof_conflicts : int) (params : const SearchParams&) -> [lbool] -| -| Description: -| Search for a model the specified number of conflicts. -| -| Output: -| 'l_True' if a partial assigment that is consistent with respect to the clauseset is found. If -| all variables are decision variables, this means that the clause set is satisfiable. 'l_False' -| if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached. -|________________________________________________________________________________________________@*/ - -void Solver::info_based_rephase(){ - int var_nums = nVars(); - for(int i=0;iin_conflict_sz;++i){ - int v = lssolver->in_conflict[i]; - if(VSIDS){ - varBumpActivity(v-1,lssolver->conflict_ct[v]); - }else{ - conflicted[v-1] += lssolver->conflict_ct[v]; - } - } - - - -} - -void Solver::rand_based_rephase(){ - int var_nums = nVars(); - int pick_rand = rand()%1000; - - //local search - if ((pick_rand-=100)<0){ - for(int i=0;i learnt_clause; - bool cached = false; - starts++; - - freeze_ls_restart_num--; - bool can_call_ls = true; - - if(freeze_ls_restart_num<1){ - - bool res = call_ls(top_trail_UP); - - if(res){ - solved_by_ls = true; - return l_True; - } - - } - - // if(ls_call_num>1){ - if(rand()%100<50) info_based_rephase(); - else rand_based_rephase(); - // } - - - - // simplify - // - if (conflicts >= curSimplify * nbconfbeforesimplify){ - // printf("c ### simplifyAll on conflict : %lld\n", conflicts); - //printf("nbClauses: %d, nbLearnts_core: %d, nbLearnts_tier2: %d, nbLearnts_local: %d, nbLearnts: %d\n", - // clauses.size(), learnts_core.size(), learnts_tier2.size(), learnts_local.size(), - // learnts_core.size() + learnts_tier2.size() + learnts_local.size()); - nbSimplifyAll++; - if (!simplifyAll()){ - return l_False; - } - curSimplify = (conflicts / nbconfbeforesimplify) + 1; - nbconfbeforesimplify += incSimplify; - } - - for (;;){ - if (decisionLevel() == 0) { // We import clauses - if (!importClauses()) return l_False; - } - CRef confl = propagate(); - - - if (confl != CRef_Undef){ - // CONFLICT - if (VSIDS){ - if (--timer == 0 && var_decay < 0.95) timer = 5000, var_decay += 0.01; - }else - if (step_size > min_step_size) step_size -= step_size_dec; - - conflicts++; nof_conflicts--; - //if (conflicts == 100000 && learnts_core.size() < 100) core_lbd_cut = 5; - ConflictData data = FindConflictLevel(confl); - if (data.nHighestLevel == 0) return l_False; - if (data.bOnlyOneLitFromHighest) - { - cancelUntil(data.nHighestLevel - 1); - continue; - } - - learnt_clause.clear(); - analyze(confl, learnt_clause, backtrack_level, lbd); - if (cbkExportClause != NULL) - cbkExportClause(issuer, lbd, learnt_clause); - - // check chrono backtrack condition - if ((confl_to_chrono < 0 || confl_to_chrono <= conflicts) && chrono > -1 && (decisionLevel() - backtrack_level) >= chrono) - { - ++chrono_backtrack; - cancelUntil(data.nHighestLevel -1); - } - else // default behavior - { - ++non_chrono_backtrack; - cancelUntil(backtrack_level); - } - - lbd--; - if (VSIDS){ - cached = false; - conflicts_VSIDS++; - lbd_queue.push(lbd); - global_lbd_sum += (lbd > 50 ? 50 : lbd); } - - if (learnt_clause.size() == 1){ - uncheckedEnqueue(learnt_clause[0]); - }else{ - CRef cr = ca.alloc(learnt_clause, true); - ca[cr].set_lbd(lbd); - //duplicate learnts - int id = 0; - if (lbd <= max_lbd_dup){ - std::vector tmp; - for (int i = 0; i < learnt_clause.size(); i++) - tmp.push_back(learnt_clause[i].x); - id = is_duplicate(tmp); - if (id == min_number_of_learnts_copies +1){ - duplicates_added_conflicts++; - } - if (id == min_number_of_learnts_copies){ - duplicates_added_tier2++; - } - } - //duplicate learnts - - if ((lbd <= core_lbd_cut) || (id == min_number_of_learnts_copies+1)){ - learnts_core.push(cr); - ca[cr].mark(CORE); - }else if ((lbd <= 6)||(id == min_number_of_learnts_copies)){ - learnts_tier2.push(cr); - ca[cr].mark(TIER2); - ca[cr].touched() = conflicts; - }else{ - learnts_local.push(cr); - claBumpActivity(ca[cr]); } - attachClause(cr); - - uncheckedEnqueue(learnt_clause[0], backtrack_level, cr); -#ifdef PRINT_OUT - std::cout << "new " << ca[cr] << "\n"; - std::cout << "ci " << learnt_clause[0] << " l " << backtrack_level << "\n"; -#endif - } - if (drup_file){ -#ifdef BIN_DRUP - binDRUP('a', learnt_clause, drup_file); -#else - for (int i = 0; i < learnt_clause.size(); i++) - fprintf(drup_file, "%i ", (var(learnt_clause[i]) + 1) * (-2 * sign(learnt_clause[i]) + 1)); - fprintf(drup_file, "0\n"); -#endif - } - - if (VSIDS) varDecayActivity(); - claDecayActivity(); - - /*if (--learntsize_adjust_cnt == 0){ - learntsize_adjust_confl *= learntsize_adjust_inc; - learntsize_adjust_cnt = (int)learntsize_adjust_confl; - max_learnts *= learntsize_inc; - - if (verbosity >= 1) - printf("c | %9d | %7d %8d %8d | %8d %8d %6.0f | %6.3f %% |\n", - (int)conflicts, - (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]), nClauses(), (int)clauses_literals, - (int)max_learnts, nLearnts(), (double)learnts_literals/nLearnts(), progressEstimate()*100); - }*/ - - // the top_trail_soln should be update after each conflict - if(trail.size() > max_trail){ - max_trail = trail.size(); - build_soln_with_UP(); - int var_nums = nVars(); - for(int i=0;i (int)(conflict_ratio * nVars()) || trail.size() > (int)(percent_ratio * max_trail) )\ - // //&& up_time_ratio * search_start_cpu_time > ls_used_time - // ){ - - // can_call_ls = false; - // mediation_used = false; - // freeze_ls_restart_num = restarts_gap; - // bool res = call_ls(current_UP); - - // if(res){ - // solved_by_ls = true; - // return l_True; - // } - // } - - - - bool restart = false; - if (!VSIDS) - restart = nof_conflicts <= 0; - else if (!cached){ - restart = lbd_queue.full() && (lbd_queue.avg() * 0.8 > global_lbd_sum / conflicts_VSIDS); - cached = true; - } - if (restart || !withinBudget()){ - lbd_queue.clear(); - cached = false; - // Reached bound on number of conflicts: - progress_estimate = progressEstimate(); - cancelUntil(0); - return l_Undef; } - - // Simplify the set of problem clauses: - if (decisionLevel() == 0 && !simplify()) - return l_False; - - if (conflicts >= next_T2_reduce){ - next_T2_reduce = conflicts + 10000; - reduceDB_Tier2(); } - if (conflicts >= next_L_reduce){ - next_L_reduce = conflicts + 15000; - reduceDB(); } - - Lit next = lit_Undef; - /*while (decisionLevel() < assumptions.size()){ - // Perform user provided assumption: - Lit p = assumptions[decisionLevel()]; - if (value(p) == l_True){ - // Dummy decision level: - newDecisionLevel(); - }else if (value(p) == l_False){ - analyzeFinal(~p, conflict); - return l_False; - }else{ - next = p; - break; - } - } - - if (next == lit_Undef)*/{ - // New variable decision: - decisions++; - next = pickBranchLit(); - - if (next == lit_Undef) - // Model found: - return l_True; - } - - // Increase decision level and enqueue 'next' - newDecisionLevel(); - uncheckedEnqueue(next, decisionLevel()); -#ifdef PRINT_OUT - std::cout << "d " << next << " l " << decisionLevel() << "\n"; -#endif - } - } -} - - -double Solver::progressEstimate() const -{ - double progress = 0; - double F = 1.0 / nVars(); - - for (int i = 0; i <= decisionLevel(); i++){ - int beg = i == 0 ? 0 : trail_lim[i - 1]; - int end = i == decisionLevel() ? trail.size() : trail_lim[i]; - progress += pow(F, i) * (end - beg); - } - - return progress / nVars(); -} - -/* - Finite subsequences of the Luby-sequence: - - 0: 1 - 1: 1 1 2 - 2: 1 1 2 1 1 2 4 - 3: 1 1 2 1 1 2 4 1 1 2 1 1 2 4 8 - ... - - - */ - -static double luby(double y, int x){ - - // Find the finite subsequence that contains index 'x', and the - // size of that subsequence: - int size, seq; - for (size = 1, seq = 0; size < x+1; seq++, size = 2*size+1); - - while (size-1 != x){ - size = (size-1)>>1; - seq--; - x = x % size; - } - - return pow(y, seq); -} - -static bool switch_mode = false; -static void SIGALRM_switch(int signum) { switch_mode = true; } - -// NOTE: assumptions passed in member-variable 'assumptions'. -lbool Solver::solve_() -{ - // signal(SIGALRM, SIGALRM_switch); - // alarm(2500); - restarts_gap = 300; - restarts_basic = 300; - // if trail.size() over c*nVars or p*max_trail, call ls. - // float conflict_ratio = 0.4; - // float percent_ratio = 0.9; - // // control ls time total use. - // float up_time_ratio = 0.2; - // control ls memory use per call. - ls_mems_num = 50*1000*1000; - // whether the mediation_soln is used as rephase, if not - // bool mediation_used = false; - - switch_heristic_mod = 500;//starts - last_switch_conflicts; - - //informations - // bool lssolver_constructed = false; - freeze_ls_restart_num = 0; - ls_used_time = 0; - ls_call_num = 0; - ls_best_unsat_num = INT_MAX; - solved_by_ls = false; - max_trail = 0; - max_trail_improved = false; - up_build_num = 0; - up_build_time = 0.0; - - - ccanr_has_constructed=false; - model.clear(); - conflict.clear(); - if (!ok) return l_False; - - solves++; - - max_learnts = nClauses() * learntsize_factor; - learntsize_adjust_confl = learntsize_adjust_start_confl; - learntsize_adjust_cnt = (int)learntsize_adjust_confl; - lbool status = l_Undef; - - - ls_mediation_soln = new char[nVars()+2]; - ls_best_soln = new char[nVars()+2]; - top_trail_soln = new char[nVars()+2]; - tmp_up_build_soln = new char[nVars()+2]; - - if (verbosity >= 1){ - printf("c ============================[ Search Statistics ]==============================\n"); - printf("c | Conflicts | ORIGINAL | LEARNT | Progress |\n"); - printf("c | | Vars Clauses Literals | Limit Clauses Lit/Cl | |\n"); - printf("c ===============================================================================\n"); - } - - add_tmp.clear(); - - lssolver = (CCAnr*)malloc(sizeof(CCAnr)*1); - int fls_res = call_ls(current_UP); - if(fls_res){ - status = l_True; - } - for(int i=0;i 0 && withinBudget()) - status = search(init); - VSIDS = false; - - duplicates_added_conflicts = 0; - duplicates_added_minimization=0; - duplicates_added_tier2 =0; - - dupl_db_size=0; - size_t dupl_db_size_limit = dupl_db_init_size; - - // Search: - int curr_restarts = 0; - last_switch_conflicts = starts; - while (status == l_Undef && withinBudget()){ - if (dupl_db_size >= dupl_db_size_limit){ - // printf("c Duplicate learnts added (Minimization) %i.\n",duplicates_added_minimization); - // printf("c Duplicate learnts added (conflicts) %i.\n",duplicates_added_conflicts); - // printf("c Duplicate learnts added (tier2) %i.\n",duplicates_added_tier2); - // printf("c Duptime: %i\n",duptime.count()); - // printf("c Number of conflicts: %i\n",conflicts); - // printf("c Core size: %i\n",learnts_core.size()); - - uint32_t removed_duplicates = 0; - std::vector> tmp; - //std::map>> ht; - for (auto & outer_mp: ht){//variables - for (auto &inner_mp:outer_mp.second){//sizes - for (auto &in_in_mp: inner_mp.second){ - if (in_in_mp.second >= min_number_of_learnts_copies){ - tmp.push_back({outer_mp.first,inner_mp.first,in_in_mp.first,in_in_mp.second}); - } - } - } - } - removed_duplicates = dupl_db_size-tmp.size(); - ht.clear(); - for (auto i=0;i switch_heristic_mod){ - if(VSIDS){ - VSIDS = false; - }else{ - VSIDS = true; -// picked.clear(); -// conflicted.clear(); -// almost_conflicted.clear(); -// #ifdef ANTI_EXPLORATION -// canceled.clear(); -// #endif - } - last_switch_conflicts = starts; -// cout<<"c Swith"<= 1) - printf("c ===============================================================================\n"); - -#ifdef BIN_DRUP - if (drup_file && status == l_False) binDRUP_flush(drup_file); -#endif - - if (status == l_True){ - // Extend & copy model: - model.growTo(nVars()); - if(solved_by_ls) - for (int i = 0; i < nVars(); i++) model[i] = ls_mediation_soln[i]?l_True:l_False; - else - for (int i = 0; i < nVars(); i++) model[i] = value(i); - - }else if (status == l_False && conflict.size() == 0) - ok = false; - - cancelUntil(0); - delete [] ls_mediation_soln; - delete [] ls_best_soln; - delete [] top_trail_soln; - delete [] tmp_up_build_soln; - if (lssolver) { - free_memory(lssolver); - free(lssolver); - } - lssolver = NULL; - return status; -} - -//================================================================================================= -// Writing CNF to DIMACS: -// -// FIXME: this needs to be rewritten completely. - -static Var mapVar(Var x, vec& map, Var& max) -{ - if (map.size() <= x || map[x] == -1){ - map.growTo(x+1, -1); - map[x] = max++; - } - return map[x]; -} - - -void Solver::toDimacs(FILE* f, Clause& c, vec& map, Var& max) -{ - if (satisfied(c)) return; - - for (int i = 0; i < c.size(); i++) - if (value(c[i]) != l_False) - fprintf(f, "%s%d ", sign(c[i]) ? "-" : "", mapVar(var(c[i]), map, max)+1); - fprintf(f, "0\n"); -} - - -void Solver::toDimacs(const char *file, const vec& assumps) -{ - FILE* f = fopen(file, "wr"); - if (f == NULL) - fprintf(stderr, "could not open file %s\n", file), exit(1); - toDimacs(f, assumps); - fclose(f); -} - - -void Solver::toDimacs(FILE* f, const vec& assumps) -{ - // Handle case when solver is in contradictory state: - if (!ok){ - fprintf(f, "p cnf 1 2\n1 0\n-1 0\n"); - return; } - - vec map; Var max = 0; - - // Cannot use removeClauses here because it is not safe - // to deallocate them at this point. Could be improved. - int cnt = 0; - for (int i = 0; i < clauses.size(); i++) - if (!satisfied(ca[clauses[i]])) - cnt++; - - for (int i = 0; i < clauses.size(); i++) - if (!satisfied(ca[clauses[i]])){ - Clause& c = ca[clauses[i]]; - for (int j = 0; j < c.size(); j++) - if (value(c[j]) != l_False) - mapVar(var(c[j]), map, max); - } - - // Assumptions are added as unit clauses: - cnt += assumptions.size(); - - fprintf(f, "p cnf %d %d\n", max, cnt); - - for (int i = 0; i < assumptions.size(); i++){ - assert(value(assumptions[i]) != l_False); - fprintf(f, "%s%d 0\n", sign(assumptions[i]) ? "-" : "", mapVar(var(assumptions[i]), map, max)+1); - } - - for (int i = 0; i < clauses.size(); i++) - toDimacs(f, ca[clauses[i]], map, max); - - if (verbosity > 0) - printf("c Wrote %d clauses with %d variables.\n", cnt, max); -} - - -//================================================================================================= -// Garbage Collection methods: - -void Solver::relocAll(ClauseAllocator& to) -{ - // All watchers: - // - // for (int i = 0; i < watches.size(); i++) - watches.cleanAll(); - watches_bin.cleanAll(); - for (int v = 0; v < nVars(); v++) - for (int s = 0; s < 2; s++){ - Lit p = mkLit(v, s); - // printf(" >>> RELOCING: %s%d\n", sign(p)?"-":"", var(p)+1); - vec& ws = watches[p]; - for (int j = 0; j < ws.size(); j++) - ca.reloc(ws[j].cref, to); - vec& ws_bin = watches_bin[p]; - for (int j = 0; j < ws_bin.size(); j++) - ca.reloc(ws_bin[j].cref, to); - } - - // All reasons: - // - for (int i = 0; i < trail.size(); i++){ - Var v = var(trail[i]); - - if (reason(v) != CRef_Undef && (ca[reason(v)].reloced() || locked(ca[reason(v)]))) - ca.reloc(vardata[v].reason, to); - } - - // All learnt: - // - for (int i = 0; i < learnts_core.size(); i++) - ca.reloc(learnts_core[i], to); - for (int i = 0; i < learnts_tier2.size(); i++) - ca.reloc(learnts_tier2[i], to); - for (int i = 0; i < learnts_local.size(); i++) - ca.reloc(learnts_local[i], to); - - // All original: - // - int i, j; - for (i = j = 0; i < clauses.size(); i++) - if (ca[clauses[i]].mark() != 1){ - ca.reloc(clauses[i], to); - clauses[j++] = clauses[i]; } - clauses.shrink(i - j); -} - - -void Solver::garbageCollect() -{ - // Initialize the next region to a size corresponding to the estimated utilization degree. This - // is not precise but should avoid some unnecessary reallocations for the new region: - ClauseAllocator to(ca.size() - ca.wasted()); - - relocAll(to); - if (verbosity >= 2) - printf("c | Garbage collection: %12d bytes => %12d bytes |\n", - ca.size()*ClauseAllocator::Unit_Size, to.size()*ClauseAllocator::Unit_Size); - to.moveTo(ca); -} - - - - -void Solver::load_ls_data(){ - using namespace std; - int ls_var_nums = nVars(); - int ls_cls_nums = nClauses()+learnts_core.size()+learnts_tier2.size(); - int ls_trail_sz; - if(trail_lim.size()>0) ls_trail_sz = trail_lim[0]; - else ls_trail_sz = trail.size(); - ls_cls_nums += ls_trail_sz; - lssolver->num_vars = ls_var_nums; - lssolver->num_clauses = ls_cls_nums; - lssolver->mems_left = (long long) ls_mems_num; - lssolver->ratio = (lssolver->num_clauses+0.0)/lssolver->num_vars; - alloc_memory(lssolver); - for (int c = 0; c < lssolver->num_clauses; c++) - lssolver->clause_lit_count[c] = lssolver->clause_delete[c] = 0; - for (int v=1; v<=lssolver->num_vars; ++v) - lssolver->var_lit_count[v] = lssolver->fix[v] = 0; - lssolver->max_clause_len = 0; - lssolver->min_clause_len = lssolver->num_vars; - - using namespace std; - int cls_ct = 0; - for(int idx=0;idx<3;++idx){ - vec &vs = (idx==0)?clauses:(idx==1?learnts_core:(idx==2?learnts_tier2:learnts_local)); - int vs_sz = vs.size(); - for(int j=0;jclause_lit_count[cls_ct] = c.size(); - lssolver->clause_lit[cls_ct] = (lit*)malloc(sizeof(lit)*(lssolver->clause_lit_count[cls_ct]+1)); - int i=0; - for(;iclause_lit_count[cls_ct];i++){ - int cur_lit = toFormal(c[i]); - lssolver->clause_lit[cls_ct][i].clause_num = cls_ct; - lssolver->clause_lit[cls_ct][i].var_num = abs(cur_lit); - if (cur_lit > 0) lssolver->clause_lit[cls_ct][i].sense = 1; - else lssolver->clause_lit[cls_ct][i].sense = 0; - lssolver->var_lit_count[lssolver->clause_lit[cls_ct][i].var_num]++; - } - lssolver->clause_lit[cls_ct][i].var_num=0; - lssolver->clause_lit[cls_ct][i].clause_num = -1; - //unit clause - if(lssolver->clause_lit_count[cls_ct]==1){ - lssolver->unitclause_queue[lssolver->unitclause_queue_end_pointer++] = lssolver->clause_lit[cls_ct][0]; - lssolver->clause_delete[cls_ct]=1; - lssolver->clause_lit_count[cls_ct]=0; - } - if(lssolver->clause_lit_count[cls_ct] > lssolver->max_clause_len) - lssolver->max_clause_len = lssolver->clause_lit_count[cls_ct]; - else if(lssolver->clause_lit_count[cls_ct] < lssolver->min_clause_len) - lssolver->min_clause_len = lssolver->clause_lit_count[cls_ct]; - lssolver->formula_len += lssolver->clause_lit_count[cls_ct]; - - cls_ct++; - } - } - for(int j=0;jclause_lit_count[cls_ct] = 1; - lssolver->clause_lit[cls_ct] = (lit*)malloc(sizeof(lit)*(2)); - lssolver->clause_lit[cls_ct][0].clause_num = cls_ct; - lssolver->clause_lit[cls_ct][0].var_num = abs(cur_lit); - if (cur_lit > 0) lssolver->clause_lit[cls_ct][0].sense = 1; - else lssolver->clause_lit[cls_ct][0].sense = 0; - lssolver->var_lit_count[lssolver->clause_lit[cls_ct][0].var_num]++; - lssolver->clause_lit[cls_ct][1].var_num=0; - lssolver->clause_lit[cls_ct][1].clause_num=-1; - lssolver->unitclause_queue[lssolver->unitclause_queue_end_pointer++] = lssolver->clause_lit[cls_ct][0]; - lssolver->clause_delete[cls_ct]=1; - lssolver->clause_lit_count[cls_ct]=0; - if(lssolver->min_clause_len > 1)lssolver->min_clause_len = 1; - lssolver->formula_len += 1; - cls_ct++; - } - - for (int c = 0; c < lssolver->num_clauses; ++c) - { - if(lssolver->clause_delete[c]==1) { - continue; - } - - for(int i=0; iclause_lit_count[c]; ++i) - { - int v = lssolver->clause_lit[c][i].var_num; - - if (v > 0 && v <= lssolver->num_vars); - else { - printf("\n111wrong v %d clause id: %d\n", v, c); - for(int ii=0; iiclause_lit_count[c]; ++ii) - printf("%d ", lssolver->clause_lit[c][ii].var_num); - puts(""); - } - if (lssolver->var_lit_count[v] >= 0 && lssolver->var_lit_count[v] <= lssolver->num_clauses); - else printf("111wrong var_lit_count[v] %d\n", lssolver->var_lit_count[v]); - - } - } - // printf("finish check 1\n"); - // ofstream fout("test.txt"); - - // for (int c = 0; c < lssolver->num_clauses; ++c) - // { - // if(lssolver->clause_delete[c]==1) { - // continue; - // } - // fout << c << ": "; - // for(int i=0; iclause_lit_count[c]; ++i) - // { - // int v = lssolver->clause_lit[c][i].var_num; - // int p = lssolver->clause_lit[c][i].sense; - // fout << (p==1 ? v:-v) << " "; - // } - // fout << endl; - // } - // fout.close(); - update_after_build(lssolver); - for (int c = 0; c < lssolver->num_clauses; ++c) - { - if(lssolver->clause_delete[c]==1) { - continue; - } - - for(int i=0; iclause_lit_count[c]; ++i) - { - int v = lssolver->clause_lit[c][i].var_num; - - if (v > 0 && v <= lssolver->num_vars); - else { - printf("\n333wrong v %d clause id: %d\n", v, c); - for(int ii=0; iiclause_lit_count[c]; ++ii) - printf("%d ", lssolver->clause_lit[c][ii].var_num); - puts(""); - } - if (lssolver->var_lit_count[v] >= 0 && lssolver->var_lit_count[v] <= lssolver->num_clauses); - else printf("333wrong var_lit_count[v] %d\n", lssolver->var_lit_count[v]); - - } - } - // printf("finish check 3\n"); -} - -void Solver::build_soln_with_UP(){ - #include - using std::vector; - double start_time = cpuTime(); - int var_nums = nVars(); - int trl_sz = trail.size(); - int trl_loc = qhead; - Lit* trl = new Lit[var_nums+1]; - int undef_vars_sz = 0; - int* undef_vars = new int[var_nums+1]; - int* idx_in_undef_vars = new int[var_nums+1]; - // -1 undef, 0 false, 1 true - for(int i=0;i0){ - while(trl_loc0){ - Lit &p = trl[trl_loc++]; - - // watch binary codes - vec& ws_bin = watches_bin[p]; - int ws_bin_sz = ws_bin.size(); - for(int k=0;k& ws = watches[p]; - Watcher *i,*j,*end; - for(i=j=(Watcher*)ws,end=i+ws.size();i!=end;){ - Lit blocker = i->blocker; - // the clause is already SAT - if(tmp_up_build_soln[var(blocker)]==!sign(blocker)){*j++ = *i++;continue;} - - CRef cr = i->cref; - Clause& c = ca[cr]; - - // make sure c[1] is the false_lit to swap - Lit false_lit = ~p; - if(c[0]==false_lit) c[0]=c[1],c[1]=false_lit; - i++; - - // judge if the first lit is l_true - Lit first = c[0]; - Var first_var = var(first); - Watcher w = Watcher(cr,first); - if(first!=blocker && tmp_up_build_soln[first_var]==!sign(first)){*j++ = w; continue;} - - // first is l_false or l_undef - // then find another !l_false lit - int c_sz = c.size(); - bool should_goto_next_cls = false; - for(int k=2;kunsat_stack_fill_pointer; - // double construct_time = cpuTime()-start_time; - res = local_search(lssolver); - confl_trans(lssolver); - int ls_var_nums=nVars(); - for(int i=0;ibest_soln[i+1]; - if(lssolver->best_cost <= ls_best_unsat_num){ - restarts_gap-=restarts_basic; - if(restarts_gapbest_cost; - for(int i=0;ifix_var_ct)+"v,del"+to_string(lssolver->del_cls_ct)+"c)" - // <<",(v="<num_vars)+",c="+to_string(lssolver->num_clauses)+")" - // <<",(unsat:"<"<best_cost)+")" - // <<",("<step)<<"s)" - // <<",["< -using std::ofstream; -#define pop(stack) stack[--stack ## _fill_pointer] -#define push(item, stack) stack[stack ## _fill_pointer++] = item -#define ccanr_Mersenne_N 624 -#define ccanr_Mersenne_M 397 -#define ccanr_Mersenne_MATRIX_A 0x9908b0dfUL -#define ccanr_Mersenne_UPPER_MASK 0x80000000UL -#define ccanr_Mersenne_LOWER_MASK 0x7fffffffUL -void ccanr_Mersenne_init_with_seed(ccanr_randgen* randgen, int seed); -int ccanr_Mersenne_next(ccanr_randgen* randgen, int bound); -int ccanr_rand(CCAnr*, int); - - -int pick_var(CCAnr*); -void init(CCAnr*,char*); -void unit_propagation(CCAnr*); -void preprocess(CCAnr*); -void flip(CCAnr*,int); -void smooth_clause_weights(CCAnr*); -void update_clause_weights(CCAnr*); -void set_clause_weighting(CCAnr*); - -void default_initialize(CCAnr* lssolver){ - lssolver->formula_len=0; - lssolver->unitclause_queue_beg_pointer=0; - lssolver->unitclause_queue_end_pointer=0; - lssolver->max_tries = 10000; - lssolver->max_flips = 200000000; - lssolver->ave_weight=1; - lssolver->delta_total_weight=0; - lssolver->q_scale=0; - lssolver->q_init=0; - lssolver->mems_left=50000000; -} - -void alloc_memory(CCAnr *lssolver){ - int var_mem = lssolver->num_vars+2; - int cls_mem = lssolver->num_clauses+2; - lssolver->score_inc_vars = (int*)malloc(sizeof(int)*var_mem); - lssolver->score_inc_flag = (int*)malloc(sizeof(int)*var_mem); - lssolver->var_lit = (lit**)malloc(sizeof(lit*)*var_mem); - lssolver->var_lit_count = (int*)malloc(sizeof(int)*var_mem); - lssolver->clause_lit = (lit**)malloc(sizeof(lit*)*cls_mem); - lssolver->clause_lit_count = (int*)malloc(sizeof(int)*cls_mem); - lssolver->score = (int*)malloc(sizeof(int)*var_mem); - lssolver->time_stamp = (int*)malloc(sizeof(int)*var_mem); - lssolver->fix = (int*)malloc(sizeof(int)*var_mem); - lssolver->cscc = (int*)malloc(sizeof(int)*var_mem); - lssolver->clause_weight = (int*)malloc(sizeof(int)*cls_mem); - lssolver->sat_count = (int*)malloc(sizeof(int)*cls_mem); - lssolver->sat_var = (int*)malloc(sizeof(int)*cls_mem); - lssolver->unsat_stack = (int*)malloc(sizeof(int)*cls_mem); - lssolver->index_in_unsat_stack=(int*)malloc(sizeof(int)*cls_mem); - lssolver->unsatvar_stack = (int*)malloc(sizeof(int)*var_mem); - lssolver->index_in_unsatvar_stack = (int*)malloc(sizeof(int)*var_mem); - lssolver->unsat_app_count = (int*)malloc(sizeof(int)*var_mem); - lssolver->goodvar_stack = (int*)malloc(sizeof(int)*var_mem); - lssolver->already_in_goodvar_stack = (int*)malloc(sizeof(int)*var_mem); - lssolver->unitclause_queue = (lit*)malloc(sizeof(lit)*var_mem); - lssolver->clause_delete = (int*)malloc(sizeof(int)*cls_mem); - lssolver->cur_soln = (char*)malloc(sizeof(int)*var_mem); - lssolver->best_soln = (char*)malloc(sizeof(int)*var_mem); - lssolver->conflict_ct = (int*)malloc(sizeof(int)*var_mem); - lssolver->in_conflict = (int*)malloc(sizeof(int)*var_mem); - for(int i=1;i<=lssolver->num_vars;++i) lssolver->conflict_ct[i]=0; -} - -void free_memory(CCAnr *lssolver) -{ - int i; - for (i = 0; i < lssolver->num_clauses; i++) - { - free(lssolver->clause_lit[i]); - } - - for(i=1; i<=lssolver->num_vars; ++i) - { - free(lssolver->var_lit[i]); - } - - free(lssolver->score_inc_vars); - free(lssolver->score_inc_flag); - free(lssolver->var_lit); - free(lssolver->var_lit_count); - free(lssolver->clause_lit); - free(lssolver->clause_lit_count); - free(lssolver->score); - free(lssolver->time_stamp); - free(lssolver->fix); - free(lssolver->cscc); - free(lssolver->clause_weight); - free(lssolver->sat_count); - free(lssolver->sat_var); - free(lssolver->unsat_stack); - free(lssolver->index_in_unsat_stack); - free(lssolver->unsatvar_stack); - free(lssolver->index_in_unsatvar_stack); - free(lssolver->unsat_app_count); - free(lssolver->goodvar_stack); - free(lssolver->already_in_goodvar_stack); - free(lssolver->unitclause_queue); - free(lssolver->clause_delete); - free(lssolver->cur_soln); - free(lssolver->best_soln); - free(lssolver->conflict_ct); - free(lssolver->in_conflict); -} - - -//pick a var to be flip -int pick_var(CCAnr *lssolver) -{ - int i,k,c,v; - int best_var; - lit* clause_c; - - /**Greedy Mode**/ - /*CCD (configuration changed decreasing) mode, the level with configuation chekcing*/ - if(lssolver->goodvar_stack_fill_pointer>0) - { - lssolver->mems_left -= lssolver->goodvar_stack_fill_pointer; - best_var = lssolver->goodvar_stack[0]; - - for(i=1; igoodvar_stack_fill_pointer; ++i) - { - v=lssolver->goodvar_stack[i]; - if(lssolver->score[v]>lssolver->score[best_var]) best_var = v; - else if(lssolver->score[v]==lssolver->score[best_var] && lssolver->time_stamp[v]time_stamp[best_var]) best_var = v; - } - - return best_var; - } - - /*SD (significant decreasing) mode, the level with aspiration*/ - best_var = 0; - for(i=0; iunsatvar_stack_fill_pointer; ++i) - { - if(lssolver->score[lssolver->unsatvar_stack[i]]>lssolver->ave_weight) - { - best_var = lssolver->unsatvar_stack[i]; - break; - } - } - - for(++i; iunsatvar_stack_fill_pointer; ++i) - { - v=lssolver->unsatvar_stack[i]; - if(lssolver->score[v]>lssolver->score[best_var]) best_var = v; - else if(lssolver->score[v]==lssolver->score[best_var] && lssolver->time_stamp[v]time_stamp[best_var]) best_var = v; - } - - if(best_var!=0) return best_var; - - /**Diversification Mode**/ - update_clause_weights(lssolver); - - /*focused random walk*/ - c = lssolver->unsat_stack[ccanr_rand(lssolver,lssolver->unsat_stack_fill_pointer)]; - clause_c = lssolver->clause_lit[c]; - best_var = clause_c[0].var_num; - for(k=1; kclause_lit_count[c]; ++k) - { - v=clause_c[k].var_num; - //if(time_stamp[v]score[v]>lssolver->score[best_var]) best_var = v; - else if(lssolver->score[v]==lssolver->score[best_var]&&lssolver->time_stamp[v]time_stamp[best_var]) best_var = v; - } - - return best_var; -} - -//set functions in the algorithm -void settings(CCAnr *lssolver,char *soln) -{ - set_clause_weighting(lssolver); - init(lssolver,soln); -} - -bool local_search(CCAnr *lssolver) -{ - int flipvar; - lssolver->best_cost = lssolver->num_clauses; - for (lssolver->step = 0; lssolver->stepmax_flips; lssolver->step++) - { - //find a solution - if(lssolver->unsat_stack_fill_pointer < lssolver->best_cost){ - lssolver->best_cost = lssolver->unsat_stack_fill_pointer; - for(int i=1;i<=lssolver->num_vars;++i) lssolver->best_soln[i]=lssolver->cur_soln[i]; - } - if(lssolver->unsat_stack_fill_pointer==0) return true; - if(lssolver->mems_left<0 && lssolver->step>1000) return false; - flipvar = pick_var(lssolver); - flip(lssolver,flipvar); - lssolver->time_stamp[flipvar] = lssolver->step; - - //update conflicts information - for(int i=0;iunsatvar_stack_fill_pointer;++i) - ++lssolver->conflict_ct[lssolver->unsatvar_stack[i]]; - - } - return false; -} - -inline void unsat(CCAnr *lssolver, int clause) -{ - lssolver->index_in_unsat_stack[clause] = lssolver->unsat_stack_fill_pointer; - push(clause,lssolver->unsat_stack); - - //update appreance count of each var in unsat clause and update stack of vars in unsat clauses - int v; - for(lit* p=lssolver->clause_lit[clause]; (v=p->var_num)!=0; p++) - { - lssolver->unsat_app_count[v]++; - if(lssolver->unsat_app_count[v]==1) - { - lssolver->index_in_unsatvar_stack[v] = lssolver->unsatvar_stack_fill_pointer; - push(v,lssolver->unsatvar_stack); - } - } -} - -inline void sat(CCAnr *lssolver, int clause) -{ - int index,last_unsat_clause; - - //since the clause is satisfied, its position can be reused to store the last_unsat_clause - last_unsat_clause = pop(lssolver->unsat_stack); - index = lssolver->index_in_unsat_stack[clause]; - lssolver->unsat_stack[index] = last_unsat_clause; - lssolver->index_in_unsat_stack[last_unsat_clause] = index; - - //update appreance count of each var in unsat clause and update stack of vars in unsat clauses - int v,last_unsat_var; - for(lit* p=lssolver->clause_lit[clause]; (v=p->var_num)!=0; p++) - { - lssolver->unsat_app_count[v]--; - if(lssolver->unsat_app_count[v]==0) - { - last_unsat_var = pop(lssolver->unsatvar_stack); - index = lssolver->index_in_unsatvar_stack[v]; - lssolver->unsatvar_stack[index] = last_unsat_var; - lssolver->index_in_unsatvar_stack[last_unsat_var] = index; - } - } -} - -//initiation of the algorithm -void init(CCAnr *lssolver,char *soln) -{ - int v,c; - int i,j; - - //Initialize edge weights - for (c = 0; cnum_clauses; c++) - lssolver->clause_weight[c] = 1; - - //init unsat_stack - lssolver->unsat_stack_fill_pointer = 0; - lssolver->unsatvar_stack_fill_pointer = 0; - - //init solution - for (v = 1; v <= lssolver->num_vars; v++) { - - if(lssolver->fix[v]==0){ - if(soln==NULL){ - if(ccanr_rand(lssolver,2)==1) lssolver->cur_soln[v] = 1; - else lssolver->cur_soln[v] = 0; - }else{ - lssolver->cur_soln[v] = soln[v-1]; - } - - lssolver->time_stamp[v] = 0; - lssolver->unsat_app_count[v] = 0; - lssolver->cscc[v] = 1; - lssolver->score_inc_flag[v]=0; - } - - - } - - /* figure out sat_count, and init unsat_stack */ - for (c=0; cnum_clauses; ++c) - { - if(lssolver->clause_delete[c]==1) continue; - - lssolver->sat_count[c] = 0; - - for(j=0; jclause_lit_count[c]; ++j) - { - if (lssolver->cur_soln[lssolver->clause_lit[c][j].var_num] == lssolver->clause_lit[c][j].sense) - { - lssolver->sat_count[c]++; - lssolver->sat_var[c] = lssolver->clause_lit[c][j].var_num; - } - } - - if (lssolver->sat_count[c] == 0) - unsat(lssolver,c); - } - - /*figure out var score*/ - int lit_count; - for (v=1; v<=lssolver->num_vars; v++) - { - if(lssolver->fix[v]==1) - { - lssolver->score[v] = -10000000; - continue; - } - - lssolver->score[v] = 0; - - lit_count = lssolver->var_lit_count[v]; - - for(i=0; ivar_lit[v][i].clause_num; - if (lssolver->sat_count[c]==0) lssolver->score[v]++; - else if (lssolver->sat_count[c]==1 && lssolver->var_lit[v][i].sense==lssolver->cur_soln[v]) lssolver->score[v]--; - } - } - - - //init goodvars stack - lssolver->goodvar_stack_fill_pointer = 0; - for (v=1; v<=lssolver->num_vars; v++) - { - if(lssolver->fix[v]==1) continue; - if(lssolver->score[v]>0)// && conf_change[v]==1) - { - lssolver->already_in_goodvar_stack[v] = 1; - push(v,lssolver->goodvar_stack); - - } - else lssolver->already_in_goodvar_stack[v] = 0; - } - - //setting for the virtual var 0 - lssolver->time_stamp[0]=0; - //pscore[0]=0; -} - -void flip(CCAnr *lssolver, int flipvar) -{ - lssolver->cur_soln[flipvar] = 1 - lssolver->cur_soln[flipvar]; - - lssolver->score_inc_count=0; - - int i; - int v,c; - - lit* clause_c; - - int org_flipvar_score = lssolver->score[flipvar]; - - //update related clauses and neighbor vars - lssolver->mems_left-=lssolver->var_lit_count[flipvar]; - for(lit *q = lssolver->var_lit[flipvar]; (c=q->clause_num)>=0; q++) - { - clause_c = lssolver->clause_lit[c]; - if(lssolver->cur_soln[flipvar] == q->sense) - { - ++lssolver->sat_count[c]; - - if (lssolver->sat_count[c] == 2) //sat_count from 1 to 2 - { - lssolver->score[lssolver->sat_var[c]] += lssolver->clause_weight[c]; - - if(lssolver->score_inc_flag[lssolver->sat_var[c]]!=1) - { - lssolver->score_inc_vars[lssolver->score_inc_count++]=lssolver->sat_var[c]; - lssolver->score_inc_flag[lssolver->sat_var[c]]=1; - } - } - else if (lssolver->sat_count[c] == 1) // sat_count from 0 to 1 - { - lssolver->sat_var[c] = flipvar;//record the only true lit's var - for(lit* p=clause_c; (v=p->var_num)!=0; p++) - { - lssolver->score[v] -= lssolver->clause_weight[c]; - lssolver->cscc[v] = 1; - } - - sat(lssolver,c); - } - } - else // cur_soln[flipvar] != cur_lit.sense - { - --lssolver->sat_count[c]; - if (lssolver->sat_count[c] == 1) //sat_count from 2 to 1 - { - for(lit* p=clause_c; (v=p->var_num)!=0; p++) - { - if(p->sense == lssolver->cur_soln[v] ) - { - lssolver->score[v] -= lssolver->clause_weight[c]; - lssolver->sat_var[c] = v; - break; - } - } - } - else if (lssolver->sat_count[c] == 0) //sat_count from 1 to 0 - { - for(lit* p=clause_c; (v=p->var_num)!=0; p++) - { - lssolver->score[v] += lssolver->clause_weight[c]; - lssolver->cscc[v] = 1; - - if(lssolver->score_inc_flag[v]!=1) - { - lssolver->score_inc_vars[lssolver->score_inc_count++]=v; - lssolver->score_inc_flag[v]=1; - } - } - unsat(lssolver,c); - }//end else if - - }//end else - } - - lssolver->score[flipvar] = -org_flipvar_score; - - lssolver->cscc[flipvar] = 0; - - /*update CCD */ - int index; - - for(index=lssolver->goodvar_stack_fill_pointer-1; index>=0; index--) - { - v = lssolver->goodvar_stack[index]; - if(lssolver->score[v]<=0) - { - lssolver->goodvar_stack[index] = pop(lssolver->goodvar_stack); - lssolver->already_in_goodvar_stack[v] = 0; - } - } - - - for (i=0; iscore_inc_count; ++i) - { - v = lssolver->score_inc_vars[i]; - if(lssolver->score[v]>0 && lssolver->cscc[v]==1 && lssolver->already_in_goodvar_stack[v] ==0) - { - push(v,lssolver->goodvar_stack); - lssolver->already_in_goodvar_stack[v] = 1; - } - lssolver->score_inc_flag[v]=0; - } -} - -void update_after_build(CCAnr *lssolver){ - int i,c,v; - lssolver->avg_clause_len = (double)(lssolver->formula_len+0.0)/lssolver->num_clauses; - - //creat var literal arrays - for (v=1; v<=lssolver->num_vars; ++v) - { - lssolver->var_lit[v] = (lit*)malloc(sizeof(lit)*(lssolver->var_lit_count[v]+1)); - lssolver->var_lit_count[v] = 0; //reset to 0, for build up the array - } - //scan all clauses to build up var literal arrays - for (c = 0; c < lssolver->num_clauses; ++c) - { - if(lssolver->clause_delete[c]==1) - continue; - for(i=0; iclause_lit_count[c]; ++i) - { - v = lssolver->clause_lit[c][i].var_num; - lssolver->var_lit[v][lssolver->var_lit_count[v]] = lssolver->clause_lit[c][i]; - ++lssolver->var_lit_count[v]; - } - } - for (v=1; v<=lssolver->num_vars; ++v) //set boundary - lssolver->var_lit[v][lssolver->var_lit_count[v]].clause_num=-1; - - for (int c = 0; c < lssolver->num_clauses; ++c) - { - if(lssolver->clause_delete[c]==1) { - continue; - } - - for(int i=0; iclause_lit_count[c]; ++i) - { - int v = lssolver->clause_lit[c][i].var_num; - - if (v > 0 && v <= lssolver->num_vars); - else { - printf("\n222wrong v %d clause id: %d\n", v, c); - for(int ii=0; iiclause_lit_count[c]; ++ii) - printf("%d ", lssolver->clause_lit[c][ii].var_num); - puts(""); - } - if (lssolver->var_lit_count[v] >= 0 && lssolver->var_lit_count[v] <= lssolver->num_clauses); - else printf("222wrong var_lit_count[v] %d\n", lssolver->var_lit_count[v]); - - } - } - // printf("finish check 2\n"); - if(lssolver->unitclause_queue_end_pointer>0) preprocess(lssolver); - -} - - - -void smooth_clause_weights(CCAnr *lssolver) -{ - int j,c,v; - int new_total_weight=0; - - for (v=1; v<=lssolver->num_vars; ++v) - lssolver->score[v] = 0; - - //smooth clause score and update score of variables - for (c = 0; cnum_clauses; ++c) - { - if (lssolver->clause_delete[c]==1) continue; - - lssolver->clause_weight[c] = lssolver->clause_weight[c]*lssolver->p_scale+lssolver->scale_ave; - if(lssolver->clause_weight[c]<1) lssolver->clause_weight[c] = 1; - - new_total_weight+=lssolver->clause_weight[c]; - - //update score of variables in this clause - if (lssolver->sat_count[c]==0) - { - for(j=0; jclause_lit_count[c]; ++j) - { - lssolver->score[lssolver->clause_lit[c][j].var_num] += lssolver->clause_weight[c]; - } - } - else if(lssolver->sat_count[c]==1) - lssolver->score[lssolver->sat_var[c]]-=lssolver->clause_weight[c]; - } - - lssolver->ave_weight=new_total_weight/lssolver->num_clauses; -} - -void update_clause_weights(CCAnr *lssolver) -{ - int i,v; - lssolver->mems_left -= lssolver->unsat_stack_fill_pointer; - for(i=0; i < lssolver->unsat_stack_fill_pointer; ++i) - lssolver->clause_weight[lssolver->unsat_stack[i]]++; - - for(i=0; iunsatvar_stack_fill_pointer; ++i) - { - v = lssolver->unsatvar_stack[i]; - lssolver->score[v] += lssolver->unsat_app_count[v]; - if(lssolver->score[v]>0 && lssolver->cscc[v]==1 && lssolver->already_in_goodvar_stack[v] ==0) - { - push(v,lssolver->goodvar_stack); - lssolver->already_in_goodvar_stack[v] =1; - } - } - - lssolver->delta_total_weight+=lssolver->unsat_stack_fill_pointer; - if(lssolver->delta_total_weight>=lssolver->num_clauses) - { - lssolver->ave_weight+=1; - lssolver->delta_total_weight -= lssolver->num_clauses; - - //smooth weights - if(lssolver->ave_weight>lssolver->threshold) - smooth_clause_weights(lssolver); - } -} - -void set_clause_weighting(CCAnr *lssolver) -{ - lssolver->threshold=300; - lssolver->p_scale=0.3; - if(lssolver->q_init==0) - { - if(lssolver->ratio<=15) lssolver->q_scale=0; - else lssolver->q_scale=0.7; - } - else - { - if(lssolver->q_scale<0.5) //0 - lssolver->q_scale = 0.7; - else - lssolver->q_scale = 0; - } - - lssolver->scale_ave=(lssolver->threshold+1)*lssolver->q_scale; - lssolver->q_init = 1; -} - -//preprocess -void unit_propagation(CCAnr *lssolver) -{ - lit uc_lit; - int uc_clause; - int uc_var; - bool uc_sense; - - int c; - int i,j; - lit cur; - - - for(lssolver->unitclause_queue_beg_pointer=0; lssolver->unitclause_queue_beg_pointer < lssolver->unitclause_queue_end_pointer; lssolver->unitclause_queue_beg_pointer++) - { - uc_lit = lssolver->unitclause_queue[lssolver->unitclause_queue_beg_pointer]; - - uc_var = uc_lit.var_num; - uc_sense = uc_lit.sense; - - if(lssolver->fix[uc_var]==1) {if(uc_sense!=lssolver->cur_soln[uc_var])printf("c wants to fix a variable twice, forbid\n");continue;} - - lssolver->cur_soln[uc_var] = uc_sense;//fix the variable in unit clause - lssolver->fix[uc_var] = 1; - - for(i = 0; ivar_lit_count[uc_var]; ++i) - { - cur = lssolver->var_lit[uc_var][i]; - c = cur.clause_num; - - if(lssolver->clause_delete[c]==1) continue; - - if(cur.sense == uc_sense)//then remove the clause from var's var_lit[] array - { - lssolver->clause_delete[c]=1; - lssolver->clause_lit_count[c]=0; - } - else - { - if(lssolver->clause_lit_count[c]==2) - { - if(lssolver->clause_lit[c][0].var_num == uc_var) - { - lssolver->unitclause_queue[lssolver->unitclause_queue_end_pointer++] = lssolver->clause_lit[c][1]; - } - else - { - lssolver->unitclause_queue[lssolver->unitclause_queue_end_pointer++] = lssolver->clause_lit[c][0]; - } - - lssolver->clause_delete[c]=1; - lssolver->clause_lit_count[c]=0; - } - else - { - for(j=0; jclause_lit_count[c]; ++j) - { - if(lssolver->clause_lit[c][j].var_num == uc_var) - { - lssolver->clause_lit[c][j]=lssolver->clause_lit[c][lssolver->clause_lit_count[c]-1]; - - lssolver->clause_lit_count[c]--; - - break; - } - } - } - } - } - } - -} - -void preprocess(CCAnr *lssolver) -{ - int c,v,i; - int delete_clause_count=0; - int fix_var_count=0; - // ofstream fout("test2.txt"); - - // for (int c = 0; c < lssolver->num_clauses; ++c) - // { - // if(lssolver->clause_delete[c]==1) { - // continue; - // } - // fout << c << ": "; - // for(int i=0; iclause_lit_count[c]; ++i) - // { - // int v = lssolver->clause_lit[c][i].var_num; - // int p = lssolver->clause_lit[c][i].sense; - // fout << (p==1 ? v:-v) << " "; - // } - // fout << std::endl; - // } - // fout.close(); - unit_propagation(lssolver); - - //rescan all clauses to build up var literal arrays - for (v=1; v<=lssolver->num_vars; ++v) - lssolver->var_lit_count[v] = 0; - - lssolver->max_clause_len = 0; - lssolver->min_clause_len = lssolver->num_vars; - int formula_len=0; - - for (c = 0; c < lssolver->num_clauses; ++c) - { - if(lssolver->clause_delete[c]==1) { - delete_clause_count++; - continue; - } - - for(i=0; iclause_lit_count[c]; ++i) - { - v = lssolver->clause_lit[c][i].var_num; - - if (v > 0 && v <= lssolver->num_vars); - else { - printf("\n444wrong v %d clause id: %d\n", v, c); - for(int ii=0; iiclause_lit_count[c]; ++ii) - printf("%d ", lssolver->clause_lit[c][ii].var_num); - puts(""); - } - if (lssolver->var_lit_count[v] >= 0 && lssolver->var_lit_count[v] <= lssolver->num_clauses); - else printf("444wrong var_lit_count[v] %d\n", lssolver->var_lit_count[v]); - - lssolver->var_lit[v][lssolver->var_lit_count[v]] = lssolver->clause_lit[c][i]; - ++lssolver->var_lit_count[v]; - } - lssolver->clause_lit[c][i].var_num=0; //new clause boundary - lssolver->clause_lit[c][i].clause_num = -1; - - //about clause length - formula_len += lssolver->clause_lit_count[c]; - - if(lssolver->clause_lit_count[c] > lssolver->max_clause_len) - lssolver->max_clause_len = lssolver->clause_lit_count[c]; - else if(lssolver->clause_lit_count[c] < lssolver->min_clause_len) - lssolver->min_clause_len = lssolver->clause_lit_count[c]; - } - - lssolver->avg_clause_len = (double)(formula_len+0.0)/lssolver->num_clauses; - - for (v=1; v<=lssolver->num_vars; ++v) - { - if(lssolver->fix[v]==1) - { - fix_var_count++; - } - lssolver->var_lit[v][lssolver->var_lit_count[v]].clause_num=-1;//new var_lit boundary - } - lssolver->fix_var_ct = fix_var_count; - lssolver->del_cls_ct = delete_clause_count; - // printf("c unit propagation fixes %d variables, and deletes %d clauses\n",fix_var_count,delete_clause_count); - -} - - - -void ccanr_merseene_init(CCAnr* lssolver, int seed){ - ccanr_Mersenne_init_with_seed(&(lssolver->randgen),seed); -} - -int ccanr_rand(CCAnr* lssolver,int bound){ - return ccanr_Mersenne_next(&(lssolver->randgen),bound); -} - - -void ccanr_Mersenne_init_with_seed(ccanr_randgen* randgen, int seed){ - unsigned int s = ((unsigned int) (seed << 1)) + 1; - randgen->mt[0] = s & 0xffffffffUL; - for(randgen->mti = 1; randgen->mti < ccanr_Mersenne_N; randgen->mti++) { - randgen->mt[randgen->mti] = (1812433253UL * (randgen->mt[randgen->mti - 1] ^ (randgen->mt[randgen->mti - 1] >> 30)) + randgen->mti); - randgen->mt[randgen->mti] &= 0xffffffffUL; - } -} - -int ccanr_Mersenne_next31(ccanr_randgen* randgen){ - unsigned int y; - static unsigned int mag01[2] = {0x0UL, ccanr_Mersenne_MATRIX_A}; - if(randgen->mti >= ccanr_Mersenne_N) { - int kk; - for(kk = 0; kk < ccanr_Mersenne_N - ccanr_Mersenne_M; kk++) { - y = (randgen->mt[kk] & ccanr_Mersenne_UPPER_MASK) | (randgen->mt[kk + 1] & ccanr_Mersenne_LOWER_MASK); - randgen->mt[kk] = randgen->mt[kk + ccanr_Mersenne_M] ^ (y >> 1) ^ mag01[y & 0x1UL]; - } - for(; kk < ccanr_Mersenne_N - 1; kk++) { - y = (randgen->mt[kk] & ccanr_Mersenne_UPPER_MASK) | (randgen->mt[kk + 1] & ccanr_Mersenne_LOWER_MASK); - randgen->mt[kk] = randgen->mt[kk + (ccanr_Mersenne_M - ccanr_Mersenne_N)] ^ (y >> 1) ^ mag01[y & 0x1UL]; - } - y = (randgen->mt[ccanr_Mersenne_N - 1] & ccanr_Mersenne_UPPER_MASK) | (randgen->mt[0] & ccanr_Mersenne_LOWER_MASK); - randgen->mt[ccanr_Mersenne_N - 1] = randgen->mt[ccanr_Mersenne_M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL]; - randgen->mti = 0; - } - y = randgen->mt[randgen->mti++]; - y ^= (y >> 11); - y ^= (y << 7) & 0x9d2c5680UL; - y ^= (y << 15) & 0xefc60000UL; - y ^= (y >> 18); - return (int) (y>>1); -} - -int ccanr_Mersenne_next(ccanr_randgen* randgen, int bound){ - unsigned int value; - do { - value = ccanr_Mersenne_next31(randgen); - } while(value + (unsigned int) bound >= 0x80000000UL); - return (int) (value % bound); -} - - -void init_CCAnr(CCAnr* lssolver){ - int seed = 1; - ccanr_merseene_init(lssolver,seed); - default_initialize(lssolver); -} - -void reinit_CCAnr(CCAnr *lssolver){ - if (lssolver) free_memory(lssolver); - init_CCAnr(lssolver); -} - -void confl_trans(CCAnr* lssolver){ - lssolver->in_conflict_sz = 0; - if(lssolver->step==0) return; - for(int i=1;i<=lssolver->num_vars;++i){ - lssolver->conflict_ct[i] = lssolver->conflict_ct[i]*100/lssolver->step; - if(lssolver->conflict_ct[i]>0){ - lssolver->in_conflict[lssolver->in_conflict_sz++] = i; - } - } -} \ No newline at end of file diff --git a/lstech_maple/lstech/utils/ccnr.h b/lstech_maple/lstech/utils/ccnr.h deleted file mode 100755 index af39a70..0000000 --- a/lstech_maple/lstech/utils/ccnr.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef _CCA_H_ -#define _CCA_H_ - -#include -#include -#include -#include -#include //these two h files are for linux -#include - -// mersenne twist -typedef struct ccanr_randgen ccanr_randgen; -struct ccanr_randgen -{ - unsigned mt[624]; - int mti; -}; - - -// Define a data structure for a literal in the SAT problem. -typedef struct lit lit; - -struct lit { - int clause_num; //clause num, begin with 0 - int var_num; //variable num, begin with 1 - int sense; //is 1 for true literals, 0 for false literals. -}; - -typedef struct CCAnr CCAnr; - -struct CCAnr{ - /*parameters of the instance*/ - int num_vars; //var index from 1 to num_vars - int num_clauses; //clause index from 0 to num_clauses-1 - int max_clause_len; - int min_clause_len; - int formula_len; - double avg_clause_len; - double ratio; - int ave_weight; //significant score(sigscore) needed for aspiration - int delta_total_weight; - int threshold; - float p_scale;//w=w*p+ave_w*q - float q_scale; - int scale_ave;//scale_ave==ave_weight*q_scale - int q_init; - long long mems_left; - //cutoff - int max_tries; - int tries; - int max_flips; - int step; - int* score_inc_vars; - int* score_inc_flag; - int score_inc_count; - /* literal arrays */ - lit** var_lit; //var_lit[i][j] means the j'th literal of var i. - int* var_lit_count; //amount of literals of each var - lit** clause_lit; //clause_lit[i][j] means the j'th literal of clause i. - int* clause_lit_count; // amount of literals in each clause - - - /* Information about the variables. */ - int* score; - int* time_stamp; - int* fix; - int* cscc; - - /* Information about the clauses */ - int* clause_weight; - int* sat_count; - int* sat_var; - - //unsat clauses stack - int* unsat_stack; //store the unsat clause number - int unsat_stack_fill_pointer; - int* index_in_unsat_stack;//which position is a clause in the unsat_stack - - //variables in unsat clauses - int* unsatvar_stack; - int unsatvar_stack_fill_pointer; - int* index_in_unsatvar_stack; - int* unsat_app_count; //a varible appears in how many unsat clauses - - //configuration changed decreasing variables (score>0 and confchange=1) - int* goodvar_stack; - int goodvar_stack_fill_pointer; - int* already_in_goodvar_stack; - - //unit clauses preprocess - lit* unitclause_queue; - int unitclause_queue_beg_pointer; - int unitclause_queue_end_pointer; - int* clause_delete; - - /* Information about solution */ - char* cur_soln; //the current solution, with 1's for True variables, and 0's for False variables - ccanr_randgen randgen; - char* best_soln; - int best_cost; - // confl_trans - int* conflict_ct; - int in_conflict_sz; - int* in_conflict; - - // preprocess - int fix_var_ct; - int del_cls_ct; -}; - - -void init_CCAnr(CCAnr*); -void reinit_CCAnr(CCAnr*); -void confl_trans(CCAnr*); - - -bool local_search(CCAnr*); -int build_instance(CCAnr*,char *filename); -void print_solution(CCAnr*); -int verify_sol(CCAnr*); -void alloc_memory(CCAnr*); -void free_memory(CCAnr*); -void settings(CCAnr*, char*); -void ccanr_merseene_init(CCAnr*, int); -void update_after_build(CCAnr*); - - -#endif - diff --git a/lstech_maple/lstech/utils/ccnr.or b/lstech_maple/lstech/utils/ccnr.or deleted file mode 100755 index 36da6ae..0000000 Binary files a/lstech_maple/lstech/utils/ccnr.or and /dev/null differ diff --git a/lstech_maple/starexec_build b/lstech_maple/starexec_build deleted file mode 100755 index 01aa251..0000000 --- a/lstech_maple/starexec_build +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -rm build/*.o build/*.or -rm build/libRelaxed.a -rm build/Relaxed -rm bin/lstech_maple -cd lstech/simp -make clean -make rs -cp glucose_static ../../bin/lstech_maple diff --git a/m4ri-20140914/m4ri/.libs/brilliantrussian.o b/m4ri-20140914/m4ri/.libs/brilliantrussian.o deleted file mode 100644 index c9df264..0000000 Binary files a/m4ri-20140914/m4ri/.libs/brilliantrussian.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/debug_dump.o b/m4ri-20140914/m4ri/.libs/debug_dump.o deleted file mode 100644 index 142636a..0000000 Binary files a/m4ri-20140914/m4ri/.libs/debug_dump.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/djb.o b/m4ri-20140914/m4ri/.libs/djb.o deleted file mode 100644 index dde7271..0000000 Binary files a/m4ri-20140914/m4ri/.libs/djb.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/echelonform.o b/m4ri-20140914/m4ri/.libs/echelonform.o deleted file mode 100644 index 3524340..0000000 Binary files a/m4ri-20140914/m4ri/.libs/echelonform.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/graycode.o b/m4ri-20140914/m4ri/.libs/graycode.o deleted file mode 100644 index ef1c35a..0000000 Binary files a/m4ri-20140914/m4ri/.libs/graycode.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/io.o b/m4ri-20140914/m4ri/.libs/io.o deleted file mode 100644 index 372e3cf..0000000 Binary files a/m4ri-20140914/m4ri/.libs/io.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/misc.o b/m4ri-20140914/m4ri/.libs/misc.o deleted file mode 100644 index 20033c2..0000000 Binary files a/m4ri-20140914/m4ri/.libs/misc.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/mmc.o b/m4ri-20140914/m4ri/.libs/mmc.o deleted file mode 100644 index 145ea30..0000000 Binary files a/m4ri-20140914/m4ri/.libs/mmc.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/mp.o b/m4ri-20140914/m4ri/.libs/mp.o deleted file mode 100644 index 4b33e54..0000000 Binary files a/m4ri-20140914/m4ri/.libs/mp.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/mzd.o b/m4ri-20140914/m4ri/.libs/mzd.o deleted file mode 100644 index 7784b96..0000000 Binary files a/m4ri-20140914/m4ri/.libs/mzd.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/mzp.o b/m4ri-20140914/m4ri/.libs/mzp.o deleted file mode 100644 index c692e6c..0000000 Binary files a/m4ri-20140914/m4ri/.libs/mzp.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/ple.o b/m4ri-20140914/m4ri/.libs/ple.o deleted file mode 100644 index 68eecc9..0000000 Binary files a/m4ri-20140914/m4ri/.libs/ple.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/ple_russian.o b/m4ri-20140914/m4ri/.libs/ple_russian.o deleted file mode 100644 index a1ed50f..0000000 Binary files a/m4ri-20140914/m4ri/.libs/ple_russian.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/solve.o b/m4ri-20140914/m4ri/.libs/solve.o deleted file mode 100644 index 3099c8a..0000000 Binary files a/m4ri-20140914/m4ri/.libs/solve.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/strassen.o b/m4ri-20140914/m4ri/.libs/strassen.o deleted file mode 100644 index c8a15ba..0000000 Binary files a/m4ri-20140914/m4ri/.libs/strassen.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/triangular.o b/m4ri-20140914/m4ri/.libs/triangular.o deleted file mode 100644 index 66623f9..0000000 Binary files a/m4ri-20140914/m4ri/.libs/triangular.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/.libs/triangular_russian.o b/m4ri-20140914/m4ri/.libs/triangular_russian.o deleted file mode 100644 index aa912ed..0000000 Binary files a/m4ri-20140914/m4ri/.libs/triangular_russian.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/brilliantrussian.o b/m4ri-20140914/m4ri/brilliantrussian.o deleted file mode 100644 index 1033df6..0000000 Binary files a/m4ri-20140914/m4ri/brilliantrussian.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/debug_dump.o b/m4ri-20140914/m4ri/debug_dump.o deleted file mode 100644 index 212a09e..0000000 Binary files a/m4ri-20140914/m4ri/debug_dump.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/djb.o b/m4ri-20140914/m4ri/djb.o deleted file mode 100644 index 240fd09..0000000 Binary files a/m4ri-20140914/m4ri/djb.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/echelonform.o b/m4ri-20140914/m4ri/echelonform.o deleted file mode 100644 index 5badf81..0000000 Binary files a/m4ri-20140914/m4ri/echelonform.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/graycode.o b/m4ri-20140914/m4ri/graycode.o deleted file mode 100644 index 164fe64..0000000 Binary files a/m4ri-20140914/m4ri/graycode.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/io.o b/m4ri-20140914/m4ri/io.o deleted file mode 100644 index 2b7c8a1..0000000 Binary files a/m4ri-20140914/m4ri/io.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/misc.o b/m4ri-20140914/m4ri/misc.o deleted file mode 100644 index f59d942..0000000 Binary files a/m4ri-20140914/m4ri/misc.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/mmc.o b/m4ri-20140914/m4ri/mmc.o deleted file mode 100644 index 1f52e38..0000000 Binary files a/m4ri-20140914/m4ri/mmc.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/mp.o b/m4ri-20140914/m4ri/mp.o deleted file mode 100644 index 7e3d285..0000000 Binary files a/m4ri-20140914/m4ri/mp.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/mzd.o b/m4ri-20140914/m4ri/mzd.o deleted file mode 100644 index c83b642..0000000 Binary files a/m4ri-20140914/m4ri/mzd.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/mzp.o b/m4ri-20140914/m4ri/mzp.o deleted file mode 100644 index a780afc..0000000 Binary files a/m4ri-20140914/m4ri/mzp.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/ple.o b/m4ri-20140914/m4ri/ple.o deleted file mode 100644 index 2e618a1..0000000 Binary files a/m4ri-20140914/m4ri/ple.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/ple_russian.o b/m4ri-20140914/m4ri/ple_russian.o deleted file mode 100644 index a41e6fa..0000000 Binary files a/m4ri-20140914/m4ri/ple_russian.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/solve.o b/m4ri-20140914/m4ri/solve.o deleted file mode 100644 index 8774693..0000000 Binary files a/m4ri-20140914/m4ri/solve.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/strassen.o b/m4ri-20140914/m4ri/strassen.o deleted file mode 100644 index f7ad1d3..0000000 Binary files a/m4ri-20140914/m4ri/strassen.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/triangular.o b/m4ri-20140914/m4ri/triangular.o deleted file mode 100644 index 41b2bec..0000000 Binary files a/m4ri-20140914/m4ri/triangular.o and /dev/null differ diff --git a/m4ri-20140914/m4ri/triangular_russian.o b/m4ri-20140914/m4ri/triangular_russian.o deleted file mode 100644 index e783969..0000000 Binary files a/m4ri-20140914/m4ri/triangular_russian.o and /dev/null differ diff --git a/makefile b/makefile index 5e13b26..5502f25 100644 --- a/makefile +++ b/makefile @@ -9,8 +9,8 @@ CXX := mpicxx CXXFLAGS := -std=c++17 -O3 -Wall -Wextra -MMD -MP -march=native -mtune=native -g LIBS := -Wl,-Bstatic -lkissat -L kissat-inc/build -I kissat-inc/ \ - -llstech -L lstech_maple/build/release/lib -I lstech_maple/lstech/ \ - -lm4ri -L m4ri-20140914/.libs -I m4ri-20140914/ \ + -lmapleCOMSPS -L mapleCOMSPS/build/release/lib -I mapleCOMSPS/mapleCOMSPS/ \ + -lm4ri -L mapleCOMSPS/m4ri-20140914/.libs -I mapleCOMSPS/m4ri-20140914/ \ -pthread -lz -lm -lboost_thread -lboost_date_time -lboost_system \ -Wl,-Bdynamic -lmpi_cxx -lmpi diff --git a/lstech_maple/Makefile b/mapleCOMSPS/Makefile old mode 100755 new mode 100644 similarity index 82% rename from lstech_maple/Makefile rename to mapleCOMSPS/Makefile index 8878e5d..b192dea --- a/lstech_maple/Makefile +++ b/mapleCOMSPS/Makefile @@ -49,8 +49,8 @@ datarootdir ?= $(prefix)/share mandir ?= $(datarootdir)/man # Target file names -MAPLE = lstech# Name of MiniSat main executable. -MAPLE_CORE = lstech_core# Name of simplified MiniSat executable (only core solver support). +MAPLE = mapleCOMSPS# Name of MiniSat main executable. +MAPLE_CORE = mapleCOMSPS_core# Name of simplified MiniSat executable (only core solver support). MAPLE_SLIB = lib$(MAPLE).a# Name of MiniSat static library. MAPLE_DLIB = lib$(MAPLE).so# Name of MiniSat shared library. @@ -59,8 +59,8 @@ SOMAJOR=2 SOMINOR=1 SORELEASE?=.0# Declare empty to leave out from library file name. -MAPLE_CXXFLAGS = -I. -Ilstech/ -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -Wall -Wno-parentheses -Wextra -std=c++11 -MAPLE_LDFLAGS = -Wall -lz +MAPLE_CXXFLAGS = -I. -Im4ri-20140914 -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -Wall -Wno-parentheses -Wextra -std=c++11 +MAPLE_LDFLAGS = -Wall -lz -Lm4ri-20140914/.libs -lm4ri ECHO=@echo ifeq ($(VERB),) @@ -69,8 +69,8 @@ else VERB= endif -SRCS = $(wildcard lstech/core/*.cc) $(wildcard lstech/simp/*.cc) $(wildcard lstech/utils/*.cc) -HDRS = $(wildcard lstech/mtl/*.h) $(wildcard lstech/core/*.h) $(wildcard lstech/simp/*.h) $(wildcard lstech/utils/*.h) +SRCS = $(wildcard mapleCOMSPS/core/*.cc) $(wildcard mapleCOMSPS/simp/*.cc) $(wildcard mapleCOMSPS/utils/*.cc) +HDRS = $(wildcard mapleCOMSPS/mtl/*.h) $(wildcard mapleCOMSPS/core/*.h) $(wildcard mapleCOMSPS/simp/*.h) $(wildcard mapleCOMSPS/utils/*.h) OBJS = $(filter-out %Main.o, $(SRCS:.cc=.o)) r: $(BUILD_DIR)/release/bin/$(MAPLE) @@ -101,18 +101,18 @@ $(BUILD_DIR)/profile/bin/$(MAPLE_CORE): MAPLE_LDFLAGS += -pg $(BUILD_DIR)/release/bin/$(MAPLE_CORE): MAPLE_LDFLAGS += --static $(MAPLE_RELSYM) ## Executable dependencies -$(BUILD_DIR)/release/bin/$(MAPLE): $(BUILD_DIR)/release/lstech/simp/Main.o $(BUILD_DIR)/release/lib/$(MAPLE_SLIB) -$(BUILD_DIR)/debug/bin/$(MAPLE): $(BUILD_DIR)/debug/lstech/simp/Main.o $(BUILD_DIR)/debug/lib/$(MAPLE_SLIB) -$(BUILD_DIR)/profile/bin/$(MAPLE): $(BUILD_DIR)/profile/lstech/simp/Main.o $(BUILD_DIR)/profile/lib/$(MAPLE_SLIB) +$(BUILD_DIR)/release/bin/$(MAPLE): $(BUILD_DIR)/release/mapleCOMSPS/simp/Main.o $(BUILD_DIR)/release/lib/$(MAPLE_SLIB) +$(BUILD_DIR)/debug/bin/$(MAPLE): $(BUILD_DIR)/debug/mapleCOMSPS/simp/Main.o $(BUILD_DIR)/debug/lib/$(MAPLE_SLIB) +$(BUILD_DIR)/profile/bin/$(MAPLE): $(BUILD_DIR)/profile/mapleCOMSPS/simp/Main.o $(BUILD_DIR)/profile/lib/$(MAPLE_SLIB) # need the main-file be compiled with fpic? -$(BUILD_DIR)/dynamic/bin/$(MAPLE): $(BUILD_DIR)/dynamic/lstech/simp/Main.o $(BUILD_DIR)/dynamic/lib/$(MAPLE_DLIB) +$(BUILD_DIR)/dynamic/bin/$(MAPLE): $(BUILD_DIR)/dynamic/mapleCOMSPS/simp/Main.o $(BUILD_DIR)/dynamic/lib/$(MAPLE_DLIB) ## Executable dependencies (core-version) -$(BUILD_DIR)/release/bin/$(MAPLE_CORE): $(BUILD_DIR)/release/lstech/core/Main.o $(BUILD_DIR)/release/lib/$(MAPLE_SLIB) -$(BUILD_DIR)/debug/bin/$(MAPLE_CORE): $(BUILD_DIR)/debug/lstech/core/Main.o $(BUILD_DIR)/debug/lib/$(MAPLE_SLIB) -$(BUILD_DIR)/profile/bin/$(MAPLE_CORE): $(BUILD_DIR)/profile/lstech/core/Main.o $(BUILD_DIR)/profile/lib/$(MAPLE_SLIB) +$(BUILD_DIR)/release/bin/$(MAPLE_CORE): $(BUILD_DIR)/release/mapleCOMSPS/core/Main.o $(BUILD_DIR)/release/lib/$(MAPLE_SLIB) +$(BUILD_DIR)/debug/bin/$(MAPLE_CORE): $(BUILD_DIR)/debug/mapleCOMSPS/core/Main.o $(BUILD_DIR)/debug/lib/$(MAPLE_SLIB) +$(BUILD_DIR)/profile/bin/$(MAPLE_CORE): $(BUILD_DIR)/profile/mapleCOMSPS/core/Main.o $(BUILD_DIR)/profile/lib/$(MAPLE_SLIB) # need the main-file be compiled with fpic? -$(BUILD_DIR)/dynamic/bin/$(MAPLE_CORE): $(BUILD_DIR)/dynamic/lstech/core/Main.o $(BUILD_DIR)/dynamic/lib/$(MAPLE_DLIB) +$(BUILD_DIR)/dynamic/bin/$(MAPLE_CORE): $(BUILD_DIR)/dynamic/mapleCOMSPS/core/Main.o $(BUILD_DIR)/dynamic/lib/$(MAPLE_DLIB) ## Library dependencies $(BUILD_DIR)/release/lib/$(MAPLE_SLIB): $(foreach o,$(OBJS),$(BUILD_DIR)/release/$(o)) @@ -171,9 +171,9 @@ install-debug: install-headers install-lib-debug install-headers: # Create directories - $(INSTALL) -d $(DESTDIR)$(includedir)/lstech + $(INSTALL) -d $(DESTDIR)$(includedir)/mapleCOMSPS for dir in mtl utils core simp; do \ - $(INSTALL) -d $(DESTDIR)$(includedir)/lstech/$$dir ; \ + $(INSTALL) -d $(DESTDIR)$(includedir)/mapleCOMSPS/$$dir ; \ done # Install headers for h in $(HDRS) ; do \ diff --git a/m4ri-20140914/.libs/libm4ri-0.0.20140914.so b/mapleCOMSPS/m4ri-20140914/.libs/libm4ri-0.0.20140914.so similarity index 94% rename from m4ri-20140914/.libs/libm4ri-0.0.20140914.so rename to mapleCOMSPS/m4ri-20140914/.libs/libm4ri-0.0.20140914.so index 23f9377..c791d3e 100755 Binary files a/m4ri-20140914/.libs/libm4ri-0.0.20140914.so and b/mapleCOMSPS/m4ri-20140914/.libs/libm4ri-0.0.20140914.so differ diff --git a/m4ri-20140914/.libs/libm4ri.a b/mapleCOMSPS/m4ri-20140914/.libs/libm4ri.a similarity index 94% rename from m4ri-20140914/.libs/libm4ri.a rename to mapleCOMSPS/m4ri-20140914/.libs/libm4ri.a index cba3f1f..4ac1c31 100644 Binary files a/m4ri-20140914/.libs/libm4ri.a and b/mapleCOMSPS/m4ri-20140914/.libs/libm4ri.a differ diff --git a/m4ri-20140914/.libs/libm4ri.la b/mapleCOMSPS/m4ri-20140914/.libs/libm4ri.la similarity index 100% rename from m4ri-20140914/.libs/libm4ri.la rename to mapleCOMSPS/m4ri-20140914/.libs/libm4ri.la diff --git a/m4ri-20140914/.libs/libm4ri.lai b/mapleCOMSPS/m4ri-20140914/.libs/libm4ri.lai similarity index 100% rename from m4ri-20140914/.libs/libm4ri.lai rename to mapleCOMSPS/m4ri-20140914/.libs/libm4ri.lai diff --git a/m4ri-20140914/.libs/libm4ri.so b/mapleCOMSPS/m4ri-20140914/.libs/libm4ri.so similarity index 100% rename from m4ri-20140914/.libs/libm4ri.so rename to mapleCOMSPS/m4ri-20140914/.libs/libm4ri.so diff --git a/m4ri-20140914/AUTHORS b/mapleCOMSPS/m4ri-20140914/AUTHORS similarity index 100% rename from m4ri-20140914/AUTHORS rename to mapleCOMSPS/m4ri-20140914/AUTHORS diff --git a/m4ri-20140914/COPYING b/mapleCOMSPS/m4ri-20140914/COPYING similarity index 100% rename from m4ri-20140914/COPYING rename to mapleCOMSPS/m4ri-20140914/COPYING diff --git a/m4ri-20140914/ChangeLog b/mapleCOMSPS/m4ri-20140914/ChangeLog similarity index 100% rename from m4ri-20140914/ChangeLog rename to mapleCOMSPS/m4ri-20140914/ChangeLog diff --git a/m4ri-20140914/INSTALL b/mapleCOMSPS/m4ri-20140914/INSTALL similarity index 100% rename from m4ri-20140914/INSTALL rename to mapleCOMSPS/m4ri-20140914/INSTALL diff --git a/m4ri-20140914/Makefile b/mapleCOMSPS/m4ri-20140914/Makefile similarity index 100% rename from m4ri-20140914/Makefile rename to mapleCOMSPS/m4ri-20140914/Makefile diff --git a/m4ri-20140914/Makefile.am b/mapleCOMSPS/m4ri-20140914/Makefile.am similarity index 100% rename from m4ri-20140914/Makefile.am rename to mapleCOMSPS/m4ri-20140914/Makefile.am diff --git a/m4ri-20140914/Makefile.in b/mapleCOMSPS/m4ri-20140914/Makefile.in similarity index 100% rename from m4ri-20140914/Makefile.in rename to mapleCOMSPS/m4ri-20140914/Makefile.in diff --git a/m4ri-20140914/NEWS b/mapleCOMSPS/m4ri-20140914/NEWS similarity index 100% rename from m4ri-20140914/NEWS rename to mapleCOMSPS/m4ri-20140914/NEWS diff --git a/m4ri-20140914/aclocal.m4 b/mapleCOMSPS/m4ri-20140914/aclocal.m4 similarity index 100% rename from m4ri-20140914/aclocal.m4 rename to mapleCOMSPS/m4ri-20140914/aclocal.m4 diff --git a/m4ri-20140914/compile b/mapleCOMSPS/m4ri-20140914/compile similarity index 100% rename from m4ri-20140914/compile rename to mapleCOMSPS/m4ri-20140914/compile diff --git a/m4ri-20140914/config.guess b/mapleCOMSPS/m4ri-20140914/config.guess similarity index 100% rename from m4ri-20140914/config.guess rename to mapleCOMSPS/m4ri-20140914/config.guess diff --git a/m4ri-20140914/config.log b/mapleCOMSPS/m4ri-20140914/config.log similarity index 100% rename from m4ri-20140914/config.log rename to mapleCOMSPS/m4ri-20140914/config.log diff --git a/m4ri-20140914/config.status b/mapleCOMSPS/m4ri-20140914/config.status similarity index 100% rename from m4ri-20140914/config.status rename to mapleCOMSPS/m4ri-20140914/config.status diff --git a/m4ri-20140914/config.sub b/mapleCOMSPS/m4ri-20140914/config.sub similarity index 100% rename from m4ri-20140914/config.sub rename to mapleCOMSPS/m4ri-20140914/config.sub diff --git a/m4ri-20140914/configure b/mapleCOMSPS/m4ri-20140914/configure similarity index 100% rename from m4ri-20140914/configure rename to mapleCOMSPS/m4ri-20140914/configure diff --git a/m4ri-20140914/configure.ac b/mapleCOMSPS/m4ri-20140914/configure.ac similarity index 100% rename from m4ri-20140914/configure.ac rename to mapleCOMSPS/m4ri-20140914/configure.ac diff --git a/m4ri-20140914/depcomp b/mapleCOMSPS/m4ri-20140914/depcomp similarity index 100% rename from m4ri-20140914/depcomp rename to mapleCOMSPS/m4ri-20140914/depcomp diff --git a/m4ri-20140914/install-sh b/mapleCOMSPS/m4ri-20140914/install-sh similarity index 100% rename from m4ri-20140914/install-sh rename to mapleCOMSPS/m4ri-20140914/install-sh diff --git a/m4ri-20140914/libm4ri.la b/mapleCOMSPS/m4ri-20140914/libm4ri.la similarity index 100% rename from m4ri-20140914/libm4ri.la rename to mapleCOMSPS/m4ri-20140914/libm4ri.la diff --git a/m4ri-20140914/libtool b/mapleCOMSPS/m4ri-20140914/libtool similarity index 100% rename from m4ri-20140914/libtool rename to mapleCOMSPS/m4ri-20140914/libtool diff --git a/m4ri-20140914/ltmain.sh b/mapleCOMSPS/m4ri-20140914/ltmain.sh similarity index 100% rename from m4ri-20140914/ltmain.sh rename to mapleCOMSPS/m4ri-20140914/ltmain.sh diff --git a/m4ri-20140914/m4/ax_cache_size.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_cache_size.m4 similarity index 100% rename from m4ri-20140914/m4/ax_cache_size.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_cache_size.m4 diff --git a/m4ri-20140914/m4/ax_cache_size_tune.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_cache_size_tune.m4 similarity index 100% rename from m4ri-20140914/m4/ax_cache_size_tune.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_cache_size_tune.m4 diff --git a/m4ri-20140914/m4/ax_check_compiler_flags.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_check_compiler_flags.m4 similarity index 100% rename from m4ri-20140914/m4/ax_check_compiler_flags.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_check_compiler_flags.m4 diff --git a/m4ri-20140914/m4/ax_cpu_vendor.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_cpu_vendor.m4 similarity index 100% rename from m4ri-20140914/m4/ax_cpu_vendor.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_cpu_vendor.m4 diff --git a/m4ri-20140914/m4/ax_ext.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_ext.m4 similarity index 100% rename from m4ri-20140914/m4/ax_ext.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_ext.m4 diff --git a/m4ri-20140914/m4/ax_func_posix_memalign.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_func_posix_memalign.m4 similarity index 100% rename from m4ri-20140914/m4/ax_func_posix_memalign.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_func_posix_memalign.m4 diff --git a/m4ri-20140914/m4/ax_gcc_x86_cpuid.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_gcc_x86_cpuid.m4 similarity index 100% rename from m4ri-20140914/m4/ax_gcc_x86_cpuid.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_gcc_x86_cpuid.m4 diff --git a/m4ri-20140914/m4/ax_guess_path_header.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_guess_path_header.m4 similarity index 100% rename from m4ri-20140914/m4/ax_guess_path_header.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_guess_path_header.m4 diff --git a/m4ri-20140914/m4/ax_guess_path_lib.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_guess_path_lib.m4 similarity index 100% rename from m4ri-20140914/m4/ax_guess_path_lib.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_guess_path_lib.m4 diff --git a/m4ri-20140914/m4/ax_openmp.m4 b/mapleCOMSPS/m4ri-20140914/m4/ax_openmp.m4 similarity index 100% rename from m4ri-20140914/m4/ax_openmp.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ax_openmp.m4 diff --git a/m4ri-20140914/m4/libtool.m4 b/mapleCOMSPS/m4ri-20140914/m4/libtool.m4 similarity index 100% rename from m4ri-20140914/m4/libtool.m4 rename to mapleCOMSPS/m4ri-20140914/m4/libtool.m4 diff --git a/m4ri-20140914/m4/ltoptions.m4 b/mapleCOMSPS/m4ri-20140914/m4/ltoptions.m4 similarity index 100% rename from m4ri-20140914/m4/ltoptions.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ltoptions.m4 diff --git a/m4ri-20140914/m4/ltsugar.m4 b/mapleCOMSPS/m4ri-20140914/m4/ltsugar.m4 similarity index 100% rename from m4ri-20140914/m4/ltsugar.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ltsugar.m4 diff --git a/m4ri-20140914/m4/ltversion.m4 b/mapleCOMSPS/m4ri-20140914/m4/ltversion.m4 similarity index 100% rename from m4ri-20140914/m4/ltversion.m4 rename to mapleCOMSPS/m4ri-20140914/m4/ltversion.m4 diff --git a/m4ri-20140914/m4/lt~obsolete.m4 b/mapleCOMSPS/m4ri-20140914/m4/lt~obsolete.m4 similarity index 100% rename from m4ri-20140914/m4/lt~obsolete.m4 rename to mapleCOMSPS/m4ri-20140914/m4/lt~obsolete.m4 diff --git a/m4ri-20140914/m4/pkg.m4 b/mapleCOMSPS/m4ri-20140914/m4/pkg.m4 similarity index 100% rename from m4ri-20140914/m4/pkg.m4 rename to mapleCOMSPS/m4ri-20140914/m4/pkg.m4 diff --git a/m4ri-20140914/m4ri.pc b/mapleCOMSPS/m4ri-20140914/m4ri.pc similarity index 100% rename from m4ri-20140914/m4ri.pc rename to mapleCOMSPS/m4ri-20140914/m4ri.pc diff --git a/m4ri-20140914/m4ri.pc.in b/mapleCOMSPS/m4ri-20140914/m4ri.pc.in similarity index 100% rename from m4ri-20140914/m4ri.pc.in rename to mapleCOMSPS/m4ri-20140914/m4ri.pc.in diff --git a/m4ri-20140914/m4ri/.deps/.dirstamp b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/.dirstamp similarity index 100% rename from m4ri-20140914/m4ri/.deps/.dirstamp rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/.dirstamp diff --git a/m4ri-20140914/m4ri/.deps/brilliantrussian.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/brilliantrussian.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/brilliantrussian.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/brilliantrussian.Plo diff --git a/m4ri-20140914/m4ri/.deps/debug_dump.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/debug_dump.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/debug_dump.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/debug_dump.Plo diff --git a/m4ri-20140914/m4ri/.deps/djb.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/djb.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/djb.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/djb.Plo diff --git a/m4ri-20140914/m4ri/.deps/echelonform.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/echelonform.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/echelonform.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/echelonform.Plo diff --git a/m4ri-20140914/m4ri/.deps/graycode.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/graycode.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/graycode.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/graycode.Plo diff --git a/m4ri-20140914/m4ri/.deps/io.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/io.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/io.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/io.Plo diff --git a/m4ri-20140914/m4ri/.deps/misc.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/misc.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/misc.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/misc.Plo diff --git a/m4ri-20140914/m4ri/.deps/mmc.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/mmc.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/mmc.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/mmc.Plo diff --git a/m4ri-20140914/m4ri/.deps/mp.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/mp.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/mp.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/mp.Plo diff --git a/m4ri-20140914/m4ri/.deps/mzd.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/mzd.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/mzd.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/mzd.Plo diff --git a/m4ri-20140914/m4ri/.deps/mzp.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/mzp.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/mzp.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/mzp.Plo diff --git a/m4ri-20140914/m4ri/.deps/ple.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/ple.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/ple.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/ple.Plo diff --git a/m4ri-20140914/m4ri/.deps/ple_russian.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/ple_russian.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/ple_russian.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/ple_russian.Plo diff --git a/m4ri-20140914/m4ri/.deps/solve.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/solve.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/solve.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/solve.Plo diff --git a/m4ri-20140914/m4ri/.deps/strassen.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/strassen.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/strassen.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/strassen.Plo diff --git a/m4ri-20140914/m4ri/.deps/triangular.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/triangular.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/triangular.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/triangular.Plo diff --git a/m4ri-20140914/m4ri/.deps/triangular_russian.Plo b/mapleCOMSPS/m4ri-20140914/m4ri/.deps/triangular_russian.Plo similarity index 100% rename from m4ri-20140914/m4ri/.deps/triangular_russian.Plo rename to mapleCOMSPS/m4ri-20140914/m4ri/.deps/triangular_russian.Plo diff --git a/m4ri-20140914/m4ri/.dirstamp b/mapleCOMSPS/m4ri-20140914/m4ri/.dirstamp similarity index 100% rename from m4ri-20140914/m4ri/.dirstamp rename to mapleCOMSPS/m4ri-20140914/m4ri/.dirstamp diff --git a/m4ri-20140914/m4ri/Doxyfile b/mapleCOMSPS/m4ri-20140914/m4ri/Doxyfile similarity index 100% rename from m4ri-20140914/m4ri/Doxyfile rename to mapleCOMSPS/m4ri-20140914/m4ri/Doxyfile diff --git a/m4ri-20140914/m4ri/brilliantrussian.c b/mapleCOMSPS/m4ri-20140914/m4ri/brilliantrussian.c similarity index 100% rename from m4ri-20140914/m4ri/brilliantrussian.c rename to mapleCOMSPS/m4ri-20140914/m4ri/brilliantrussian.c diff --git a/m4ri-20140914/m4ri/brilliantrussian.h b/mapleCOMSPS/m4ri-20140914/m4ri/brilliantrussian.h similarity index 100% rename from m4ri-20140914/m4ri/brilliantrussian.h rename to mapleCOMSPS/m4ri-20140914/m4ri/brilliantrussian.h diff --git a/m4ri-20140914/m4ri/brilliantrussian.lo b/mapleCOMSPS/m4ri-20140914/m4ri/brilliantrussian.lo similarity index 100% rename from m4ri-20140914/m4ri/brilliantrussian.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/brilliantrussian.lo diff --git a/m4ri-20140914/m4ri/config.h b/mapleCOMSPS/m4ri-20140914/m4ri/config.h similarity index 100% rename from m4ri-20140914/m4ri/config.h rename to mapleCOMSPS/m4ri-20140914/m4ri/config.h diff --git a/m4ri-20140914/m4ri/config.h.in b/mapleCOMSPS/m4ri-20140914/m4ri/config.h.in similarity index 100% rename from m4ri-20140914/m4ri/config.h.in rename to mapleCOMSPS/m4ri-20140914/m4ri/config.h.in diff --git a/m4ri-20140914/m4ri/debug_dump.c b/mapleCOMSPS/m4ri-20140914/m4ri/debug_dump.c similarity index 100% rename from m4ri-20140914/m4ri/debug_dump.c rename to mapleCOMSPS/m4ri-20140914/m4ri/debug_dump.c diff --git a/m4ri-20140914/m4ri/debug_dump.h b/mapleCOMSPS/m4ri-20140914/m4ri/debug_dump.h similarity index 100% rename from m4ri-20140914/m4ri/debug_dump.h rename to mapleCOMSPS/m4ri-20140914/m4ri/debug_dump.h diff --git a/m4ri-20140914/m4ri/debug_dump.lo b/mapleCOMSPS/m4ri-20140914/m4ri/debug_dump.lo similarity index 100% rename from m4ri-20140914/m4ri/debug_dump.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/debug_dump.lo diff --git a/m4ri-20140914/m4ri/djb.c b/mapleCOMSPS/m4ri-20140914/m4ri/djb.c similarity index 100% rename from m4ri-20140914/m4ri/djb.c rename to mapleCOMSPS/m4ri-20140914/m4ri/djb.c diff --git a/m4ri-20140914/m4ri/djb.h b/mapleCOMSPS/m4ri-20140914/m4ri/djb.h similarity index 100% rename from m4ri-20140914/m4ri/djb.h rename to mapleCOMSPS/m4ri-20140914/m4ri/djb.h diff --git a/m4ri-20140914/m4ri/djb.lo b/mapleCOMSPS/m4ri-20140914/m4ri/djb.lo similarity index 100% rename from m4ri-20140914/m4ri/djb.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/djb.lo diff --git a/m4ri-20140914/m4ri/echelonform.c b/mapleCOMSPS/m4ri-20140914/m4ri/echelonform.c similarity index 100% rename from m4ri-20140914/m4ri/echelonform.c rename to mapleCOMSPS/m4ri-20140914/m4ri/echelonform.c diff --git a/m4ri-20140914/m4ri/echelonform.h b/mapleCOMSPS/m4ri-20140914/m4ri/echelonform.h similarity index 100% rename from m4ri-20140914/m4ri/echelonform.h rename to mapleCOMSPS/m4ri-20140914/m4ri/echelonform.h diff --git a/m4ri-20140914/m4ri/echelonform.lo b/mapleCOMSPS/m4ri-20140914/m4ri/echelonform.lo similarity index 100% rename from m4ri-20140914/m4ri/echelonform.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/echelonform.lo diff --git a/m4ri-20140914/m4ri/graycode.c b/mapleCOMSPS/m4ri-20140914/m4ri/graycode.c similarity index 100% rename from m4ri-20140914/m4ri/graycode.c rename to mapleCOMSPS/m4ri-20140914/m4ri/graycode.c diff --git a/m4ri-20140914/m4ri/graycode.h b/mapleCOMSPS/m4ri-20140914/m4ri/graycode.h similarity index 100% rename from m4ri-20140914/m4ri/graycode.h rename to mapleCOMSPS/m4ri-20140914/m4ri/graycode.h diff --git a/m4ri-20140914/m4ri/graycode.lo b/mapleCOMSPS/m4ri-20140914/m4ri/graycode.lo similarity index 100% rename from m4ri-20140914/m4ri/graycode.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/graycode.lo diff --git a/m4ri-20140914/m4ri/io.c b/mapleCOMSPS/m4ri-20140914/m4ri/io.c similarity index 100% rename from m4ri-20140914/m4ri/io.c rename to mapleCOMSPS/m4ri-20140914/m4ri/io.c diff --git a/m4ri-20140914/m4ri/io.h b/mapleCOMSPS/m4ri-20140914/m4ri/io.h similarity index 100% rename from m4ri-20140914/m4ri/io.h rename to mapleCOMSPS/m4ri-20140914/m4ri/io.h diff --git a/m4ri-20140914/m4ri/io.lo b/mapleCOMSPS/m4ri-20140914/m4ri/io.lo similarity index 100% rename from m4ri-20140914/m4ri/io.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/io.lo diff --git a/m4ri-20140914/m4ri/m4ri.h b/mapleCOMSPS/m4ri-20140914/m4ri/m4ri.h similarity index 100% rename from m4ri-20140914/m4ri/m4ri.h rename to mapleCOMSPS/m4ri-20140914/m4ri/m4ri.h diff --git a/m4ri-20140914/m4ri/m4ri_config.h b/mapleCOMSPS/m4ri-20140914/m4ri/m4ri_config.h similarity index 100% rename from m4ri-20140914/m4ri/m4ri_config.h rename to mapleCOMSPS/m4ri-20140914/m4ri/m4ri_config.h diff --git a/m4ri-20140914/m4ri/m4ri_config.h.in b/mapleCOMSPS/m4ri-20140914/m4ri/m4ri_config.h.in similarity index 100% rename from m4ri-20140914/m4ri/m4ri_config.h.in rename to mapleCOMSPS/m4ri-20140914/m4ri/m4ri_config.h.in diff --git a/m4ri-20140914/m4ri/misc.c b/mapleCOMSPS/m4ri-20140914/m4ri/misc.c similarity index 100% rename from m4ri-20140914/m4ri/misc.c rename to mapleCOMSPS/m4ri-20140914/m4ri/misc.c diff --git a/m4ri-20140914/m4ri/misc.h b/mapleCOMSPS/m4ri-20140914/m4ri/misc.h similarity index 100% rename from m4ri-20140914/m4ri/misc.h rename to mapleCOMSPS/m4ri-20140914/m4ri/misc.h diff --git a/m4ri-20140914/m4ri/misc.lo b/mapleCOMSPS/m4ri-20140914/m4ri/misc.lo similarity index 100% rename from m4ri-20140914/m4ri/misc.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/misc.lo diff --git a/m4ri-20140914/m4ri/mmc.c b/mapleCOMSPS/m4ri-20140914/m4ri/mmc.c similarity index 100% rename from m4ri-20140914/m4ri/mmc.c rename to mapleCOMSPS/m4ri-20140914/m4ri/mmc.c diff --git a/m4ri-20140914/m4ri/mmc.h b/mapleCOMSPS/m4ri-20140914/m4ri/mmc.h similarity index 100% rename from m4ri-20140914/m4ri/mmc.h rename to mapleCOMSPS/m4ri-20140914/m4ri/mmc.h diff --git a/m4ri-20140914/m4ri/mmc.lo b/mapleCOMSPS/m4ri-20140914/m4ri/mmc.lo similarity index 100% rename from m4ri-20140914/m4ri/mmc.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/mmc.lo diff --git a/m4ri-20140914/m4ri/mp.c b/mapleCOMSPS/m4ri-20140914/m4ri/mp.c similarity index 100% rename from m4ri-20140914/m4ri/mp.c rename to mapleCOMSPS/m4ri-20140914/m4ri/mp.c diff --git a/m4ri-20140914/m4ri/mp.h b/mapleCOMSPS/m4ri-20140914/m4ri/mp.h similarity index 100% rename from m4ri-20140914/m4ri/mp.h rename to mapleCOMSPS/m4ri-20140914/m4ri/mp.h diff --git a/m4ri-20140914/m4ri/mp.lo b/mapleCOMSPS/m4ri-20140914/m4ri/mp.lo similarity index 100% rename from m4ri-20140914/m4ri/mp.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/mp.lo diff --git a/m4ri-20140914/m4ri/mzd.c b/mapleCOMSPS/m4ri-20140914/m4ri/mzd.c similarity index 100% rename from m4ri-20140914/m4ri/mzd.c rename to mapleCOMSPS/m4ri-20140914/m4ri/mzd.c diff --git a/m4ri-20140914/m4ri/mzd.h b/mapleCOMSPS/m4ri-20140914/m4ri/mzd.h similarity index 100% rename from m4ri-20140914/m4ri/mzd.h rename to mapleCOMSPS/m4ri-20140914/m4ri/mzd.h diff --git a/m4ri-20140914/m4ri/mzd.lo b/mapleCOMSPS/m4ri-20140914/m4ri/mzd.lo similarity index 100% rename from m4ri-20140914/m4ri/mzd.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/mzd.lo diff --git a/m4ri-20140914/m4ri/mzp.c b/mapleCOMSPS/m4ri-20140914/m4ri/mzp.c similarity index 100% rename from m4ri-20140914/m4ri/mzp.c rename to mapleCOMSPS/m4ri-20140914/m4ri/mzp.c diff --git a/m4ri-20140914/m4ri/mzp.h b/mapleCOMSPS/m4ri-20140914/m4ri/mzp.h similarity index 100% rename from m4ri-20140914/m4ri/mzp.h rename to mapleCOMSPS/m4ri-20140914/m4ri/mzp.h diff --git a/m4ri-20140914/m4ri/mzp.lo b/mapleCOMSPS/m4ri-20140914/m4ri/mzp.lo similarity index 100% rename from m4ri-20140914/m4ri/mzp.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/mzp.lo diff --git a/m4ri-20140914/m4ri/parity.h b/mapleCOMSPS/m4ri-20140914/m4ri/parity.h similarity index 100% rename from m4ri-20140914/m4ri/parity.h rename to mapleCOMSPS/m4ri-20140914/m4ri/parity.h diff --git a/m4ri-20140914/m4ri/ple.c b/mapleCOMSPS/m4ri-20140914/m4ri/ple.c similarity index 100% rename from m4ri-20140914/m4ri/ple.c rename to mapleCOMSPS/m4ri-20140914/m4ri/ple.c diff --git a/m4ri-20140914/m4ri/ple.h b/mapleCOMSPS/m4ri-20140914/m4ri/ple.h similarity index 100% rename from m4ri-20140914/m4ri/ple.h rename to mapleCOMSPS/m4ri-20140914/m4ri/ple.h diff --git a/m4ri-20140914/m4ri/ple.lo b/mapleCOMSPS/m4ri-20140914/m4ri/ple.lo similarity index 100% rename from m4ri-20140914/m4ri/ple.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/ple.lo diff --git a/m4ri-20140914/m4ri/ple_russian.c b/mapleCOMSPS/m4ri-20140914/m4ri/ple_russian.c similarity index 100% rename from m4ri-20140914/m4ri/ple_russian.c rename to mapleCOMSPS/m4ri-20140914/m4ri/ple_russian.c diff --git a/m4ri-20140914/m4ri/ple_russian.h b/mapleCOMSPS/m4ri-20140914/m4ri/ple_russian.h similarity index 100% rename from m4ri-20140914/m4ri/ple_russian.h rename to mapleCOMSPS/m4ri-20140914/m4ri/ple_russian.h diff --git a/m4ri-20140914/m4ri/ple_russian.lo b/mapleCOMSPS/m4ri-20140914/m4ri/ple_russian.lo similarity index 100% rename from m4ri-20140914/m4ri/ple_russian.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/ple_russian.lo diff --git a/m4ri-20140914/m4ri/ple_russian_template.h b/mapleCOMSPS/m4ri-20140914/m4ri/ple_russian_template.h similarity index 100% rename from m4ri-20140914/m4ri/ple_russian_template.h rename to mapleCOMSPS/m4ri-20140914/m4ri/ple_russian_template.h diff --git a/m4ri-20140914/m4ri/solve.c b/mapleCOMSPS/m4ri-20140914/m4ri/solve.c similarity index 100% rename from m4ri-20140914/m4ri/solve.c rename to mapleCOMSPS/m4ri-20140914/m4ri/solve.c diff --git a/m4ri-20140914/m4ri/solve.h b/mapleCOMSPS/m4ri-20140914/m4ri/solve.h similarity index 100% rename from m4ri-20140914/m4ri/solve.h rename to mapleCOMSPS/m4ri-20140914/m4ri/solve.h diff --git a/m4ri-20140914/m4ri/solve.lo b/mapleCOMSPS/m4ri-20140914/m4ri/solve.lo similarity index 100% rename from m4ri-20140914/m4ri/solve.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/solve.lo diff --git a/m4ri-20140914/m4ri/stamp-h1 b/mapleCOMSPS/m4ri-20140914/m4ri/stamp-h1 similarity index 100% rename from m4ri-20140914/m4ri/stamp-h1 rename to mapleCOMSPS/m4ri-20140914/m4ri/stamp-h1 diff --git a/m4ri-20140914/m4ri/strassen.c b/mapleCOMSPS/m4ri-20140914/m4ri/strassen.c similarity index 100% rename from m4ri-20140914/m4ri/strassen.c rename to mapleCOMSPS/m4ri-20140914/m4ri/strassen.c diff --git a/m4ri-20140914/m4ri/strassen.h b/mapleCOMSPS/m4ri-20140914/m4ri/strassen.h similarity index 100% rename from m4ri-20140914/m4ri/strassen.h rename to mapleCOMSPS/m4ri-20140914/m4ri/strassen.h diff --git a/m4ri-20140914/m4ri/strassen.lo b/mapleCOMSPS/m4ri-20140914/m4ri/strassen.lo similarity index 100% rename from m4ri-20140914/m4ri/strassen.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/strassen.lo diff --git a/m4ri-20140914/m4ri/triangular.c b/mapleCOMSPS/m4ri-20140914/m4ri/triangular.c similarity index 100% rename from m4ri-20140914/m4ri/triangular.c rename to mapleCOMSPS/m4ri-20140914/m4ri/triangular.c diff --git a/m4ri-20140914/m4ri/triangular.h b/mapleCOMSPS/m4ri-20140914/m4ri/triangular.h similarity index 100% rename from m4ri-20140914/m4ri/triangular.h rename to mapleCOMSPS/m4ri-20140914/m4ri/triangular.h diff --git a/m4ri-20140914/m4ri/triangular.lo b/mapleCOMSPS/m4ri-20140914/m4ri/triangular.lo similarity index 100% rename from m4ri-20140914/m4ri/triangular.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/triangular.lo diff --git a/m4ri-20140914/m4ri/triangular_russian.c b/mapleCOMSPS/m4ri-20140914/m4ri/triangular_russian.c similarity index 100% rename from m4ri-20140914/m4ri/triangular_russian.c rename to mapleCOMSPS/m4ri-20140914/m4ri/triangular_russian.c diff --git a/m4ri-20140914/m4ri/triangular_russian.h b/mapleCOMSPS/m4ri-20140914/m4ri/triangular_russian.h similarity index 100% rename from m4ri-20140914/m4ri/triangular_russian.h rename to mapleCOMSPS/m4ri-20140914/m4ri/triangular_russian.h diff --git a/m4ri-20140914/m4ri/triangular_russian.lo b/mapleCOMSPS/m4ri-20140914/m4ri/triangular_russian.lo similarity index 100% rename from m4ri-20140914/m4ri/triangular_russian.lo rename to mapleCOMSPS/m4ri-20140914/m4ri/triangular_russian.lo diff --git a/m4ri-20140914/m4ri/xor.h b/mapleCOMSPS/m4ri-20140914/m4ri/xor.h similarity index 100% rename from m4ri-20140914/m4ri/xor.h rename to mapleCOMSPS/m4ri-20140914/m4ri/xor.h diff --git a/m4ri-20140914/m4ri/xor_template.h b/mapleCOMSPS/m4ri-20140914/m4ri/xor_template.h similarity index 100% rename from m4ri-20140914/m4ri/xor_template.h rename to mapleCOMSPS/m4ri-20140914/m4ri/xor_template.h diff --git a/m4ri-20140914/missing b/mapleCOMSPS/m4ri-20140914/missing similarity index 100% rename from m4ri-20140914/missing rename to mapleCOMSPS/m4ri-20140914/missing diff --git a/m4ri-20140914/test-driver b/mapleCOMSPS/m4ri-20140914/test-driver similarity index 100% rename from m4ri-20140914/test-driver rename to mapleCOMSPS/m4ri-20140914/test-driver diff --git a/m4ri-20140914/testsuite/.deps/test_colswap-test_colswap.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_colswap-test_colswap.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_colswap-test_colswap.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_colswap-test_colswap.Po diff --git a/m4ri-20140914/testsuite/.deps/test_elimination-test_elimination.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_elimination-test_elimination.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_elimination-test_elimination.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_elimination-test_elimination.Po diff --git a/m4ri-20140914/testsuite/.deps/test_invert-test_invert.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_invert-test_invert.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_invert-test_invert.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_invert-test_invert.Po diff --git a/m4ri-20140914/testsuite/.deps/test_kernel-test_kernel.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_kernel-test_kernel.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_kernel-test_kernel.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_kernel-test_kernel.Po diff --git a/m4ri-20140914/testsuite/.deps/test_misc-test_misc.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_misc-test_misc.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_misc-test_misc.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_misc-test_misc.Po diff --git a/m4ri-20140914/testsuite/.deps/test_multiplication-test_multiplication.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_multiplication-test_multiplication.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_multiplication-test_multiplication.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_multiplication-test_multiplication.Po diff --git a/m4ri-20140914/testsuite/.deps/test_ple-test_ple.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_ple-test_ple.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_ple-test_ple.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_ple-test_ple.Po diff --git a/m4ri-20140914/testsuite/.deps/test_random-test_random.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_random-test_random.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_random-test_random.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_random-test_random.Po diff --git a/m4ri-20140914/testsuite/.deps/test_smallops-test_smallops.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_smallops-test_smallops.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_smallops-test_smallops.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_smallops-test_smallops.Po diff --git a/m4ri-20140914/testsuite/.deps/test_smallops-testing.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_smallops-testing.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_smallops-testing.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_smallops-testing.Po diff --git a/m4ri-20140914/testsuite/.deps/test_solve-test_solve.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_solve-test_solve.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_solve-test_solve.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_solve-test_solve.Po diff --git a/m4ri-20140914/testsuite/.deps/test_transpose-test_transpose.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_transpose-test_transpose.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_transpose-test_transpose.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_transpose-test_transpose.Po diff --git a/m4ri-20140914/testsuite/.deps/test_trsm-test_trsm.Po b/mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_trsm-test_trsm.Po similarity index 100% rename from m4ri-20140914/testsuite/.deps/test_trsm-test_trsm.Po rename to mapleCOMSPS/m4ri-20140914/testsuite/.deps/test_trsm-test_trsm.Po diff --git a/m4ri-20140914/testsuite/Makefile b/mapleCOMSPS/m4ri-20140914/testsuite/Makefile similarity index 100% rename from m4ri-20140914/testsuite/Makefile rename to mapleCOMSPS/m4ri-20140914/testsuite/Makefile diff --git a/m4ri-20140914/testsuite/Makefile.in b/mapleCOMSPS/m4ri-20140914/testsuite/Makefile.in similarity index 100% rename from m4ri-20140914/testsuite/Makefile.in rename to mapleCOMSPS/m4ri-20140914/testsuite/Makefile.in diff --git a/m4ri-20140914/testsuite/test_colswap.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_colswap.c similarity index 100% rename from m4ri-20140914/testsuite/test_colswap.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_colswap.c diff --git a/m4ri-20140914/testsuite/test_elimination.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_elimination.c similarity index 100% rename from m4ri-20140914/testsuite/test_elimination.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_elimination.c diff --git a/m4ri-20140914/testsuite/test_invert.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_invert.c similarity index 100% rename from m4ri-20140914/testsuite/test_invert.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_invert.c diff --git a/m4ri-20140914/testsuite/test_kernel.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_kernel.c similarity index 100% rename from m4ri-20140914/testsuite/test_kernel.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_kernel.c diff --git a/m4ri-20140914/testsuite/test_misc.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_misc.c similarity index 100% rename from m4ri-20140914/testsuite/test_misc.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_misc.c diff --git a/m4ri-20140914/testsuite/test_multiplication.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_multiplication.c similarity index 100% rename from m4ri-20140914/testsuite/test_multiplication.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_multiplication.c diff --git a/m4ri-20140914/testsuite/test_ple.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_ple.c similarity index 100% rename from m4ri-20140914/testsuite/test_ple.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_ple.c diff --git a/m4ri-20140914/testsuite/test_random.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_random.c similarity index 100% rename from m4ri-20140914/testsuite/test_random.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_random.c diff --git a/m4ri-20140914/testsuite/test_smallops.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_smallops.c similarity index 100% rename from m4ri-20140914/testsuite/test_smallops.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_smallops.c diff --git a/m4ri-20140914/testsuite/test_solve.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_solve.c similarity index 100% rename from m4ri-20140914/testsuite/test_solve.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_solve.c diff --git a/m4ri-20140914/testsuite/test_transpose.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_transpose.c similarity index 100% rename from m4ri-20140914/testsuite/test_transpose.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_transpose.c diff --git a/m4ri-20140914/testsuite/test_trsm.c b/mapleCOMSPS/m4ri-20140914/testsuite/test_trsm.c similarity index 100% rename from m4ri-20140914/testsuite/test_trsm.c rename to mapleCOMSPS/m4ri-20140914/testsuite/test_trsm.c diff --git a/m4ri-20140914/testsuite/testing.c b/mapleCOMSPS/m4ri-20140914/testsuite/testing.c similarity index 100% rename from m4ri-20140914/testsuite/testing.c rename to mapleCOMSPS/m4ri-20140914/testsuite/testing.c diff --git a/m4ri-20140914/testsuite/testing.h b/mapleCOMSPS/m4ri-20140914/testsuite/testing.h similarity index 100% rename from m4ri-20140914/testsuite/testing.h rename to mapleCOMSPS/m4ri-20140914/testsuite/testing.h diff --git a/mapleCOMSPS/mapleCOMSPS/LICENSE b/mapleCOMSPS/mapleCOMSPS/LICENSE new file mode 100644 index 0000000..9ecdbc9 --- /dev/null +++ b/mapleCOMSPS/mapleCOMSPS/LICENSE @@ -0,0 +1,23 @@ +MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson + Copyright (c) 2007-2010 Niklas Sorensson + +Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/mapleCOMSPS/mapleCOMSPS/README b/mapleCOMSPS/mapleCOMSPS/README new file mode 100644 index 0000000..e5e5617 --- /dev/null +++ b/mapleCOMSPS/mapleCOMSPS/README @@ -0,0 +1,24 @@ +================================================================================ +DIRECTORY OVERVIEW: + +mtl/ Mini Template Library +utils/ Generic helper code (I/O, Parsing, CPU-time, etc) +core/ A core version of the solver +simp/ An extended solver with simplification capabilities +README +LICENSE + +================================================================================ +BUILDING: (release version: without assertions, statically linked, etc) + +export MROOT= (or setenv in cshell) +cd { core | simp } +gmake rs +cp minisat_static /minisat + +================================================================================ +EXAMPLES: + +Run minisat with same heuristics as version 2.0: + +> minisat -no-luby -rinc=1.5 -phase-saving=0 -rnd-freq=0.02 diff --git a/lstech_maple/lstech/core/Dimacs.h b/mapleCOMSPS/mapleCOMSPS/core/Dimacs.h old mode 100755 new mode 100644 similarity index 57% rename from lstech_maple/lstech/core/Dimacs.h rename to mapleCOMSPS/mapleCOMSPS/core/Dimacs.h index 9550e04..acae3de --- a/lstech_maple/lstech/core/Dimacs.h +++ b/mapleCOMSPS/mapleCOMSPS/core/Dimacs.h @@ -18,15 +18,15 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Dimacs_h -#define Minisat_Dimacs_h +#ifndef MapleCOMSPS_Dimacs_h +#define MapleCOMSPS_Dimacs_h #include -#include "utils/ParseUtils.h" -#include "core/SolverTypes.h" +#include "../utils/ParseUtils.h" +#include "../core/SolverTypes.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // DIMACS Parser: @@ -83,75 +83,7 @@ static void parse_DIMACS(gzFile input_stream, Solver& S) { StreamBuffer in(input_stream); parse_DIMACS_main(in, S); } -//================================================================================================= - -template -static void simple_readClause(B& in, Solver& S, vec& lits) { - int parsed_lit, var; - lits.clear(); - for (;;){ - parsed_lit = parseInt(in); - if (parsed_lit == 0) break; - var = abs(parsed_lit)-1; - lits.push( (parsed_lit > 0) ? mkLit(var) : ~mkLit(var) ); - } -} - -template -static void check_solution_DIMACS_main(B& in, Solver& S) { - vec lits; - int vars = 0; - int clauses = 0; - int cnt = 0; - bool ok=true; - for (;;){ - skipWhitespace(in); - if (*in == EOF) break; - else if (*in == 'p'){ - if (eagerMatch(in, "p cnf")){ - vars = parseInt(in); - clauses = parseInt(in); - // SATRACE'06 hack - // if (clauses > 4000000) - // S.eliminate(true); - }else{ - printf("c PARSE ERROR! Unexpected char: %c\n", *in), exit(3); - } - } else if (*in == 'c' || *in == 'p') - skipLine(in); - else{ - cnt++; - int parsed_lit, var; - bool ok=false; - for(;;) { - parsed_lit = parseInt(in); - if (parsed_lit == 0) break; //{printf("\n"); break;} - var = abs(parsed_lit)-1; - // printf("%d ", parsed_lit); - if ((parsed_lit>0 && S.model[var]==l_True) || - (parsed_lit<0 && S.model[var]==l_False)) - ok=true; - } - if (!ok) { - printf("c clause %d is not satisfied\n", cnt); - ok=false; - // break; - } - } - } - if (cnt != clauses) - printf("c WARNING! DIMACS header mismatch: wrong number of clauses.%d %d\n", cnt, clauses); - else if (ok) - printf("c solution checked against the original DIMACS file\n"); -} - -template -static void check_solution_DIMACS(gzFile input_stream, Solver& S) { - StreamBuffer in(input_stream); - check_solution_DIMACS_main(in, S); } - //================================================================================================= } #endif - diff --git a/lstech_maple/lstech/core/Main.cc b/mapleCOMSPS/mapleCOMSPS/core/Main.cc old mode 100755 new mode 100644 similarity index 89% rename from lstech_maple/lstech/core/Main.cc rename to mapleCOMSPS/mapleCOMSPS/core/Main.cc index bfa0007..6fa2f85 --- a/lstech_maple/lstech/core/Main.cc +++ b/mapleCOMSPS/mapleCOMSPS/core/Main.cc @@ -1,14 +1,8 @@ -/***************************************************************************************[Solver.cc] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - Copyright (c) 2007-2010, Niklas Sorensson - +/*****************************************************************************************[Main.cc] +Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson +Copyright (c) 2007-2010, Niklas Sorensson + Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh - -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. - -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -31,13 +25,13 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA #include #include -#include "utils/System.h" -#include "utils/ParseUtils.h" -#include "utils/Options.h" -#include "core/Dimacs.h" -#include "core/Solver.h" +#include "../utils/System.h" +#include "../utils/ParseUtils.h" +#include "../utils/Options.h" +#include "../core/Dimacs.h" +#include "../core/Solver.h" -using namespace Minisat; +using namespace MapleCOMSPS; //================================================================================================= @@ -150,12 +144,12 @@ int main(int argc, char** argv) if (S.verbosity > 0){ printf("c | Parse time: %12.2f s |\n", parsed_time - initial_time); printf("c | |\n"); } - + // Change to signal-handlers that will only notify the solver and allow it to terminate // voluntarily: signal(SIGINT, SIGINT_interrupt); signal(SIGXCPU,SIGINT_interrupt); - + if (!S.simplify()){ if (res != NULL) fprintf(res, "UNSAT\n"), fclose(res); if (S.verbosity > 0){ @@ -171,11 +165,6 @@ int main(int argc, char** argv) lbool ret = S.solveLimited(dummy); if (S.verbosity > 0){ printStats(S); - if (ret == l_True) { - in = (argc == 1) ? gzdopen(0, "rb") : gzopen(argv[1], "rb"); - // check_solution_DIMACS(in, S); - gzclose(in); - } printf("\n"); } printf(ret == l_True ? "s SATISFIABLE\n" : ret == l_False ? "s UNSATISFIABLE\n" : "s UNKNOWN\n"); if (ret == l_True){ @@ -186,7 +175,6 @@ int main(int argc, char** argv) printf(" 0\n"); } - if (res != NULL){ if (ret == l_True){ fprintf(res, "SAT\n"); diff --git a/lstech_maple/lstech/core/Makefile b/mapleCOMSPS/mapleCOMSPS/core/Makefile old mode 100755 new mode 100644 similarity index 61% rename from lstech_maple/lstech/core/Makefile rename to mapleCOMSPS/mapleCOMSPS/core/Makefile index c724f55..5de1f72 --- a/lstech_maple/lstech/core/Makefile +++ b/mapleCOMSPS/mapleCOMSPS/core/Makefile @@ -1,5 +1,4 @@ -EXEC = glucose +EXEC = minisat DEPDIR = mtl utils -MROOT = .. include $(MROOT)/mtl/template.mk diff --git a/mapleCOMSPS/mapleCOMSPS/core/Solver.cc b/mapleCOMSPS/mapleCOMSPS/core/Solver.cc new file mode 100644 index 0000000..b54f15e --- /dev/null +++ b/mapleCOMSPS/mapleCOMSPS/core/Solver.cc @@ -0,0 +1,1743 @@ +/***************************************************************************************[Solver.cc] +MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson + Copyright (c) 2007-2010, Niklas Sorensson + +Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +**************************************************************************************************/ + +#include + +#include "../mtl/Sort.h" +#include "../core/Solver.h" + +using namespace MapleCOMSPS; + +#ifdef BIN_DRUP +int Solver::buf_len = 0; +unsigned char Solver::drup_buf[2 * 1024 * 1024]; +unsigned char* Solver::buf_ptr = drup_buf; +#endif + +//================================================================================================= +// Options: + + +static const char* _cat = "CORE"; + +static DoubleOption opt_step_size (_cat, "step-size", "Initial step size", 0.40, DoubleRange(0, false, 1, false)); +static DoubleOption opt_step_size_dec (_cat, "step-size-dec","Step size decrement", 0.000001, DoubleRange(0, false, 1, false)); +static DoubleOption opt_min_step_size (_cat, "min-step-size","Minimal step size", 0.06, DoubleRange(0, false, 1, false)); +static DoubleOption opt_var_decay (_cat, "var-decay", "The variable activity decay factor", 0.80, DoubleRange(0, false, 1, false)); +static DoubleOption opt_clause_decay (_cat, "cla-decay", "The clause activity decay factor", 0.999, DoubleRange(0, false, 1, false)); +static DoubleOption opt_random_var_freq (_cat, "rnd-freq", "The frequency with which the decision heuristic tries to choose a random variable", 0, DoubleRange(0, true, 1, true)); +static DoubleOption opt_random_seed (_cat, "rnd-seed", "Used by the random variable selection", 91648253, DoubleRange(0, false, HUGE_VAL, false)); +static IntOption opt_ccmin_mode (_cat, "ccmin-mode", "Controls conflict clause minimization (0=none, 1=basic, 2=deep)", 2, IntRange(0, 2)); +static IntOption opt_phase_saving (_cat, "phase-saving", "Controls the level of phase saving (0=none, 1=limited, 2=full)", 2, IntRange(0, 2)); +static BoolOption opt_rnd_init_act (_cat, "rnd-init", "Randomize the initial activity", false); +static IntOption opt_restart_first (_cat, "rfirst", "The base restart interval", 100, IntRange(1, INT32_MAX)); +static DoubleOption opt_restart_inc (_cat, "rinc", "Restart interval increase factor", 2, DoubleRange(1, false, HUGE_VAL, false)); +static DoubleOption opt_garbage_frac (_cat, "gc-frac", "The fraction of wasted memory allowed before a garbage collection is triggered", 0.20, DoubleRange(0, false, HUGE_VAL, false)); + + +//================================================================================================= +// Constructor/Destructor: + + +Solver::Solver() : + + // Parameters (user settable): + // + + drup_file (NULL) + , verbosity (0) + , step_size (opt_step_size) + , step_size_dec (opt_step_size_dec) + , min_step_size (opt_min_step_size) + , timer (5000) + , var_decay (opt_var_decay) + , clause_decay (opt_clause_decay) + , random_var_freq (opt_random_var_freq) + , random_seed (opt_random_seed) + , VSIDS (false) + , verso (true) + , ccmin_mode (opt_ccmin_mode) + , phase_saving (opt_phase_saving) + , rnd_pol (false) + , rnd_init_act (opt_rnd_init_act) + , garbage_frac (opt_garbage_frac) + , restart_first (opt_restart_first) + , restart_inc (opt_restart_inc) + + // Parameters (the rest): + // + , learntsize_factor((double)1/(double)3), learntsize_inc(1.1) + + // Parameters (experimental): + // + , learntsize_adjust_start_confl (100) + , learntsize_adjust_inc (1.5) + + // Statistics: (formerly in 'SolverStats') + // + , solves(0), starts(0), decisions(0), rnd_decisions(0), propagations(0), conflicts(0), conflicts_VSIDS(0) + , dec_vars(0), clauses_literals(0), learnts_literals(0), max_literals(0), tot_literals(0) + + , ok (true) + , cla_inc (1) + , var_inc (1) + , watches_bin (WatcherDeleted(ca)) + , watches (WatcherDeleted(ca)) + , qhead (0) + , simpDB_assigns (-1) + , simpDB_props (0) + , order_heap_CHB (VarOrderLt(activity_CHB, verso)) + , order_heap_VSIDS (VarOrderLt(activity_VSIDS, verso)) + , progress_estimate (0) + , remove_satisfied (true) + + , core_lbd_cut (3) + , global_lbd_sum (0) + , lbd_queue (50) + , next_T2_reduce (10000) + , next_L_reduce (15000) + + , counter (0) + + // Resource constraints: + // + , conflict_budget (-1) + , propagation_budget (-1) + , asynch_interrupt (false) +{} + +Solver::Solver(const Solver &s) : + // Parameters (user settable): + // + drup_file (s.drup_file) + , verbosity (s.verbosity) + , step_size (s.step_size) + , step_size_dec (s.step_size_dec) + , min_step_size (s.min_step_size) + , timer (s.timer) + , var_decay (s.var_decay) + , clause_decay (s.clause_decay) + , random_var_freq (s.random_var_freq) + , random_seed (s.random_seed) + , VSIDS (s.VSIDS) + , verso (s.verso) + , ccmin_mode (s.ccmin_mode) + , phase_saving (s.phase_saving) + , rnd_pol (s.rnd_pol) + , rnd_init_act (s.rnd_init_act) + , garbage_frac (s.garbage_frac) + , restart_first (s.restart_first) + , restart_inc (s.restart_inc) + , learntsize_factor(s.learntsize_factor) + + , learntsize_adjust_start_confl(s.learntsize_adjust_start_confl) + , learntsize_adjust_inc(s.learntsize_adjust_inc) + + // Statistics: (formerly in 'SolverStats') + // + , solves(s.solves), starts(s.starts), decisions(s.decisions), rnd_decisions(s.rnd_decisions) + , propagations(s.propagations), conflicts(s.conflicts), conflicts_VSIDS (s.conflicts_VSIDS) + , dec_vars(s.dec_vars), clauses_literals(s.clauses_literals) + , learnts_literals(s.learnts_literals), max_literals(s.max_literals), tot_literals(s.tot_literals) + + , ok(true) + , cla_inc(s.cla_inc) + , var_inc(s.var_inc) + , watches_bin(WatcherDeleted(ca)) + , watches(WatcherDeleted(ca)) + , qhead(s.qhead) + , simpDB_assigns(s.simpDB_assigns) + , simpDB_props(s.simpDB_props) + , order_heap_CHB(VarOrderLt(activity_CHB, verso)) + , order_heap_VSIDS(VarOrderLt(activity_VSIDS, verso)) + , progress_estimate(s.progress_estimate) + , remove_satisfied(s.remove_satisfied) + + , core_lbd_cut (s.core_lbd_cut) + , global_lbd_sum (s.global_lbd_sum) + , lbd_queue (s.lbd_queue) + , next_T2_reduce (s.next_T2_reduce) + , next_L_reduce (s.next_L_reduce) + + , counter (s.counter) + + // Resource constraints: + // + , conflict_budget (s.conflict_budget) + , propagation_budget (s.propagation_budget) + , asynch_interrupt (s.asynch_interrupt) + +{ + // Copy clauses. + s.ca.copyTo(ca); + ca.extra_clause_field = s.ca.extra_clause_field; + + // Copy all search vectors + s.watches.copyTo(watches); + s.watches_bin.copyTo(watches_bin); + s.assigns.memCopyTo(assigns); + s.vardata.memCopyTo(vardata); + s.activity_CHB.memCopyTo(activity_CHB); + s.activity_VSIDS.memCopyTo(activity_VSIDS); + s.seen.memCopyTo(seen); + s.analyze_stack.memCopyTo(analyze_stack); + s.analyze_toclear.memCopyTo(analyze_toclear); + s.seen2.memCopyTo(seen2); + s.add_tmp.memCopyTo(add_tmp); + s.add_oc.memCopyTo(add_oc); + s.polarity.memCopyTo(polarity); + s.decision.memCopyTo(decision); + s.trail.memCopyTo(trail); + s.trail_lim.memCopyTo(trail_lim); + s.order_heap_CHB.copyTo(order_heap_CHB); + s.order_heap_VSIDS.copyTo(order_heap_VSIDS); + s.clauses.memCopyTo(clauses); + s.learnts_core.memCopyTo(learnts_core); + s.learnts_tier2.memCopyTo(learnts_tier2); + s.learnts_local.memCopyTo(learnts_local); + s.picked.memCopyTo(picked); + s.conflicted.memCopyTo(conflicted); + s.almost_conflicted.memCopyTo(almost_conflicted); + s.discovered.memCopyTo(discovered); + s.finished.memCopyTo(finished); + s.observed.memCopyTo(observed); + s.flag.memCopyTo(flag); + s.root.memCopyTo(root); + s.parent.memCopyTo(parent); + s.rec_stack.memCopyTo(rec_stack); + s.scc.memCopyTo(scc); +#ifdef ANTI_EXPLORATION + s.canceled.memCopyTo(canceled); +#endif +} + +Solver::~Solver() +{ +} + + +//================================================================================================= +// Minor methods: + + +// Creates a new SAT variable in the solver. If 'decision' is cleared, variable will not be +// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result). +// +Var Solver::newVar(bool sign, bool dvar) +{ + int v = nVars(); + watches_bin.init(mkLit(v, false)); + watches_bin.init(mkLit(v, true )); + watches .init(mkLit(v, false)); + watches .init(mkLit(v, true )); + assigns .push(l_Undef); + vardata .push(mkVarData(CRef_Undef, 0)); + activity_CHB .push(0); + activity_VSIDS.push(rnd_init_act ? drand(random_seed) * 0.00001 : 0); + + picked.push(0); + conflicted.push(0); + almost_conflicted.push(0); + + seen .push(0); + seen2 .push(0); + polarity .push(sign); + decision .push(); + trail .capacity(v+1); + setDecisionVar(v, dvar); + + // Additional space needed for stamping. + // TODO: allocate exact memory. + seen .push(0); + discovered.push(0); discovered.push(0); + finished .push(0); finished .push(0); + observed .push(0); observed .push(0); + flag .push(0); flag .push(0); + root .push(lit_Undef); root .push(lit_Undef); + parent .push(lit_Undef); parent .push(lit_Undef); + return v; +} + + +bool Solver::addClause_(vec& ps) +{ + assert(decisionLevel() == 0); + if (!ok) return false; + + // Check if clause is satisfied and remove false/duplicate literals: + sort(ps); + Lit p; int i, j; + + if (drup_file){ + add_oc.clear(); + for (int i = 0; i < ps.size(); i++) add_oc.push(ps[i]); } + + for (i = j = 0, p = lit_Undef; i < ps.size(); i++) + if (value(ps[i]) == l_True || ps[i] == ~p) + return true; + else if (value(ps[i]) != l_False && ps[i] != p) + ps[j++] = p = ps[i]; + ps.shrink(i - j); + + if (drup_file && i != j){ +#ifdef BIN_DRUP + binDRUP('a', ps, drup_file); + binDRUP('d', add_oc, drup_file); +#else + for (int i = 0; i < ps.size(); i++) + fprintf(drup_file, "%i ", (var(ps[i]) + 1) * (-2 * sign(ps[i]) + 1)); + fprintf(drup_file, "0\n"); + + fprintf(drup_file, "d "); + for (int i = 0; i < add_oc.size(); i++) + fprintf(drup_file, "%i ", (var(add_oc[i]) + 1) * (-2 * sign(add_oc[i]) + 1)); + fprintf(drup_file, "0\n"); +#endif + } + + if (ps.size() == 0) + return ok = false; + else if (ps.size() == 1){ + uncheckedEnqueue(ps[0]); + return ok = (propagate() == CRef_Undef); + }else{ + CRef cr = ca.alloc(ps, false); + clauses.push(cr); + attachClause(cr); + } + + return true; +} + +bool Solver::importClauses() { + assert(decisionLevel() == 0); + + if (cbkImportClause == NULL) + return true; + int lbd, k, l; + bool alreadySat; + while (cbkImportClause(issuer, &lbd, importedClause)) { + alreadySat = false; + // Simplify clause before add + for (k = l = 0; k < importedClause.size(); k++) { + if (value(importedClause[k]) == l_True) { + alreadySat = true; + break; + } else if (value(importedClause[k]) == l_Undef) { + importedClause[l++] = importedClause[k]; + } + } + importedClause.shrink(k - l); + + if (alreadySat) { + importedClause.clear(); + continue; + } + + if (importedClause.size() == 0) { + return false; + } else if (importedClause.size() == 1) { + uncheckedEnqueue(importedClause[0]); + } else { + CRef cr = ca.alloc(importedClause, true); + lbd = importedClause.size(); + ca[cr].set_lbd(lbd); + if (lbd <= core_lbd_cut) { + learnts_core.push(cr); + ca[cr].mark(CORE); + } else if (lbd <= 6) { + learnts_tier2.push(cr); + ca[cr].mark(TIER2); + ca[cr].touched() = conflicts; + } else { + learnts_local.push(cr); + claBumpActivity(ca[cr]); + } + attachClause(cr); + } + importedClause.clear(); + } + + return true; +} + + +void Solver::attachClause(CRef cr) { + const Clause& c = ca[cr]; + assert(c.size() > 1); + OccLists, WatcherDeleted>& ws = c.size() == 2 ? watches_bin : watches; + ws[~c[0]].push(Watcher(cr, c[1])); + ws[~c[1]].push(Watcher(cr, c[0])); + if (c.learnt()) learnts_literals += c.size(); + else clauses_literals += c.size(); } + + +void Solver::detachClause(CRef cr, bool strict) { + const Clause& c = ca[cr]; + assert(c.size() > 1); + OccLists, WatcherDeleted>& ws = c.size() == 2 ? watches_bin : watches; + + if (strict){ + remove(ws[~c[0]], Watcher(cr, c[1])); + remove(ws[~c[1]], Watcher(cr, c[0])); + }else{ + // Lazy detaching: (NOTE! Must clean all watcher lists before garbage collecting this clause) + ws.smudge(~c[0]); + ws.smudge(~c[1]); + } + + if (c.learnt()) learnts_literals -= c.size(); + else clauses_literals -= c.size(); } + + +void Solver::removeClause(CRef cr) { + Clause& c = ca[cr]; + + if (drup_file){ + if (c.mark() != 1){ +#ifdef BIN_DRUP + binDRUP('d', c, drup_file); +#else + fprintf(drup_file, "d "); + for (int i = 0; i < c.size(); i++) + fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1)); + fprintf(drup_file, "0\n"); +#endif + }else + printf("c Bug: removeClause(). I don't expect this to happen.\n"); + } + + detachClause(cr); + // Don't leave pointers to free'd memory! + if (locked(c)){ + Lit implied = c.size() != 2 ? c[0] : (value(c[0]) == l_True ? c[0] : c[1]); + vardata[var(implied)].reason = CRef_Undef; } + c.mark(1); + ca.free(cr); +} + + +bool Solver::satisfied(const Clause& c) const { + for (int i = 0; i < c.size(); i++) + if (value(c[i]) == l_True) + return true; + return false; } + + +// Revert to the state at given level (keeping all assignment at 'level' but not beyond). +// +void Solver::cancelUntil(int level) { + if (decisionLevel() > level){ + for (int c = trail.size()-1; c >= trail_lim[level]; c--){ + Var x = var(trail[c]); + + if (!VSIDS){ + uint32_t age = conflicts - picked[x]; + if (age > 0){ + double adjusted_reward = ((double) (conflicted[x] + almost_conflicted[x])) / ((double) age); + double old_activity = activity_CHB[x]; + activity_CHB[x] = step_size * adjusted_reward + ((1 - step_size) * old_activity); + if (order_heap_CHB.inHeap(x)){ + if (activity_CHB[x] > old_activity) + order_heap_CHB.decrease(x); + else + order_heap_CHB.increase(x); + } + } + } + + assigns [x] = l_Undef; + + if (phase_saving > 1 || (phase_saving == 1) && c > trail_lim.last()) + polarity[x] = sign(trail[c]); + insertVarOrder(x); } + qhead = trail_lim[level]; + trail.shrink(trail.size() - trail_lim[level]); + trail_lim.shrink(trail_lim.size() - level); + } } + + +//================================================================================================= +// Major methods: + + +Lit Solver::pickBranchLit() +{ + Var next = var_Undef; + Heap& order_heap = VSIDS ? order_heap_VSIDS : order_heap_CHB; + + // Random decision: + /*if (drand(random_seed) < random_var_freq && !order_heap.empty()){ + next = order_heap[irand(random_seed,order_heap.size())]; + if (value(next) == l_Undef && decision[next]) + rnd_decisions++; }*/ + + // Activity based decision: + while (next == var_Undef || value(next) != l_Undef || !decision[next]) + if (order_heap.empty()) + return lit_Undef; + else + next = order_heap.removeMin(); + + return mkLit(next, polarity[next]); +} + + +/*_________________________________________________________________________________________________ +| +| analyze : (confl : Clause*) (out_learnt : vec&) (out_btlevel : int&) -> [void] +| +| Description: +| Analyze conflict and produce a reason clause. +| +| Pre-conditions: +| * 'out_learnt' is assumed to be cleared. +| * Current decision level must be greater than root level. +| +| Post-conditions: +| * 'out_learnt[0]' is the asserting literal at level 'out_btlevel'. +| * If out_learnt.size() > 1 then 'out_learnt[1]' has the greatest decision level of the +| rest of literals. There may be others from the same level though. +| +|________________________________________________________________________________________________@*/ +void Solver::analyze(CRef confl, vec& out_learnt, int& out_btlevel, int& out_lbd) +{ + int pathC = 0; + Lit p = lit_Undef; + + // Generate conflict clause: + // + out_learnt.push(); // (leave room for the asserting literal) + int index = trail.size() - 1; + + do{ + assert(confl != CRef_Undef); // (otherwise should be UIP) + Clause& c = ca[confl]; + + // For binary clauses, we don't rearrange literals in propagate(), so check and make sure the first is an implied lit. + if (p != lit_Undef && c.size() == 2 && value(c[0]) == l_False){ + assert(value(c[1]) == l_True); + Lit tmp = c[0]; + c[0] = c[1], c[1] = tmp; } + + // Update LBD if improved. + if (c.learnt() && c.mark() != CORE){ + int lbd = computeLBD(c); + if (lbd < c.lbd()){ + if (c.lbd() <= 30) c.removable(false); // Protect once from reduction. + c.set_lbd(lbd); + if (lbd <= core_lbd_cut){ + learnts_core.push(confl); + c.mark(CORE); + }else if (lbd <= 6 && c.mark() == LOCAL){ + // Bug: 'cr' may already be in 'learnts_tier2', e.g., if 'cr' was demoted from TIER2 + // to LOCAL previously and if that 'cr' is not cleaned from 'learnts_tier2' yet. + learnts_tier2.push(confl); + c.mark(TIER2); } + } + + if (c.mark() == TIER2) + c.touched() = conflicts; + else if (c.mark() == LOCAL) + claBumpActivity(c); + } + + for (int j = (p == lit_Undef) ? 0 : 1; j < c.size(); j++){ + Lit q = c[j]; + + if (!seen[var(q)] && level(var(q)) > 0){ + if (VSIDS){ + varBumpActivity(var(q), .5); + add_tmp.push(q); + }else + conflicted[var(q)]++; + seen[var(q)] = 1; + if (level(var(q)) >= decisionLevel()){ + pathC++; + }else + out_learnt.push(q); + } + } + + // Select next clause to look at: + while (!seen[var(trail[index--])]); + p = trail[index+1]; + confl = reason(var(p)); + seen[var(p)] = 0; + pathC--; + + }while (pathC > 0); + out_learnt[0] = ~p; + + // Simplify conflict clause: + // + int i, j; + out_learnt.copyTo(analyze_toclear); + if (ccmin_mode == 2){ + uint32_t abstract_level = 0; + for (i = 1; i < out_learnt.size(); i++) + abstract_level |= abstractLevel(var(out_learnt[i])); // (maintain an abstraction of levels involved in conflict) + + for (i = j = 1; i < out_learnt.size(); i++) + if (reason(var(out_learnt[i])) == CRef_Undef || !litRedundant(out_learnt[i], abstract_level)) + out_learnt[j++] = out_learnt[i]; + + }else if (ccmin_mode == 1){ + for (i = j = 1; i < out_learnt.size(); i++){ + Var x = var(out_learnt[i]); + + if (reason(x) == CRef_Undef) + out_learnt[j++] = out_learnt[i]; + else{ + Clause& c = ca[reason(var(out_learnt[i]))]; + for (int k = c.size() == 2 ? 0 : 1; k < c.size(); k++) + if (!seen[var(c[k])] && level(var(c[k])) > 0){ + out_learnt[j++] = out_learnt[i]; + break; } + } + } + }else + i = j = out_learnt.size(); + + max_literals += out_learnt.size(); + out_learnt.shrink(i - j); + tot_literals += out_learnt.size(); + + out_lbd = computeLBD(out_learnt); + if (out_lbd <= 6 && out_learnt.size() <= 30) // Try further minimization? + if (binResMinimize(out_learnt)) + out_lbd = computeLBD(out_learnt); // Recompute LBD if minimized. + + // Find correct backtrack level: + // + if (out_learnt.size() == 1) + out_btlevel = 0; + else{ + int max_i = 1; + // Find the first literal assigned at the next-highest level: + for (int i = 2; i < out_learnt.size(); i++) + if (level(var(out_learnt[i])) > level(var(out_learnt[max_i]))) + max_i = i; + // Swap-in this literal at index 1: + Lit p = out_learnt[max_i]; + out_learnt[max_i] = out_learnt[1]; + out_learnt[1] = p; + out_btlevel = level(var(p)); + } + + if (VSIDS){ + for (int i = 0; i < add_tmp.size(); i++){ + Var v = var(add_tmp[i]); + if (level(v) >= out_btlevel - 1) + varBumpActivity(v, 1); + } + add_tmp.clear(); + }else{ + seen[var(p)] = true; + for(int i = out_learnt.size() - 1; i >= 0; i--){ + Var v = var(out_learnt[i]); + CRef rea = reason(v); + if (rea != CRef_Undef){ + const Clause& reaC = ca[rea]; + for (int i = 0; i < reaC.size(); i++){ + Lit l = reaC[i]; + if (!seen[var(l)]){ + seen[var(l)] = true; + almost_conflicted[var(l)]++; + analyze_toclear.push(l); } } } } } + + for (int j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0; // ('seen[]' is now cleared) +} + + +// Try further learnt clause minimization by means of binary clause resolution. +bool Solver::binResMinimize(vec& out_learnt) +{ + // Preparation: remember which false variables we have in 'out_learnt'. + counter++; + for (int i = 1; i < out_learnt.size(); i++) + seen2[var(out_learnt[i])] = counter; + + // Get the list of binary clauses containing 'out_learnt[0]'. + const vec& ws = watches_bin[~out_learnt[0]]; + + int to_remove = 0; + for (int i = 0; i < ws.size(); i++){ + Lit the_other = ws[i].blocker; + // Does 'the_other' appear negatively in 'out_learnt'? + if (seen2[var(the_other)] == counter && value(the_other) == l_True){ + to_remove++; + seen2[var(the_other)] = counter - 1; // Remember to remove this variable. + } + } + + // Shrink. + if (to_remove > 0){ + int last = out_learnt.size() - 1; + for (int i = 1; i < out_learnt.size() - to_remove; i++) + if (seen2[var(out_learnt[i])] != counter) + out_learnt[i--] = out_learnt[last--]; + out_learnt.shrink(to_remove); + } + return to_remove != 0; +} + + +// Check if 'p' can be removed. 'abstract_levels' is used to abort early if the algorithm is +// visiting literals at levels that cannot be removed later. +bool Solver::litRedundant(Lit p, uint32_t abstract_levels) +{ + analyze_stack.clear(); analyze_stack.push(p); + int top = analyze_toclear.size(); + while (analyze_stack.size() > 0){ + assert(reason(var(analyze_stack.last())) != CRef_Undef); + Clause& c = ca[reason(var(analyze_stack.last()))]; analyze_stack.pop(); + + // Special handling for binary clauses like in 'analyze()'. + if (c.size() == 2 && value(c[0]) == l_False){ + assert(value(c[1]) == l_True); + Lit tmp = c[0]; + c[0] = c[1], c[1] = tmp; } + + for (int i = 1; i < c.size(); i++){ + Lit p = c[i]; + if (!seen[var(p)] && level(var(p)) > 0){ + if (reason(var(p)) != CRef_Undef && (abstractLevel(var(p)) & abstract_levels) != 0){ + seen[var(p)] = 1; + analyze_stack.push(p); + analyze_toclear.push(p); + }else{ + for (int j = top; j < analyze_toclear.size(); j++) + seen[var(analyze_toclear[j])] = 0; + analyze_toclear.shrink(analyze_toclear.size() - top); + return false; + } + } + } + } + + return true; +} + + +/*_________________________________________________________________________________________________ +| +| analyzeFinal : (p : Lit) -> [void] +| +| Description: +| Specialized analysis procedure to express the final conflict in terms of assumptions. +| Calculates the (possibly empty) set of assumptions that led to the assignment of 'p', and +| stores the result in 'out_conflict'. +|________________________________________________________________________________________________@*/ +void Solver::analyzeFinal(Lit p, vec& out_conflict) +{ + out_conflict.clear(); + out_conflict.push(p); + + if (decisionLevel() == 0) + return; + + seen[var(p)] = 1; + + for (int i = trail.size()-1; i >= trail_lim[0]; i--){ + Var x = var(trail[i]); + if (seen[x]){ + if (reason(x) == CRef_Undef){ + assert(level(x) > 0); + out_conflict.push(~trail[i]); + }else{ + Clause& c = ca[reason(x)]; + for (int j = c.size() == 2 ? 0 : 1; j < c.size(); j++) + if (level(var(c[j])) > 0) + seen[var(c[j])] = 1; + } + seen[x] = 0; + } + } + + seen[var(p)] = 0; +} + + +void Solver::uncheckedEnqueue(Lit p, CRef from) +{ + assert(value(p) == l_Undef); + Var x = var(p); + if (!VSIDS){ + picked[x] = conflicts; + conflicted[x] = 0; + almost_conflicted[x] = 0; + } + + assigns[x] = lbool(!sign(p)); + vardata[x] = mkVarData(from, decisionLevel()); + trail.push_(p); +} + + +/*_________________________________________________________________________________________________ +| +| propagate : [void] -> [Clause*] +| +| Description: +| Propagates all enqueued facts. If a conflict arises, the conflicting clause is returned, +| otherwise CRef_Undef. +| +| Post-conditions: +| * the propagation queue is empty, even if there was a conflict. +|________________________________________________________________________________________________@*/ +CRef Solver::propagate() +{ + CRef confl = CRef_Undef; + int num_props = 0; + watches.cleanAll(); + watches_bin.cleanAll(); + + while (qhead < trail.size()){ + Lit p = trail[qhead++]; // 'p' is enqueued fact to propagate. + vec& ws = watches[p]; + Watcher *i, *j, *end; + num_props++; + + vec& ws_bin = watches_bin[p]; // Propagate binary clauses first. + for (int k = 0; k < ws_bin.size(); k++){ + Lit the_other = ws_bin[k].blocker; + if (value(the_other) == l_False){ + confl = ws_bin[k].cref; +#ifdef LOOSE_PROP_STAT + return confl; +#else + goto ExitProp; +#endif + }else if(value(the_other) == l_Undef) + uncheckedEnqueue(the_other, ws_bin[k].cref); + } + + for (i = j = (Watcher*)ws, end = i + ws.size(); i != end;){ + // Try to avoid inspecting the clause: + Lit blocker = i->blocker; + if (value(blocker) == l_True){ + *j++ = *i++; continue; } + + // Make sure the false literal is data[1]: + CRef cr = i->cref; + Clause& c = ca[cr]; + Lit false_lit = ~p; + if (c[0] == false_lit) + c[0] = c[1], c[1] = false_lit; + assert(c[1] == false_lit); + i++; + + // If 0th watch is true, then clause is already satisfied. + Lit first = c[0]; + Watcher w = Watcher(cr, first); + if (first != blocker && value(first) == l_True){ + *j++ = w; continue; } + + // Look for new watch: + for (int k = 2; k < c.size(); k++) + if (value(c[k]) != l_False){ + c[1] = c[k]; c[k] = false_lit; + watches[~c[1]].push(w); + goto NextClause; } + + // Did not find watch -- clause is unit under assignment: + *j++ = w; + if (value(first) == l_False){ + confl = cr; + qhead = trail.size(); + // Copy the remaining watches: + while (i < end) + *j++ = *i++; + }else + uncheckedEnqueue(first, cr); + + NextClause:; + } + ws.shrink(i - j); + } + +ExitProp:; + propagations += num_props; + simpDB_props -= num_props; + + return confl; +} + + +/*_________________________________________________________________________________________________ +| +| reduceDB : () -> [void] +| +| Description: +| Remove half of the learnt clauses, minus the clauses locked by the current assignment. Locked +| clauses are clauses that are reason to some assignment. Binary clauses are never removed. +|________________________________________________________________________________________________@*/ +struct reduceDB_lt { + ClauseAllocator& ca; + reduceDB_lt(ClauseAllocator& ca_) : ca(ca_) {} + bool operator () (CRef x, CRef y) const { return ca[x].activity() < ca[y].activity(); } +}; +void Solver::reduceDB() +{ + int i, j; + //if (local_learnts_dirty) cleanLearnts(learnts_local, LOCAL); + //local_learnts_dirty = false; + + sort(learnts_local, reduceDB_lt(ca)); + + int limit = learnts_local.size() / 2; + for (i = j = 0; i < learnts_local.size(); i++){ + Clause& c = ca[learnts_local[i]]; + if (c.mark() == LOCAL) + if (c.removable() && !locked(c) && i < limit) + removeClause(learnts_local[i]); + else{ + if (!c.removable()) limit++; + c.removable(true); + learnts_local[j++] = learnts_local[i]; } + } + learnts_local.shrink(i - j); + + checkGarbage(); +} +void Solver::reduceDB_Tier2() +{ + int i, j; + for (i = j = 0; i < learnts_tier2.size(); i++){ + Clause& c = ca[learnts_tier2[i]]; + if (c.mark() == TIER2) + if (!locked(c) && c.touched() + 30000 < conflicts){ + learnts_local.push(learnts_tier2[i]); + c.mark(LOCAL); + //c.removable(true); + c.activity() = 0; + claBumpActivity(c); + }else + learnts_tier2[j++] = learnts_tier2[i]; + } + learnts_tier2.shrink(i - j); +} + + +void Solver::removeSatisfied(vec& cs) +{ + int i, j; + for (i = j = 0; i < cs.size(); i++){ + Clause& c = ca[cs[i]]; + if (satisfied(c)) + removeClause(cs[i]); + else + cs[j++] = cs[i]; + } + cs.shrink(i - j); +} + +void Solver::rebuildOrderHeap() +{ + vec vs; + for (Var v = 0; v < nVars(); v++) + if (decision[v] && value(v) == l_Undef) + vs.push(v); + + order_heap_CHB .build(vs); + order_heap_VSIDS.build(vs); +} + + +/*_________________________________________________________________________________________________ +| +| simplify : [void] -> [bool] +| +| Description: +| Simplify the clause database according to the current top-level assigment. Currently, the only +| thing done here is the removal of satisfied clauses, but more things can be put here. +|________________________________________________________________________________________________@*/ +bool Solver::simplify(bool do_stamping) +{ + assert(decisionLevel() == 0); + + if (!ok || propagate() != CRef_Undef) + return ok = false; + + if (nAssigns() == simpDB_assigns || (simpDB_props > 0)) + return true; + + // Remove satisfied clauses: + safeRemoveSatisfiedCompact(learnts_core, CORE); + safeRemoveSatisfiedCompact(learnts_tier2, TIER2); + safeRemoveSatisfiedCompact(learnts_local, LOCAL); + if (remove_satisfied) // Can be turned off. + removeSatisfied(clauses); + + if (do_stamping) + ok = stampAll(true); + + checkGarbage(); + rebuildOrderHeap(); + + simpDB_assigns = nAssigns(); + simpDB_props = clauses_literals + learnts_literals; // (shouldn't depend on stats really, but it will do for now) + + return ok; +} + + +// TODO: very dirty and hackish. +void Solver::removeClauseHack(CRef cr, Lit watched0, Lit watched1) +{ + assert(ca[cr].size() >= 2); + + Clause& c = ca[cr]; + if (drup_file) // Hackish. + if (c.mark() != 1){ +#ifdef BIN_DRUP + binDRUP('d', add_oc, drup_file); // 'add_oc' not 'c'. +#else + for (int i = 0; i < add_oc.size(); i++) + fprintf(drup_file, "%i ", (var(add_oc[i]) + 1) * (-2 * sign(add_oc[i]) + 1)); + fprintf(drup_file, "0\n"); +#endif + }else + printf("c Bug: removeClauseHack(). I don't expect this to happen.\n"); + + // TODO: dirty hack to exploit 'detachClause'. 'c' hasn't shrunk yet, so this will work fine. + c[0] = watched0, c[1] = watched1; + detachClause(cr); + // Don't leave pointers to free'd memory! + if (locked(c)){ + Lit implied = c.size() != 2 ? c[0] : (value(c[0]) == l_True ? c[0] : c[1]); + vardata[var(implied)].reason = CRef_Undef; } + c.mark(1); + ca.free(cr); +} + +// TODO: needs clean up. +void Solver::safeRemoveSatisfiedCompact(vec& cs, unsigned valid_mark) +{ + int i, j, k, l; + for (i = j = 0; i < cs.size(); i++){ + Clause& c = ca[cs[i]]; + if (c.mark() != valid_mark) continue; + + Lit c0 = c[0], c1 = c[1]; + if (drup_file){ // Remember the original clause before attempting to modify it. + add_oc.clear(); + for (int i = 0; i < c.size(); i++) add_oc.push(c[i]); } + + // Remove false literals at the same time. + for (k = l = 0; k < c.size(); k++) + if (value(c[k]) == l_True){ + removeClauseHack(cs[i], c0, c1); + goto NextClause; // Clause already satisfied; forget about it. + }else if (value(c[k]) == l_Undef) + c[l++] = c[k]; + assert(1 < l && l <= k); + + // If became binary, we also need to migrate watchers. The easiest way is to allocate a new binary. + if (l == 2 && k != 2){ + assert(add_tmp.size() == 0); + add_tmp.push(c[0]); add_tmp.push(c[1]); + bool learnt = c.learnt(); // Need a copy; see right below. + int lbd = c.lbd(); + int m = c.mark(); + CRef cr = ca.alloc(add_tmp, learnt); // Caution! 'alloc' may invalidate the 'c' reference. + if (learnt){ + if (m != CORE) learnts_core.push(cr); + ca[cr].mark(CORE); + ca[cr].set_lbd(lbd > 2 ? 2 : lbd); } + attachClause(cr); + + if (drup_file){ +#ifdef BIN_DRUP + binDRUP('a', add_tmp, drup_file); +#else + for (int i = 0; i < add_tmp.size(); i++) + fprintf(drup_file, "%i ", (var(add_tmp[i]) + 1) * (-2 * sign(add_tmp[i]) + 1)); + fprintf(drup_file, "0\n"); +#endif + } + add_tmp.clear(); + + removeClauseHack(cs[i], c0, c1); + cs[j++] = cr; // Should be after 'removeClauseHack' because 'i' may be equal to 'j'. + goto NextClause; + } + + c.shrink(k - l); // FIXME: fix (statistical) memory leak. + if (c.learnt()) learnts_literals -= (k - l); + else clauses_literals -= (k - l); + + if (drup_file && k != l){ +#ifdef BIN_DRUP + binDRUP('a', c, drup_file); + binDRUP('d', add_oc, drup_file); +#else + for (int i = 0; i < c.size(); i++) + fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1)); + fprintf(drup_file, "0\n"); + + fprintf(drup_file, "d "); + for (int i = 0; i < add_oc.size(); i++) + fprintf(drup_file, "%i ", (var(add_oc[i]) + 1) * (-2 * sign(add_oc[i]) + 1)); + fprintf(drup_file, "0\n"); +#endif + } + + cs[j++] = cs[i]; +NextClause:; + } + cs.shrink(i - j); +} + +/*_________________________________________________________________________________________________ +| +| search : (nof_conflicts : int) (params : const SearchParams&) -> [lbool] +| +| Description: +| Search for a model the specified number of conflicts. +| +| Output: +| 'l_True' if a partial assigment that is consistent with respect to the clauseset is found. If +| all variables are decision variables, this means that the clause set is satisfiable. 'l_False' +| if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached. +|________________________________________________________________________________________________@*/ +lbool Solver::search(int& nof_conflicts) +{ + assert(ok); + int backtrack_level; + int lbd; + vec learnt_clause; + bool cached = false; + starts++; + + for (;;){ + if (decisionLevel() == 0) { // We import clauses + if (!importClauses()) return l_False; + } + + CRef confl = propagate(); + + if (confl != CRef_Undef){ + // CONFLICT + if (VSIDS){ + if (--timer == 0 && var_decay < 0.95) timer = 5000, var_decay += 0.01; + }else + if (step_size > min_step_size) step_size -= step_size_dec; + + conflicts++; nof_conflicts--; + if (conflicts == 100000 && learnts_core.size() < 100) core_lbd_cut = 5; + if (decisionLevel() == 0) return l_False; + + learnt_clause.clear(); + analyze(confl, learnt_clause, backtrack_level, lbd); + if (cbkExportClause != NULL) + cbkExportClause(issuer, lbd, learnt_clause); + + cancelUntil(backtrack_level); + + if (VSIDS) + for (int i = 0; i < learnt_clause.size(); i++) + varBumpActivity(var(learnt_clause[i]), 1. / lbd); + + lbd--; + if (VSIDS){ + cached = false; + conflicts_VSIDS++; + lbd_queue.push(lbd); + global_lbd_sum += (lbd > 50 ? 50 : lbd); } + + if (learnt_clause.size() == 1){ + uncheckedEnqueue(learnt_clause[0]); + }else{ + CRef cr = ca.alloc(learnt_clause, true); + ca[cr].set_lbd(lbd); + if (lbd <= core_lbd_cut){ + learnts_core.push(cr); + ca[cr].mark(CORE); + }else if (lbd <= 6){ + learnts_tier2.push(cr); + ca[cr].mark(TIER2); + ca[cr].touched() = conflicts; + }else{ + learnts_local.push(cr); + claBumpActivity(ca[cr]); } + attachClause(cr); + uncheckedEnqueue(learnt_clause[0], cr); + } + if (drup_file){ +#ifdef BIN_DRUP + binDRUP('a', learnt_clause, drup_file); +#else + for (int i = 0; i < learnt_clause.size(); i++) + fprintf(drup_file, "%i ", (var(learnt_clause[i]) + 1) * (-2 * sign(learnt_clause[i]) + 1)); + fprintf(drup_file, "0\n"); +#endif + } + + if (VSIDS) varDecayActivity(); + claDecayActivity(); + + /*if (--learntsize_adjust_cnt == 0){ + learntsize_adjust_confl *= learntsize_adjust_inc; + learntsize_adjust_cnt = (int)learntsize_adjust_confl; + max_learnts *= learntsize_inc; + + if (verbosity >= 1) + printf("c | %9d | %7d %8d %8d | %8d %8d %6.0f | %6.3f %% |\n", + (int)conflicts, + (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]), nClauses(), (int)clauses_literals, + (int)max_learnts, nLearnts(), (double)learnts_literals/nLearnts(), progressEstimate()*100); + }*/ + + }else{ + // NO CONFLICT + bool restart = false; + if (!VSIDS) + restart = nof_conflicts <= 0; + else if (!cached){ + restart = lbd_queue.full() && (lbd_queue.avg() * 0.8 > global_lbd_sum / conflicts_VSIDS); + cached = true; + } + if (restart /*|| !withinBudget()*/){ + lbd_queue.clear(); + cached = false; + // Reached bound on number of conflicts: + progress_estimate = progressEstimate(); + cancelUntil(0); + return l_Undef; } + + // Simplify the set of problem clauses: + if (decisionLevel() == 0 && !simplify(true)) + return l_False; + + if (conflicts >= next_T2_reduce){ + next_T2_reduce = conflicts + 10000; + reduceDB_Tier2(); } + if (conflicts >= next_L_reduce){ + next_L_reduce = conflicts + 15000; + reduceDB(); } + + Lit next = lit_Undef; + while (decisionLevel() < assumptions.size()){ + // Perform user provided assumption: + Lit p = assumptions[decisionLevel()]; + if (value(p) == l_True){ + // Dummy decision level: + newDecisionLevel(); + }else if (value(p) == l_False){ + analyzeFinal(~p, conflict); + return l_False; + }else{ + next = p; + break; + } + } + + if (next == lit_Undef) { + if (assumptions.size() > 0) { // Hack deguelasse + shrinkAssumptions(); + return l_True; + } + + // New variable decision: + decisions++; + next = pickBranchLit(); + + if (next == lit_Undef) + // Model found: + return l_True; + } + + // Increase decision level and enqueue 'next' + newDecisionLevel(); + uncheckedEnqueue(next); + } + } +} + +bool Solver::shrinkAssumptions() { + assert(ok); + // Should be exactly equal because dummy levels are introduced + assert(decisionLevel() == assumptions.size()); + unsigned int sz = assumptions.size(); + // Remove literals corresponding to dummy decision levels + int i, j; + for( i = j = 0; i < assumptions.size(); i++ ) { + if ( trail_lim[i] < trail.size() && trail[trail_lim[i]] == assumptions[i]) { + assumptions[j++] = assumptions[i]; + } + } + assumptions.shrink(i-j); + return assumptions.size() < sz; +} + +void Solver::getAssumptions(vec& lits) { + for (int i = 0; i < assumptions.size(); i++) { + lits.push(assumptions[i]); + } +} + +double Solver::progressEstimate() const +{ + double progress = 0; + double F = 1.0 / nVars(); + + for (int i = 0; i <= decisionLevel(); i++){ + int beg = i == 0 ? 0 : trail_lim[i - 1]; + int end = i == decisionLevel() ? trail.size() : trail_lim[i]; + progress += pow(F, i) * (end - beg); + } + + return progress / nVars(); +} + +/* + Finite subsequences of the Luby-sequence: + + 0: 1 + 1: 1 1 2 + 2: 1 1 2 1 1 2 4 + 3: 1 1 2 1 1 2 4 1 1 2 1 1 2 4 8 + ... + + + */ + +static double luby(double y, int x){ + + // Find the finite subsequence that contains index 'x', and the + // size of that subsequence: + int size, seq; + for (size = 1, seq = 0; size < x+1; seq++, size = 2*size+1); + + while (size-1 != x){ + size = (size-1)>>1; + seq--; + x = x % size; + } + + return pow(y, seq); +} + +// NOTE: assumptions passed in member-variable 'assumptions'. +lbool Solver::solve_() +{ + model.clear(); + conflict.clear(); + if (!ok) return l_False; + + solves++; + + max_learnts = nClauses() * learntsize_factor; + learntsize_adjust_confl = learntsize_adjust_start_confl; + learntsize_adjust_cnt = (int)learntsize_adjust_confl; + lbool status = l_Undef; + + if (verbosity >= 1){ + printf("c ============================[ Search Statistics ]==============================\n"); + printf("c | Conflicts | ORIGINAL | LEARNT | Progress |\n"); + printf("c | | Vars Clauses Literals | Limit Clauses Lit/Cl | |\n"); + printf("c ===============================================================================\n"); + } + + add_tmp.clear(); + + //VSIDS = true; + //int init = 10000; + //while (status == l_Undef && init > 0 /*&& withinBudget()*/) + // status = search(init); + //VSIDS = false; + + // Search: + int phase_allotment = 10000; + int curr_restarts = 0; + for (;;){ + int weighted = phase_allotment; + fflush(stdout); + + while (status == l_Undef && weighted > 0 /*&& withinBudget()*/) + if (VSIDS) + status = search(weighted); + else{ + int nof_conflicts = luby(restart_inc, curr_restarts) * restart_first; + curr_restarts++; + weighted -= nof_conflicts; + status = search(nof_conflicts); + } + + if (status != l_Undef /*|| !withinBudget()*/) + break; // Should break here for correctness in incremental SAT solving. + + //VSIDS = !VSIDS; + if (!VSIDS) + phase_allotment *= 2; + } + + if (verbosity >= 1) + printf("c ===============================================================================\n"); + +#ifdef BIN_DRUP + if (drup_file && status == l_False) binDRUP_flush(drup_file); +#endif + + if (status == l_True){ + // Extend & copy model: + model.growTo(nVars()); + for (int i = 0; i < nVars(); i++) model[i] = value(i); + }else if (status == l_False && conflict.size() == 0) + ok = false; + + cancelUntil(0); + return status; +} + +//================================================================================================= +// Writing CNF to DIMACS: +// +// FIXME: this needs to be rewritten completely. + +static Var mapVar(Var x, vec& map, Var& max) +{ + if (map.size() <= x || map[x] == -1){ + map.growTo(x+1, -1); + map[x] = max++; + } + return map[x]; +} + + +void Solver::toDimacs(FILE* f, Clause& c, vec& map, Var& max) +{ + if (satisfied(c)) return; + + for (int i = 0; i < c.size(); i++) + if (value(c[i]) != l_False) + fprintf(f, "%s%d ", sign(c[i]) ? "-" : "", mapVar(var(c[i]), map, max)+1); + fprintf(f, "0\n"); +} + + +void Solver::toDimacs(const char *file, const vec& assumps) +{ + FILE* f = fopen(file, "wr"); + if (f == NULL) + fprintf(stderr, "could not open file %s\n", file), exit(1); + toDimacs(f, assumps); + fclose(f); +} + + +void Solver::toDimacs(FILE* f, const vec& assumps) +{ + // Handle case when solver is in contradictory state: + if (!ok){ + fprintf(f, "p cnf 1 2\n1 0\n-1 0\n"); + return; } + + vec map; Var max = 0; + + // Cannot use removeClauses here because it is not safe + // to deallocate them at this point. Could be improved. + int cnt = 0; + for (int i = 0; i < clauses.size(); i++) + if (!satisfied(ca[clauses[i]])) + cnt++; + + for (int i = 0; i < clauses.size(); i++) + if (!satisfied(ca[clauses[i]])){ + Clause& c = ca[clauses[i]]; + for (int j = 0; j < c.size(); j++) + if (value(c[j]) != l_False) + mapVar(var(c[j]), map, max); + } + + // Assumptions are added as unit clauses: + cnt += assumptions.size(); + + fprintf(f, "p cnf %d %d\n", max, cnt); + + for (int i = 0; i < assumptions.size(); i++){ + assert(value(assumptions[i]) != l_False); + fprintf(f, "%s%d 0\n", sign(assumptions[i]) ? "-" : "", mapVar(var(assumptions[i]), map, max)+1); + } + + for (int i = 0; i < clauses.size(); i++) + toDimacs(f, ca[clauses[i]], map, max); + + if (verbosity > 0) + printf("c Wrote %d clauses with %d variables.\n", cnt, max); +} + + +//================================================================================================= +// Garbage Collection methods: + +void Solver::relocAll(ClauseAllocator& to) +{ + // All watchers: + // + // for (int i = 0; i < watches.size(); i++) + watches.cleanAll(); + watches_bin.cleanAll(); + for (int v = 0; v < nVars(); v++) + for (int s = 0; s < 2; s++){ + Lit p = mkLit(v, s); + // printf(" >>> RELOCING: %s%d\n", sign(p)?"-":"", var(p)+1); + vec& ws = watches[p]; + for (int j = 0; j < ws.size(); j++) + ca.reloc(ws[j].cref, to); + vec& ws_bin = watches_bin[p]; + for (int j = 0; j < ws_bin.size(); j++) + ca.reloc(ws_bin[j].cref, to); + } + + // All reasons: + // + for (int i = 0; i < trail.size(); i++){ + Var v = var(trail[i]); + + if (reason(v) != CRef_Undef && (ca[reason(v)].reloced() || locked(ca[reason(v)]))) + ca.reloc(vardata[v].reason, to); + } + + // All learnt: + // + for (int i = 0; i < learnts_core.size(); i++) + ca.reloc(learnts_core[i], to); + for (int i = 0; i < learnts_tier2.size(); i++) + ca.reloc(learnts_tier2[i], to); + for (int i = 0; i < learnts_local.size(); i++) + ca.reloc(learnts_local[i], to); + + // All original: + // + int i, j; + for (i = j = 0; i < clauses.size(); i++) + if (ca[clauses[i]].mark() != 1){ + ca.reloc(clauses[i], to); + clauses[j++] = clauses[i]; } + clauses.shrink(i - j); +} + + +void Solver::garbageCollect() +{ + // Initialize the next region to a size corresponding to the estimated utilization degree. This + // is not precise but should avoid some unnecessary reallocations for the new region: + ClauseAllocator to(ca.size() - ca.wasted()); + + relocAll(to); + if (verbosity >= 2) + printf("c | Garbage collection: %12d bytes => %12d bytes |\n", + ca.size()*ClauseAllocator::Unit_Size, to.size()*ClauseAllocator::Unit_Size); + to.moveTo(ca); +} + + +inline int gcd(int a, int b) { + int tmp; + if (a < b) tmp = a, a = b, b = tmp; + while (b) tmp = b, b = a % b, a = tmp; + return a; +} + +bool Solver::stampAll(bool use_bin_learnts) +{ + // Initialization. + int stamp_time = 0; + int nLits = 2*nVars(); + for (int i = 0; i < nVars(); i++){ + int m = i*2, n = i*2 + 1; + discovered[m] = discovered[n] = finished[m] = finished[n] = observed[m] = observed[n] = 0; + root[m] = root[n] = parent[m] = parent[n] = lit_Undef; + flag[m] = flag[n] = 0; } + + for (int roots_only = 1; roots_only >= 0; roots_only--){ + int l = irand(random_seed, nLits); + int l_inc = irand(random_seed, nLits-1) + 1; // Avoid 0 but ensure less than 'nLits'. + while (gcd(nLits, l_inc) > 1) + if (++l_inc == nLits) l_inc = 1; + + int first = l; + do{ + Lit p = toLit(l); + if (value(p) == l_Undef && !discovered[toInt(p)] && + (!roots_only || isRoot(p, use_bin_learnts)) && + implExistsByBin(p, use_bin_learnts)){ + stamp_time = stamp(p, stamp_time, use_bin_learnts); + + if (!ok || propagate() != CRef_Undef) + return ok = false; + } + + // Compute next literal to look at. + l += l_inc; + if (l >= nLits) l -= nLits; + + }while(l != first); + } + + return true; +} + +int Solver::stamp(Lit p, int stamp_time, bool use_bin_learnts) +{ + assert(value(p) == l_Undef && !discovered[toInt(p)] && !finished[toInt(p)]); + assert(rec_stack.size() == 0 && scc.size() == 0); + + int start_stamp = 0; + rec_stack.push(Frame(Frame::START, p, lit_Undef, 0)); + + while (rec_stack.size()){ + const Frame f = rec_stack.last(); rec_stack.pop(); + int i_curr = toInt(f.curr); + int i_next = toInt(f.next); + + if (f.type == Frame::START){ + if (discovered[i_curr]){ + observed[i_curr] = stamp_time; + continue; } + + assert(!finished[i_curr]); + discovered[i_curr] = observed[i_curr] = ++stamp_time; + + if (start_stamp == 0){ + start_stamp = stamp_time; + root[i_curr] = f.curr; + assert(parent[i_curr] == lit_Undef); } + rec_stack.push(Frame(Frame::CLOSE, f.curr, lit_Undef, 0)); + + assert(!flag[i_curr]); + flag[i_curr] = 1; + scc.push(f.curr); + + for (int undiscovered = 0; undiscovered <= 1; undiscovered++){ + int prev_top = rec_stack.size(); + analyze_toclear.clear(); + + const vec& ws = watches_bin[f.curr]; + for (int k = 0; k < ws.size(); k++){ + Lit the_other = ws[k].blocker; + + if (value(the_other) == l_Undef + && !seen[toInt(the_other)] + && undiscovered == !discovered[toInt(the_other)]) +// && (use_bin_learnts || !ca[ws[k].cref].learnt())) + { + seen[toInt(the_other)] = 1; + analyze_toclear.push(the_other); + + rec_stack.push(Frame(Frame::ENTER, f.curr, the_other, 0)); + //rec_stack.push(Frame(Frame::ENTER, f.curr, the_other, ca[ws[k].cref].learnt())); + } + } + for (int k = 0; k < analyze_toclear.size(); k++) seen[toInt(analyze_toclear[k])] = 0; + + // Now randomize child nodes to visit by shuffling pushed stack entries. + int stacked = rec_stack.size() - prev_top; + for (int i = 0; i < stacked - 1; i++){ + int j = i + irand(random_seed, stacked - i); // i <= j < stacked + if (i != j){ + Frame tmp = rec_stack[prev_top + i]; + rec_stack[prev_top + i] = rec_stack[prev_top + j]; + rec_stack[prev_top + j] = tmp; } + } + } + + }else if (f.type == Frame::ENTER){ + rec_stack.push(Frame(Frame::RETURN, f.curr, f.next, f.learnt)); + + int neg_observed = observed[toInt(~f.next)]; + if (start_stamp <= neg_observed){ // Failed literal? + Lit failed; + for (failed = f.curr; + discovered[toInt(failed)] > neg_observed; + failed = parent[toInt(failed)]) + assert(failed != lit_Undef); + + if (drup_file && value(~failed) != l_True){ +#ifdef BIN_DRUP + assert(add_tmp.size() == 0); + add_tmp.push(~failed); + binDRUP('a', add_tmp, drup_file); + add_tmp.clear(); +#else + fprintf(drup_file, "%i 0\n", (var(~failed) + 1) * (-2 * sign(~failed) + 1)); +#endif + } + + if (!(ok = enqueue(~failed))) + return -1; // Who cares what? + + if (discovered[toInt(~f.next)] && !finished[toInt(~f.next)]){ + rec_stack.pop(); // Skip this edge after a failed literal. + continue; } + } + + if (!discovered[i_next]){ + parent[i_next] = f.curr; + root[i_next] = p; + rec_stack.push(Frame(Frame::START, f.next, lit_Undef, 0)); } + + }else if (f.type == Frame::RETURN){ + if (!finished[i_next] && discovered[i_next] < discovered[i_curr]){ + discovered[i_curr] = discovered[i_next]; + flag[i_curr] = 0; + } + observed[i_next] = stamp_time; + + }else if (f.type == Frame::CLOSE){ + if (flag[i_curr]){ + stamp_time++; + int curr_discovered = discovered[i_curr]; + Lit q; + do{ + q = scc.last(); scc.pop(); + flag [toInt(q)] = 0; + discovered[toInt(q)] = curr_discovered; + finished [toInt(q)] = stamp_time; + }while (q != f.curr); + } + + }else assert(false); + } + + return stamp_time; +} + +bool Solver::implExistsByBin(Lit p, bool use_bin_learnts) const { + assert(value(p) == l_Undef); + + const vec& ws = watches_bin[p]; + for (int i = 0; i < ws.size(); i++){ + Lit the_other = ws[i].blocker; + assert(value(the_other) != l_False); // Propagate then. + + if (value(the_other) != l_True && !discovered[toInt(the_other)]) + if (use_bin_learnts || !ca[ws[i].cref].learnt()) + return true; + } + return false; +} + +bool Solver::isRoot(Lit p, bool use_bin_learnts) const { return !implExistsByBin(~p, use_bin_learnts); } diff --git a/lstech_maple/lstech/core/Solver.h b/mapleCOMSPS/mapleCOMSPS/core/Solver.h old mode 100755 new mode 100644 similarity index 77% rename from lstech_maple/lstech/core/Solver.h rename to mapleCOMSPS/mapleCOMSPS/core/Solver.h index fc8033d..9b4e219 --- a/lstech_maple/lstech/core/Solver.h +++ b/mapleCOMSPS/mapleCOMSPS/core/Solver.h @@ -1,22 +1,8 @@ -/***************************************************************************************[Solver.cc] +/****************************************************************************************[Solver.h] MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson Copyright (c) 2007-2010, Niklas Sorensson - + Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh - -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. - -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - -MapleLCMDistChronoBT, based on Maple_LCM_Dist -- Copyright (c), Alexander Nadel, Vadim Ryvchin: "Chronological Backtracking" in SAT-2018, pp. 111-121. - -MapleLCMDistChronoBT-DL, based on MapleLCMDistChronoBT -- Copyright (c), Stepan Kochemazov, Oleg Zaikin, Victor Kondratiev, Alexander Semenov: The solver was augmented with heuristic that moves duplicate learnt clauses into the core/tier2 tiers depending on a number of parameters. - -lstech, Relaxed_newTech -- Copyright (c) 2019-2021, Shaowei Cai, Xindi Zhang -Reference: Shaowei Cai, Xindi Zhang: Deep Cooperation of CDCL and Local Search for SAT. -Xindi Zhang, Shaowei Cai: Relaxed Backtracking with Rephasing. - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -33,10 +19,10 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FO DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Solver_h -#define Minisat_Solver_h -#define ANTI_EXPLORATION +#ifndef MapleCOMSPS_Solver_h +#define MapleCOMSPS_Solver_h + #define BIN_DRUP #define GLUCOSE23 @@ -44,34 +30,24 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA //#define LOOSE_PROP_STAT #ifdef GLUCOSE23 -#define INT_QUEUE_AVG -#define LOOSE_PROP_STAT + #define INT_QUEUE_AVG + #define LOOSE_PROP_STAT #endif -#include "mtl/Vec.h" -#include "mtl/Heap.h" -#include "mtl/Alg.h" -#include "utils/Options.h" -#include "core/SolverTypes.h" -#include "utils/ccnr.h" - -// duplicate learnts version -#include -#include -#include -#include -#include -#include -#include -// duplicate learnts version +#include +#include "../mtl/Vec.h" +#include "../mtl/Heap.h" +#include "../mtl/Alg.h" +#include "../utils/Options.h" +#include "../core/SolverTypes.h" // Don't change the actual numbers. #define LOCAL 0 #define TIER2 2 #define CORE 3 -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // Solver -- the main class: @@ -86,6 +62,7 @@ private: vec q; public: MyQueue(int sz) : max_sz(sz), q_sz(0), ptr(0), sum(0) { assert(sz > 0); q.growTo(sz); } + MyQueue(const MyQueue& other) : max_sz(other.max_sz), q_sz(other.q_sz), ptr(other.ptr), sum(other.sum) { other.q.copyTo(q); } inline bool full () const { return q_sz == max_sz; } #ifdef INT_QUEUE_AVG inline T avg () const { assert(full()); return sum / max_sz; } @@ -103,22 +80,25 @@ private: }; public: + // Constructor/Destructor: // Solver(); + Solver(const Solver & s); virtual ~Solver(); // Problem specification: // Var newVar (bool polarity = true, bool dvar = true); // Add a new variable with parameters specifying variable mode. + bool addClause (const vec& ps); // Add a clause to the solver. bool addEmptyClause(); // Add the empty clause, making the solver contradictory. bool addClause (Lit p); // Add a unit clause to the solver. bool addClause (Lit p, Lit q); // Add a binary clause to the solver. bool addClause (Lit p, Lit q, Lit r); // Add a ternary clause to the solver. bool addClause_( vec& ps); // Add a clause to the solver without making superflous internal copy. Will - // change the passed vector 'ps'. - + // change the passed vector 'ps'. + // Parallel support // bool importClauses(); @@ -129,9 +109,12 @@ public: bool (* cbkImportClause)(void *, int *, vec &); void (* cbkExportClause)(void *, int, vec &); // callback for clause learning + // Solving: // - bool simplify (); // Removes already satisfied clauses. + bool shrinkAssumptions(); + void getAssumptions(vec& lits); + bool simplify (bool do_stamping = false); // Removes already satisfied clauses. bool solve (const vec& assumps); // Search for a model that respects a given set of assumptions. lbool solveLimited (const vec& assumps); // Search for a model that respects a given set of assumptions (With resource constraints). bool solve (); // Search without assumptions. @@ -149,7 +132,7 @@ public: void toDimacs (const char* file, Lit p); void toDimacs (const char* file, Lit p, Lit q); void toDimacs (const char* file, Lit p, Lit q, Lit r); - + // Variable mode: // void setPolarity (Var v, bool b); // Declare which polarity the decision heuristic should use for a variable. Requires mode 'polarity_user'. @@ -185,14 +168,11 @@ public: // vec model; // If problem is satisfiable, this vector contains the model (if any). vec conflict; // If problem is unsatisfiable (possibly under assumptions), - // this vector represent the final conflict clause expressed in the assumptions. + // this vector represent the final conflict clause expressed in the assumptions. // Mode of operation: // FILE* drup_file; - int worker_index; - int worker_number; - int worker_seed; int verbosity; double step_size; double step_size_dec; @@ -203,6 +183,7 @@ public: double random_var_freq; double random_seed; bool VSIDS; + bool verso; int ccmin_mode; // Controls conflict clause minimization (0=none, 1=basic, 2=deep). int phase_saving; // Controls the level of phase saving (0=none, 1=limited, 2=full). bool rnd_pol; // Use random polarities for branching heuristics. @@ -217,36 +198,14 @@ public: int learntsize_adjust_start_confl; double learntsize_adjust_inc; - - // duplicate learnts version - - uint32_t min_number_of_learnts_copies; - uint32_t dupl_db_init_size; - uint32_t max_lbd_dup; - std::chrono::microseconds duptime; - // duplicate learnts version - // Statistics: (read-only member variable) // uint64_t solves, starts, decisions, rnd_decisions, propagations, conflicts, conflicts_VSIDS; uint64_t dec_vars, clauses_literals, learnts_literals, max_literals, tot_literals; - uint64_t chrono_backtrack, non_chrono_backtrack; - - - // duplicate learnts version - uint64_t duplicates_added_conflicts; - uint64_t duplicates_added_tier2; - uint64_t duplicates_added_minimization; - uint64_t dupl_db_size; - - // duplicate learnts version vec picked; vec conflicted; vec almost_conflicted; -#ifdef ANTI_EXPLORATION - vec canceled; -#endif protected: @@ -272,35 +231,29 @@ protected: struct VarOrderLt { const vec& activity; - bool operator () (Var x, Var y) const { return activity[x] > activity[y]; } - VarOrderLt(const vec& act) : activity(act) { } + const bool & verso; + bool operator () (Var x, Var y) const { + if (verso) return activity[x] > activity[y]; + return activity[x] >= activity[y]; + } + VarOrderLt(const vec& act, const bool & v) : activity(act), verso(v) { + } }; - - struct ConflictData - { - ConflictData() : - nHighestLevel(-1), - bOnlyOneLitFromHighest(false) - {} - - int nHighestLevel; - bool bOnlyOneLitFromHighest; - }; // Solver state: // bool ok; // If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used! vec clauses; // List of problem clauses. vec learnts_core, // List of learnt clauses. - learnts_tier2, - learnts_local; + learnts_tier2, + learnts_local; double cla_inc; // Amount to bump next clause with. vec activity_CHB, // A heuristic measurement of the activity of a variable. - activity_VSIDS; + activity_VSIDS; double var_inc; // Amount to bump next variable with. OccLists, WatcherDeleted> - watches_bin, // Watches for binary clauses only. - watches; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true). + watches_bin, // Watches for binary clauses only. + watches; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true). vec assigns; // The current assignments. vec polarity; // The preferred polarity of each variable. vec decision; // Declares if a variable is eligible for selection in the decision heuristic. @@ -312,7 +265,7 @@ protected: int64_t simpDB_props; // Remaining number of propagations that must be made before next execution of 'simplify()'. vec assumptions; // Current set of assumptions provided to solve by the user. Heap order_heap_CHB, // A priority queue of variables ordered with respect to the variable activity. - order_heap_VSIDS; + order_heap_VSIDS; double progress_estimate;// Set by 'search()'. bool remove_satisfied; // Indicates whether possibly inefficient linear scan for satisfied clauses should be performed in 'simplify'. @@ -321,17 +274,9 @@ protected: MyQueue lbd_queue; // For computing moving averages of recent LBD values. uint64_t next_T2_reduce, - next_L_reduce; + next_L_reduce; ClauseAllocator ca; - - // duplicate learnts version - std::map>> ht; - - // duplicate learnts version - - int confl_to_chrono; - int chrono; // Temporaries (to reduce allocation overhead). Each variable is prefixed by the method in which it is // used, exept 'seen' wich is used in several places. @@ -360,7 +305,7 @@ protected: void insertVarOrder (Var x); // Insert a variable in the decision order priority queue. Lit pickBranchLit (); // Return the next decision variable. void newDecisionLevel (); // Begins a new decision level. - void uncheckedEnqueue (Lit p, int level = 0, CRef from = CRef_Undef); // Enqueue a literal. Assumes value of literal is undefined. + void uncheckedEnqueue (Lit p, CRef from = CRef_Undef); // Enqueue a literal. Assumes value of literal is undefined. bool enqueue (Lit p, CRef from = CRef_Undef); // Test if fact 'p' contradicts current state, enqueue otherwise. CRef propagate (); // Perform unit propagation. Returns possibly conflicting clause. void cancelUntil (int level); // Backtrack until a certain level. @@ -372,7 +317,7 @@ protected: void reduceDB (); // Reduce the set of learnt clauses. void reduceDB_Tier2 (); void removeSatisfied (vec& cs); // Shrink 'cs' to contain only non-satisfied clauses. - void safeRemoveSatisfied(vec& cs, unsigned valid_mark); + void safeRemoveSatisfiedCompact(vec& cs, unsigned valid_mark); void rebuildOrderHeap (); bool binResMinimize (vec& out_learnt); // Further learnt clause minimization by binary resolution. @@ -388,26 +333,18 @@ protected: void attachClause (CRef cr); // Attach a clause to watcher lists. void detachClause (CRef cr, bool strict = false); // Detach a clause to watcher lists. void removeClause (CRef cr); // Detach and free a clause. + void removeClauseHack (CRef cr, Lit watched0, Lit watched1); bool locked (const Clause& c) const; // Returns TRUE if a clause is a reason for some implication in the current state. bool satisfied (const Clause& c) const; // Returns TRUE if a clause is satisfied in the current state. void relocAll (ClauseAllocator& to); -// duplicate learnts version - int is_duplicate (std::vector&c); //returns TRUE if a clause is duplicate -// duplicate learnts version - // Misc: // int decisionLevel () const; // Gives the current decisionlevel. uint32_t abstractLevel (Var x) const; // Used to represent an abstraction of sets of decision levels. CRef reason (Var x) const; - - ConflictData FindConflictLevel(CRef cind); - -public: int level (Var x) const; -protected: double progressEstimate () const; // DELETE THIS ?? IT'S NOT VERY USEFUL ... bool withinBudget () const; @@ -456,7 +393,6 @@ protected: } static inline void binDRUP_flush(FILE* drup_file){ -// fwrite(drup_buf, sizeof(unsigned char), buf_len, drup_file); fwrite_unlocked(drup_buf, sizeof(unsigned char), buf_len, drup_file); buf_ptr = drup_buf; buf_len = 0; } @@ -476,84 +412,29 @@ protected: static inline int irand(double& seed, int size) { return (int)(drand(seed) * size); } + // For (advanced) stamping. + struct Frame { + enum TYPE { START = 0, ENTER = 1, RETURN = 2, CLOSE = 3 }; + Lit curr, next; + unsigned type : 3; + unsigned learnt : 1; + Frame(TYPE t, Lit p, Lit q, unsigned l) : curr(p), next(q), type(t), learnt(l) {} + }; - // simplify - // -public: - bool simplifyAll(); - void simplifyLearnt(Clause& c); - bool simplifyLearnt_x(vec& learnts_x); - bool simplifyLearnt_core(); - bool simplifyLearnt_tier2(); - int trailRecord; - void litsEnqueue(int cutP, Clause& c); - void cancelUntilTrailRecord(); - void simpleUncheckEnqueue(Lit p, CRef from = CRef_Undef); - CRef simplePropagate(); - uint64_t nbSimplifyAll; - uint64_t simplified_length_record, original_length_record; - uint64_t s_propagations; + vec discovered; + vec finished; + vec observed; + vec flag; + vec root; + vec parent; - vec simp_learnt_clause; - vec simp_reason_clause; - void simpleAnalyze(CRef confl, vec& out_learnt, vec& reason_clause, bool True_confl); + vec rec_stack; + vec scc; // Strongly connected component. - // in redundant - bool removed(CRef cr); - // adjust simplifyAll occasion - long curSimplify; - int nbconfbeforesimplify; - int incSimplify; - -private: - // to avoid the init_soln of two LS too near. - int restarts_gap = 300; - int restarts_basic = 300; - // if trail.size() over c*nVars or p*max_trail, call ls. - // float conflict_ratio = 0.4; - // float percent_ratio = 0.9; - // // control ls time total use. - // float up_time_ratio = 0.2; - // control ls memory use per call. - long long ls_mems_num = 50*1000*1000; - // whether the mediation_soln is used as rephase, if not - // bool mediation_used = false; - - int switch_heristic_mod = 500;//starts - int last_switch_conflicts; - - //informations - // bool lssolver_constructed = false; - CCAnr *lssolver; - int freeze_ls_restart_num = 0; - double ls_used_time = 0; - int ls_call_num = 0; - int ls_best_unsat_num = INT_MAX; - bool solved_by_ls = false; - int max_trail = 0; - bool max_trail_improved = false; - int up_build_num = 0; - double up_build_time = 0.0; - - //Phases - // save the recent ls soln and best ls soln, need to call ls once. - char* ls_mediation_soln; - // with the minimum unsat clauses num in LS. - char* ls_best_soln; - // hold the soln with the best trail size. - char* top_trail_soln; - char* tmp_up_build_soln; - - - //functions - // bool call_ls(bool use_up_build); - bool ccanr_has_constructed = false; - enum build_type{current_UP,top_trail_UP,random_build}; - bool call_ls(build_type type); - void load_ls_data(); - void build_soln_with_UP(); - void rand_based_rephase(); - void info_based_rephase(); + bool stampAll(bool use_bin_learnts); + int stamp(Lit p, int stamp_time, bool use_bin_learnts); + inline bool implExistsByBin(Lit p, bool use_bin_learnts) const; + inline bool isRoot(Lit p, bool use_bin_learnts) const; }; @@ -564,8 +445,7 @@ inline CRef Solver::reason(Var x) const { return vardata[x].reason; } inline int Solver::level (Var x) const { return vardata[x].level; } inline void Solver::insertVarOrder(Var x) { - // Heap& order_heap = VSIDS ? order_heap_VSIDS : order_heap_CHB; - Heap& order_heap = ((!VSIDS)? order_heap_CHB:order_heap_VSIDS); + Heap& order_heap = VSIDS ? order_heap_VSIDS : order_heap_CHB; if (!order_heap.inHeap(x) && decision[x]) order_heap.insert(x); } inline void Solver::varDecayActivity() { @@ -583,11 +463,11 @@ inline void Solver::varBumpActivity(Var v, double mult) { inline void Solver::claDecayActivity() { cla_inc *= (1 / clause_decay); } inline void Solver::claBumpActivity (Clause& c) { - if ( (c.activity() += cla_inc) > 1e20 ) { - // Rescale: - for (int i = 0; i < learnts_local.size(); i++) - ca[learnts_local[i]].activity() *= 1e-20; - cla_inc *= 1e-20; } } + if ( (c.activity() += cla_inc) > 1e20 ) { + // Rescale: + for (int i = 0; i < learnts_local.size(); i++) + ca[learnts_local[i]].activity() *= 1e-20; + cla_inc *= 1e-20; } } inline void Solver::checkGarbage(void){ return checkGarbage(garbage_frac); } inline void Solver::checkGarbage(double gf){ @@ -595,7 +475,7 @@ inline void Solver::checkGarbage(double gf){ garbageCollect(); } // NOTE: enqueue does not set the ok flag! (only public methods do) -inline bool Solver::enqueue (Lit p, CRef from) { return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, decisionLevel(), from), true); } +inline bool Solver::enqueue (Lit p, CRef from) { return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, from), true); } inline bool Solver::addClause (const vec& ps) { ps.copyTo(add_tmp); return addClause_(add_tmp); } inline bool Solver::addEmptyClause () { add_tmp.clear(); return addClause_(add_tmp); } inline bool Solver::addClause (Lit p) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp); } @@ -619,15 +499,15 @@ inline int Solver::nLearnts () const { return learnts_core.size inline int Solver::nVars () const { return vardata.size(); } inline int Solver::nFreeVars () const { return (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]); } inline void Solver::setPolarity (Var v, bool b) { polarity[v] = b; } -inline void Solver::setDecisionVar(Var v, bool b) -{ +inline void Solver::setDecisionVar(Var v, bool b) +{ if ( b && !decision[v]) dec_vars++; else if (!b && decision[v]) dec_vars--; decision[v] = b; if (b && !order_heap_CHB.inHeap(v)){ order_heap_CHB.insert(v); - order_heap_VSIDS.insert(v);} + order_heap_VSIDS.insert(v); } } inline void Solver::setConfBudget(int64_t x){ conflict_budget = conflicts + x; } inline void Solver::setPropBudget(int64_t x){ propagation_budget = propagations + x; } @@ -636,8 +516,8 @@ inline void Solver::clearInterrupt(){ asynch_interrupt = false; } inline void Solver::budgetOff(){ conflict_budget = propagation_budget = -1; } inline bool Solver::withinBudget() const { return !asynch_interrupt && - (conflict_budget < 0 || conflicts < (uint64_t)conflict_budget) && - (propagation_budget < 0 || propagations < (uint64_t)propagation_budget); } + (conflict_budget < 0 || conflicts < (uint64_t)conflict_budget) && + (propagation_budget < 0 || propagations < (uint64_t)propagation_budget); } // FIXME: after the introduction of asynchronous interrruptions the solve-versions that return a // pure bool do not give a safe interface. Either interrupts must be possible to turn off here, or @@ -655,6 +535,7 @@ inline void Solver::toDimacs (const char* file, Lit p){ vec as; as. inline void Solver::toDimacs (const char* file, Lit p, Lit q){ vec as; as.push(p); as.push(q); toDimacs(file, as); } inline void Solver::toDimacs (const char* file, Lit p, Lit q, Lit r){ vec as; as.push(p); as.push(q); as.push(r); toDimacs(file, as); } + //================================================================================================= // Debug etc: diff --git a/lstech_maple/lstech/core/SolverTypes.h b/mapleCOMSPS/mapleCOMSPS/core/SolverTypes.h old mode 100755 new mode 100644 similarity index 88% rename from lstech_maple/lstech/core/SolverTypes.h rename to mapleCOMSPS/mapleCOMSPS/core/SolverTypes.h index f3292c7..979fbdf --- a/lstech_maple/lstech/core/SolverTypes.h +++ b/mapleCOMSPS/mapleCOMSPS/core/SolverTypes.h @@ -1,15 +1,9 @@ /***********************************************************************************[SolverTypes.h] MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson Copyright (c) 2007-2010, Niklas Sorensson - + Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. - -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, @@ -27,19 +21,18 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA **************************************************************************************************/ -#ifndef Minisat_SolverTypes_h -#define Minisat_SolverTypes_h +#ifndef MapleCOMSPS_SolverTypes_h +#define MapleCOMSPS_SolverTypes_h #include -#include "mtl/IntTypes.h" -#include "mtl/Alg.h" -#include "mtl/Vec.h" -#include "mtl/Map.h" -#include "mtl/Alloc.h" -#include +#include "../mtl/IntTypes.h" +#include "../mtl/Alg.h" +#include "../mtl/Vec.h" +#include "../mtl/Map.h" +#include "../mtl/Alloc.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // Variables, literals, lifted booleans, clauses: @@ -56,14 +49,15 @@ struct Lit { int x; // Use this as a constructor: - friend Lit mkLit(Var var, bool sign ); + friend Lit mkLit(Var var, bool sign); bool operator == (Lit p) const { return x == p.x; } bool operator != (Lit p) const { return x != p.x; } bool operator < (Lit p) const { return x < p.x; } // '<' makes p, ~p adjacent in the ordering. }; -inline Lit mkLit (Var var, bool sign= false) { Lit p; p.x = var + var + (int)sign; return p; } + +inline Lit mkLit (Var var, bool sign = false) { Lit p; p.x = var + var + (int)sign; return p; } inline Lit operator ~(Lit p) { Lit q; q.x = p.x ^ 1; return q; } inline Lit operator ^(Lit p, bool b) { Lit q; q.x = p.x ^ (unsigned int)b; return q; } inline bool sign (Lit p) { return p.x & 1; } @@ -81,17 +75,6 @@ const Lit lit_Undef = { -2 }; // }- Useful special constants. const Lit lit_Error = { -1 }; // } -inline int toFormal(Lit p) { return sign(p) ? -var(p) - 1 : var(p) + 1; } - - -inline std::ostream& operator<<(std::ostream& out, const Lit& val) -{ - out << (sign(val) ? -var(val) : var(val)) << std::flush; - return out; -} - - - //================================================================================================= // Lifted booleans: // @@ -117,7 +100,7 @@ public: bool operator != (lbool b) const { return !(*this == b); } lbool operator ^ (bool b) const { return lbool((uint8_t)(value^(uint8_t)b)); } - lbool operator && (lbool b) const { + lbool operator && (lbool b) const { uint8_t sel = (this->value << 1) | (b.value << 3); uint8_t v = (0xF7F755F4 >> sel) & 3; return lbool(v); } @@ -147,9 +130,7 @@ class Clause { unsigned reloced : 1; unsigned lbd : 26; unsigned removable : 1; - unsigned size : 32; - //simplify - unsigned simplified : 1;} header; + unsigned size : 32; } header; union { Lit lit; float act; uint32_t abs; uint32_t touched; CRef rel; } data[0]; friend class ClauseAllocator; @@ -164,18 +145,15 @@ class Clause { header.size = ps.size(); header.lbd = 0; header.removable = 1; - //simplify - // - header.simplified = 0; - for (int i = 0; i < ps.size(); i++) + for (int i = 0; i < ps.size(); i++) data[i].lit = ps[i]; if (header.has_extra){ if (header.learnt){ - data[header.size].act = 0; + data[header.size].act = 0; data[header.size+1].touched = 0; - }else + }else calcAbstraction(); } } @@ -218,10 +196,6 @@ public: Lit subsumes (const Clause& other) const; void strengthen (Lit p); - // simplify - // - void setSimplified(bool b) { header.simplified = b; } - bool simplified() { return header.simplified; } }; @@ -234,7 +208,7 @@ class ClauseAllocator : public RegionAllocator { static int clauseWord32Size(int size, int extras){ return (sizeof(Clause) + (sizeof(Lit) * (size + extras))) / sizeof(uint32_t); } -public: + public: bool extra_clause_field; ClauseAllocator(uint32_t start_cap) : RegionAllocator(start_cap), extra_clause_field(false){} @@ -280,7 +254,7 @@ public: cr = to.alloc(c, c.learnt()); c.relocate(cr); - // Copy extra data-fields: + // Copy extra data-fields: // (This could be cleaned-up. Generalize Clause-constructor to be applicable here instead?) to[cr].mark(c.mark()); if (to[cr].learnt()){ @@ -288,25 +262,12 @@ public: to[cr].activity() = c.activity(); to[cr].set_lbd(c.lbd()); to[cr].removable(c.removable()); - // simplify - // - to[cr].setSimplified(c.simplified()); } else if (to[cr].has_extra()) to[cr].calcAbstraction(); } }; -inline std::ostream& operator<<(std::ostream& out, const Clause& cls) -{ - for (int i = 0; i < cls.size(); ++i) - { - out << cls[i] << " "; - } - - return out; -} - //================================================================================================= // OccLists -- a class for maintaining occurence lists with lazy deletion: @@ -318,11 +279,11 @@ class OccLists vec dirties; Deleted deleted; -public: + public: OccLists(const Deleted& d) : deleted(d) {} void init (const Idx& idx){ occs.growTo(toInt(idx)+1); dirty.growTo(toInt(idx)+1, 0); } - // Vec& operator[](const Idx& idx){ return occs[toInt(idx)]; } + const Vec& operator[](const Idx& idx) const { return occs[toInt(idx)]; } Vec& operator[](const Idx& idx){ return occs[toInt(idx)]; } Vec& lookup (const Idx& idx){ if (dirty[toInt(idx)]) clean(idx); return occs[toInt(idx)]; } @@ -340,6 +301,14 @@ public: dirty .clear(free); dirties.clear(free); } + + void copyTo(OccLists ©) const { + copy.occs.growTo(occs.size()); + for(int i = 0;i HashTable; HashTable map; - -public: + + public: // Size-operations: void clear () { map.clear(); } int size () const { return map.elems(); } @@ -405,7 +374,7 @@ public: // TMP debug: void debug(){ - printf("c --- size = %d, bucket_count = %d\n", size(), map.bucket_count()); } + printf(" --- size = %d, bucket_count = %d\n", size(), map.bucket_count()); } }; @@ -447,7 +416,7 @@ inline Lit Clause::subsumes(const Clause& other) const // did not find it return lit_Error; -ok:; + ok:; } return ret; diff --git a/mapleCOMSPS/mapleCOMSPS/doc/ReleaseNotes-2.2.0.txt b/mapleCOMSPS/mapleCOMSPS/doc/ReleaseNotes-2.2.0.txt new file mode 100644 index 0000000..7f084de --- /dev/null +++ b/mapleCOMSPS/mapleCOMSPS/doc/ReleaseNotes-2.2.0.txt @@ -0,0 +1,79 @@ +Release Notes for MiniSat 2.2.0 +=============================== + +Changes since version 2.0: + + * Started using a more standard release numbering. + + * Includes some now well-known heuristics: phase-saving and luby + restarts. The old heuristics are still present and can be activated + if needed. + + * Detection/Handling of out-of-memory and vector capacity + overflow. This is fairly new and relatively untested. + + * Simple resource controls: CPU-time, memory, number of + conflicts/decisions. + + * CPU-time limiting is implemented by a more general, but simple, + asynchronous interruption feature. This means that the solving + procedure can be interrupted from another thread or in a signal + handler. + + * Improved portability with respect to building on Solaris and with + Visual Studio. This is not regularly tested and chances are that + this have been broken since, but should be fairly easy to fix if + so. + + * Changed C++ file-extention to the less problematic ".cc". + + * Source code is now namespace-protected + + * Introducing a new Clause Memory Allocator that brings reduced + memory consumption on 64-bit architechtures and improved + performance (to some extent). The allocator uses a region-based + approach were all references to clauses are represented as a 32-bit + index into a global memory region that contains all clauses. To + free up and compact memory it uses a simple copying garbage + collector. + + * Improved unit-propagation by Blocking Literals. For each entry in + the watcher lists, pair the pointer to a clause with some + (arbitrary) literal from the clause. The idea is that if the + literal is currently true (i.e. the clause is satisfied) the + watchers of the clause does not need to be altered. This can thus + be detected without touching the clause's memory at all. As often + as can be done cheaply, the blocking literal for entries to the + watcher list of a literal 'p' is set to the other literal watched + in the corresponding clause. + + * Basic command-line/option handling system. Makes it easy to specify + options in the class that they affect, and whenever that class is + used in an executable, parsing of options and help messages are + brought in automatically. + + * General clean-up and various minor bug-fixes. + + * Changed implementation of variable-elimination/model-extension: + + - The interface is changed so that arbitrary remembering is no longer + possible. If you need to mention some variable again in the future, + this variable has to be frozen. + + - When eliminating a variable, only clauses that contain the variable + with one sign is necessary to store. Thereby making the other sign + a "default" value when extending models. + + - The memory consumption for eliminated clauses is further improved + by storing all eliminated clauses in a single contiguous vector. + + * Some common utility code (I/O, Parsing, CPU-time, etc) is ripped + out and placed in a separate "utils" directory. + + * The DIMACS parse is refactored so that it can be reused in other + applications (not very elegant, but at least possible). + + * Some simple improvements to scalability of preprocessing, using + more lazy clause removal from data-structures and a couple of + ad-hoc limits (the longest clause that can be produced in variable + elimination, and the longest clause used in backward subsumption). diff --git a/lstech_maple/lstech/mtl/Alg.h b/mapleCOMSPS/mapleCOMSPS/mtl/Alg.h old mode 100755 new mode 100644 similarity index 96% rename from lstech_maple/lstech/mtl/Alg.h rename to mapleCOMSPS/mapleCOMSPS/mtl/Alg.h index bb1ee5a..c3859a5 --- a/lstech_maple/lstech/mtl/Alg.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/Alg.h @@ -18,12 +18,12 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Alg_h -#define Minisat_Alg_h +#ifndef MapleCOMSPS_Alg_h +#define MapleCOMSPS_Alg_h -#include "mtl/Vec.h" +#include "../mtl/Vec.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // Useful functions on vector-like types: diff --git a/lstech_maple/lstech/mtl/Alloc.h b/mapleCOMSPS/mapleCOMSPS/mtl/Alloc.h old mode 100755 new mode 100644 similarity index 91% rename from lstech_maple/lstech/mtl/Alloc.h rename to mapleCOMSPS/mapleCOMSPS/mtl/Alloc.h index 76322b8..d71a435 --- a/lstech_maple/lstech/mtl/Alloc.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/Alloc.h @@ -18,13 +18,13 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA **************************************************************************************************/ -#ifndef Minisat_Alloc_h -#define Minisat_Alloc_h +#ifndef MapleCOMSPS_Alloc_h +#define MapleCOMSPS_Alloc_h -#include "mtl/XAlloc.h" -#include "mtl/Vec.h" +#include "../mtl/XAlloc.h" +#include "../mtl/Vec.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // Simple Region-based memory allocator: @@ -79,7 +79,14 @@ class RegionAllocator sz = cap = wasted_ = 0; } - + void copyTo(RegionAllocator& to) const { + // if (to.memory != NULL) ::free(to.memory); + to.memory = (T*)xrealloc(to.memory, sizeof(T)*cap); + memcpy(to.memory,memory,sizeof(T)*cap); + to.sz = sz; + to.cap = cap; + to.wasted_ = wasted_; + } }; template diff --git a/lstech_maple/lstech/mtl/Heap.h b/mapleCOMSPS/mapleCOMSPS/mtl/Heap.h old mode 100755 new mode 100644 similarity index 96% rename from lstech_maple/lstech/mtl/Heap.h rename to mapleCOMSPS/mapleCOMSPS/mtl/Heap.h index b73f9e2..aa27ab6 --- a/lstech_maple/lstech/mtl/Heap.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/Heap.h @@ -18,12 +18,12 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Heap_h -#define Minisat_Heap_h +#ifndef MapleCOMSPS_Heap_h +#define MapleCOMSPS_Heap_h -#include "mtl/Vec.h" +#include "../mtl/Vec.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // A heap implementation with support for decrease/increase key. @@ -84,6 +84,7 @@ class Heap { void decrease (int n) { assert(inHeap(n)); percolateUp (indices[n]); } void increase (int n) { assert(inHeap(n)); percolateDown(indices[n]); } + void copyTo(Heap& copy) const {heap.copyTo(copy.heap);indices.copyTo(copy.indices);} // Safe variant of insert/decrease/increase: void update(int n) diff --git a/lstech_maple/lstech/mtl/IntTypes.h b/mapleCOMSPS/mapleCOMSPS/mtl/IntTypes.h old mode 100755 new mode 100644 similarity index 96% rename from lstech_maple/lstech/mtl/IntTypes.h rename to mapleCOMSPS/mapleCOMSPS/mtl/IntTypes.h index c488162..498fa45 --- a/lstech_maple/lstech/mtl/IntTypes.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/IntTypes.h @@ -17,8 +17,8 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_IntTypes_h -#define Minisat_IntTypes_h +#ifndef MapleCOMSPS_IntTypes_h +#define MapleCOMSPS_IntTypes_h #ifdef __sun // Not sure if there are newer versions that support C99 headers. The diff --git a/lstech_maple/lstech/mtl/Map.h b/mapleCOMSPS/mapleCOMSPS/mtl/Map.h old mode 100755 new mode 100644 similarity index 98% rename from lstech_maple/lstech/mtl/Map.h rename to mapleCOMSPS/mapleCOMSPS/mtl/Map.h index 8a82d0e..3ba1f92 --- a/lstech_maple/lstech/mtl/Map.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/Map.h @@ -17,13 +17,13 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Map_h -#define Minisat_Map_h +#ifndef MapleCOMSPS_Map_h +#define MapleCOMSPS_Map_h -#include "mtl/IntTypes.h" -#include "mtl/Vec.h" +#include "../mtl/IntTypes.h" +#include "../mtl/Vec.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // Default hash/equals functions diff --git a/lstech_maple/lstech/mtl/Queue.h b/mapleCOMSPS/mapleCOMSPS/mtl/Queue.h old mode 100755 new mode 100644 similarity index 92% rename from lstech_maple/lstech/mtl/Queue.h rename to mapleCOMSPS/mapleCOMSPS/mtl/Queue.h index 17567d6..13fd4b0 --- a/lstech_maple/lstech/mtl/Queue.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/Queue.h @@ -18,12 +18,12 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Queue_h -#define Minisat_Queue_h +#ifndef MapleCOMSPS_Queue_h +#define MapleCOMSPS_Queue_h -#include "mtl/Vec.h" +#include "../mtl/Vec.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= @@ -46,6 +46,11 @@ public: T peek () const { assert(first != end); return buf[first]; } void pop () { assert(first != end); first++; if (first == buf.size()) first = 0; } + void copyTo(Queue& copy) const { + copy.first = first; + copy.end = end; + buf.memCopyTo(copy.buf); + } void insert(T elem) { // INVARIANT: buf[end] is always unused buf[end++] = elem; if (end == buf.size()) end = 0; diff --git a/lstech_maple/lstech/mtl/Sort.h b/mapleCOMSPS/mapleCOMSPS/mtl/Sort.h old mode 100755 new mode 100644 similarity index 96% rename from lstech_maple/lstech/mtl/Sort.h rename to mapleCOMSPS/mapleCOMSPS/mtl/Sort.h index e9313ef..484cbd1 --- a/lstech_maple/lstech/mtl/Sort.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/Sort.h @@ -18,16 +18,16 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Sort_h -#define Minisat_Sort_h +#ifndef MapleCOMSPS_Sort_h +#define MapleCOMSPS_Sort_h -#include "mtl/Vec.h" +#include "../mtl/Vec.h" //================================================================================================= // Some sorting algorithms for vec's -namespace Minisat { +namespace MapleCOMSPS { template struct LessThan_default { diff --git a/lstech_maple/lstech/mtl/Vec.h b/mapleCOMSPS/mapleCOMSPS/mtl/Vec.h old mode 100755 new mode 100644 similarity index 94% rename from lstech_maple/lstech/mtl/Vec.h rename to mapleCOMSPS/mapleCOMSPS/mtl/Vec.h index 9e22085..fe368a1 --- a/lstech_maple/lstech/mtl/Vec.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/Vec.h @@ -18,16 +18,17 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Vec_h -#define Minisat_Vec_h +#ifndef MapleCOMSPS_Vec_h +#define MapleCOMSPS_Vec_h #include #include +#include -#include "mtl/IntTypes.h" -#include "mtl/XAlloc.h" +#include "../mtl/IntTypes.h" +#include "../mtl/XAlloc.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // Automatically resizable arrays @@ -89,6 +90,11 @@ public: // Duplicatation (preferred instead): void copyTo(vec& copy) const { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; } void moveTo(vec& dest) { dest.clear(true); dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; } + void memCopyTo(vec& copy) const{ + copy.capacity(cap); + copy.sz = sz; + memcpy(copy.data,data,sizeof(T)*cap); + } }; diff --git a/lstech_maple/lstech/mtl/XAlloc.h b/mapleCOMSPS/mapleCOMSPS/mtl/XAlloc.h old mode 100755 new mode 100644 similarity index 95% rename from lstech_maple/lstech/mtl/XAlloc.h rename to mapleCOMSPS/mapleCOMSPS/mtl/XAlloc.h index 1da1760..6eb0ec3 --- a/lstech_maple/lstech/mtl/XAlloc.h +++ b/mapleCOMSPS/mapleCOMSPS/mtl/XAlloc.h @@ -18,13 +18,13 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA **************************************************************************************************/ -#ifndef Minisat_XAlloc_h -#define Minisat_XAlloc_h +#ifndef MapleCOMSPS_XAlloc_h +#define MapleCOMSPS_XAlloc_h #include #include -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= // Simple layer on top of malloc/realloc to catch out-of-memory situtaions and provide some typing: diff --git a/lstech_maple/lstech/mtl/config.mk b/mapleCOMSPS/mapleCOMSPS/mtl/config.mk old mode 100755 new mode 100644 similarity index 100% rename from lstech_maple/lstech/mtl/config.mk rename to mapleCOMSPS/mapleCOMSPS/mtl/config.mk diff --git a/lstech_maple/lstech/mtl/template.mk b/mapleCOMSPS/mapleCOMSPS/mtl/template.mk old mode 100755 new mode 100644 similarity index 88% rename from lstech_maple/lstech/mtl/template.mk rename to mapleCOMSPS/mapleCOMSPS/mtl/template.mk index 8db220e..616a252 --- a/lstech_maple/lstech/mtl/template.mk +++ b/mapleCOMSPS/mapleCOMSPS/mtl/template.mk @@ -1,107 +1,107 @@ -## -## Template makefile for Standard, Profile, Debug, Release, and Release-static versions -## -## eg: "make rs" for a statically linked release version. -## "make d" for a debug version (no optimizations). -## "make" for the standard version (optimized, but with debug information and assertions active) - -PWD = $(shell pwd) -EXEC ?= $(notdir $(PWD)) - -CSRCS = $(wildcard $(PWD)/*.cc) -DSRCS = $(foreach dir, $(DEPDIR), $(filter-out $(MROOT)/$(dir)/Main.cc, $(wildcard $(MROOT)/$(dir)/*.cc))) -CHDRS = $(wildcard $(PWD)/*.h) -COBJS = $(CSRCS:.cc=.o) $(DSRCS:.cc=.o) - -PCOBJS = $(addsuffix p, $(COBJS)) -DCOBJS = $(addsuffix d, $(COBJS)) -RCOBJS = $(addsuffix r, $(COBJS)) - - -CXX ?= g++ -CFLAGS ?= -Wall -Wno-parentheses -std=c++11 -LFLAGS ?= -Wall - -COPTIMIZE ?= -O3 - -CFLAGS += -I$(MROOT) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -LFLAGS += -lz - -.PHONY : s p d r rs clean - -s: $(EXEC) -p: $(EXEC)_profile -d: $(EXEC)_debug -r: $(EXEC)_release -rs: $(EXEC)_static - -libs: lib$(LIB)_standard.a -libp: lib$(LIB)_profile.a -libd: lib$(LIB)_debug.a -libr: lib$(LIB)_release.a - -## Compile options -%.o: CFLAGS +=$(COPTIMIZE) -g -D DEBUG -%.op: CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG -%.od: CFLAGS +=-O0 -g -D DEBUG -%.or: CFLAGS +=$(COPTIMIZE) -g -D NDEBUG - -## Link options -$(EXEC): LFLAGS += -g -$(EXEC)_profile: LFLAGS += -g -pg -$(EXEC)_debug: LFLAGS += -g -#$(EXEC)_release: LFLAGS += ... -$(EXEC)_static: LFLAGS += --static - -## Dependencies -$(EXEC): $(COBJS) -$(EXEC)_profile: $(PCOBJS) -$(EXEC)_debug: $(DCOBJS) -$(EXEC)_release: $(RCOBJS) -$(EXEC)_static: $(RCOBJS) - -lib$(LIB)_standard.a: $(filter-out */Main.o, $(COBJS)) -lib$(LIB)_profile.a: $(filter-out */Main.op, $(PCOBJS)) -lib$(LIB)_debug.a: $(filter-out */Main.od, $(DCOBJS)) -lib$(LIB)_release.a: $(filter-out */Main.or, $(RCOBJS)) - - -## Build rule -%.o %.op %.od %.or: %.cc - @echo Compiling: $(subst $(MROOT)/,,$@) - @$(CXX) $(CFLAGS) -c -o $@ $< - -## Linking rules (standard/profile/debug/release) -$(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static: - @echo Linking: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" - @$(CXX) $^ $(LFLAGS) -o $@ - -## Library rules (standard/profile/debug/release) -lib$(LIB)_standard.a lib$(LIB)_profile.a lib$(LIB)_release.a lib$(LIB)_debug.a: - @echo Making library: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" - @$(AR) -rcsv $@ $^ - -## Library Soft Link rule: -libs libp libd libr: - @echo "Making Soft Link: $^ -> lib$(LIB).a" - @ln -sf $^ lib$(LIB).a - -## Clean rule -clean: - @rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \ - $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk - -## Make dependencies -depend.mk: $(CSRCS) $(CHDRS) - @echo Making dependencies - @$(CXX) $(CFLAGS) -I$(MROOT) \ - $(CSRCS) -MM | sed 's|\(.*\):|$(PWD)/\1 $(PWD)/\1r $(PWD)/\1d $(PWD)/\1p:|' > depend.mk - @for dir in $(DEPDIR); do \ - if [ -r $(MROOT)/$${dir}/depend.mk ]; then \ - echo Depends on: $${dir}; \ - cat $(MROOT)/$${dir}/depend.mk >> depend.mk; \ - fi; \ - done - --include $(MROOT)/mtl/config.mk --include depend.mk +## +## Template makefile for Standard, Profile, Debug, Release, and Release-static versions +## +## eg: "make rs" for a statically linked release version. +## "make d" for a debug version (no optimizations). +## "make" for the standard version (optimized, but with debug information and assertions active) + +PWD = $(shell pwd) +EXEC ?= $(notdir $(PWD)) + +CSRCS = $(wildcard $(PWD)/*.cc) +DSRCS = $(foreach dir, $(DEPDIR), $(filter-out $(MROOT)/$(dir)/Main.cc, $(wildcard $(MROOT)/$(dir)/*.cc))) +CHDRS = $(wildcard $(PWD)/*.h) +COBJS = $(CSRCS:.cc=.o) $(DSRCS:.cc=.o) + +PCOBJS = $(addsuffix p, $(COBJS)) +DCOBJS = $(addsuffix d, $(COBJS)) +RCOBJS = $(addsuffix r, $(COBJS)) + + +CXX ?= g++ +CFLAGS ?= -Wall -Wno-parentheses +LFLAGS ?= -Wall + +COPTIMIZE ?= -O3 + +CFLAGS += -I$(MROOT) -I$(MROOT)/../m4ri-20140914 -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS +LFLAGS += -L$(MROOT)/../m4ri-20140914/.libs -lz -lm4ri + +.PHONY : s p d r rs clean + +s: $(EXEC) +p: $(EXEC)_profile +d: $(EXEC)_debug +r: $(EXEC)_release +rs: $(EXEC)_static + +libs: lib$(LIB)_standard.a +libp: lib$(LIB)_profile.a +libd: lib$(LIB)_debug.a +libr: lib$(LIB)_release.a + +## Compile options +%.o: CFLAGS +=$(COPTIMIZE) -g -D DEBUG +%.op: CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG +%.od: CFLAGS +=-O0 -g -D DEBUG +%.or: CFLAGS +=$(COPTIMIZE) -g -D NDEBUG + +## Link options +$(EXEC): LFLAGS += -g +$(EXEC)_profile: LFLAGS += -g -pg +$(EXEC)_debug: LFLAGS += -g +#$(EXEC)_release: LFLAGS += ... +$(EXEC)_static: LFLAGS += --static + +## Dependencies +$(EXEC): $(COBJS) +$(EXEC)_profile: $(PCOBJS) +$(EXEC)_debug: $(DCOBJS) +$(EXEC)_release: $(RCOBJS) +$(EXEC)_static: $(RCOBJS) + +lib$(LIB)_standard.a: $(filter-out */Main.o, $(COBJS)) +lib$(LIB)_profile.a: $(filter-out */Main.op, $(PCOBJS)) +lib$(LIB)_debug.a: $(filter-out */Main.od, $(DCOBJS)) +lib$(LIB)_release.a: $(filter-out */Main.or, $(RCOBJS)) + + +## Build rule +%.o %.op %.od %.or: %.cc + @echo Compiling: $(subst $(MROOT)/,,$@) + @$(CXX) $(CFLAGS) -c -o $@ $< + +## Linking rules (standard/profile/debug/release) +$(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static: + @echo Linking: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" + @$(CXX) $^ $(LFLAGS) -o $@ + +## Library rules (standard/profile/debug/release) +lib$(LIB)_standard.a lib$(LIB)_profile.a lib$(LIB)_release.a lib$(LIB)_debug.a: + @echo Making library: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" + @$(AR) -rcsv $@ $^ + +## Library Soft Link rule: +libs libp libd libr: + @echo "Making Soft Link: $^ -> lib$(LIB).a" + @ln -sf $^ lib$(LIB).a + +## Clean rule +clean: + @rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \ + $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk + +## Make dependencies +depend.mk: $(CSRCS) $(CHDRS) + @echo Making dependencies + @$(CXX) $(CFLAGS) -I$(MROOT) \ + $(CSRCS) -MM | sed 's|\(.*\):|$(PWD)/\1 $(PWD)/\1r $(PWD)/\1d $(PWD)/\1p:|' > depend.mk + @for dir in $(DEPDIR); do \ + if [ -r $(MROOT)/$${dir}/depend.mk ]; then \ + echo Depends on: $${dir}; \ + cat $(MROOT)/$${dir}/depend.mk >> depend.mk; \ + fi; \ + done + +-include $(MROOT)/mtl/config.mk +-include depend.mk diff --git a/lstech_maple/lstech/simp/Main.cc b/mapleCOMSPS/mapleCOMSPS/simp/Main.cc old mode 100755 new mode 100644 similarity index 85% rename from lstech_maple/lstech/simp/Main.cc rename to mapleCOMSPS/mapleCOMSPS/simp/Main.cc index 9570e59..400412a --- a/lstech_maple/lstech/simp/Main.cc +++ b/mapleCOMSPS/mapleCOMSPS/simp/Main.cc @@ -3,16 +3,7 @@ Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson Copyright (c) 2007, Niklas Sorensson Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh - -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - -MapleLCMDistChronoBT, based on Maple_LCM_Dist -- Copyright (c), Alexander Nadel, Vadim Ryvchin: "Chronological Backtracking" in SAT-2018, pp. 111-121. - -MapleLCMDistChronoBT-DL, based on MapleLCMDistChronoBT -- Copyright (c), Stepan Kochemazov, Oleg Zaikin, Victor Kondratiev, Alexander Semenov: The solver was augmented with heuristic that moves duplicate learnt clauses into the core/tier2 tiers depending on a number of parameters. - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, @@ -35,13 +26,13 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA #include #include -#include "utils/System.h" -#include "utils/ParseUtils.h" -#include "utils/Options.h" -#include "core/Dimacs.h" -#include "simp/SimpSolver.h" +#include "../utils/System.h" +#include "../utils/ParseUtils.h" +#include "../utils/Options.h" +#include "../core/Dimacs.h" +#include "../simp/SimpSolver.h" -using namespace Minisat; +using namespace MapleCOMSPS; //================================================================================================= @@ -51,13 +42,10 @@ void printStats(Solver& solver) double cpu_time = cpuTime(); double mem_used = memUsedPeak(); printf("c restarts : %"PRIu64"\n", solver.starts); - printf("c duplicate learnts_cnf : %"PRIu64"\n", solver.duplicates_added_conflicts); - printf("c duplicate learnts_min : %"PRIu64"\n", solver.duplicates_added_minimization); printf("c conflicts : %-12"PRIu64" (%.0f /sec)\n", solver.conflicts , solver.conflicts /cpu_time); printf("c decisions : %-12"PRIu64" (%4.2f %% random) (%.0f /sec)\n", solver.decisions, (float)solver.rnd_decisions*100 / (float)solver.decisions, solver.decisions /cpu_time); printf("c propagations : %-12"PRIu64" (%.0f /sec)\n", solver.propagations, solver.propagations/cpu_time); printf("c conflict literals : %-12"PRIu64" (%4.2f %% deleted)\n", solver.tot_literals, (solver.max_literals - solver.tot_literals)*100 / (double)solver.max_literals); - printf("c backtracks : %-12"PRIu64" (NCB %0.f%% , CB %0.f%%)\n", solver.non_chrono_backtrack + solver.chrono_backtrack, (solver.non_chrono_backtrack * 100) / (double)(solver.non_chrono_backtrack + solver.chrono_backtrack), (solver.chrono_backtrack * 100) / (double)(solver.non_chrono_backtrack + solver.chrono_backtrack)); if (mem_used != 0) printf("c Memory used : %.2f MB\n", mem_used); printf("c CPU time : %g s\n", cpu_time); } @@ -86,7 +74,7 @@ int main(int argc, char** argv) { try { setUsageHelp("USAGE: %s [options] \n\n where input may be either in plain or gzipped DIMACS.\n"); - printf("c This is MapleLCMDistChronoBT-DL.\n"); + printf("c This is COMiniSatPS.\n"); #if defined(__linux__) fpu_control_t oldcw, newcw; @@ -112,7 +100,6 @@ int main(int argc, char** argv) S.parsing = true; S.verbosity = verb; - S.drup_file = NULL; if (drup || strlen(drup_file)){ S.drup_file = strlen(drup_file) ? fopen(drup_file, "wb") : stdout; if (S.drup_file == NULL){ @@ -219,8 +206,6 @@ int main(int argc, char** argv) printf("\n"); } printf(ret == l_True ? "s SATISFIABLE\n" : ret == l_False ? "s UNSATISFIABLE\n" : "s UNKNOWN\n"); if (ret == l_True){ - // check_solution_DIMACS(in, S); - // printf("%d",S.nVars()); printf("v "); for (int i = 0; i < S.nVars(); i++) if (S.model[i] != l_Undef) @@ -228,7 +213,6 @@ int main(int argc, char** argv) printf(" 0\n"); } - if (S.drup_file && ret == l_False){ #ifdef BIN_DRUP fputc('a', S.drup_file); fputc(0, S.drup_file); diff --git a/lstech_maple/lstech/simp/Makefile b/mapleCOMSPS/mapleCOMSPS/simp/Makefile old mode 100755 new mode 100644 similarity index 62% rename from lstech_maple/lstech/simp/Makefile rename to mapleCOMSPS/mapleCOMSPS/simp/Makefile index 0004de8..27b45f4 --- a/lstech_maple/lstech/simp/Makefile +++ b/mapleCOMSPS/mapleCOMSPS/simp/Makefile @@ -1,5 +1,4 @@ -EXEC = glucose +EXEC = minisat DEPDIR = mtl utils core -MROOT = ../ include $(MROOT)/mtl/template.mk diff --git a/lstech_maple/lstech/simp/SimpSolver.cc b/mapleCOMSPS/mapleCOMSPS/simp/SimpSolver.cc old mode 100755 new mode 100644 similarity index 59% rename from lstech_maple/lstech/simp/SimpSolver.cc rename to mapleCOMSPS/mapleCOMSPS/simp/SimpSolver.cc index 15c4c7a..0e75d5e --- a/lstech_maple/lstech/simp/SimpSolver.cc +++ b/mapleCOMSPS/mapleCOMSPS/simp/SimpSolver.cc @@ -1,22 +1,8 @@ -/***************************************************************************************[Solver.cc] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson +/***********************************************************************************[SimpSolver.cc] +MiniSat -- Copyright (c) 2006, Niklas Een, Niklas Sorensson Copyright (c) 2007-2010, Niklas Sorensson - + Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh - -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. - -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - -MapleLCMDistChronoBT, based on Maple_LCM_Dist -- Copyright (c), Alexander Nadel, Vadim Ryvchin: "Chronological Backtracking" in SAT-2018, pp. 111-121. - -MapleLCMDistChronoBT-DL, based on MapleLCMDistChronoBT -- Copyright (c), Stepan Kochemazov, Oleg Zaikin, Victor Kondratiev, Alexander Semenov: The solver was augmented with heuristic that moves duplicate learnt clauses into the core/tier2 tiers depending on a number of parameters. - -lstech, Relaxed_newTech -- Copyright (c) 2019-2021, Shaowei Cai, Xindi Zhang -Reference: Shaowei Cai, Xindi Zhang: Deep Cooperation of CDCL and Local Search for SAT. -Xindi Zhang, Shaowei Cai: Relaxed Backtracking with Rephasing. - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -34,11 +20,25 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#include "mtl/Sort.h" -#include "simp/SimpSolver.h" -#include "utils/System.h" +#include +#include +#include "../mtl/Sort.h" +#include "../simp/SimpSolver.h" +#include "../utils/System.h" -using namespace Minisat; +using namespace MapleCOMSPS; + +using std::set; + +typedef set::const_iterator CISETIT; // Not using C++11 at the moment. + +static int stat_gauss = 0, + stat_gauss_case1 = 0, + stat_gauss_case2 = 0, + stat_gauss_bin_added = 0; +static double stat_gauss_time = 0; + +static bool xors_found = false; //================================================================================================= // Options: @@ -84,93 +84,53 @@ SimpSolver::SimpSolver() : remove_satisfied = false; } +SimpSolver::SimpSolver(const SimpSolver &s) : Solver(s) + , parsing (s.parsing) + , grow (s.grow) + , clause_lim (s.clause_lim) + , subsumption_lim (s.subsumption_lim) + , simp_garbage_frac (s.simp_garbage_frac) + , use_asymm (s.use_asymm) + , use_rcheck (s.use_rcheck) + , use_elim (s.use_elim) + , merges (s.merges) + , asymm_lits (s.asymm_lits) + , eliminated_vars (s.eliminated_vars) + , elimorder (s.elimorder) + , use_simplification (s.use_simplification) + , occurs (ClauseDeleted(ca)) + , elim_heap (ElimLt(n_occ)) + , bwdsub_assigns (s.bwdsub_assigns) + , n_touched (s.n_touched) +{ + vec dummy(1,lit_Undef); + ca.extra_clause_field = true; // NOTE: must happen before allocating the dummy + //clause below. + bwdsub_tmpunit = ca.alloc(dummy); + remove_satisfied = false; + + s.elimclauses.memCopyTo(elimclauses); + s.touched.memCopyTo(touched); + s.occurs.copyTo(occurs); + s.n_occ.memCopyTo(n_occ); + s.elim_heap.copyTo(elim_heap); + s.subsumption_queue.copyTo(subsumption_queue); + s.frozen.memCopyTo(frozen); + s.eliminated.memCopyTo(eliminated); + + use_simplification = s.use_simplification; + bwdsub_assigns = s.bwdsub_assigns; + n_touched = s.n_touched; + bwdsub_tmpunit = s.bwdsub_tmpunit; + qhead = s.qhead; + ok = s.ok; +} + SimpSolver::~SimpSolver() { } -void SimpSolver::varGrowTo(int maxVar) { - for (int v = 0; v < maxVar; v++) { - watches_bin.init(mkLit(v, false)); - watches_bin.init(mkLit(v, true )); - watches .init(mkLit(v, false)); - watches .init(mkLit(v, true )); - assigns .push(l_Undef); - vardata .push(mkVarData(CRef_Undef, 0)); - activity_CHB .push(0); - activity_VSIDS.push(rnd_init_act ? drand(random_seed) * 0.00001 : 0); - - picked.push(0); - conflicted.push(0); - almost_conflicted.push(0); - #ifdef ANTI_EXPLORATION - canceled.push(0); - #endif - seen .push(0); - seen2 .push(0); - polarity .push(true); - decision .push(); - trail .capacity(v+1); - - frozen .push((char)false); - eliminated.push((char)false); - - if (use_simplification){ - n_occ .push(0); - n_occ .push(0); - occurs .init(v); - touched .push(0); - elim_heap .insert(v); - } - } - - int seed = worker_seed; - int index = worker_index; - int number = worker_number; - if (seed != -1) { - int *id; - id = (int *)malloc(sizeof(int) * (maxVar)); - for (int i = 0; i < maxVar; i++) id[i] = i; - if (seed) { - unsigned int rseed = seed; - for (int i = 0; i < maxVar; i++) { - int j = rand_r(&rseed) % maxVar; - int x = id[i]; - id[i] = id[j]; - id[j] = x; - } - } - int block_size = maxVar / number; - int cursor = index * block_size; - for (int v = cursor; v < maxVar; v++) { - setDecisionVar(id[v], true); - } - for (int v = 0; v < cursor; v++) { - setDecisionVar(id[v], true); - } - // printf("c maxVar %d, index:%d number:%d seed:%d\n", maxVar, index, number, seed); - // for (int v = cursor; v < maxVar; v++) { - // printf("%d ", id[v]); - // } - // for (int v = 0; v < cursor; v++) { - // printf("%d ", id[v]); - // } - // puts(""); - free(id); - } - else { - for (int v = 0; v < maxVar; v++) { - setDecisionVar(v, true); - } - // printf("c maxVar %d, index:%d number:%d seed:%d\n", maxVar, index, number, seed); - // for (int v = 0; v < maxVar; v++) { - // printf("%d ", v); - // } - // puts(""); - } -} - - Var SimpSolver::newVar(bool sign, bool dvar) { Var v = Solver::newVar(sign, dvar); @@ -209,7 +169,6 @@ lbool SimpSolver::solve_(bool do_simp, bool turn_off_simp) setFrozen(v, true); extra_frozen.push(v); } } - result = lbool(eliminate(turn_off_simp)); } @@ -619,7 +578,7 @@ bool SimpSolver::eliminateVar(Var v) for (int i = 0; i < pos.size(); i++) for (int j = 0; j < neg.size(); j++) - if (merge(ca[pos[i]], ca[neg[j]], v, clause_size) && + if (merge(ca[pos[i]], ca[neg[j]], v, clause_size) && (++cnt > cls.size() + grow || (clause_lim != -1 && clause_size > clause_lim))) return true; @@ -646,11 +605,11 @@ bool SimpSolver::eliminateVar(Var v) return false; for (int i = 0; i < cls.size(); i++) - removeClause(cls[i]); + removeClause(cls[i]); // Free occurs list for this variable: occurs[v].clear(true); - + // Free watchers lists for this variable, if possible: watches_bin[ mkLit(v)].clear(true); watches_bin[~mkLit(v)].clear(true); @@ -672,7 +631,7 @@ bool SimpSolver::substitute(Var v, Lit x) eliminated[v] = true; setDecisionVar(v, false); const vec& cls = occurs.lookup(v); - + vec& subst_clause = add_tmp; for (int i = 0; i < cls.size(); i++){ Clause& c = ca[cls[i]]; @@ -732,7 +691,14 @@ bool SimpSolver::eliminate(bool turn_off_elim) int iter = 0; int n_cls, n_cls_init, n_vars; - if (nVars() == 0) goto cleanup; // User disabling preprocessing. + if (nVars() == 0 || !use_simplification){ + if (!simplify()) return false; + goto cleanup; } + + if (GE) { + res = gaussElim(); + if (!res) goto cleanup; + } // Get an initial number of clauses (more accurately). if (trail.size() != 0) removeSatisfied(); @@ -746,6 +712,10 @@ bool SimpSolver::eliminate(bool turn_off_elim) //printf("c Reduced to %d vars, %d cls (grow=%d)\n", n_vars, n_cls, grow); + if (!xors_found && GE){ // Second chance to do Gaussian elimination. + res = gaussElim(); + if (!res) goto cleanup; } + if ((double)n_cls / n_vars >= 10 || n_vars < 10000){ //printf("c No iterative elimination performed. (vars=%d, c/v ratio=%.1f)\n", n_vars, (double)n_cls / n_vars); goto cleanup; } @@ -782,6 +752,8 @@ bool SimpSolver::eliminate(bool turn_off_elim) //printf("c No. effective iterative eliminations: %d\n", iter); cleanup: + //printf("c [GE] total time: %.2f\n", stat_gauss_time); + touched .clear(true); occurs .clear(true); n_occ .clear(true); @@ -815,7 +787,7 @@ bool SimpSolver::eliminate_() gatherTouchedClauses(); // printf(" ## (time = %6.2f s) BWD-SUB: queue = %d, trail = %d\n", cpuTime(), subsumption_queue.size(), trail.size() - bwdsub_assigns); - if ((subsumption_queue.size() > 0 || bwdsub_assigns < trail.size()) && + if ((subsumption_queue.size() > 0 || bwdsub_assigns < trail.size()) && !backwardSubsumptionCheck(true)){ ok = false; goto cleanup; } @@ -830,7 +802,7 @@ bool SimpSolver::eliminate_() // printf(" ## (time = %6.2f s) ELIM: vars = %d\n", cpuTime(), elim_heap.size()); for (int cnt = 0; !elim_heap.empty(); cnt++){ Var elim = elim_heap.removeMin(); - + if (asynch_interrupt) break; if (isEliminated(elim) || value(elim) != l_Undef) continue; @@ -870,7 +842,7 @@ bool SimpSolver::eliminate_() checkGarbage(); if (verbosity >= 1 && elimclauses.size() > 0) - printf("c | Eliminated clauses: %10.2f Mb |\n", + printf("c | Eliminated clauses: %10.2f Mb |\n", double(elimclauses.size() * sizeof(uint32_t)) / (1024*1024)); return ok; @@ -909,13 +881,382 @@ void SimpSolver::garbageCollect() { // Initialize the next region to a size corresponding to the estimated utilization degree. This // is not precise but should avoid some unnecessary reallocations for the new region: - ClauseAllocator to(ca.size() - ca.wasted()); + ClauseAllocator to(ca.size() - ca.wasted()); to.extra_clause_field = ca.extra_clause_field; // NOTE: this is important to keep (or lose) the extra fields. relocAll(to); Solver::relocAll(to); if (verbosity >= 2) - printf("c | Garbage collection: %12d bytes => %12d bytes |\n", + printf("c | Garbage collection: %12d bytes => %12d bytes |\n", ca.size()*ClauseAllocator::Unit_Size, to.size()*ClauseAllocator::Unit_Size); to.moveTo(ca); } + + +#ifndef NDEBUG +static bool sanityCheck(const vec& xor_sccs, const vec& v2scc_id, const vec >& var_sccs, int nVars) { + int n_sccs = 0; vec seen_id(var_sccs.size(), 0), seen_v(nVars, 0), seen_v2(nVars, 0); + assert(v2scc_id.size() == nVars); + for (int i = 0; i < v2scc_id.size(); i++){ + int id = v2scc_id[i]; + if (id != -1){ + if (!seen_id[id]) n_sccs++; + seen_v[i] = seen_id[id] = 1; } } + for (int i = 0; i < xor_sccs.size(); i++){ + n_sccs--; assert(xor_sccs[i]); assert(xor_sccs[i]->vars.size() > 2); assert(xor_sccs[i]->xors.size() != 0); + for (int j = 0; j < xor_sccs[i]->xors.size(); j++){ + const Xor& x = *xor_sccs[i]->xors[j]; + for (int k = 0; k < x.size(); k++){ + assert(seen_v[x[k]]); + seen_v2[x[k]] = 1; } } } + for (int i = 0; i < seen_v2.size(); i++) + if (seen_v2[i]) assert(v2scc_id[i] != -1); + else assert(v2scc_id[i] == -1); + assert(n_sccs == 0); + for (int i = 0; i < var_sccs.size(); i++) assert(var_sccs[i].size() == 0); + return true; +} +#endif + +class Stopwatch { + double init, ticked; +public: + Stopwatch() { init = ticked = cpuTime(); } + double total() { return ticked - init; } + double tick() { + double now = cpuTime(); + double dur = now - ticked; + ticked = now; + return dur; + } +}; + +bool SimpSolver::gaussElim() { assert(decisionLevel() == 0); + if (drup_file) return true; + + vec xors; // XORs found by "searchXors()". + vec > var_sccs; // SCCs in terms of vars + vec v2scc_id; // var --> SCC ID map + vec xor_sccs; // SCCs in terms of XORs + Stopwatch timer; + + xors_found = searchXors(xors); + printf("c [GE] XORs: %d (time: %.2f)\n", xors.size(), timer.tick()); + + int upper_limit = computeVarSccs(v2scc_id, var_sccs, xors); + computeXorSccs(xor_sccs, xors, v2scc_id, var_sccs, upper_limit); + printf("c [GE] XOR SCCs: %d (time: %.2f)\n", xor_sccs.size(), timer.tick()); + + ok = performGaussElim(xor_sccs); + + for (int i = 0; i < xors.size(); i++) delete xors[i]; + for (int i = 0; i < xor_sccs.size(); i++) delete xor_sccs[i]; + + printf("c [GE] matrices: %d, unary xor: %d, bin xor: %d, bin added: %d (time: %.2f)\n", + stat_gauss, stat_gauss_case1, stat_gauss_case2, stat_gauss_bin_added, timer.tick()); + stat_gauss_time += timer.total(); + if (!ok) printf("c [GE] UNSAT\n"); + + return ok; +} + +// TODO: might not worth checking dup; probably dups are very rare. +void SimpSolver::addBinNoDup(Lit p, Lit q) { + watches_bin.cleanAll(); + const vec& ws_p = watches_bin[~p]; + const vec& ws_q = watches_bin[~q]; + + if (ws_p.size() != 0 && ws_q.size() != 0){ + const vec& ws = ws_p.size() < ws_q.size() ? ws_p : ws_q; + Lit the_other = ws_p.size() < ws_q.size() ? q : p; + for (int i = 0; i < ws.size(); i++) + if (ws[i].blocker == the_other) + return; } // A dup exists; skip. + + add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); + addClause_(add_tmp); + stat_gauss_bin_added++; +} + +bool SimpSolver::performGaussElim(vec& xor_sccs) { + vec v2mzd_v(nVars(), -1); // CNF var --> matrix var + vec mzd_v2v; // matrix var --> CNF var + + for (int i = 0; i < xor_sccs.size(); i++){ + XorScc& scc = *xor_sccs[i]; + if (scc.xors.size() == 1) continue; + assert(scc.vars.size() > 3); assert(scc.xors.size() > 1); + //printf("c SCC %d: %d XORs, %d vars\n", i+1, scc.xors.size(), scc.vars.size()); + if (((uint64_t) scc.vars.size()) * scc.xors.size() > 10000000ULL) continue; + + mzd_v2v.clear(); + sort(scc.vars); + for (int j = 0; j < scc.vars.size(); j++){ // Set up CNF var <--> matrix var mapping + v2mzd_v[scc.vars[j]] = j; + mzd_v2v.push(scc.vars[j]); } + + // Create and fill a matrix. + int cols = scc.vars.size() + 1/*rhs*/; + mzd_t* mat = mzd_init(scc.xors.size(), cols); assert(mzd_is_zero(mat)); + for (int row = 0; row < scc.xors.size(); row++){ + const Xor& x = *scc.xors[row]; + for (int k = 0; k < x.size(); k++){ assert(v2mzd_v[x[k]] < cols-1); + mzd_write_bit(mat, row, v2mzd_v[x[k]], 1); } + if (x.rhs) mzd_write_bit(mat, row, cols-1, 1); } + + stat_gauss++; + mzd_echelonize(mat, true); + mzd_free(mat); + + // Examine the result. + for (int row = 0, rhs; row < scc.xors.size(); row++){ + vec ones; + for (int col = 0; col < cols-1; col++) + if (mzd_read_bit(mat, row, col)){ + if (ones.size() == 2) goto NextRow; // More than two columns have 1; give up. + ones.push(mzd_v2v[col]); } + + rhs = mzd_read_bit(mat, row, cols-1); + if (ones.size() == 1){ + stat_gauss_case1++; + uncheckedEnqueue(mkLit(ones[0], !rhs)); + }else if (ones.size() == 2){ // If so, we may add two binary clauses. + stat_gauss_case2++; + + // x + y = 1 --> same signs, i.e., ( x v y) ^ (~x v ~y) + // x + y = 0 --> different signs, i.e., (~x v y) ^ ( x v ~y) + Lit p = mkLit(ones[0], false); + Lit q = mkLit(ones[1], !rhs); + addBinNoDup(p, q); addBinNoDup(~p, ~q); + }else // empty case + if (rhs) return false; // 0 = 1, i.e., UNSAT + NextRow:; + } + } + + return propagate() == CRef_Undef; +} + +inline static void sortAfterCopy(const Clause& c, vec& out) { + out.clear(); + for (int i = 0; i < c.size(); i++) out.push(c[i]); + sort(out); +} + +int SimpSolver::toDupMarkerIdx(const Clause& c) { + sortAfterCopy(c, add_tmp); + + int idx = 0; + for (int i = 0; i < add_tmp.size(); i++) + if (sign(add_tmp[i])) + idx |= (1 << i); + return idx; +} + +class SeenMarker { + const Clause& c; + vec& seen; +public: + SeenMarker(const Clause& c_, vec& seen_) : c(c_), seen(seen_) { + for (int i = 0; i < c.size(); i++) seen[var(c[i])] = 1; + } + ~SeenMarker() { + for (int i = 0; i < c.size(); i++) seen[var(c[i])] = 0; + } +}; + +class ClauseMarker { // Will break if garbage collection happens before destruction. + ClauseAllocator& ca; + vec to_clean; +public: + ClauseMarker(ClauseAllocator& ca_) : ca(ca_) {} + ~ClauseMarker() { + for (int i = 0; i < to_clean.size(); i++) {assert(ca[to_clean[i]].mark() == 3); + ca[to_clean[i]].mark(0); } + } + + inline void mark3(CRef cr) { assert(ca[cr].mark() == 0); + ca[cr].mark(3); + to_clean.push(cr); + } +}; + +#define MAX_XOR_SIZE_LIMIT 6 +bool SimpSolver::searchXors(vec& /*out*/ xors) { assert(xors.size() == 0); + vec pool; + vec dup_table; + ClauseMarker cl_marker(ca); + + for (int i = 0; i < clauses.size(); i++){ + Clause& c = ca[clauses[i]]; assert(c.mark() == 0 || c.mark() == 3); + + if (c.mark() == 3) continue; + cl_marker.mark3(clauses[i]); + + if (c.size() == 2 || c.size() > MAX_XOR_SIZE_LIMIT) continue; + + // Find a var with a min-size occurrences list. + Var min_occ_v = var_Undef; + int min_occ = INT_MAX; + const int required_h = 1 << (c.size() - 2); // half of #required clauses to form a single XOR + bool skip = false; + for (int j = 0; j < c.size(); j++){ + int n_occ_p = n_occ[toInt(c[j])]; + int n_occ_not_p = n_occ[toInt(~c[j])]; + if (n_occ_p < required_h || n_occ_not_p < required_h){ + skip = true; break; } + + int occ = n_occ_p + n_occ_not_p; + if (occ < min_occ){ + min_occ = occ; + min_occ_v = var(c[j]); } } + if (skip) continue; // Short-circuit if not enough clauses to form an XOR. + + // Gather classes to look into. + pool.clear(); + pool.push(clauses[i]); + vec& occs = occurs.lookup(min_occ_v); + for (int j = 0; j < occs.size(); j++){ + const Clause& c2 = ca[occs[j]]; assert(c2.mark() == 0 || c2.mark() == 3); + + if (c2.mark() == 0 && c2.size() == c.size() && c2.abstraction() == c.abstraction()) + pool.push(occs[j]); } + if (pool.size() < 2 * required_h) continue; // Short-circuit if not enough clauses. + + // We'll consider only clauses with the exact same set of vars. + SeenMarker seen_marker(c, seen); + + dup_table.clear(); + dup_table.growTo(1 << MAX_XOR_SIZE_LIMIT, false); + int rhs[2] = { 0, 0 }, idx; + for (int j = 0; j < pool.size(); j++){ + Clause& c2 = ca[pool[j]]; assert(c2.size() == c.size()); + assert(j == 0 || c2.mark() == 0); assert(j != 0 || c2.mark() == 3); + bool even_negs = true; + for (int k = 0; k < c2.size(); k++){ + if (!seen[var(c2[k])]) goto Next; + if (sign(c2[k])) even_negs = !even_negs; } + + // CNF might have duplicate clauses. (Typically unusual, but to be safe.) + idx = toDupMarkerIdx(c2); + if (dup_table[idx]) continue; + dup_table[idx] = true; + + rhs[even_negs]++; + + if (j != 0) cl_marker.mark3(pool[j]); + Next:; + } + + assert(rhs[0] <= 2 * required_h); assert(rhs[1] <= 2 * required_h); + if (rhs[0] == 2 * required_h) xors.push(new Xor(c, 0 /*rhs*/)); + if (rhs[1] == 2 * required_h) xors.push(new Xor(c, 1 /*rhs*/)); + } + + return xors.size() != 0; +} + +struct SizeDec { + bool operator () (const Xor* a, const Xor* b) const { + return a->size() > b->size(); + } +}; + +int SimpSolver::computeVarSccs(vec& /*out*/ scc_id, vec >& /*out*/ sccs, vec& xors) const { + assert(scc_id.size() == 0); assert(sccs.size() == 0); +/* + Commenting out: why bother removing solitary XORs (XOR not connected to any XORs)? + This case will naturally be taken care of when computing SCCs. + + vec seen(nVars(), 0); + for (int i = 0; i < xors.size(); i++) + for (int j = 0; j < x.size(); j++) + seen[x[j]]++; + + for (int i = j = 0; i < xors.size(); i++){ + vec& x = *xors[i]; + bool solitary = true; + for (int j = 0; j < x.size(); j++){ + if (seen[x[j]] != 1){ + solitary = false; break; }} + + if (solitary) xors[i]; + else xors[j++] = xors[i]; + } + xors.shrink(i - j); +*/ + scc_id.growTo(nVars(), -1); // var --> SSC ID map + + set x_ids; + sort(xors, SizeDec()); // optimization + for (int i = 0; i < xors.size(); i++){ assert(xors[i]); + const Xor& x = *xors[i]; assert(x.size() > 2); + + x_ids.clear(); + for (int j = 0; j < x.size(); j++) + if (scc_id[x[j]] != -1) + x_ids.insert(scc_id[x[j]]); + + if (x_ids.empty()){ // No mapping exists for all the vars. Create a new SCC. + sccs.push(); + for (int j = 0; j < x.size(); j++){ assert(x[j] < scc_id.size()); assert(scc_id[x[j]] == -1); + scc_id[x[j]] = sccs.size() - 1; assert(scc_id[x[j]] >= 0); + sccs.last().push(x[j]); } assert(sccs.last().size() == x.size()); + }else if (x_ids.size() == 1){ // Not really necessary but for optimization. + int id = *x_ids.begin(); assert(id != -1); assert(id < sccs.size()); + for (int j = 0; j < x.size(); j++){ assert(x[j] < scc_id.size()); + if (scc_id[x[j]] == -1) { + scc_id[x[j]] = id; + sccs[id].push(x[j]); }else assert(scc_id[x[j]] == id); } + }else{ + // Identify the largest SCC, into which we'll merge smaller SCCs. + // (Not sure if it's worth doing this optimization though.) + int id_max = -1; int sz_max = 0; + for (CISETIT it = x_ids.begin(); it != x_ids.end(); it++) + if (sccs[*it].size() > sz_max) + sz_max = sccs[id_max = *it].size(); + + // Now merge smaller SCCs into it. + for (CISETIT it = x_ids.begin(); it != x_ids.end(); it++) + if (*it != id_max){ + vec& vars = sccs[*it]; + for (int j = 0; j < vars.size(); j++){ assert(scc_id[vars[j]] == *it); + scc_id[vars[j]] = id_max; + sccs[id_max].push(vars[j]); } + vars.clear(); assert(sccs[*it].size() == 0); } + + // Take care of the remaining vars not yet associated with any SCC. + for (int j = 0; j < x.size(); j++) + if (scc_id[x[j]] == -1){ + scc_id[x[j]] = id_max; + sccs[id_max].push(x[j]); } + } + } + + return sccs.size(); // Upper limit, as there are merged (empty) components. +} + +void SimpSolver::computeXorSccs(vec& /*out*/ xor_sccs, + const vec& xors, const vec& v2scc_id, vec >& var_sccs, int upper_limit) const { + assert(xor_sccs.size() == 0); + xor_sccs.growTo(upper_limit, NULL); + + for (int i = 0; i < xors.size(); i++){ + const Xor& x = *xors[i]; assert(x.size() > 2); + int id = v2scc_id[x[0]]; assert(id != -1); assert(id < xor_sccs.size()); + + XorScc* scc = xor_sccs[id]; + if (scc == NULL) + xor_sccs[id] = scc = new XorScc; + scc->xors.push(xors[i]); + if (scc->vars.size() == 0) {assert(var_sccs[id].size() != 0); + var_sccs[id].moveTo(scc->vars); }else assert(var_sccs[id].size() == 0); + } + + // Compact the data structure. + int i, j; + for (i = j = 0; i < xor_sccs.size(); i++) + if (xor_sccs[i] != NULL) {assert(xor_sccs[i]->xors.size() != 0); assert(xor_sccs[i]->vars.size() > 2); + xor_sccs[j++] = xor_sccs[i]; } + xor_sccs.shrink(i - j); assert(sanityCheck(xor_sccs, v2scc_id, var_sccs, nVars())); +} diff --git a/lstech_maple/lstech/simp/SimpSolver.h b/mapleCOMSPS/mapleCOMSPS/simp/SimpSolver.h old mode 100755 new mode 100644 similarity index 84% rename from lstech_maple/lstech/simp/SimpSolver.h rename to mapleCOMSPS/mapleCOMSPS/simp/SimpSolver.h index 4d4576d..88fa4e0 --- a/lstech_maple/lstech/simp/SimpSolver.h +++ b/mapleCOMSPS/mapleCOMSPS/simp/SimpSolver.h @@ -1,22 +1,8 @@ -/***************************************************************************************[Solver.cc] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson +/************************************************************************************[SimpSolver.h] +MiniSat -- Copyright (c) 2006, Niklas Een, Niklas Sorensson Copyright (c) 2007-2010, Niklas Sorensson - + Chanseok Oh's MiniSat Patch Series -- Copyright (c) 2015, Chanseok Oh - -Maple_LCM, Based on MapleCOMSPS_DRUP -- Copyright (c) 2017, Mao Luo, Chu-Min LI, Fan Xiao: implementing a learnt clause minimisation approach -Reference: M. Luo, C.-M. Li, F. Xiao, F. Manya, and Z. L. , “An effective learnt clause minimization approach for cdcl sat solvers,” in IJCAI-2017, 2017, pp. to–appear. - -Maple_LCM_Dist, Based on Maple_LCM -- Copyright (c) 2017, Fan Xiao, Chu-Min LI, Mao Luo: using a new branching heuristic called Distance at the beginning of search - -MapleLCMDistChronoBT, based on Maple_LCM_Dist -- Copyright (c), Alexander Nadel, Vadim Ryvchin: "Chronological Backtracking" in SAT-2018, pp. 111-121. - -MapleLCMDistChronoBT-DL, based on MapleLCMDistChronoBT -- Copyright (c), Stepan Kochemazov, Oleg Zaikin, Victor Kondratiev, Alexander Semenov: The solver was augmented with heuristic that moves duplicate learnt clauses into the core/tier2 tiers depending on a number of parameters. - -lstech, Relaxed_newTech -- Copyright (c) 2019-2021, Shaowei Cai, Xindi Zhang -Reference: Shaowei Cai, Xindi Zhang: Deep Cooperation of CDCL and Local Search for SAT. -Xindi Zhang, Shaowei Cai: Relaxed Backtracking with Rephasing. - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -34,28 +20,47 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_SimpSolver_h -#define Minisat_SimpSolver_h +#ifndef MapleCOMSPS_SimpSolver_h +#define MapleCOMSPS_SimpSolver_h -#include "mtl/Queue.h" -#include "core/Solver.h" +#include "../mtl/Queue.h" +#include "../core/Solver.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================= +// For Gaussian elimination +class Xor { + vec vars; +public: + bool rhs; + + Xor(const Clause& c, bool _rhs) : rhs(_rhs) { + for (int i = 0; i < c.size(); i++) + vars.push(var(c[i])); + } + + inline int size() const { return vars.size(); } + inline const Var& operator [] (int i) const { return vars[i]; } +}; +struct XorScc { + vec xors; + vec vars; +}; + class SimpSolver : public Solver { public: // Constructor/Destructor: // SimpSolver(); + SimpSolver(const SimpSolver &s); ~SimpSolver(); // Problem specification: // - void varGrowTo (int maxVar); Var newVar (bool polarity = true, bool dvar = true); bool addClause (const vec& ps); bool addEmptyClause(); // Add the empty clause to the solver. @@ -65,8 +70,12 @@ class SimpSolver : public Solver { bool addClause_( vec& ps); bool substitute(Var v, Lit x); // Replace all occurences of v with x (may cause a contradiction). + // Parallel support: + // + bool GE; + // Variable mode: - // + // void setFrozen (Var v, bool b); // If a variable is frozen it will not be eliminated. bool isEliminated(Var v) const; @@ -75,10 +84,10 @@ class SimpSolver : public Solver { bool solve (const vec& assumps, bool do_simp = true, bool turn_off_simp = false); lbool solveLimited(const vec& assumps, bool do_simp = true, bool turn_off_simp = false); bool solve ( bool do_simp = true, bool turn_off_simp = false); - bool solve (Lit p , bool do_simp = true, bool turn_off_simp = false); + bool solve (Lit p , bool do_simp = true, bool turn_off_simp = false); bool solve (Lit p, Lit q, bool do_simp = true, bool turn_off_simp = false); bool solve (Lit p, Lit q, Lit r, bool do_simp = true, bool turn_off_simp = false); - bool eliminate (bool turn_off_elim = false); // Perform variable elimination based simplification. + bool eliminate (bool turn_off_elim = false); // Perform variable elimination based simplification. bool eliminate_ (); void removeSatisfied(); @@ -97,6 +106,9 @@ class SimpSolver : public Solver { void toDimacs (const char* file, Lit p, Lit q, Lit r); #endif + + void disableSimplification() { use_simplification = false; } + // Mode of operation: // bool parsing; @@ -128,9 +140,9 @@ class SimpSolver : public Solver { // 32-bit implementation instead then, but this will have to do for now. uint64_t cost (Var x) const { return (uint64_t)n_occ[toInt(mkLit(x))] * (uint64_t)n_occ[toInt(~mkLit(x))]; } bool operator()(Var x, Var y) const { return cost(x) < cost(y); } - + // TODO: investigate this order alternative more. - // bool operator()(Var x, Var y) const { + // bool operator()(Var x, Var y) const { // int c_x = cost(x); // int c_y = cost(y); // return c_x < c_y || c_x == c_y && x < y; } @@ -178,6 +190,22 @@ class SimpSolver : public Solver { bool strengthenClause (CRef cr, Lit l); bool implied (const vec& c); void relocAll (ClauseAllocator& to); + + + // Gaussian elimination: + // + bool gaussElim(); + + bool searchXors(vec& /*out*/ xors); + // Given XORs, compute SCCs in terms of vars. + int computeVarSccs(vec& /*out*/ v2scc_id, vec >& /*out*/ var_sccs, vec& xors) const; + // Given var SCCs, compute SCCs in terms of XORs. + void computeXorSccs(vec& /*out*/ xor_sccs, const vec& xors, + const vec& v2scc_id, vec >& var_sccs, int upper_limit) const; + bool performGaussElim(vec& xor_sccs); + + int toDupMarkerIdx(const Clause& c); + void addBinNoDup(Lit a, Lit b); }; @@ -187,7 +215,8 @@ class SimpSolver : public Solver { inline bool SimpSolver::isEliminated (Var v) const { return eliminated[v]; } inline void SimpSolver::updateElimHeap(Var v) { - assert(use_simplification); + if (!use_simplification) return; + /* assert(use_simplification); */ // if (!frozen[v] && !isEliminated(v) && value(v) == l_Undef) if (elim_heap.inHeap(v) || (!frozen[v] && !isEliminated(v) && value(v) == l_Undef)) elim_heap.update(v); } @@ -204,10 +233,10 @@ inline bool SimpSolver::solve ( bool do_simp, bool tu inline bool SimpSolver::solve (Lit p , bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); return solve_(do_simp, turn_off_simp) == l_True; } inline bool SimpSolver::solve (Lit p, Lit q, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); return solve_(do_simp, turn_off_simp) == l_True; } inline bool SimpSolver::solve (Lit p, Lit q, Lit r, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_(do_simp, turn_off_simp) == l_True; } -inline bool SimpSolver::solve (const vec& assumps, bool do_simp, bool turn_off_simp){ +inline bool SimpSolver::solve (const vec& assumps, bool do_simp, bool turn_off_simp){ budgetOff(); assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp) == l_True; } -inline lbool SimpSolver::solveLimited (const vec& assumps, bool do_simp, bool turn_off_simp){ +inline lbool SimpSolver::solveLimited (const vec& assumps, bool do_simp, bool turn_off_simp){ assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp); } //================================================================================================= diff --git a/lstech_maple/lstech/utils/Makefile b/mapleCOMSPS/mapleCOMSPS/utils/Makefile old mode 100755 new mode 100644 similarity index 100% rename from lstech_maple/lstech/utils/Makefile rename to mapleCOMSPS/mapleCOMSPS/utils/Makefile diff --git a/lstech_maple/lstech/utils/Options.cc b/mapleCOMSPS/mapleCOMSPS/utils/Options.cc old mode 100755 new mode 100644 similarity index 88% rename from lstech_maple/lstech/utils/Options.cc rename to mapleCOMSPS/mapleCOMSPS/utils/Options.cc index ec5a6e9..d021965 --- a/lstech_maple/lstech/utils/Options.cc +++ b/mapleCOMSPS/mapleCOMSPS/utils/Options.cc @@ -17,13 +17,13 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#include "mtl/Sort.h" -#include "utils/Options.h" -#include "utils/ParseUtils.h" +#include "../mtl/Sort.h" +#include "../utils/Options.h" +#include "../utils/ParseUtils.h" -using namespace Minisat; +using namespace MapleCOMSPS; -void Minisat::parseOptions(int& argc, char** argv, bool strict) +void MapleCOMSPS::parseOptions(int& argc, char** argv, bool strict) { int i, j; for (i = j = 1; i < argc; i++){ @@ -54,9 +54,9 @@ void Minisat::parseOptions(int& argc, char** argv, bool strict) } -void Minisat::setUsageHelp (const char* str){ Option::getUsageString() = str; } -void Minisat::setHelpPrefixStr (const char* str){ Option::getHelpPrefixString() = str; } -void Minisat::printUsageAndExit (int argc, char** argv, bool verbose) +void MapleCOMSPS::setUsageHelp (const char* str){ Option::getUsageString() = str; } +void MapleCOMSPS::setHelpPrefixStr (const char* str){ Option::getHelpPrefixString() = str; } +void MapleCOMSPS::printUsageAndExit (int argc, char** argv, bool verbose) { const char* usage = Option::getUsageString(); if (usage != NULL) diff --git a/lstech_maple/lstech/utils/Options.h b/mapleCOMSPS/mapleCOMSPS/utils/Options.h old mode 100755 new mode 100644 similarity index 97% rename from lstech_maple/lstech/utils/Options.h rename to mapleCOMSPS/mapleCOMSPS/utils/Options.h index 9c1f406..164a650 --- a/lstech_maple/lstech/utils/Options.h +++ b/mapleCOMSPS/mapleCOMSPS/utils/Options.h @@ -17,19 +17,19 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_Options_h -#define Minisat_Options_h +#ifndef MapleCOMSPS_Options_h +#define MapleCOMSPS_Options_h #include #include #include #include -#include "mtl/IntTypes.h" -#include "mtl/Vec.h" -#include "utils/ParseUtils.h" +#include "../mtl/IntTypes.h" +#include "../mtl/Vec.h" +#include "../utils/ParseUtils.h" -namespace Minisat { +namespace MapleCOMSPS { //================================================================================================== // Top-level option parse/help functions: @@ -282,15 +282,15 @@ class Int64Option : public Option if (range.begin == INT64_MIN) fprintf(stderr, "imin"); else - fprintf(stderr, "%4"PRIi64, range.begin); + fprintf(stderr, "%4" PRIi64, range.begin); fprintf(stderr, " .. "); if (range.end == INT64_MAX) fprintf(stderr, "imax"); else - fprintf(stderr, "%4"PRIi64, range.end); + fprintf(stderr, "%4" PRIi64, range.end); - fprintf(stderr, "] (default: %"PRIi64")\n", value); + fprintf(stderr, "] (default: %" PRIi64 ")\n", value); if (verbose){ fprintf(stderr, "\n %s\n", description); fprintf(stderr, "\n"); diff --git a/lstech_maple/lstech/utils/ParseUtils.h b/mapleCOMSPS/mapleCOMSPS/utils/ParseUtils.h old mode 100755 new mode 100644 similarity index 97% rename from lstech_maple/lstech/utils/ParseUtils.h rename to mapleCOMSPS/mapleCOMSPS/utils/ParseUtils.h index d307164..b4f303f --- a/lstech_maple/lstech/utils/ParseUtils.h +++ b/mapleCOMSPS/mapleCOMSPS/utils/ParseUtils.h @@ -18,15 +18,15 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_ParseUtils_h -#define Minisat_ParseUtils_h +#ifndef MapleCOMSPS_ParseUtils_h +#define MapleCOMSPS_ParseUtils_h #include #include #include -namespace Minisat { +namespace MapleCOMSPS { //------------------------------------------------------------------------------------------------- // A simple buffered character stream class: diff --git a/lstech_maple/lstech/utils/System.cc b/mapleCOMSPS/mapleCOMSPS/utils/System.cc old mode 100755 new mode 100644 similarity index 89% rename from lstech_maple/lstech/utils/System.cc rename to mapleCOMSPS/mapleCOMSPS/utils/System.cc index 4662f1b..8da37be --- a/lstech_maple/lstech/utils/System.cc +++ b/mapleCOMSPS/mapleCOMSPS/utils/System.cc @@ -18,14 +18,14 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#include "utils/System.h" +#include "../utils/System.h" #if defined(__linux__) #include #include -using namespace Minisat; +using namespace MapleCOMSPS; // TODO: split the memory reading functions into two: one for reading high-watermark of RSS, and // one for reading the current virtual memory size. @@ -67,14 +67,14 @@ static inline int memReadPeak(void) return peak_kb; } -double Minisat::memUsed() { return (double)memReadStat(0) * (double)getpagesize() / (1024*1024); } -double Minisat::memUsedPeak() { +double MapleCOMSPS::memUsed() { return (double)memReadStat(0) * (double)getpagesize() / (1024*1024); } +double MapleCOMSPS::memUsedPeak() { double peak = memReadPeak() / 1024; return peak == 0 ? memUsed() : peak; } #elif defined(__FreeBSD__) -double Minisat::memUsed(void) { +double MapleCOMSPS::memUsed(void) { struct rusage ru; getrusage(RUSAGE_SELF, &ru); return (double)ru.ru_maxrss / 1024; } @@ -84,12 +84,12 @@ double MiniSat::memUsedPeak(void) { return memUsed(); } #elif defined(__APPLE__) #include -double Minisat::memUsed(void) { +double MapleCOMSPS::memUsed(void) { malloc_statistics_t t; malloc_zone_statistics(NULL, &t); return (double)t.max_size_in_use / (1024*1024); } -double Minisat::memUsedPeak(void) {return memUsed(); } + #else -double Minisat::memUsed() { +double MapleCOMSPS::memUsed() { return 0; } #endif diff --git a/lstech_maple/lstech/utils/System.h b/mapleCOMSPS/mapleCOMSPS/utils/System.h old mode 100755 new mode 100644 similarity index 89% rename from lstech_maple/lstech/utils/System.h rename to mapleCOMSPS/mapleCOMSPS/utils/System.h index 1758192..edca5e9 --- a/lstech_maple/lstech/utils/System.h +++ b/mapleCOMSPS/mapleCOMSPS/utils/System.h @@ -18,18 +18,18 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ -#ifndef Minisat_System_h -#define Minisat_System_h +#ifndef MapleCOMSPS_System_h +#define MapleCOMSPS_System_h #if defined(__linux__) #include #endif -#include "mtl/IntTypes.h" +#include "../mtl/IntTypes.h" //------------------------------------------------------------------------------------------------- -namespace Minisat { +namespace MapleCOMSPS { static inline double cpuTime(void); // CPU-time in seconds. extern double memUsed(); // Memory in mega bytes (returns 0 for unsupported architectures). @@ -43,14 +43,14 @@ extern double memUsedPeak(); // Peak-memory in mega bytes (returns 0 for #if defined(_MSC_VER) || defined(__MINGW32__) #include -static inline double Minisat::cpuTime(void) { return (double)clock() / CLOCKS_PER_SEC; } +static inline double MapleCOMSPS::cpuTime(void) { return (double)clock() / CLOCKS_PER_SEC; } #else #include #include #include -static inline double Minisat::cpuTime(void) { +static inline double MapleCOMSPS::cpuTime(void) { struct rusage ru; getrusage(RUSAGE_SELF, &ru); return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; } diff --git a/run.sh b/run.sh index c783cc6..c7dd524 100755 --- a/run.sh +++ b/run.sh @@ -21,10 +21,11 @@ # - 367c25ad50259a685a25b86d6dd171b2-GP_100_950_33.cnf # 这个存在问题 -DIR=/pub/data/chenzh/data/sat2022 -INSTANCE=72329bc80f5f55dcc356a22f3f11ebec-GP_200_313_5.cnf +DIR=/pub/data/chenzh/data/sat2021 +# INSTANCE=tseitingrid7x165_shuffled.cnf +INSTANCE=WS_500_16_70_10.apx_0.cnf -# make -j && mpirun --bind-to none -np 9 --allow-run-as-root ./light -i $DIR/$INSTANCE --shuffle=1 --share=1 --threads=16 --times=3600 --share_method=0 +make -j && mpirun --bind-to none -np 9 --allow-run-as-root ./light -i $DIR/$INSTANCE --shuffle=1 --share=1 --threads=16 --times=3600 --share_method=0 -make -j 16 && mpirun --mca btl_tcp_if_include 192.168.100.0/24 --hostfile ./experiment/hostfile --bind-to none -np 65 --allow-run-as-root ./light -i $DIR/$INSTANCE --share=1 --threads=16 --times=3600 --share_method=0 +# make -j 16 && mpirun --mca btl_tcp_if_include 192.168.100.0/24 --hostfile ./experiment/hostfile --bind-to none -np 65 --allow-run-as-root ./light -i $DIR/$INSTANCE --share=1 --threads=16 --times=3600 --share_method=0 #./light -i $DIR/$INSTANCE --share=1 --threads=16 --times=3600 diff --git a/src/light.hpp b/src/light.hpp index 2a9612a..75aa4d6 100644 --- a/src/light.hpp +++ b/src/light.hpp @@ -42,7 +42,7 @@ public: sharer* s; std::vector> sharing_groups; - enum { KISSAT, LSTECH } solver_type; + enum { KISSAT, MAPLE } solver_type; enum { SAT, UNSAT, DEFAULT } worker_type; int worker_rs; diff --git a/src/preprocess/gauss.cpp b/src/preprocess/gauss.cpp deleted file mode 100644 index 16063b3..0000000 --- a/src/preprocess/gauss.cpp +++ /dev/null @@ -1,283 +0,0 @@ -#include "preprocess.hpp" -#include -#include -#include "m4ri/m4ri.h" -#define MAX_XOR 6 - -bool cmpvar(int x, int y) { - if (abs(x) == abs(y)) return x > y; - return abs(x) < abs(y); -} - -int preprocess::cal_dup_val(int i) { - for (int j = 0; j < clause[i].size(); j++) a[j] = clause[i][j]; - std::sort(a, a + clause[i].size(), cmpvar); - int v = 0; - for (int j = 0; j < clause[i].size(); j++) - if (a[j] < 0) v |= (1 << j); - return v; -} - -int preprocess::search_xors() { - vec xorsp; - vec dup_table; - for (int i = 1; i <= vars; i++) { - seen[i] = 0; - occurp[i].clear(); - occurn[i].clear(); - } - for (int i = 1; i <= clauses; i++) { - abstract[i] = clause_delete[i] = nxtc[i] = 0; - int l = clause[i].size(); - for (int j = 0; j < l; j++) { - if (clause[i][j] > 0) occurp[clause[i][j]].push(i); - else occurn[-clause[i][j]].push(i); - abstract[i] |= 1 << (abs(clause[i][j]) & 31); - } - } - for (int i = 1; i <= clauses; i++) { - if (nxtc[i]) continue; - nxtc[i] = 1; - int l = clause[i].size(); - if (l <= 2 || l > MAX_XOR) continue; - int required_num = 1 << (l - 2), skip = 0, mino = clauses + 1, mino_id = 0; - for (int j = 0; j < l; j++) { - int idx = abs(clause[i][j]); - if (occurp[idx].size() < required_num || occurn[idx].size() < required_num) { - skip = 1; break; - } - if (occurp[idx].size() + occurn[idx].size() < mino) { - mino = occurp[idx].size() + occurn[idx].size(); - mino_id = idx; - } - } - if (skip) continue; - xorsp.clear(); - xorsp.push(i); - for (int j = 0; j < occurp[mino_id].size(); j++) { - int o = occurp[mino_id][j]; - if (!nxtc[o] && clause[o].size() == l && abstract[o] == abstract[i]) - xorsp.push(o); - } - for (int j = 0; j < occurn[mino_id].size(); j++) { - int o = occurn[mino_id][j]; - if (!nxtc[o] && clause[o].size() == l && abstract[o] == abstract[i]) - xorsp.push(o); - } - if (xorsp.size() < 2 * required_num) continue; - - int rhs[2] = {0, 0}; - for (int j = 0; j < l; j++) - seen[abs(clause[i][j])] = i; - dup_table.clear(); - dup_table.growTo(1 << MAX_XOR, false); - - for (int j = 0; j < xorsp.size(); j++) { - int o = xorsp[j], dup_v; - bool xor_sign = true; - for (int k = 0; k < clause[o].size(); k++) { - if (seen[abs(clause[o][k])] != i) goto Next; - if (clause[o][k] < 0) xor_sign = !xor_sign; - } - dup_v = cal_dup_val(o); - if (dup_table[dup_v]) continue; - dup_table[dup_v] = true; - rhs[xor_sign]++; - if (j) nxtc[o] = 1; - Next:; - } - assert(rhs[0] <= 2 * required_num); - assert(rhs[1] <= 2 * required_num); - if (rhs[0] == 2 * required_num) - xors.push(xorgate(i, 0, l)); - if (rhs[1] == 2 * required_num) - xors.push(xorgate(i, 1, l)); - // if (rhs[0] == 2 * required_num && rhs[1] == 2 * required_num) { - // printf("%d %d\n", rhs[0], rhs[1]); - // for (int j = 0; j < xorsp.size(); j++) { - // int o = xorsp[j]; - // for (int k = 0; k < clause[o].size(); k++) { - // printf("%d ", clause[o][k]); - // } - // printf(" ---------- %d\n", o); - // } - // } - // int a = abs(clause[i][0]) - 1; - // int b = abs(clause[i][1]) - 1; - // int c = abs(clause[i][2]) - 1; - // if (a > b) std::swap(a, b); - // if (a > c) std::swap(a, c); - // if (b > c) std::swap(b, c); - // printf("%d %d %d ", a, b, c); - // puts(""); - } - return xors.size(); -} - -bool cmpxorgate(xorgate a, xorgate b) { - return a.sz > b.sz; -} - -int preprocess::ecc_var() { - scc_id.clear(); - scc_id.growTo(vars + 1, -1); - scc.clear(); - //sort(xors.data, xors.data + xors.sz, cmpxorgate); - std::set xids; - - for (int i = 0; i < xors.size(); i++) { - int x = xors[i].c; - xids.clear(); - for (int j = 0; j < clause[x].size(); j++) - if (scc_id[abs(clause[x][j])] != -1) - xids.insert(scc_id[abs(clause[x][j])]); - - if (xids.size() == 0) { - scc.push(); - for (int j = 0; j < clause[x].size(); j++) { - scc_id[abs(clause[x][j])] = scc.size() - 1; - scc[scc.size() - 1].push(abs(clause[x][j])); - } - } - else if (xids.size() == 1) { - int id = *xids.begin(); - for (int j = 0; j < clause[x].size(); j++) { - if (scc_id[abs(clause[x][j])] == -1) { - scc_id[abs(clause[x][j])] = id; - scc[id].push(abs(clause[x][j])); - } - } - } - else { - int id_max = -1; int sz_max = 0; - for (std::set::iterator it = xids.begin(); it != xids.end(); it++) { - if (scc[*it].size() > sz_max) - sz_max = scc[*it].size(), id_max = *it; - } - for (std::set::iterator it = xids.begin(); it != xids.end(); it++) { - if (*it != id_max) { - vec& v = scc[*it]; - for (int k = 0; k < v.size(); k++) { - scc_id[v[k]] = id_max; - scc[id_max].push(v[k]); - } - v.clear(); - } - } - for (int j = 0; j < clause[x].size(); j++) { - if (scc_id[abs(clause[x][j])] == -1) { - scc_id[abs(clause[x][j])] = id_max; - scc[id_max].push(abs(clause[x][j])); - } - } - } - } - return scc.size(); -} - -int preprocess::ecc_xor() { - for (int i = 0; i < scc.size(); i++) seen[i] = -1; - for (int i = 0; i < xors.size(); i++) { - int id = scc_id[abs(clause[xors[i].c][0])]; - if (seen[id] == -1) xor_scc.push(), seen[id] = xor_scc.size() - 1; - int id2 = seen[id]; - xor_scc[id2].push(i); - } - return xor_scc.size(); -} - -int preprocess::gauss_elimination() { - gauss_eli_unit = gauss_eli_binary = 0; - vec v2mzd(vars + 1, -1); - vec mzd2v; - for (int i = 0; i < xor_scc.size(); i++) { - if (xor_scc[i].size() == 1) continue; - int id = scc_id[abs(clause[xors[xor_scc[i][0]].c][0])]; - assert(scc[id].size() > 3); - if (scc[id].size() > 1e7 / xor_scc[i].size()) continue; - mzd2v.clear(); - std::sort(scc[id].data, scc[id].data + scc[id].size(), cmpvar); - for (int j = 0; j < scc[id].size(); j++) { - assert(scc[id][j] > 0); - assert(scc[id][j] <= vars); - v2mzd[scc[id][j]] = j; - mzd2v.push(scc[id][j]); - } - int cols = scc[id].size() + 1; - mzd_t* mat = mzd_init(xor_scc[i].size(), cols); - for (int row = 0; row < xor_scc[i].size(); row++) { - int k = xors[xor_scc[i][row]].c; - for (int j = 0; j < clause[k].size(); j++) - mzd_write_bit(mat, row, v2mzd[abs(clause[k][j])], 1); - if (xors[xor_scc[i][row]].rhs) - mzd_write_bit(mat, row, cols - 1, 1); - } - mzd_echelonize(mat, true); - mzd_free(mat); - for (int row = 0, rhs; row < xor_scc[i].size(); row++) { - vec ones; - for (int col = 0; col < cols - 1; col++) - if (mzd_read_bit(mat, row, col)) { - if (ones.size() == 2) goto NextRow; - ones.push(mzd2v[col]); - } - - rhs = mzd_read_bit(mat, row, cols - 1); - if (ones.size() == 1) { - ++gauss_eli_unit; - clause.push(); - ++clauses; - clause[clauses].push(ones[0] * (rhs ? 1 : -1)); - } - else if (ones.size() == 2) { - ++gauss_eli_binary; - // assert(clauses == clause.size() - 1); - int p = ones[0], q = rhs ? ones[1] : -ones[1]; - clause.push(); - ++clauses; - clause[clauses].push(p); - clause[clauses].push(q); - clause.push(); - ++clauses; - clause[clauses].push(-p); - clause[clauses].push(-q); - } - else if (rhs) { - // for (int row = 0; row < xor_scc[i].size(); row++) { - // int k = xors[xor_scc[i][row]].c; - // for (int j = 0; j < clause[k].size(); j++) - // printf("%d ", clause[k][j]); - // printf("-------- %d %d %d\n", xor_scc[i][row], k, xors[xor_scc[i][row]].rhs); - // } - return false; - } - NextRow:; - } - } - return true; -} - -bool preprocess::preprocess_gauss() { - int nxors = search_xors(); - printf("c [GE] XORs: %d (time: 0.00)\n", nxors); - if (!nxors) return true; - int nvarscc = ecc_var(); - printf("c [GE] VAR SCC: %d\n", nvarscc); - int nxorscc = ecc_xor(); - printf("c [GE] XOR SCCs: %d (time: 0.00)\n", nxorscc); - int res = gauss_elimination(); - printf("c [GE] unary xor: %d, bin xor: %d, bin added\n", gauss_eli_unit, gauss_eli_binary); - if (!res) {printf("c [GE] UNSAT\n");} - xors.clear(true); - scc_id.clear(true); - for (int i = 0; i < scc.size(); i++) - scc[i].clear(true); - scc.clear(true); - for (int i = 0; i < xor_scc.size(); i++) - xor_scc[i].clear(true); - xor_scc.clear(true); - if (!res) return false; - clause_delete.growTo(clauses + 1, 0); - nxtc.growTo(clauses + 1, 0); - return true; -} \ No newline at end of file diff --git a/src/preprocess/preprocess.cpp b/src/preprocess/preprocess.cpp index 55fe87a..e37aa46 100644 --- a/src/preprocess/preprocess.cpp +++ b/src/preprocess/preprocess.cpp @@ -15,7 +15,6 @@ void preprocess::preprocess_init() { q = new int[vars + 10]; clean = new int[vars + 10]; seen = new int[(vars << 1) + 10]; - abstract = new int[clauses + 10]; clause_delete.growTo(clauses+1, 0); nxtc.growTo(clauses+1, 0); occurp = new vec[vars + 1]; @@ -49,7 +48,6 @@ void preprocess::release() { delete []a; delete []mapfrom; - delete []abstract; for (int i = 0; i <= vars; i++) occurp[i].clear(true), occurn[i].clear(true); delete []occurp; @@ -173,15 +171,6 @@ int preprocess::do_preprocess(char* filename) { preprocess_init(); int res = 1; - // if (vars <= 1e5 && clauses <= 1e6) { - // res = preprocess_gauss(); - // if (!res) { - // printf("c solved by gauss elimination\n"); - // release(); - // return 0; - // } - // } - res = preprocess_up(); if (!res) { release(); @@ -191,7 +180,6 @@ int preprocess::do_preprocess(char* filename) { return 0; } - if (vars <= 1e5 && clauses <= 1e6) { res = preprocess_card(); if (!res) { diff --git a/src/preprocess/preprocess.hpp b/src/preprocess/preprocess.hpp index 49ef65e..3b08852 100644 --- a/src/preprocess/preprocess.hpp +++ b/src/preprocess/preprocess.hpp @@ -71,20 +71,6 @@ public: int card_elimination(); int scc_almost_one(); void upd_occur(int v, int s); - - int *abstract; - int gauss_eli_unit; - int gauss_eli_binary; - vec xors; - vec scc_id; - vec> scc; - vec> xor_scc; - bool preprocess_gauss(); - int search_xors(); - int cal_dup_val(int i); - int ecc_var(); - int ecc_xor(); - int gauss_elimination(); }; diff --git a/src/sharer.cpp b/src/sharer.cpp index a1548cf..9922227 100644 --- a/src/sharer.cpp +++ b/src/sharer.cpp @@ -291,6 +291,7 @@ int sharer::sort_clauses(int x) { } } } + printf("c share %d lits\n", OPT(share_lits) - space); return (OPT(share_lits) - space) * 100 / OPT(share_lits); } diff --git a/src/solve.cpp b/src/solve.cpp index 5446396..2bc585b 100644 --- a/src/solve.cpp +++ b/src/solve.cpp @@ -1,6 +1,6 @@ #include "light.hpp" #include "solver_api/basekissat.hpp" -#include "solver_api/baselstech.hpp" +#include "solver_api/basemaple.hpp" #include "sharer.hpp" #include "paras.hpp" #include @@ -28,7 +28,7 @@ void * solve_worker(void *arg) { while (!terminated) { int res = sq->solve(); if (res && !terminated) { - //printf("c result: %d, winner is %d, winner run %d confs\n", res, sq->id, sq->get_conflicts()); + printf("c result: %d, winner is %d, winner run %d confs\n", res, sq->id, sq->get_conflicts()); // terminated = 1; // sq->controller->terminate_workers(); @@ -41,7 +41,7 @@ void * solve_worker(void *arg) { terminated = 1; sq->controller->terminate_workers(); } - //printf("get result %d with res %d\n", sq->id, res); + printf("get result %d with res %d\n", sq->id, res); } return NULL; } @@ -53,9 +53,9 @@ void light::init_workers() { basekissat* kissat = new basekissat(i, this); workers.push(kissat); } - else if (solver_type == LSTECH) { - baselstech* lstech = new baselstech(i, this); - workers.push(lstech); + else if (solver_type == MAPLE) { + basemaple* maple = new basemaple(i, this); + workers.push(maple); } } } @@ -63,10 +63,9 @@ void light::init_workers() { void light::diversity_workers() { // printf("c num %d\n", num_procs); for (int i = 0; i < OPT(threads); i++) { - if(solver_type == LSTECH) { - workers[i]->configure("worker_seed", 0); - workers[i]->configure("worker_index", i); - workers[i]->configure("worker_number", OPT(threads)); + if(solver_type == MAPLE) { + workers[i]->configure("", 0); + OPT(share_lits) = 3000; continue; } @@ -308,7 +307,7 @@ void light::seperate_groups() { // [sat_procs+unsat_procs+1, sat_procs+unsat_procs+lstech_procs] for ls-tech if(rank >= sat_procs+unsat_procs+1 && rank <= sat_procs+unsat_procs+lstech_procs) { - solver_type = LSTECH; + solver_type = MAPLE; OPT(share) = 0; } @@ -331,7 +330,8 @@ void light::seperate_groups() { } else { // 总线程太小就跑默认策略 - worker_type = light::DEFAULT; + worker_type = light::UNSAT; + solver_type = MAPLE; std::vector tmp; for(int i=1; i<=worker_procs; i++) { tmp.push_back(i); diff --git a/src/solver_api/baselstech.cpp b/src/solver_api/baselstech.cpp index 3126b3e..093a7b9 100755 --- a/src/solver_api/baselstech.cpp +++ b/src/solver_api/baselstech.cpp @@ -2,48 +2,56 @@ #include "core/Dimacs.h" #include "simp/SimpSolver.h" -#include "baselstech.hpp" +#include "basemaple.hpp" -// using namespace Minisat; +// using namespace MapleCOMSPS; // Macros for minisat literal representation conversion -#define MINI_LIT(lit) lit > 0 ? Minisat::mkLit(lit - 1, false) : Minisat::mkLit((-lit) - 1, true) +#define MINI_LIT(lit) lit > 0 ? MapleCOMSPS::mkLit(lit - 1, false) : MapleCOMSPS::mkLit((-lit) - 1, true) #define INT_LIT(lit) sign(lit) ? -(var(lit) + 1) : (var(lit) + 1) -void baselstech::add(int l) { +void basemaple::add(int l) { puts("wrong"); } -int baselstech::configure(const char* name, int val) { - if (strcmp(name, "worker_index") == 0) solver->worker_index = val; - if (strcmp(name, "worker_seed") == 0) solver->worker_seed = val; - if (strcmp(name, "worker_number") == 0) solver->worker_number = val; +int basemaple::configure(const char* name, int val) { + // if (strcmp(name, "worker_index") == 0) solver->worker_index = val; + // if (strcmp(name, "worker_seed") == 0) solver->worker_seed = val; + // if (strcmp(name, "worker_number") == 0) solver->worker_number = val; + printf("c maple configure %d\n", id); + // solver->GE = 1; + if (id == 1) solver->GE = 1; + else solver->GE = 0; + if (id % 2) solver->VSIDS = false; + else solver->VSIDS = true; + if (id % 4 >= 2) solver->verso = false; + else solver->verso = true; return 1; } -int baselstech::solve() { - Minisat::vec miniAssumptions; - Minisat::lbool res = solver->solveLimited(miniAssumptions); - if (res == (Minisat::lbool((uint8_t)0))) return 10; - if (res == (Minisat::lbool((uint8_t)1))) return 20; +int basemaple::solve() { + MapleCOMSPS::vec miniAssumptions; + MapleCOMSPS::lbool res = solver->solveLimited(miniAssumptions); + if (res == (MapleCOMSPS::lbool((uint8_t)0))) return 10; + if (res == (MapleCOMSPS::lbool((uint8_t)1))) return 20; return 0; } -int baselstech::val(int l) { - if (solver->model[l] != (Minisat::lbool((uint8_t)2))) { - int lit = solver->model[l] == (Minisat::lbool((uint8_t)0)) ? l + 1 : -(l + 1); +int basemaple::val(int l) { + if (solver->model[l] != (MapleCOMSPS::lbool((uint8_t)2))) { + int lit = solver->model[l] == (MapleCOMSPS::lbool((uint8_t)0)) ? l + 1 : -(l + 1); return lit; } return l; } -void baselstech::terminate() { +void basemaple::terminate() { solver->interrupt(); } -void cbkLstechExportClause(void * issuer, int lbd, Minisat::vec &cls) { - baselstech* mp = (baselstech*)issuer; +void cbkLstechExportClause(void * issuer, int lbd, MapleCOMSPS::vec &cls) { + basemaple* mp = (basemaple*)issuer; if (lbd > mp->good_clause_lbd) return; shared_ptr ncls = std::make_shared(cls.size()); @@ -55,23 +63,23 @@ void cbkLstechExportClause(void * issuer, int lbd, Minisat::vec &c mp->export_clause.push(ncls); } -bool cbkLstechImportClause(void * issuer, int * lbd, Minisat::vec & mcls) { - baselstech* mp = (baselstech*)issuer; +bool cbkLstechImportClause(void * issuer, int * lbd, MapleCOMSPS::vec & mcls) { + basemaple* mp = (basemaple*)issuer; shared_ptr cls = NULL; if (mp->import_clause.pop(cls) == false) return false; *lbd = cls->lbd; mcls.clear(); for (size_t i = 0; i < cls->size; i++) { - Minisat::Lit lit = MINI_LIT(cls->data[i]); + MapleCOMSPS::Lit lit = MINI_LIT(cls->data[i]); mcls.push(lit); } cls->free_clause(); return true; } -baselstech::baselstech(int id, light* light) : basesolver(id, light) { +basemaple::basemaple(int id, light* light) : basesolver(id, light) { printf("c id is %d\n", id); - solver = new Minisat::SimpSolver(); + solver = new MapleCOMSPS::SimpSolver(); solver->issuer = this; solver->cbkExportClause = NULL; solver->cbkImportClause = NULL; @@ -81,26 +89,26 @@ baselstech::baselstech(int id, light* light) : basesolver(id, light) { } } -baselstech::~baselstech() +basemaple::~basemaple() { delete solver; } -void baselstech::parse_from_MEM(char* instance) { +void basemaple::parse_from_MEM(char* instance) { int vars, clauses; vec> clause; readinstance(instance, &vars, &clauses, clause); maxvar = vars; - solver->varGrowTo(vars); - Minisat::vec lits; + while (vars > solver->nVars()) solver->newVar(); + MapleCOMSPS::vec lits; for (int i = 1; i <= clauses; i++) { int l = clause[i].size(); lits.clear(); - for (int j = 0; j < l; j++) + for (int j = 0; j < l; j++) lits.push(MINI_LIT(clause[i][j])); solver->addClause_(lits); } } -int baselstech::get_conflicts() { +int basemaple::get_conflicts() { return 0; } \ No newline at end of file diff --git a/src/solver_api/baselstech.hpp b/src/solver_api/baselstech.hpp index c98a03b..e8be60b 100755 --- a/src/solver_api/baselstech.hpp +++ b/src/solver_api/baselstech.hpp @@ -1,13 +1,13 @@ #include "basesolver.hpp" -namespace Minisat +namespace MapleCOMSPS { class SimpSolver; class Lit; template class vec; } -class baselstech : public basesolver { +class basemaple : public basesolver { public: void terminate(); void add(int l); @@ -24,10 +24,10 @@ public: puts("wrong"); } - baselstech(int id, light *light); - ~baselstech(); + basemaple(int id, light *light); + ~basemaple(); - Minisat::SimpSolver* solver; - friend bool cbkLstechImportClause(void *, int *, Minisat::vec &); - friend void cbkLstechExportClause(void *, int, Minisat::vec &); + MapleCOMSPS::SimpSolver* solver; + friend bool cbkLstechImportClause(void *, int *, MapleCOMSPS::vec &); + friend void cbkLstechExportClause(void *, int, MapleCOMSPS::vec &); }; diff --git a/src/solver_api/basemaple.cpp b/src/solver_api/basemaple.cpp new file mode 100755 index 0000000..093a7b9 --- /dev/null +++ b/src/solver_api/basemaple.cpp @@ -0,0 +1,114 @@ +#include "utils/System.h" +#include "core/Dimacs.h" +#include "simp/SimpSolver.h" + +#include "basemaple.hpp" + +// using namespace MapleCOMSPS; + +// Macros for minisat literal representation conversion +#define MINI_LIT(lit) lit > 0 ? MapleCOMSPS::mkLit(lit - 1, false) : MapleCOMSPS::mkLit((-lit) - 1, true) + +#define INT_LIT(lit) sign(lit) ? -(var(lit) + 1) : (var(lit) + 1) + +void basemaple::add(int l) { + puts("wrong"); +} + +int basemaple::configure(const char* name, int val) { + // if (strcmp(name, "worker_index") == 0) solver->worker_index = val; + // if (strcmp(name, "worker_seed") == 0) solver->worker_seed = val; + // if (strcmp(name, "worker_number") == 0) solver->worker_number = val; + printf("c maple configure %d\n", id); + // solver->GE = 1; + if (id == 1) solver->GE = 1; + else solver->GE = 0; + if (id % 2) solver->VSIDS = false; + else solver->VSIDS = true; + if (id % 4 >= 2) solver->verso = false; + else solver->verso = true; + return 1; +} + +int basemaple::solve() { + MapleCOMSPS::vec miniAssumptions; + MapleCOMSPS::lbool res = solver->solveLimited(miniAssumptions); + if (res == (MapleCOMSPS::lbool((uint8_t)0))) return 10; + if (res == (MapleCOMSPS::lbool((uint8_t)1))) return 20; + return 0; +} + +int basemaple::val(int l) { + if (solver->model[l] != (MapleCOMSPS::lbool((uint8_t)2))) { + int lit = solver->model[l] == (MapleCOMSPS::lbool((uint8_t)0)) ? l + 1 : -(l + 1); + return lit; + } + return l; +} + +void basemaple::terminate() { + solver->interrupt(); +} + +void cbkLstechExportClause(void * issuer, int lbd, MapleCOMSPS::vec &cls) { + basemaple* mp = (basemaple*)issuer; + if (lbd > mp->good_clause_lbd) return; + + shared_ptr ncls = std::make_shared(cls.size()); + for (int i = 0; i < cls.size(); i++) { + ncls->data[i] = INT_LIT(cls[i]); + } + + ncls->lbd = lbd; + mp->export_clause.push(ncls); +} + +bool cbkLstechImportClause(void * issuer, int * lbd, MapleCOMSPS::vec & mcls) { + basemaple* mp = (basemaple*)issuer; + shared_ptr cls = NULL; + if (mp->import_clause.pop(cls) == false) return false; + *lbd = cls->lbd; + mcls.clear(); + for (size_t i = 0; i < cls->size; i++) { + MapleCOMSPS::Lit lit = MINI_LIT(cls->data[i]); + mcls.push(lit); + } + cls->free_clause(); + return true; +} + +basemaple::basemaple(int id, light* light) : basesolver(id, light) { + printf("c id is %d\n", id); + solver = new MapleCOMSPS::SimpSolver(); + solver->issuer = this; + solver->cbkExportClause = NULL; + solver->cbkImportClause = NULL; + if (OPT(share)) { + solver->cbkExportClause = cbkLstechExportClause; + solver->cbkImportClause = cbkLstechImportClause; + } +} + +basemaple::~basemaple() +{ + delete solver; +} + +void basemaple::parse_from_MEM(char* instance) { + int vars, clauses; + vec> clause; + readinstance(instance, &vars, &clauses, clause); + maxvar = vars; + while (vars > solver->nVars()) solver->newVar(); + MapleCOMSPS::vec lits; + for (int i = 1; i <= clauses; i++) { + int l = clause[i].size(); + lits.clear(); + for (int j = 0; j < l; j++) + lits.push(MINI_LIT(clause[i][j])); + solver->addClause_(lits); + } +} +int basemaple::get_conflicts() { + return 0; +} \ No newline at end of file diff --git a/src/solver_api/basemaple.hpp b/src/solver_api/basemaple.hpp new file mode 100755 index 0000000..e8be60b --- /dev/null +++ b/src/solver_api/basemaple.hpp @@ -0,0 +1,33 @@ +#include "basesolver.hpp" + +namespace MapleCOMSPS +{ + class SimpSolver; + class Lit; + template class vec; +} + +class basemaple : public basesolver { +public: + void terminate(); + void add(int l); + int solve(); + int val(int l); + int configure(const char* name, int id); + + int get_conflicts(); + void parse_from_MEM(char* instance); + void exp_clause(void *cl, int lbd) { + puts("wrong"); + } + bool imp_clause(shared_ptrcls, void *cl) { + puts("wrong"); + } + + basemaple(int id, light *light); + ~basemaple(); + + MapleCOMSPS::SimpSolver* solver; + friend bool cbkLstechImportClause(void *, int *, MapleCOMSPS::vec &); + friend void cbkLstechExportClause(void *, int, MapleCOMSPS::vec &); +};