From 07321bd6d12aba3cf06613c1970e0228a4147744 Mon Sep 17 00:00:00 2001 From: Utz-Uwe Haus Date: Wed, 2 Jun 2010 09:28:00 +0200 Subject: [PATCH] Import PicoSAT-913 Signed-off-by: Utz-Uwe Haus --- backends/picosat/LICENSE | 20 + backends/picosat/NEWS | 47 + backends/picosat/README | 5 + backends/picosat/VERSION | 1 + backends/picosat/app.c | 829 +++++ backends/picosat/configure | 135 + backends/picosat/main.c | 90 + backends/picosat/makefile.in | 33 + backends/picosat/mkconfig | 35 + backends/picosat/picosat.c | 7170 ++++++++++++++++++++++++++++++++++++++++++ backends/picosat/picosat.h | 397 +++ backends/picosat/version.c | 14 + 12 files changed, 8776 insertions(+) create mode 100644 backends/picosat/LICENSE create mode 100644 backends/picosat/NEWS create mode 100644 backends/picosat/README create mode 100644 backends/picosat/VERSION create mode 100644 backends/picosat/app.c create mode 100755 backends/picosat/configure create mode 100644 backends/picosat/main.c create mode 100644 backends/picosat/makefile.in create mode 100755 backends/picosat/mkconfig create mode 100644 backends/picosat/picosat.c create mode 100644 backends/picosat/picosat.h create mode 100644 backends/picosat/version.c diff --git a/backends/picosat/LICENSE b/backends/picosat/LICENSE new file mode 100644 index 0000000..8896295 --- /dev/null +++ b/backends/picosat/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2006 - 2009, Armin Biere, Johannes Kepler University. + +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/backends/picosat/NEWS b/backends/picosat/NEWS new file mode 100644 index 0000000..fa99703 --- /dev/null +++ b/backends/picosat/NEWS @@ -0,0 +1,47 @@ +news for release 91x since 846 +------------------------------ + +* propagation of binary clauses until completion + +* fixed API usage 'assume;sat;sat' + +* literals move to front (LMTF) during traversal of visited clauses + +* switched from inner/outer to Luby style restart scheduling + +* less agressive reduce schedule + +* replaced watched literals with head and tail pointers + +* add 'picosat_failed_assumption', which allows to avoid tracing and core + generation, if one is only interested in assumptions in the core + +* fixed a BUG in the generic iterator code of clauses + (should rarely happen unless you use a very sophisticated malloc lib) + +news for release 846 since 632 +------------------------------ + +* cleaned up assumption handling (actually removed buggy optimization) + +* incremental core generation + +* experimental 'all different constraint' handling as in our FMCAD'08 paper + +* new API calls: + + - picosat_add_ado_lit (add all different object literal) + - picosat_deref_top_level (deref top level assignment) + - picosat_changed (check whether extension was possible) + - picosat_measure_all_calls (per default do not measure adding time) + - picosat_set_prefix (set prefix for messages) + +* 64 bit port (and compilation options) + +* optional NVSIDS visualization code + +* resource controlled failed literal implementation + +* disconnect long clauses satisfied at lower decision level + +* controlling restarts diff --git a/backends/picosat/README b/backends/picosat/README new file mode 100644 index 0000000..89d6ea5 --- /dev/null +++ b/backends/picosat/README @@ -0,0 +1,5 @@ +These are the sources of the PicoSAT solver. +The preprocessor is not included. +To compile run './configure && make'. +The API is document in 'picosat.h'. +See also 'NEWS' and 'LICENSE'. diff --git a/backends/picosat/VERSION b/backends/picosat/VERSION new file mode 100644 index 0000000..d6904a9 --- /dev/null +++ b/backends/picosat/VERSION @@ -0,0 +1 @@ +913 diff --git a/backends/picosat/app.c b/backends/picosat/app.c new file mode 100644 index 0000000..4b6abbf --- /dev/null +++ b/backends/picosat/app.c @@ -0,0 +1,829 @@ +#include "picosat.h" + +#include +#include +#include +#include + +#define GUNZIP "gunzip -c %s" +#define GZIP "gzip -c -f > %s" + +FILE * popen (const char *, const char*); +int pclose (FILE *); + +static int lineno; +static FILE *input; +static int inputid; +static FILE *output; +static int verbose; +static char buffer[100]; +static char *bhead = buffer; +static const char *eob = buffer + 80; +static FILE * incremental_rup_file; + +extern void picosat_enter (void); +extern void picosat_leave (void); + +static char page[4096]; +static char * top; +static char * end; + +static int +next (void) +{ + size_t bytes; + int res; + + if (top == end) + { + if (end < page + sizeof page) + return EOF; + + bytes = fread (page, 1, sizeof page, input); + if (bytes == 0) + return EOF; + + top = page; + end = page + bytes; + } + + res = *top++; + + if (res == '\n') + lineno++; + + return res; +} + +static const char * +parse (int force) +{ + int ch, sign, lit, vars, clauses; + + lineno = 1; + inputid = fileno (input); + +SKIP_COMMENTS: + ch = next (); + if (ch == 'c') + { + while ((ch = next ()) != EOF && ch != '\n') + ; + goto SKIP_COMMENTS; + } + + if (isspace (ch)) + goto SKIP_COMMENTS; + + if (ch != 'p') +INVALID_HEADER: + return "missing or invalid 'p cnf ' header"; + + if (!isspace (next ())) + goto INVALID_HEADER; + + while (isspace (ch = next ())) + ; + + if (ch != 'c' || next () != 'n' || next () != 'f' || !isspace (next ())) + goto INVALID_HEADER; + + while (isspace (ch = next ())) + ; + + if (!isdigit (ch)) + goto INVALID_HEADER; + + vars = ch - '0'; + while (isdigit (ch = next ())) + vars = 10 * vars + (ch - '0'); + + if (!isspace (ch)) + goto INVALID_HEADER; + + while (isspace (ch = next ())) + ; + + if (!isdigit (ch)) + goto INVALID_HEADER; + + clauses = ch - '0'; + while (isdigit (ch = next ())) + clauses = 10 * clauses + (ch - '0'); + + if (!isspace (ch) && ch != '\n' ) + goto INVALID_HEADER; + + if (verbose) + { + fprintf (output, "c parsed header 'p cnf %d %d'\n", vars, clauses); + fflush (output); + } + + picosat_adjust (vars); + + if (incremental_rup_file) + picosat_set_incremental_rup_file (incremental_rup_file, vars, clauses); + + lit = 0; +READ_LITERAL: + ch = next (); + + if (ch == 'c') + { + while ((ch = next ()) != EOF && ch != '\n') + ; + goto READ_LITERAL; + } + + if (ch == EOF) + { + if (lit) + return "trailing 0 missing"; + + if (clauses && !force) + return "clause missing"; + + return 0; + } + + if (isspace (ch)) + goto READ_LITERAL; + + sign = 1; + if (ch == '-') + { + sign = -1; + ch = next (); + } + + if (!isdigit (ch)) + return "expected number"; + + lit = ch - '0'; + while (isdigit (ch = next ())) + lit = 10 * lit + (ch - '0'); + + if (!clauses && !force) + return "too many clauses"; + + if (lit) + { + if (lit > vars && !force) + return "maximal variable index exceeded"; + + lit *= sign; + } + else + clauses--; + + picosat_add (lit); + + goto READ_LITERAL; +} + +static void +bflush (void) +{ + *bhead = 0; + fputs (buffer, output); + fputc ('\n', output); + bhead = buffer; +} + +static void +printi (int i) +{ + char *next; + int l; + +REENTER: + if (bhead == buffer) + *bhead++ = 'v'; + + l = sprintf (bhead, " %d", i); + next = bhead + l; + + if (next >= eob) + { + bflush (); + goto REENTER; + } + else + bhead = next; +} + +static void +printa (void) +{ + int max_idx = picosat_variables (), i, lit; + + assert (bhead == buffer); + + for (i = 1; i <= max_idx; i++) + { + lit = (picosat_deref (i) > 0) ? i : -i; + printi (lit); + } + + printi (0); + if (bhead > buffer) + bflush (); +} + +static int +has_suffix (const char *str, const char *suffix) +{ + const char *tmp = strstr (str, suffix); + if (!tmp) + return 0; + + return str + strlen (str) - strlen (suffix) == tmp; +} + +static void +write_core_variables (FILE * file) +{ + int i, max_idx = picosat_variables (); + for (i = 1; i <= max_idx; i++) + if (picosat_corelit (i)) + fprintf (file, "%d\n", i); +} + +static void +write_to_file (const char *name, const char *type, void (*writer) (FILE *)) +{ + int pclose_file, zipped = has_suffix (name, ".gz"); + FILE *file; + char *cmd; + + if (zipped) + { + cmd = malloc (strlen (GZIP) + strlen (name)); + sprintf (cmd, GZIP, name); + file = popen (cmd, "w"); + free (cmd); + pclose_file = 1; + } + else + { + file = fopen (name, "w"); + pclose_file = 0; + } + + if (file) + { + if (verbose) + fprintf (output, + "c\nc writing %s%s to '%s'\n", + zipped ? "gzipped " : "", type, name); + + writer (file); + + if (pclose_file) + pclose (file); + else + fclose (file); + } + else + fprintf (output, "*** picosat: can not write to '%s'\n", name); +} + +#define USAGE \ +"usage: picosat [