version 1.0

This commit is contained in:
iHaN-o 2022-08-30 15:42:35 +08:00
commit 51be6a77a8
543 changed files with 54515 additions and 0 deletions

1
.vscode/configurationCache.log vendored Normal file
View File

@ -0,0 +1 @@
{"buildTargets":["clean","light"],"launchTargets":["/home/chenzh/solvers/Light>light()"],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":["/home/chenzh/solvers/Light","/home/chenzh/solvers/Light/kissat-inc"],"compilerArgs":["-c","paras.cpp","-o","paras.o","-O3","-lkissat","-Lkissat-inc/build/","-lpthread","-lz","-lm","-static"],"compilerPath":"/usr/bin/g++","standard":"c++11","windowsSdkVersion":""},"fileIndex":[["/home/chenzh/solvers/Light/light.cpp",{"uri":{"$mid":1,"fsPath":"/home/chenzh/solvers/Light/light.cpp","path":"/home/chenzh/solvers/Light/light.cpp","scheme":"file"},"configuration":{"defines":[],"standard":"c++11","includePath":["/home/chenzh/solvers/Light/kissat-inc"],"forcedInclude":[],"compilerPath":"/usr/bin/g++","compilerArgs":["-c","light.cpp","-o","light.o","-O3","-lkissat","-Lkissat-inc/build/","-lpthread","-lz","-lm","-static"],"windowsSdkVersion":""},"compileCommand":{"command":"g++ -c light.cpp -o light.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static","directory":"/home/chenzh/solvers/Light","file":"/home/chenzh/solvers/Light/light.cpp"}}],["/home/chenzh/solvers/Light/basekissat.cpp",{"uri":{"$mid":1,"fsPath":"/home/chenzh/solvers/Light/basekissat.cpp","path":"/home/chenzh/solvers/Light/basekissat.cpp","scheme":"file"},"configuration":{"defines":[],"standard":"c++11","includePath":["/home/chenzh/solvers/Light/kissat-inc"],"forcedInclude":[],"compilerPath":"/usr/bin/g++","compilerArgs":["-c","basekissat.cpp","-o","basekissat.o","-O3","-lkissat","-Lkissat-inc/build/","-lpthread","-lz","-lm","-static"],"windowsSdkVersion":""},"compileCommand":{"command":"g++ -c basekissat.cpp -o basekissat.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static","directory":"/home/chenzh/solvers/Light","file":"/home/chenzh/solvers/Light/basekissat.cpp"}}],["/home/chenzh/solvers/Light/main.cpp",{"uri":{"$mid":1,"fsPath":"/home/chenzh/solvers/Light/main.cpp","path":"/home/chenzh/solvers/Light/main.cpp","scheme":"file"},"configuration":{"defines":[],"standard":"c++11","includePath":["/home/chenzh/solvers/Light/kissat-inc"],"forcedInclude":[],"compilerPath":"/usr/bin/g++","compilerArgs":["-c","main.cpp","-o","main.o","-O3","-lkissat","-Lkissat-inc/build/","-lpthread","-lz","-lm","-static"],"windowsSdkVersion":""},"compileCommand":{"command":"g++ -c main.cpp -o main.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static","directory":"/home/chenzh/solvers/Light","file":"/home/chenzh/solvers/Light/main.cpp"}}],["/home/chenzh/solvers/Light/solve.cpp",{"uri":{"$mid":1,"fsPath":"/home/chenzh/solvers/Light/solve.cpp","path":"/home/chenzh/solvers/Light/solve.cpp","scheme":"file"},"configuration":{"defines":[],"standard":"c++11","includePath":["/home/chenzh/solvers/Light/kissat-inc"],"forcedInclude":[],"compilerPath":"/usr/bin/g++","compilerArgs":["-c","solve.cpp","-o","solve.o","-O3","-lkissat","-Lkissat-inc/build/","-lpthread","-lz","-lm","-static"],"windowsSdkVersion":""},"compileCommand":{"command":"g++ -c solve.cpp -o solve.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static","directory":"/home/chenzh/solvers/Light","file":"/home/chenzh/solvers/Light/solve.cpp"}}],["/home/chenzh/solvers/Light/paras.cpp",{"uri":{"$mid":1,"fsPath":"/home/chenzh/solvers/Light/paras.cpp","path":"/home/chenzh/solvers/Light/paras.cpp","scheme":"file"},"configuration":{"defines":[],"standard":"c++11","includePath":["/home/chenzh/solvers/Light/kissat-inc"],"forcedInclude":[],"compilerPath":"/usr/bin/g++","compilerArgs":["-c","paras.cpp","-o","paras.o","-O3","-lkissat","-Lkissat-inc/build/","-lpthread","-lz","-lm","-static"],"windowsSdkVersion":""},"compileCommand":{"command":"g++ -c paras.cpp -o paras.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static","directory":"/home/chenzh/solvers/Light","file":"/home/chenzh/solvers/Light/paras.cpp"}}]]}}

10
.vscode/dryrun.log vendored Normal file
View File

@ -0,0 +1,10 @@
make --dry-run --always-make --keep-going --print-directory
make: Entering directory '/home/chenzh/solvers/Light'
g++ -c light.cpp -o light.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static
g++ -c basekissat.cpp -o basekissat.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static
g++ -c main.cpp -o main.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static
g++ -c solve.cpp -o solve.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static
g++ -c paras.cpp -o paras.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static
g++ -o light light.o basekissat.o main.o solve.o paras.o -Ikissat-inc -std=c++11 -O3 -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static
make: Leaving directory '/home/chenzh/solvers/Light'

58
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,58 @@
{
"files.associations": {
"cstring": "cpp",
"typeinfo": "cpp",
"iostream": "cpp",
"map": "cpp",
"unordered_map": "cpp",
"chrono": "cpp",
"thread": "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",
"bit": "cpp",
"*.tcc": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp"
}
}

254
.vscode/targets.log vendored Normal file
View File

@ -0,0 +1,254 @@
make all --print-data-base --no-builtin-variables --no-builtin-rules --question
make: *** No rule to make target 'all'. Stop.
# GNU Make 4.2.1
# Built for x86_64-pc-linux-gnu
# Copyright (C) 1988-2016 Free Software Foundation, Inc.
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.
# Make data base, printed on Fri Aug 26 09:46:04 2022
# Variables
# automatic
<D = $(patsubst %/,%,$(dir $<))
# automatic
?F = $(notdir $?)
# default
.SHELLFLAGS := -c
# environment
VSCODE_AGENT_FOLDER = /home/chenzh/.vscode-server
# automatic
?D = $(patsubst %/,%,$(dir $?))
# automatic
@D = $(patsubst %/,%,$(dir $@))
# automatic
@F = $(notdir $@)
# makefile
CURDIR := /home/chenzh/solvers/Light
# makefile
SHELL = /bin/sh
# environment
VSCODE_NLS_CONFIG = {"locale":"zh-cn","availableLanguages":{"*":"zh-cn"},"_languagePackId":"cc0490d1397af23dc5bf44a96fe15dbb.zh-cn","_translationsConfigFile":"/home/chenzh/.vscode-server/data/clp/cc0490d1397af23dc5bf44a96fe15dbb.zh-cn/tcf.json","_cacheRoot":"/home/chenzh/.vscode-server/data/clp/cc0490d1397af23dc5bf44a96fe15dbb.zh-cn","_resolvedLanguagePackCoreLocation":"/home/chenzh/.vscode-server/data/clp/cc0490d1397af23dc5bf44a96fe15dbb.zh-cn/e4503b30fc78200f846c62cf8091b76ff5547662","_corruptedFile":"/home/chenzh/.vscode-server/data/clp/cc0490d1397af23dc5bf44a96fe15dbb.zh-cn/corrupted.info","_languagePackSupport":true}
# environment
_ = /home/chenzh/.vscode-server/bin/e4503b30fc78200f846c62cf8091b76ff5547662/node
# makefile (from 'makefile', line 1)
MAKEFILE_LIST := makefile
# 'override' directive
GNUMAKEFLAGS :=
# makefile (from 'makefile', line 10)
CXXFLAGS = -Ikissat-inc -std=c++11 -O3
# environment
XDG_DATA_DIRS = /usr/local/share:/usr/share:/var/lib/snapd/desktop
# makefile (from 'makefile', line 3)
OBJS = $(addsuffix .o, $(basename $(SRCS)))
# environment
LESSOPEN = | /usr/bin/lesspipe %s
# environment
VSCODE_CWD = /home/chenzh
# environment
SSH_CONNECTION = 172.16.2.5 62969 192.168.100.1 22
# environment
PATH = /home/chenzh/.vscode-server/bin/e4503b30fc78200f846c62cf8091b76ff5547662/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
# environment
ELECTRON_RUN_AS_NODE = 1
# environment
VSCODE_IPC_HOOK_CLI = /tmp/vscode-ipc-66783d91-6111-4309-8bbc-0cdfc3119c20.sock
# default
.FEATURES := target-specific order-only second-expansion else-if shortest-stem undefine oneshell archives jobserver output-sync check-symlink load
# environment
LS_COLORS =
# automatic
%F = $(notdir $%)
# environment
PWD = /home/chenzh/solvers/Light
# default
.LOADED :=
# automatic
*D = $(patsubst %/,%,$(dir $*))
# environment
VSCODE_AMD_ENTRYPOINT = vs/workbench/api/node/extensionHostProcess
# environment
HOME = /home/chenzh
# environment
LESSCLOSE = /usr/bin/lesspipe %s %s
# environment
LOGNAME = chenzh
# environment
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = 1
# automatic
+F = $(notdir $+)
# environment
VSCODE_HANDLES_UNCAUGHT_ERRORS = true
# automatic
^D = $(patsubst %/,%,$(dir $^))
# environment
MAKELEVEL := 0
# default
MAKE = $(MAKE_COMMAND)
# default
MAKECMDGOALS := all
# makefile (from 'makefile', line 1)
SRCS = $(shell find . -name "*.cpp")
# environment
SHLVL = 0
# makefile (from 'makefile', line 5)
EXEC = light
# default
MAKE_VERSION := 4.2.1
# environment
USER = chenzh
# makefile
.DEFAULT_GOAL := light
# automatic
%D = $(patsubst %/,%,$(dir $%))
# default
MAKE_COMMAND := make
# environment
OLDPWD = /home/chenzh/.vscode-server/bin/e4503b30fc78200f846c62cf8091b76ff5547662
# default
.VARIABLES :=
# automatic
*F = $(notdir $*)
# makefile
MAKEFLAGS = pqrR
# environment
MFLAGS = -pqrR
# environment
SSH_CLIENT = 172.16.2.5 62969 22
# automatic
+D = $(patsubst %/,%,$(dir $+))
# environment
BROWSER = /home/chenzh/.vscode-server/bin/e4503b30fc78200f846c62cf8091b76ff5547662/bin/helpers/browser.sh
# environment
VSCODE_HANDLES_SIGPIPE = true
# 'override' directive
.SHELLSTATUS := 0
# default
MAKEFILES :=
# automatic
<F = $(notdir $<)
# environment
LC_ALL = C
# makefile (from 'makefile', line 7)
LIBS = -lkissat -Lkissat-inc/build/ -lpthread -lz -lm -static
# automatic
^F = $(notdir $^)
# default
SUFFIXES :=
# default
.INCLUDE_DIRS = /usr/include /usr/local/include /usr/include
# default
.RECIPEPREFIX :=
# default
MAKE_HOST := x86_64-pc-linux-gnu
# environment
LANG = C
# environment
MOTD_SHOWN = pam
# variable set hash-table stats:
# Load=68/1024=7%, Rehash=0, Collisions=9/99=9%
# Pattern-specific Variable Values
# No pattern-specific variable values.
# Directories
# . (device 55, inode 89687378): 23 files, no impossibilities.
# 23 files, no impossibilities in 1 directories.
# Implicit Rules
%.o: %.cpp
# recipe to execute (from 'makefile', line 16):
$(CXX) -c $< -o $@ $(CXXFLAGS) $(LIBS)
# 1 implicit rules, 0 (0.0%) terminal.
# Files
# Not a target:
all:
# Command line target.
# Implicit rule search has been done.
# File does not exist.
# File has not been updated.
# Not a target:
makefile:
# Implicit rule search has been done.
# Last modified 2022-08-24 20:09:30.944291003
# File has been updated.
# Successfully updated.
# Not a target:
solve.o:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# Not a target:
.DEFAULT:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# Not a target:
light.o:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# Not a target:
basekissat.o:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
light: light.o basekissat.o main.o solve.o paras.o
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# recipe to execute (from 'makefile', line 13):
$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
clean:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# recipe to execute (from 'makefile', line 19):
rm -f $(OBJS) $(EXEC)
# Not a target:
paras.o:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# Not a target:
main.o:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# files hash-table stats:
# Load=11/1024=1%, Rehash=0, Collisions=0/26=0%
# VPATH Search Paths
# No 'vpath' search paths.
# No general ('VPATH' variable) search path.
# strcache buffers: 1 (0) / strings = 31 / storage = 286 B / avg = 9 B
# current buf: size = 8162 B / used = 286 B / count = 31 / avg = 9 B
# strcache performance: lookups = 43 / hit rate = 27%
# hash-table stats:
# Load=31/8192=0%, Rehash=0, Collisions=1/43=2%
# Finished Make data base on Fri Aug 26 09:46:04 2022

24
README.md Normal file
View File

@ -0,0 +1,24 @@
### Compile
```
make clean; make
```
### Run
$instance: input cnf
$threads: number of threads
$time-limit: maximum running time
```
./pakissat $instance $threads $time-limit
```

BIN
light Executable file

Binary file not shown.

43
light.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <chrono>
#include "light.hpp"
#include <unistd.h>
#include <thread>
using namespace std;
light::light():
finalResult (0),
winner (0),
maxtime (5000),
globalEnding (false)
{
opt = new paras();
opt->init_paras();
}
light::~light() {
for (int i = 0; i < solvers.size(); i++) delete(solvers[i]);
solvers.clear(true);
}
void light::arg_parse(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (arg[0] != '-' || arg[1] != '-') {
filename = arg; continue;
}
int l = strlen(arg), pos = 0;
for (int i = 2; i < l; i++)
if (arg[i] == '=') pos = i;
if (!pos) continue;
char name[50];
strncpy(name, arg + 2, pos - 2);
name[pos - 2] = '\0';
char* val = arg + pos + 1;
if (opt->map_int.count(name)) opt->set_para(name, atoi(val));
opt->set_para(name, atof(val));
}
opt->sync_paras();
opt->print_change();
printf("c filename: %s\n", filename);
}

