Clingo
Loading...
Searching...
No Matches
Clingo::SolveHandle Class Reference

Class to control a running search. More...

#include <solve.hh>

Classes

class  iterator
 Iterator to iterate over models found during solving. More...
 
struct  sentinel
 Sentinel indicating that models have been exhausted. More...
 

Public Types

using difference_type = iterator::difference_type
 The difference type.
 
using value_type = iterator::value_type
 The value type, which are models.
 
using reference = iterator::reference
 The reference type.
 
using pointer = iterator::pointer
 The pointer type.
 

Public Member Functions

 SolveHandle (clingo_solve_handle_t *hnd)
 Constructor from the underlying C representation.
 
auto get () const -> SolveResult
 Get the solve result.
 
void cancel ()
 Cancel the current search.
 
void close ()
 Close the solve handle.
 
void resume ()
 Resume the current search.
 
auto model () -> std::optional< ConstModel >
 Get the current model.
 
auto last () const -> std::optional< ConstModel >
 Get the last model.
 
auto core () const -> ProgramLiteralSpan
 Get the unsatisfiable core.
 
auto wait (std::optional< double > timeout) -> bool
 Wait for the next model or solve result.
 
auto begin () -> iterator
 Get an iterator to iterate over models found during solving.
 
auto end () -> sentinel
 Get a sentinel to indicate that all models have been exhausted.
 

Friends

class Control
 
auto c_cast (SolveHandle const &x) -> clingo_solve_handle_t *
 Cast the solve handle to its C representation.
 

Detailed Description

Class to control a running search.

Constructor & Destructor Documentation

◆ SolveHandle()

Clingo::SolveHandle::SolveHandle ( clingo_solve_handle_t hnd)
inlineexplicit

Constructor from the underlying C representation.

For internal use.

Parameters
hndthe C representation of the solve handle

Member Function Documentation

◆ cancel()

void Clingo::SolveHandle::cancel ( )
inline

Cancel the current search.

This is a blocking operation.

◆ close()

void Clingo::SolveHandle::close ( )
inline

Close the solve handle.

This is a blocking operation.

Closing a solver handle guarantees that the destructor of the solve handle does not throw.

◆ core()

auto Clingo::SolveHandle::core ( ) const -> ProgramLiteralSpan
inline

Get the unsatisfiable core.

This function can be called when the search was reported unsatisfiable. It contains a subset of the assumptions that made the problem unsatisfiable. The set is not necessarily minimal.

Returns
the unsatisfiable core

◆ get()

auto Clingo::SolveHandle::get ( ) const -> SolveResult
inline

Get the solve result.

This is a blocking operation and should always be called at the end of a search.

Returns
the solve result

◆ last()

auto Clingo::SolveHandle::last ( ) const -> std::optional<ConstModel>
inline

Get the last model.

This function can be called after all models have been enumerated. This is particularly useful when optimizing to inpsect the optimal model.

Returns
the last model, if available

◆ model()

auto Clingo::SolveHandle::model ( ) -> std::optional<ConstModel>
inline

Get the current model.

Return std::optional if no model is available. This can happen if models are exhausted or in an asynchronous context where the next model has not yet been found.

Returns
the current model, if available

◆ resume()

void Clingo::SolveHandle::resume ( )
inline

Resume the current search.

In a asynchronous context, this will start the search for the next model. Otherwise, it is a no-op.

◆ wait()

auto Clingo::SolveHandle::wait ( std::optional< double timeout) -> bool
inline

Wait for the next model or solve result.

If yielding is active, waits for the next model. Otherwise, waits for the solve result.

If no timeout is given, waits until the model or result is available. Otherwise, waits for the given timeout in seconds. A value of zero can be used for polling.

Parameters
timeoutthe timeout in seconds
Returns
whether a model or result is available

Friends And Related Symbol Documentation

◆ c_cast

auto c_cast ( SolveHandle const x) -> clingo_solve_handle_t *
friend

Cast the solve handle to its C representation.

Parameters
xthe solve handle to cast
Returns
the C representation of the solve handle

The documentation for this class was generated from the following file: