Python bindings
The fznso module, built with maturin from python/src/lib.rs.
Values are ordinary Python objects: a range or int_set for a domain, an int, a
Decision, a list. See Using a solver.
14 items
Classes
Section titled “Classes”Constraint
Section titled “Constraint”class ConstraintsourceA reference to a constraint, returned by LayeredModel.add_constraint.
Decision
Section titled “Decision”class DecisionsourceA reference to a decision variable, returned by LayeredModel.add_decision.
Discovered
Section titled “Discovered”class DiscoveredsourceA solver library found on the search path, reported without loading it.
nameThe solver’s name, derived from the file name.
pathThe full path to the library.
versionThe version parsed from the file name, or empty if it carries none.
Compared component-wise, so 10 is newer than 9.
DynSolver
Section titled “DynSolver”class DynSolversourceA solver instance created from a Library.
option_get(name)The current value of a named option.
option_set(name, value)Set a named option. Raises ValueError with the solver’s message on
failure.
run(model, on_solution = None, on_message = None, should_stop = None)Run the solver over model, calling on_solution for each solution and
on_message for each diagnostic. Returns the completion status, or
raises RuntimeError if the solver reports an error.
model may be a LayeredModel built with the builder, or any object
implementing the Model protocol.
should_stop, if given, is polled by the solver and ends the search
when it returns a truthy value; the run then reports
Status.Incomplete. Use it to cancel from a watchdog thread. It may be
called from several solver threads at once, so keep it cheap and
thread-safe.
statistic(name)The current value of a named solver-level statistic, or None if the
solver does not report it.
FloatSet
Section titled “FloatSet”class FloatSetsourceA float set, an ordered union of inclusive [min, max] ranges.
IntSet
Section titled “IntSet”class IntSetsourceAn integer set, an ordered union of inclusive [min, max] ranges.
LayeredModel
Section titled “LayeredModel”class LayeredModelsourceA model to hand to a solver.
Decisions and constraints are added to the current layer. Layers can be pushed, popped and committed for incremental solving.
add_constraint(ident, arguments, defines = None)Add a constraint with the given identifier and arguments.
add_decision(ty, domain = None, name = None, defined = False, in_solution = True)Add a decision variable of the given type and domain, returning its handle.
mark_permanent()Mark every current layer as permanent.
pop_layer()Pop the top layer.
push_layer()Push a new, empty layer.
set_objective(ident, argument = None)Set the objective. Pass no identifier for a satisfaction problem.
Library
Section titled “Library”class LibrarysourceA loaded solver library.
create_solver()Create a solver instance.
discover()List the solver libraries on the search path, without loading any.
Directories are visited in search_paths order and, within one
directory, the highest version of a solver comes first. Nothing is
opened, so the ABI version is not checked here; find skips solvers
built for another ABI.
find(name, version = None)Load a solver by name from the search path.
Without a version the newest is chosen, preferring earlier
directories. A version selects by whole dotted components, so "6"
matches 6.2.1 and "6.2" matches 6.2.1 but not 6.1.0.
Raises RuntimeError if no matching solver is installed, naming the
directories that were searched.
search_paths()The directories searched for solver libraries, in search order.
Solvers live in a directory of their own rather than on the normal
library path. The order is $FZNSO_SOLVER_PATH, then the per-user
directory, then the system directories.
class ModelsourceBase class for a model implemented in Python.
Subclass it and override the methods your model needs; the rest describe an
empty model. Values are ordinary Python objects (a range or int_set for
a domain, an int, a Decision, a list, and so on).
The model is read on demand while the solver runs, and the values and strings it returns are borrowed, not copied. The model must therefore keep them alive for the whole run: return objects it owns — for example stored on the instance — rather than freshly built temporaries.
By default a custom model is a single permanent layer. Override the
layer_* methods to expose several layers for incremental solving, or use
LayeredModel to build one directly.
constraint_arguments(index)The arguments of the constraint at index, as a list of values.
constraint_count()The number of constraints.
constraint_defines(index)The decision the constraint at index defines, if any.
constraint_ident(index)The identifier of the constraint at index.
constraint_layer_end(layer)One past the global index of the last constraint in layers 0..=layer.
Defaults to every constraint living in a single layer.
decision_count()The number of decision variables.
decision_defined(index)Whether the decision at index is defined by a constraint.
decision_domain(index)The domain of the decision at index, or None for no explicit domain.
decision_in_solution(index)Whether a solution may be asked for the value of the decision at
index. A model that does not say assumes every decision may be, which
is the safe answer: a solver then assigns them all.
decision_layer_end(layer)One past the global index of the last decision in layers 0..=layer.
Defaults to every decision living in a single layer.
decision_name(index)The name of the decision at index, if any.
decision_type(index)The type of the decision at index.
Unlike the other accessors this has no sensible default: a decision’s type is exactly what cannot be worked out from anything else it reports, so a model that declares decisions has to say what they are.
layer_count()The number of layers in the model. Defaults to a single layer.
layer_permanent()The number of permanently committed layers (the solver will not pop these). Defaults to all layers being permanent.
layer_redundant()The layer indices of permanent layers that are redundant. Defaults to none.
layer_unchanged()The number of trailing layers unchanged since the last run, for incremental reuse. Defaults to none.
objective_argument()The objective’s argument, or None.
objective_ident()The objective identifier, or "" for a satisfaction problem.
Solution
Section titled “Solution”class SolutionsourceA solution reported to the on_solution callback.
Valid only during that callback; using it afterwards raises an error.
statistic(name)A named statistic for this solution.
value(decision)The value assigned to a decision variable (a Decision or an index).
Status
Section titled “Status”class StatussourceThe outcome of a run.
CompleteThe outcome of a run.
IncompleteThe outcome of a run.
class TypesourceA value type: a base type plus the qualifiers that apply to it.
Any type the interface can carry is expressible. Name the qualifiers you want as keyword arguments:
fznso.Type("int", decision=True) # var intfznso.Type("int", decision=True, set_of=True) # var set of intfznso.Type("bool", list_of=True) # list of boolThe Rust and C++ bindings spell this as a builder, because neither has keyword arguments. Each qualifier is readable back under the name it was given, so a type can be taken apart and rebuilt.
baseThe base type: "bool", "int", "float" or "string".
decisionWhether this type is a decision variable rather than a parameter.
list_ofWhether this type is a list of its element type.
optWhether this type also permits the absent value.
set_ofWhether this type is over sets of its base type.
Functions
Section titled “Functions”float_set
Section titled “float_set”float_set(min, max)sourceA float set covering the inclusive range [min, max].
int_set
Section titled “int_set”int_set(min, max)sourceAn integer set covering the inclusive range [min, max].