39
light.hpp Normal file
View File

@ -0,0 +1,39 @@
#ifndef _light_hpp_INCLUDED
#define _light_hpp_INCLUDED
#include "utils/paras.hpp"
#include "preprocess.hpp"
#include <atomic>
#include <iostream>
using namespace std;
typedef long long ll;
class basesolver;
struct light
{
public:
light();
~light();
char *filename;
paras *opt;
preprocess *pre;
vec<basesolver *> solvers;
int finalResult;
int winner;
int maxtime;
atomic<bool> globalEnding;
void arg_parse(int argc, char **argv);
void init_solvers();
void diversity_solvers();
void parse_input();
int run();
int solve();
void terminate_solvers();
void print_model();
};
#endif

BIN
light.o Normal file

Binary file not shown.

9
main.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "solve.hpp"
#include <chrono>
#include <thread>
using namespace std;
int main(int argc, char **argv) {
solve(argc, argv);
return 0;
}

BIN
main.o Normal file

Binary file not shown.

19
makefile Normal file
View File

@ -0,0 +1,19 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = $(addsuffix .o, $(basename $(SRCS)))
EXEC = light
LIBS = -lkissat -Lsolvers/kissat-inc/build/ \
-lpthread -lz -lm -static
CXXFLAGS = -Isolvers/kissat-inc -std=c++11 -O3
$(EXEC): $(OBJS)
$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
%.o: %.cpp
$(CXX) -c $< -o $@ $(CXXFLAGS) $(LIBS)
clean:
rm -f $(OBJS) $(EXEC)

