GenericControl

Struct GenericControl 

Source
pub struct GenericControl<C: ControlCtx> { /* private fields */ }
Expand description

Control object holding grounding and solving state.

Implementations§

Source§

impl<C: ControlCtx> GenericControl<C>

Source

pub fn ground(&mut self, parts: &[Part]) -> Result<(), ClingoError>

Ground the selected parts Part of the current (non-ground) logic program.

After grounding, logic programs can be solved with Control::solve().

Note: Parts of a logic program without an explicit #program specification are by default put into a program called base - without arguments.

§Arguments
  • parts - array of parts to ground
§Errors
Source

pub fn register_control_context<T: ControlCtx>( self, context: T, ) -> GenericControl<T>

Register a control context

§Arguments
Source

pub fn solve( self, mode: SolveMode, assumptions: &[SolverLiteral], ) -> Result<GenericSolveHandle<C, Non>, ClingoError>

Solve the currently grounded (Control::ground()) logic program enumerating its models.

§Arguments
  • mode - configures the search mode
  • assumptions - array of assumptions to solve under
§Errors
Source

pub fn solve_with_event_handler<T: SolveEventHandler>( self, mode: SolveMode, assumptions: &[SolverLiteral], event_handler: T, ) -> Result<GenericSolveHandle<C, T>, ClingoError>

Solve the currently grounded (Control::ground()) logic program enumerating its models.

§Arguments
  • mode - configures the search mode
  • assumptions - array of assumptions to solve under
  • handler - implementing the trait SolveEventHandler
§Errors
Source

pub fn add( &mut self, name: &str, parameters: &[&str], program: &str, ) -> Result<(), ClingoError>

Extend the logic program with the given non-ground logic program in string form.

This function puts the given program into a block of form: #program name(parameters).

After extending the logic program, the corresponding program parts are typically grounded with ground().

§Arguments
  • name - name of the program block
  • parameters - string array of parameters of the program block
  • program - string representation of the program
§Errors
Source

pub fn cleanup(&mut self) -> Result<(), ClingoError>

Source

pub fn assign_external( &mut self, literal: SolverLiteral, value: TruthValue, ) -> Result<(), ClingoError>

Assign a truth value to an external atom.

If a negative literal is passed, the corresponding atom is assigned the inverted truth value.

If the atom does not exist or is not external, this is a noop.

§Arguments
  • literal - literal to assign
  • value - the truth value
§Errors
Source

pub fn release_external( &mut self, SolverLiteral: SolverLiteral, ) -> Result<(), ClingoError>

Release an external atom.

If a negative literal is passed, the corresponding atom is released.

After this call, an external atom is no longer external and subject to program simplifications. If the atom does not exist or is not external, this is a noop.

§Arguments
  • literal - literal to release
§Errors
Source

pub fn is_conflicting(&self) -> bool

Check if the solver has determined that the internal program representation is conflicting.

If this function returns true, solve calls will return immediately with an unsatisfiable solve result. Note that conflicts first have to be detected, e.g. - initial unit propagation results in an empty clause, or later if an empty clause is resolved during solving. Hence, the function might return false even if the problem is unsatisfiable.

Source

pub fn statistics(&self) -> Result<&Statistics, ClingoError>

Get a statistics object to inspect solver statistics.

Statistics are updated after a solve call.

Attention: The level of detail of the statistics depends on the stats option (which can be set using Configuration or passed as an option when creating the control object (control()). The default level zero only provides basic statistics, level one provides extended and accumulated statistics, and level two provides per-thread statistics. Furthermore, the statistics object is best accessed right after solving. Otherwise, not all of its entries have valid values.

§Errors
Source

pub fn interrupt(&mut self)

Interrupt the active solve call (or the following solve call right at the beginning).

Source

pub fn configuration_mut(&mut self) -> Result<&mut Configuration, ClingoError>

Get a configuration object to change the solver configuration.

Source

pub fn configuration(&self) -> Result<&Configuration, ClingoError>

Get a configuration object to change the solver configuration.

Source

pub fn set_enable_enumeration_assumption( &mut self, enable: bool, ) -> Result<(), ClingoError>

Configure how learnt constraints are handled during enumeration.

If the enumeration assumption is enabled, then all information learnt from the solver’s various enumeration modes is removed after a solve call. This includes enumeration of cautious or brave consequences, enumeration of answer sets with or without projection, or finding optimal models, as well as clauses added with SolveControl::add_clause().

Attention: For practical purposes, this option is only interesting for single-shot solving or before the last solve call to squeeze out a tiny bit of performance. Initially, the enumeration assumption is enabled.

§Arguments
  • enable - whether to enable the assumption
Source

pub fn get_enable_enumeration_assumption(&self) -> bool

Check whether the enumeration assumption is enabled.

See Control::set_enable_enumeration_assumption()

Returns using the enumeration assumption is enabled

Source

pub fn set_enable_cleanup(&mut self, enable: bool) -> bool

Enable automatic cleanup after solving.

Note: Cleanup is enabled by default.

§Arguments
  • enable - whether to enable cleanups

Returns whether the call was successful

See Control::cleanup() and Control::get_enable_cleanup()

Source

pub fn get_enable_cleanup(&self) -> bool

Check whether automatic cleanup is enabled.

See Control::cleanup() and Control::set_enable_cleanup()

Source

pub fn get_const(&self, name: &str) -> Result<Symbol, ClingoError>

Return the symbol for a constant definition of form: #const name = symbol.

§Arguments
  • name - the name of the constant if it exists
§Errors
Source

pub fn has_const(&self, name: &str) -> Result<bool, ClingoError>

Check if there is a constant definition for the given constant.

§Arguments
  • name - the name of the constant
§Errors

See: Control::get_const()

Source

pub fn symbolic_atoms<'a>(&self) -> Result<&'a SymbolicAtoms, ClingoError>

Get an object to inspect symbolic atoms (the relevant Herbrand base) used

Source

pub fn theory_atoms(&self) -> Result<&TheoryAtoms, ClingoError>

Get an object to inspect theory atoms that occur in the grounding.

Source

pub fn backend(&mut self) -> Result<Backend<'_>, ClingoError>

Get an object to add ground directives to the program.

§Errors
Source

pub fn add_facts(&mut self, facts: &FactBase) -> Result<(), ClingoError>

Source

pub fn all_models(self) -> Result<AllModels<C, Non>, ClingoError>

Covenience function that returns an iterator over the models. Uses Control::solve() with SolveMode::YIELD and empty assumptions.

§Errors
Source

pub fn optimal_models(self) -> Result<OptimalModels<C, Non>, ClingoError>

Covenience function that returns an iterator over the optimal models. Uses Control::solve() with SolveMode::YIELD and empty assumptions.

§Errors

Trait Implementations§

Source§

impl<C: Debug + ControlCtx> Debug for GenericControl<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: ControlCtx> Drop for GenericControl<C>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<C: ControlCtx> From<&mut GenericControl<C>> for NonNull<clingo_control>

Source§

fn from(control: &mut GenericControl<C>) -> Self

Converts to this type from the input type.
Source§

impl<C: ControlCtx> From<GenericControl<C>> for NonNull<clingo_control>

Source§

fn from(control: GenericControl<C>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<C> Freeze for GenericControl<C>

§

impl<C> RefUnwindSafe for GenericControl<C>
where C: RefUnwindSafe,

§

impl<C> !Send for GenericControl<C>

§

impl<C> !Sync for GenericControl<C>

§

impl<C> Unpin for GenericControl<C>

§

impl<C> UnwindSafe for GenericControl<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.