Skip to content

Commit

Permalink
Add seed argument to picosat module
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdrake committed Jul 5, 2015
1 parent 5502238 commit 1501476
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions pyeda/boolalg/picosatmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ PyDoc_STRVAR(_satisfy_one_docstring,
decision_limit : int\n\
Set a limit on the number of decisions. A negative value sets no\n\
decision limit.\n\
\n\
seed : int\n\
Set a seed for PicoSAT's random number generator.\n\
Defaults to 1.\n\
\n\
Returns\n\
-------\n\
Expand All @@ -311,6 +315,7 @@ _satisfy_one(PyObject *self, PyObject *args, PyObject *kwargs)
"nvars", "clauses",
"assumptions",
"verbosity", "default_phase", "propagation_limit", "decision_limit",
"seed",
NULL
};

Expand All @@ -325,6 +330,7 @@ _satisfy_one(PyObject *self, PyObject *args, PyObject *kwargs)
int default_phase = 2; /* Jeroslow-Wang */
int propagation_limit = -1;
int decision_limit = -1;
unsigned seed = 1;

/* PicoSAT return value */
int result;
Expand All @@ -333,10 +339,11 @@ _satisfy_one(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *pyret = NULL;

if (!PyArg_ParseTupleAndKeywords(
args, kwargs, "iO|Oiiii:satisfy_one", keywords,
args, kwargs, "iO|OiiiiI:satisfy_one", keywords,
&nvars, &clauses,
&assumptions,
&verbosity, &default_phase, &propagation_limit, &decision_limit))
&verbosity, &default_phase, &propagation_limit, &decision_limit,
&seed))
goto done;

if (nvars < 0) {
Expand All @@ -359,6 +366,7 @@ _satisfy_one(PyObject *self, PyObject *args, PyObject *kwargs)
picosat_set_verbosity(picosat, verbosity);
picosat_set_global_default_phase(picosat, default_phase);
picosat_set_propagation_limit(picosat, propagation_limit);
picosat_set_seed(picosat, seed);

picosat_adjust(picosat, nvars);

Expand All @@ -370,8 +378,6 @@ _satisfy_one(PyObject *self, PyObject *args, PyObject *kwargs)
goto reset_picosat;
}

/* picosat_set_seed(picosat, seed); */

/* Do the damn thing */
Py_BEGIN_ALLOW_THREADS
result = picosat_sat(picosat, decision_limit);
Expand Down Expand Up @@ -430,6 +436,10 @@ PyDoc_STRVAR(_satisfy_all_docstring,
progagation_limit : int\n\
Set a limit on the number of propagations. A negative value sets no\n\
propagation limit.\n\
\n\
seed : int\n\
Set a seed for PicoSAT's random number generator.\n\
Defaults to 1.\n\
\n\
decision_limit : int\n\
Set a limit on the number of decisions. A negative value sets no\n\
Expand Down Expand Up @@ -462,6 +472,7 @@ _satisfy_all_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
static char *keywords[] = {
"nvars", "clauses",
"verbosity", "default_phase", "propagation_limit", "decision_limit",
"seed",
NULL
};

Expand All @@ -475,14 +486,16 @@ _satisfy_all_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
int default_phase = 2; /* Jeroslow-Wang */
int propagation_limit = -1;
int decision_limit = -1;
unsigned seed = 1;

/* Python return value */
_satisfy_all_state *state;

if (!PyArg_ParseTupleAndKeywords(
args, kwargs, "iO|iiii:satisfy_all", keywords,
args, kwargs, "iO|iiiiI:satisfy_all", keywords,
&nvars, &clauses,
&verbosity, &default_phase, &propagation_limit, &decision_limit))
&verbosity, &default_phase, &propagation_limit, &decision_limit,
&seed))
goto error;

if (nvars < 0) {
Expand All @@ -505,14 +518,13 @@ _satisfy_all_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
picosat_set_verbosity(picosat, verbosity);
picosat_set_global_default_phase(picosat, default_phase);
picosat_set_propagation_limit(picosat, propagation_limit);
picosat_set_seed(picosat, seed);

picosat_adjust(picosat, nvars);

if (!_add_clauses(picosat, clauses))
goto reset_picosat;

/* picosat_set_seed(picosat, seed); */

/* Initialize iterator state */
state = (_satisfy_all_state *) cls->tp_alloc(cls, 0);
if (state == NULL)
Expand Down

0 comments on commit 1501476

Please sign in to comment.