546
preprocess.cpp Normal file
View File

@ -0,0 +1,546 @@
#include "preprocess.hpp"
preprocess::preprocess():
vars (0),
clauses (0),
maxlen (0)
{}
inline int pnsign(int x) {
return (x > 0 ? 1 : -1);
}
inline int sign(int x) {
return x & 1 ? -1 : 1;
}
inline int tolit(int x) {
return x > 0 ? ((x - 1) << 1) : ((-x - 1) << 1 | 1);
}
inline int negative(int x) {
return x ^ 1;
}
inline int toiidx(int x) {
return (x >> 1) + 1;
}
inline int toeidx(int x) {
return (x & 1 ? -toiidx(x) : toiidx(x));
}
inline ll preprocess::mapv(int a, int b) {
return 1ll * a * nlit + (ll)b;
}
int preprocess::find(int x) {
if (f[x] == x) return x;
int fa = f[x];
f[x] = find(fa);
val[x] = val[fa] * val[x];
return f[x];
}
void preprocess::preprocess_init() {
f = new int[vars + 10];
val = new int[vars + 10];
color = new int[vars + 10];
varval = new int[vars + 10];
q = new int[vars + 10];
clean = new int[vars + 10];
seen = new int[(vars << 1) + 10];
clause_delete.growTo(clauses+1, 0);
nxtc.growTo(clauses+1, 0);
occurp = new vec<int>[vars + 1];
occurn = new vec<int>[vars + 1];
for (int i = 1; i <= clauses; i++) {
int l = clause[i].size();
if (l > maxlen) maxlen = l;
}
resseen = new int[(vars << 1) + 10];
a = new int[maxlen + 1];
mapval = new int[vars + 10];
mapto = new int[vars + 10];
for (int i = 1; i <= vars; i++) mapto[i] = i, mapval[i] = 0;
}
void preprocess::release() {
delete []f;
delete []val;
delete []color;
delete []varval;
delete []q;
delete []clean;
delete []seen;
clause_delete.clear(true);
nxtc.clear(true);
delete []resseen;
delete []a;
delete []mapfrom;
for (int i = 0; i <= vars; i++)
occurp[i].clear(true), occurn[i].clear(true);
delete []occurp;
delete []occurn;
delete C;
}
bool preprocess::res_is_empty(int x) {
int op = occurp[x].size(), on = occurn[x].size();
for (int i = 0; i < op; i++) {
int o1 = occurp[x][i], l1 = clause[o1].size();
if (clause_delete[o1]) continue;
for (int j = 0; j < l1; j++)
if (abs(clause[o1][j]) != x) resseen[abs(clause[o1][j])] = pnsign(clause[o1][j]);
for (int j = 0; j < on; j++) {
int o2 = occurn[x][j], l2 = clause[o2].size(), flag = 0;
if (clause_delete[o2]) continue;
for (int k = 0; k < l2; k++)
if (abs(clause[o2][k]) != x && resseen[abs(clause[o2][k])] == -pnsign(clause[o2][k])) {
flag = 1; break;
}
if (!flag) {
for (int j = 0; j < l1; j++)
resseen[abs(clause[o1][j])] = 0;
return false;
}
}
for (int j = 0; j < l1; j++)
resseen[abs(clause[o1][j])] = 0;
}
return true;
}
bool preprocess::preprocess_resolution() {
for (int i = 1; i <= vars; i++) {
occurn[i].clear();
occurp[i].clear();
resseen[i] = resseen[i + vars] = clean[i] = seen[i] = 0;
}
for (int i = 1; i <= clauses; i++) {
int l = clause[i].size();
clause_delete[i] = 0;
for (int j = 0; j < l; j++)
if (clause[i][j] > 0) occurp[abs(clause[i][j])].push(i);
else occurn[abs(clause[i][j])].push(i);
}
for (int i = 1; i <= vars; i++)
if (occurn[i].size() == 0 && occurp[i].size() == 0) clean[i] = 1;
int l = 1, r = 0;
for (int i = 1; i <= vars; i++) {
int op = occurp[i].size(), on = occurn[i].size();
if (op * on > op + on || clean[i]) continue;
if (res_is_empty(i)) {
q[++r] = i, clean[i] = 1;
}
}
int now_turn = 0, seen_flag = 0;
vec<int> vars;
while (l <= r) {
++now_turn;
for (int j = l; j <= r; j++) {
int i = q[j];
int op = occurp[i].size(), on = occurn[i].size();
for (int j = 0; j < op; j++) clause_delete[occurp[i][j]] = 1;
for (int j = 0; j < on; j++) clause_delete[occurn[i][j]] = 1;
}
int ll = l; l = r + 1;
vars.clear();
++seen_flag;
for (int u = ll; u <= r; u++) {
int i = q[u];
int op = occurp[i].size(), on = occurn[i].size();
for (int j = 0; j < op; j++) {
int o = occurp[i][j], l = clause[o].size();
for (int k = 0; k < l; k++) {
int v = abs(clause[o][k]);
if (!clean[v] && seen[v] != seen_flag)
vars.push(v), seen[v] = seen_flag;
}
}
for (int j = 0; j < on; j++) {
int o = occurn[i][j], l = clause[o].size();
for (int k = 0; k < l; k++) {
int v = abs(clause[o][k]);
if (!clean[v] && seen[v] != seen_flag)
vars.push(v), seen[v] = seen_flag;
}
}
}
for (int u = 0; u < vars.size(); u++) {
int i = vars[u];
int op = 0, on = 0;
for (int j = 0; j < occurp[i].size(); j++) op += 1 - clause_delete[occurp[i][j]];
for (int j = 0; j < occurn[i].size(); j++) on += 1 - clause_delete[occurn[i][j]];
if (op * on > op + on) continue;
if (res_is_empty(i)) {
q[++r] = i, clean[i] = 1;
}
}
}
vars.clear(true);
if (!r) return true;
res_clauses = 0;
res_clause.push();
for (int i = 1; i <= clauses; i++) {
if (!clause_delete[i]) continue;
++res_clauses;
res_clause.push();
int l = clause[i].size();
for (int j = 0; j < l; j++) {
res_clause[res_clauses].push(pnsign(clause[i][j]) * mapfrom[abs(clause[i][j])]);
}
}
resolutions = r;
resolution.push();
for (int i = 1; i <= r; i++) {
int v = mapfrom[q[i]];
resolution.push(v);
mapto[v] = 0, mapval[v] = -10;
}
update_var_clause_label();
for (int i = 1; i <= orivars; i++) {
if (mapto[i]) {
mapto[i] = color[mapto[i]];
}
}
return true;
}
void preprocess::update_var_clause_label() {
int remain_var = 0;
for (int i = 1; i <= vars; i++) color[i] = 0;
for (int i = 1; i <= clauses; i++) {
if (clause_delete[i]) continue;
int l = clause[i].size();
for (int j = 0; j < l; j++) {
if (color[abs(clause[i][j])] == 0) color[abs(clause[i][j])] = ++remain_var;
}
}
int id = 0;
for (int i = 1; i <= clauses; i++) {
if (clause_delete[i]) {clause[i].setsize(0); continue;}
++id;
int l = clause[i].size();
if (i == id) {
for (int j = 0; j < l; j++)
clause[id][j] = color[abs(clause[i][j])] * pnsign(clause[i][j]);
continue;
}
clause[id].setsize(0);
for (int j = 0; j < l; j++)
clause[id].push(color[abs(clause[i][j])] * pnsign(clause[i][j]));
}
printf("c After preprocess: vars: %d -> %d , clauses: %d -> %d ,\n", vars, remain_var, clauses, id);
for (int i = id + 1; i <= clauses; i++)
clause[i].clear(true);
for (int i = remain_var + 1; i <= vars; i++)
occurp[i].clear(true), occurn[i].clear(true);
clause.setsize(id + 1);
vars = remain_var, clauses = id;
}
bool preprocess::preprocess_binary() {
C = new HashMap();
for (int i = 1; i <= clauses; i++) {
int l = clause[i].size();
for (int j = 0; j < l; j++)
clause[i][j] = tolit(clause[i][j]);
}
nlit = vars << 1;
for (int i = 1; i <= vars; i++) f[i] = i, val[i] = 1, color[i] = 0;
for (int i = 1; i <= clauses; i++) clause_delete[i] = 0;
int len = 0;
for (int i = 1; i <= clauses; i++) {
if (clause[i].size() != 2) continue;
nxtc[++len] = i;
ll id1 = mapv(clause[i][0], clause[i][1]),
id2 = mapv(clause[i][1], clause[i][0]);
C->insert(id1, i);
C->insert(id2, i);
}
for (int k = 1; k <= len; k++) {
int i = nxtc[k];
if (clause[i].size() != 2 || clause_delete[i]) continue;
int r = C->get(mapv(negative(clause[i][0]), negative(clause[i][1])), 0);
if (r) {
clause_delete[r] = clause_delete[i] = 1;
int u = toiidx(clause[i][0]), v = toiidx(clause[i][1]);
int fa = find(u), fb = find(v);
int sig = sign(clause[i][0]) * sign(clause[i][1]) * (-1);
//sig == 1 : a = b -1 : a = -b
if (fa != fb) {
if (fa < fb) {
f[fa] = fb;
val[fa] = sig / (val[u] * val[v]);
}
else if (fa > fb) {
f[fb] = fa;
val[fb] = sig / (val[u] * val[v]);
}
}
else if (sig != val[u] * val[v])
return false;
}
}
for (int i = 1; i <= clauses; i++) {
if (clause_delete[i]) continue;
int l = clause[i].size(), oril = l;
for (int j = 0; j < l; j++) {
int u = toiidx(clause[i][j]);
a[j] = tolit(sign(clause[i][j]) * val[u] * f[u]);
}
int t = 0;
for (int j = 0; j < l; j++) {
if (resseen[a[j]] == i) continue;
resseen[a[j]] = i, a[t++] = a[j];
}
if (t != l) l = t;
for (int j = 0; j < l; j++)
if (resseen[negative(a[j])] == i)
clause_delete[i] = 1;
for (int j = 0; j < l; j++) resseen[a[j]] = 0;
clause[i].clear();
for (int j = 0; j < l; j++)
clause[i].push(a[j]);
}
for (int i = 1; i <= clauses; i++) {
if (clause_delete[i]) continue;
int l = clause[i].size();
for (int j = 0; j < l; j++) {
clause[i][j] = toeidx(clause[i][j]);
}
}
update_var_clause_label();
for (int i = 1; i <= orivars; i++) {
if (mapval[i]) continue;
int v = mapto[i], fa = find(v);
if (color[fa]) mapto[i] = color[fa] * val[v];
else {puts("why happened"); mapval[i] = val[v], mapto[i] = 0;}
}
return true;
}
bool preprocess::preprocess_easy_clause() {
for (int i = 1; i <= vars; i++) {
varval[i] = 0;
occurp[i].clear();
occurn[i].clear();
resseen[(i - 1) << 1] = resseen[(i - 1) << 1 | 1] = 0;
}
for (int i = 1; i <= clauses; i++) clause_delete[i] = 0;
int head = 1, tail = 0;
for (int i = 1; i <= clauses; i++) {
int l = clause[i].size(), t = 0;
for (int j = 0; j < l; j++) {
int lit = tolit(clause[i][j]);
if (resseen[lit] == i) continue;
if (resseen[negative(lit)] == i) {clause_delete[i] = 1; break;}
clause[i][t++] = clause[i][j];
resseen[lit] = i;
}
if (clause_delete[i]) continue;
clause[i].setsize(t);
for (int j = 0; j < t; j++)
if (clause[i][j] > 0) occurp[clause[i][j]].push(i);
else occurn[-clause[i][j]].push(i);
if (t == 0) return false;
if (t == 1) {
int lit = clause[i][0];
clause_delete[i] = 1;
if (varval[abs(lit)]) {
if (varval[abs(lit)] == pnsign(lit)) continue;
else return false;
}
varval[abs(lit)] = pnsign(lit);
q[++tail] = abs(lit);
}
}
for (int i = 1; i <= vars + vars; i++) resseen[i] = 0;
while (head <= tail) {
int x = q[head++];
if (varval[x] == 1) {
for (int i = 0; i < occurp[x].size(); i++)
clause_delete[occurp[x][i]] = 1;
for (int i = 0; i < occurn[x].size(); i++) {
int o = occurn[x][i], t = 0;
if (clause_delete[o]) continue;
for (int j = 0; j < clause[o].size(); j++) {
if (varval[abs(clause[o][j])] == pnsign(clause[o][j])) {
clause_delete[o] = 1; break;
}
if (varval[abs(clause[o][j])] == -pnsign(clause[o][j])) continue;
clause[o][t++] = clause[o][j];
}
if (clause_delete[o]) continue;
clause[o].setsize(t);
if (t == 0) return false;
if (t == 1) {
int lit = clause[o][0];
clause_delete[o] = 1;
if (varval[abs(lit)]) {
if (varval[abs(lit)] == pnsign(lit)) continue;
else return false;
}
varval[abs(lit)] = pnsign(lit);
q[++tail] = abs(lit);
}
}
}
else {
for (int i = 0; i < occurn[x].size(); i++)
clause_delete[occurn[x][i]] = 1;
for (int i = 0; i < occurp[x].size(); i++) {
int o = occurp[x][i], t = 0;
if (clause_delete[o]) continue;
for (int j = 0; j < clause[o].size(); j++) {
if (varval[abs(clause[o][j])] == pnsign(clause[o][j])) {
clause_delete[o] = 1; break;
}
if (varval[abs(clause[o][j])] == -pnsign(clause[o][j])) continue;
clause[o][t++] = clause[o][j];
}
if (clause_delete[o]) continue;
clause[o].setsize(t);
if (t == 0) return false;
if (t == 1) {
int lit = clause[o][0];
clause_delete[o] = 1;
if (varval[abs(lit)]) {
if (varval[abs(lit)] == pnsign(lit)) continue;
else return false;
}
varval[abs(lit)] = pnsign(lit);
q[++tail] = abs(lit);
}
}
}
}
update_var_clause_label();
for (int i = 1; i <= tail; i++) {
int v = q[i];
mapval[v] = varval[v];
}
mapfrom = new int[vars + 1];
for (int i = 1; i <= vars; i++) mapfrom[i] = 0;
for (int i = 1; i <= orivars; i++) {
if (color[i])
mapto[i] = color[i], mapfrom[color[i]] = i;
else if (!mapval[i]) // not in unit queue, then it is no use var
mapto[i] = 0, mapval[i] = 1;
else
mapto[i] = 0;
}
return true;
}
void preprocess::get_complete_model() {
int r = 0;
for (int i = 1; i <= orivars; i++)
if (!mapto[i]) {
if (!mapval[i]);
else if (abs(mapval[i]) != 1) mapval[i] = 0, ++r;
}
if (r) {
occurp = new vec<int>[orivars + 1];
occurn = new vec<int>[orivars + 1];
for (int i = 1; i <= orivars; i++) {
occurp[i].clear(), occurn[i].clear();
}
vec<int> clause_state;
clause_state.growTo(res_clauses + 1, 0);
for (int i = 1; i <= res_clauses; i++) {
int satisify = 0;
for (int j = 0; j < res_clause[i].size(); j++) {
int v = res_clause[i][j];
if (v > 0) occurp[v].push(i);
else occurn[-v].push(i);
if (pnsign(v) * mapval[abs(v)] == 1) satisify = 1;
if (!mapval[abs(v)]) ++clause_state[i];
}
if (satisify) clause_state[i] = -1;
}
for (int ii = resolutions; ii >= 1; ii--) {
int v = resolution[ii];
//attempt 1
int assign = 1;
for (int i = 0; i < occurn[v].size(); i++) {
int o = occurn[v][i];
if (clause_state[o] != -1 && clause_state[o] <= 1) {assign = 0; break;}
}
if (assign == 1) {
mapval[v] = 1;
for (int i = 0; i < occurn[v].size(); i++) {
int o = occurn[v][i];
if (clause_state[o] != -1) clause_state[o]--;
}
for (int i = 0; i < occurp[v].size(); i++)
clause_state[occurp[v][i]] = -1;
continue;
}
//attempt -1
assign = -1;
for (int i = 0; i < occurp[v].size(); i++) {
int o = occurp[v][i];
if (clause_state[o] != -1 && clause_state[o] <= 1) {assign = 0; break;}
}
if (assign == -1) {
mapval[v] = -1;
for (int i = 0; i < occurp[v].size(); i++) {
int o = occurp[v][i];
if (clause_state[o] != -1) clause_state[o]--;
}
for (int i = 0; i < occurn[v].size(); i++)
clause_state[occurn[v][i]] = -1;
continue;
}
}
clause_state.clear(true);
for (int i = 1; i <= orivars; i++) {
occurp[i].clear(true), occurn[i].clear(true);
}
delete []occurp;
delete []occurn;
res_clause.clear(true);
resolution.clear(true);
}
}
int preprocess::do_preprocess(char* filename) {
readfile(filename);
preprocess_init();
int res = preprocess_easy_clause();
if (!res) {
release();
delete []mapto;
delete []mapval;
clause.clear(true);
return 0;
}
res = preprocess_resolution();
if (!res) {
release();
delete []mapto;
delete []mapval;
clause.clear(true);
res_clause.clear(true);
resolution.clear(true);
return 0;
}
res = preprocess_binary();
if (!res) {
release();
delete []mapto;
delete []mapval;
clause.clear(true);
res_clause.clear(true);
resolution.clear(true);
return 0;
}
release();
return 1;
}

