add maple interface
This commit is contained in:
parent
c7b82c2ad9
commit
c9447a1291
@ -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
|
||||
|
@ -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.
|
||||
**************************************************************************************************/
|
@ -1,32 +0,0 @@
|
||||
How to build:
|
||||
use the command "./starexec_build"
|
||||
|
||||
How to use:
|
||||
In the "bin" directory,
|
||||
use the command "./lstech_maple <input_cnf>"
|
||||
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
|
Binary file not shown.
54
lstech_maple/lstech/.vscode/settings.json
vendored
54
lstech_maple/lstech/.vscode/settings.json
vendored
@ -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"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
/home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/SimpSolver.o /home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/SimpSolver.or /home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/SimpSolver.od /home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/SimpSolver.op: \
|
||||
/home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/SimpSolver.cc \
|
||||
../mtl/Sort.h ../mtl/Vec.h ../mtl/IntTypes.h ../mtl/XAlloc.h \
|
||||
../simp/SimpSolver.h ../mtl/Queue.h ../core/Solver.h ../mtl/Heap.h \
|
||||
../mtl/Alg.h ../utils/Options.h ../utils/ParseUtils.h \
|
||||
../core/SolverTypes.h ../mtl/Map.h ../mtl/Alloc.h ../utils/ccnr.h \
|
||||
../utils/System.h
|
||||
/home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/Main.o /home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/Main.or /home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/Main.od /home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/Main.op: /home/zhangxd/solvers/rdpaper/lstech_maple/lstech/simp/Main.cc \
|
||||
../utils/System.h ../mtl/IntTypes.h ../utils/ParseUtils.h \
|
||||
../utils/Options.h ../mtl/Vec.h ../mtl/XAlloc.h ../core/Dimacs.h \
|
||||
../core/SolverTypes.h ../mtl/Alg.h ../mtl/Map.h ../mtl/Alloc.h \
|
||||
../simp/SimpSolver.h ../mtl/Queue.h ../core/Solver.h ../mtl/Heap.h \
|
||||
../utils/ccnr.h
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,822 +0,0 @@
|
||||
#include "ccnr.h"
|
||||
#include <fstream>
|
||||
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; i<lssolver->goodvar_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]<lssolver->time_stamp[best_var]) best_var = v;
|
||||
}
|
||||
|
||||
return best_var;
|
||||
}
|
||||
|
||||
/*SD (significant decreasing) mode, the level with aspiration*/
|
||||
best_var = 0;
|
||||
for(i=0; i<lssolver->unsatvar_stack_fill_pointer; ++i)
|
||||
{
|
||||
if(lssolver->score[lssolver->unsatvar_stack[i]]>lssolver->ave_weight)
|
||||
{
|
||||
best_var = lssolver->unsatvar_stack[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(++i; i<lssolver->unsatvar_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]<lssolver->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; k<lssolver->clause_lit_count[c]; ++k)
|
||||
{
|
||||
v=clause_c[k].var_num;
|
||||
//if(time_stamp[v]<time_stamp[best_var]) best_var = v;
|
||||
if(lssolver->score[v]>lssolver->score[best_var]) best_var = v;
|
||||
else if(lssolver->score[v]==lssolver->score[best_var]&&lssolver->time_stamp[v]<lssolver->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->step<lssolver->max_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;i<lssolver->unsatvar_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; c<lssolver->num_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; c<lssolver->num_clauses; ++c)
|
||||
{
|
||||
if(lssolver->clause_delete[c]==1) continue;
|
||||
|
||||
lssolver->sat_count[c] = 0;
|
||||
|
||||
for(j=0; j<lssolver->clause_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; i<lit_count; ++i)
|
||||
{
|
||||
c = lssolver->var_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; i<lssolver->score_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; i<lssolver->clause_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; i<lssolver->clause_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; ii<lssolver->clause_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; c<lssolver->num_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; j<lssolver->clause_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; i<lssolver->unsatvar_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; i<lssolver->var_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; j<lssolver->clause_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; i<lssolver->clause_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; i<lssolver->clause_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; ii<lssolver->clause_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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
#ifndef _CCA_H_
|
||||
#define _CCA_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/times.h> //these two h files are for linux
|
||||
#include <unistd.h>
|
||||
|
||||
// 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
|
||||
|
Binary file not shown.
@ -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
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
makefile
4
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
|
||||
|
||||
|
32
lstech_maple/Makefile → mapleCOMSPS/Makefile
Executable file → Normal file
32
lstech_maple/Makefile → mapleCOMSPS/Makefile
Executable file → Normal file
@ -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 \
|
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user