35
preprocess.hpp Normal file
View File

@ -0,0 +1,35 @@
#ifndef _preprocess_hpp_INCLUDED
#define _preprocess_hpp_INCLUDED
#include "utils/hashmap.hpp"
#include "utils/vec.hpp"
typedef long long ll;
struct preprocess {
public:
preprocess();
int vars;
int clauses;
vec<vec<int>> clause, res_clause;
void readfile(const char *file);
void release();
int maxlen, orivars, oriclauses, res_clauses, resolutions;
int *f, nlit, *a, *val, *color, *varval, *q, *seen, *resseen, *clean, *mapto, *mapfrom, *mapval;
HashMap* C;
vec<int> *occurp, *occurn, clause_delete, nxtc, resolution;
ll mapv(int a, int b);
int find(int x);
bool res_is_empty(int var);
void update_var_clause_label();
void preprocess_init();
bool preprocess_resolution();
bool preprocess_binary();
bool preprocess_easy_clause();
void get_complete_model();
int do_preprocess(char* filename);
};
#endif

BIN
preprocess.o Normal file

Binary file not shown.

141
solve.cpp Normal file
View File

@ -0,0 +1,141 @@
#include "light.hpp"
#include "workers/basekissat.hpp"
#include <unistd.h>
#include <chrono>
char* worker_sign = "";
atomic<int> terminated;
auto clk_st = std::chrono::high_resolution_clock::now();
int result = 0;
int winner;
vec<int> model;
void * read_worker(void *arg) {
basesolver * sq = (basesolver *)arg;
if (worker_sign == "")
sq->import_original_clause(sq->controller->pre);
else
sq->parse_dimacs(worker_sign);
return NULL;
}
void * solve_worker(void *arg) {
basesolver * sq = (basesolver *)arg;
while (!terminated) {
int res = sq->solve();
vec<int> seq_model;
if (res == 10) {
sq->get_model(seq_model);
}
if (res && !terminated) {
sq->controller->terminate_solvers();
terminated = 1;
result = res;
winner = sq->id;
if (res == 10) seq_model.copyTo(model);
}
seq_model.clear();
}
return NULL;
}
void light::init_solvers() {
for (int i = 0; i < OPT(threads); i++) {
basekissat* kissat = new basekissat(i, this);
solvers.push(kissat);
}
}
void light::diversity_solvers() {
for (int i = 0; i < OPT(threads); i++) {
solvers[i]->diversity(i);
}
}
void light::terminate_solvers() {
for (int i = 0; i < OPT(threads); i++) {
solvers[i]->terminate();
}
}
void light::parse_input() {
pthread_t *ptr = new pthread_t[OPT(threads)];
for (int i = 0; i < OPT(threads); i++) {
pthread_create(&ptr[i], NULL, read_worker, solvers[i]);
}
for (int i = 0; i < OPT(threads); i++) {
pthread_join(ptr[i], NULL);
}
delete []ptr;
}
int light::solve() {
printf("c -----------------solve start----------------------\n");
terminated = 0;
pthread_t *ptr = new pthread_t[OPT(threads)];
for (int i = 0; i < OPT(threads); i++) {
pthread_create(&ptr[i], NULL, solve_worker, solvers[i]);
}
while (!terminated) {
usleep(100000);
auto clk_now = std::chrono::high_resolution_clock::now();
int solve_time = std::chrono::duration_cast<std::chrono::seconds>(clk_now - clk_st).count();
if (solve_time >= OPT(times)) {
terminated = 1;
terminate_solvers();
}
}
for (int i = 0; i < OPT(threads); i++) {
pthread_join(ptr[i], NULL);
}
delete []ptr;
return result;
}
int light::run() {
init_solvers();
diversity_solvers();
if (OPT(simplify)) {
pre = new preprocess();
int res = pre->do_preprocess(filename);
if (!res) return 20;
}
else worker_sign = filename;
parse_input();
int res = solve();
if (res == 10 && OPT(simplify)) {
for (int i = 1; i <= pre->orivars; i++)
if (pre->mapto[i]) pre->mapval[i] = (model[abs(pre->mapto[i])-1] > 0 ? 1 : -1) * (pre->mapto[i] > 0 ? 1 : -1);
pre->get_complete_model();
model.clear();
for (int i = 1; i <= pre->orivars; i++) {
model.push(i * pre->mapval[i]);
}
}
return res;
}
void print_model(vec<int> &model) {
printf("v");
for (int i = 0; i < model.size(); i++) {
printf(" %d", model[i]);
}
puts(" 0");
}
void solve(int argc, char **argv) {
light* S = new light();
S->arg_parse(argc, argv);
int res = S->run();
if (res == 10) {
printf("s SATISFIABLE\n");
print_model(model);
}
else if (res == 20) {
printf("s UNSATISFIABLE\n");
}
else {
printf("s UNKNOWN\n");
}
delete(S);
return;
}

3
solve.hpp Normal file
View File

@ -0,0 +1,3 @@
#include "light.hpp"
void solve(int argc, char **argv);

BIN
solve.o Normal file

Binary file not shown.

View File

@ -0,0 +1,4 @@
At this point we want to keep complete ownership in one hand
to particularly avoid any additional co-authorship claims.
Thus please refrain from generating pull requests. Use the issue
tracker or send email to 'armin.biere@gmail.com' instead.

View File

@ -0,0 +1,20 @@
Copyright (c) 2019-2020 Armin Biere, Johannes Kepler University Linz, Austria
Copyright (c) 2022 Shaowei Cai, Xindi Zhang, Zhihan Chen, ISCAS, China : Modified the update of target
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.

View File

@ -0,0 +1,13 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.org/arminbiere/kissat.svg?branch=master)](https://travis-ci.org/arminbiere/kissat)
The Kissat SAT Solver
=====================
Kissat is a "keep it simple and clean bare metal SAT solver" written in C.
It is a port of CaDiCaL back to C with improved data structures, better
scheduling of inprocessing and optimized algorithms and implementation.
Coincidentally "kissat" also means "cats" in Finnish.
Run `./configure && make test` to configure, build and test in `build`.

View File

@ -0,0 +1 @@
1.0.3

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.

View File

@ -0,0 +1,5 @@
#define VERSION "1.0.3"
#define COMPILER "gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 -W -Wall -O3 -DNEMBEDDED -DNDEBUG -DNMETRICS -DNSTATISTICS"
#define ID "79d8d8f20465e71fd2b0f193b468898cd803a59a"
#define BUILD "Thu Aug 25 15:41:16 CST 2022 Linux seed1 5.4.0-120-generic x86_64"
#define DIR "/home/chenzh/solvers/Light/kissat-inc/build"

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.

BIN
solvers/kissat-inc/build/kissat Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,68 @@
CC=gcc
CFLAGS=-W -Wall -O3 -DNEMBEDDED -DNDEBUG -DNMETRICS -DNSTATISTICS
LD=gcc
AR=ar
VPATH=../src:../test
%.o: %.c ../[st]*/*.h makefile
$(CC) $(CFLAGS) -c $<
APPSRC=application.c handle.c parse.c witness.c
LIBSRT=$(sort $(wildcard ../src/*.c))
LIBSUB=$(subst ../src/,,$(LIBSRT))
LIBSRC=$(filter-out main.c,$(LIBSUB))
TSTSRT=$(sort $(wildcard ../test/*.c))
TSTSUB=$(subst ../test/,,$(TSTSRT))
TSTSRC=$(filter-out test.c,$(TSTSUB))
APPOBJ=$(APPSRC:.c=.o)
LIBOBJ=$(LIBSRC:.c=.o)
TSTOBJ=$(APPOBJ) $(TSTSRC:.c=.o)
INCLUDES=-I../$(shell pwd|sed -e 's,.*/,,')
all: libkissat.a kissat
test: all tissat
./tissat
REMOVE=*.gcda *.gcno *.gcov gmon.out *~ *.proof
clean:
rm -f kissat tissat
rm -f makefile build.h *.o *.a
rm -f $(REMOVE)
cd ../src; rm -f $(REMOVE)
cd ../test; rm -f $(REMOVE)
coverage:
@gcov -o . -s ../src/*.[ch] 2>&1 | \
../scripts/filter-coverage-output.sh
indent:
indent ../*/*.[ch]
kissat: main.o $(APPOBJ) libkissat.a makefile
$(LD) -o $@ $< $(APPOBJ) -L. -lkissat -lm
tissat: test.o $(TSTOBJ) libkissat.a makefile
$(LD) -o $@ $< $(TSTOBJ) -L. -lkissat -lm
build.h:
../scripts/generate-build-header.sh > $@
collect.o: sort.c
dense.o: sort.c
propagate.o: assign.c
watch.o: sort.c
build.o: build.c build.h ../[st]*/*.h makefile
$(CC) $(CFLAGS) $(INCLUDES) -c $<
test.o: test.c build.h ../[st]*/*.h makefile
$(CC) $(CFLAGS) $(INCLUDES) -c $<
libkissat.a: $(LIBOBJ) makefile
$(AR) rc $@ $(LIBOBJ)
.PHONY: all clean coverage indent test build.h

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.

Some files were not shown because too many files have changed in this diff Show More