Fawkes API  Fawkes Development Version
fawkes::ClingoAccess Class Reference

A wrapper around the clingo control, to control the solving process. More...

Inheritance diagram for fawkes::ClingoAccess:

Public Types

enum  DebugLevel_t {
  ASP_DBG_NONE = 0 , ASP_DBG_TIME = 10 , ASP_DBG_PROGRAMS = 20 , ASP_DBG_EXTERNALS = 30 ,
  ASP_DBG_MODELS = 40 , ASP_DBG_ALL_MODEL_SYMBOLS , ASP_DBG_ALL , ASP_DBG_EVEN_CLINGO
}
 Debug levels, higher levels include the lower values. More...
 

Public Member Functions

 ClingoAccess (Logger *logger, const std::string &log_component)
 Constructor. More...
 
 ~ClingoAccess (void)
 Destructor. More...
 
void register_model_callback (std::shared_ptr< std::function< bool(void)>> callback)
 Registers a callback for the event of a new model. More...
 
void unregister_model_callback (std::shared_ptr< std::function< bool(void)>> callback)
 Unregisters a callback for the event of a new model. More...
 
void register_finish_callback (std::shared_ptr< std::function< void(Clingo::SolveResult)>> callback)
 Registers a callback for the event of finishing the solving process. More...
 
void unregister_finish_callback (std::shared_ptr< std::function< void(Clingo::SolveResult)>> callback)
 Unregisters a callback for the event of finishing the solving process. More...
 
void set_ground_callback (Clingo::GroundCallback &&callback)
 Sets the ground callback, to implement custom functions. More...
 
bool solving (void) const noexcept
 Returns whether the solving process is running. More...
 
bool start_solving (void)
 Starts the solving process, if it isn't already running. More...
 
bool start_solving_blocking (void)
 Starts the solving process. More...
 
bool cancel_solving (void)
 Stops the solving process, if it is running. More...
 
bool reset (void)
 Tries to reset Clingo. More...
 
void set_num_threads (const int threads, const bool use_splitting=false)
 Sets the number of threads Clingo should use. More...
 
int num_threads (void) const noexcept
 Returns how many threads Clingo should use. More...
 
Clingo::SymbolVector model_symbols (void) const
 Returns a copy of the last symbols found. More...
 
bool load_file (const std::string &path)
 Loads a file in the solver. More...
 
bool ground (const Clingo::PartSpan &parts)
 Grounds a program part. More...
 
bool assign_external (const Clingo::Symbol &atom, const bool value)
 Assign external value. More...
 
bool free_external (const Clingo::Symbol &atom)
 Release external value. More...
 
bool assign_external (const Clingo::Symbol &atom, const Clingo::TruthValue value)
 Assigns an external value. More...
 
bool release_external (const Clingo::Symbol &atom)
 Releases an external value. More...
 
DebugLevel_t debug_level () const
 Get current debug level. More...
 
void set_debug_level (DebugLevel_t log_level)
 Set debug level. More...
 

Detailed Description

A wrapper around the clingo control, to control the solving process.

This class provides access to the Clingo solver. Callbacks can be used for automated notification on specific events, such if a model has been found. It provides a high-level interface to the solver, i.e., to configure, start, or cancel the solving process. It also supports assigning and releasing externals.

Author
Björn Schäpers

Definition at line 38 of file clingo_access.h.

Member Enumeration Documentation

◆ DebugLevel_t

Debug levels, higher levels include the lower values.

Enumerator
ASP_DBG_NONE 

No debug output at all.

ASP_DBG_TIME 

Print when starting/finishing grounding/solving for analysis.

ASP_DBG_PROGRAMS 

Print which programs are grounded.

ASP_DBG_EXTERNALS 

Print assignments and releases of externals.

ASP_DBG_MODELS 

Print new models.

ASP_DBG_ALL_MODEL_SYMBOLS 

Ignore '#show' statements and print all symbols of a model.

ASP_DBG_ALL 

Print everything.

ASP_DBG_EVEN_CLINGO 

Activates the –output-debug=text option for clingo.

Definition at line 42 of file clingo_access.h.

Constructor & Destructor Documentation

◆ ClingoAccess()

fawkes::ClingoAccess::ClingoAccess ( Logger logger,
const std::string &  log_component 
)

Constructor.

Parameters
[in]loggerThe used logger.
[in]log_componentThe logging component.

Definition at line 299 of file clingo_access.cpp.

◆ ~ClingoAccess()

fawkes::ClingoAccess::~ClingoAccess ( void  )

Destructor.

Definition at line 314 of file clingo_access.cpp.

Member Function Documentation

◆ assign_external() [1/2]

bool fawkes::ClingoAccess::assign_external ( const Clingo::Symbol &  atom,
const bool  value 
)
inline

Assign external value.

Parameters
atomexternal atom
valuevalue to assign
Returns
true if external was assigned, false otherwise.

Definition at line 82 of file clingo_access.h.

Referenced by free_external().

◆ assign_external() [2/2]

bool fawkes::ClingoAccess::assign_external ( const Clingo::Symbol &  atom,
const Clingo::TruthValue  value 
)

Assigns an external value.

Parameters
[in]atomThe atom to assign.
[in]valueThe assigned value.
Returns
If it could be assigned.

Definition at line 607 of file clingo_access.cpp.

References ASP_DBG_EXTERNALS, and fawkes::Logger::log_info().

◆ cancel_solving()

bool fawkes::ClingoAccess::cancel_solving ( void  )

Stops the solving process, if it is running.

Returns
If it was stopped. (Check solving() for actual state!)

Definition at line 438 of file clingo_access.cpp.

References ASP_DBG_TIME, and fawkes::Logger::log_info().

Referenced by reset().

◆ debug_level()

ClingoAccess::DebugLevel_t fawkes::ClingoAccess::debug_level ( ) const

Get current debug level.

Returns
current debug level

Definition at line 517 of file clingo_access.cpp.

◆ free_external()

bool fawkes::ClingoAccess::free_external ( const Clingo::Symbol &  atom)
inline

Release external value.

Parameters
atomexternal atom
Returns
true if external was released, false otherwise.

Definition at line 88 of file clingo_access.h.

References assign_external().

◆ ground()

bool fawkes::ClingoAccess::ground ( const Clingo::PartSpan &  parts)

Grounds a program part.

Parameters
[in]partsThe parts to ground.
Returns
true if parts could be grounded

Definition at line 563 of file clingo_access.cpp.

References ASP_DBG_PROGRAMS, ASP_DBG_TIME, and fawkes::Logger::log_info().

◆ load_file()

bool fawkes::ClingoAccess::load_file ( const std::string &  path)

Loads a file in the solver.

Parameters
[in]pathThe path of the file.
Returns
true, if file was loaded

Definition at line 546 of file clingo_access.cpp.

References fawkes::Logger::log_info().

◆ model_symbols()

Clingo::SymbolVector fawkes::ClingoAccess::model_symbols ( void  ) const

Returns a copy of the last symbols found.

Returns
copy of last symbols found

Definition at line 535 of file clingo_access.cpp.

◆ num_threads()

int fawkes::ClingoAccess::num_threads ( void  ) const
noexcept

Returns how many threads Clingo should use.

Returns
number of threads
See also
ClingoAccess::num_threads_

Definition at line 508 of file clingo_access.cpp.

◆ register_finish_callback()

void fawkes::ClingoAccess::register_finish_callback ( std::shared_ptr< std::function< void(Clingo::SolveResult)>>  callback)

Registers a callback for the event of finishing the solving process.

Parameters
[in]callbackThe callback to register.

Definition at line 347 of file clingo_access.cpp.

◆ register_model_callback()

void fawkes::ClingoAccess::register_model_callback ( std::shared_ptr< std::function< bool(void)>>  callback)

Registers a callback for the event of a new model.

The callback can control with it's return value if the search for models should continue. If one of the callbacks says yes the search is continued.

Parameters
[in]callbackThe callback to register.

Definition at line 325 of file clingo_access.cpp.

◆ release_external()

bool fawkes::ClingoAccess::release_external ( const Clingo::Symbol &  atom)

Releases an external value.

Parameters
[in]atomThe atom to release.
Returns
true, if it could be released

Definition at line 638 of file clingo_access.cpp.

◆ reset()

bool fawkes::ClingoAccess::reset ( void  )

Tries to reset Clingo.

That means deletes the control object and creates a new one.

Returns
true, if successful

Definition at line 458 of file clingo_access.cpp.

References cancel_solving(), and fawkes::Logger::log_warn().

Referenced by set_num_threads().

◆ set_debug_level()

void fawkes::ClingoAccess::set_debug_level ( ClingoAccess::DebugLevel_t  log_level)

Set debug level.

Parameters
log_levelnew debug level

Definition at line 526 of file clingo_access.cpp.

◆ set_ground_callback()

void fawkes::ClingoAccess::set_ground_callback ( Clingo::GroundCallback &&  callback)

Sets the ground callback, to implement custom functions.

Parameters
[in,out]callbackThe callback, will be moved.

Definition at line 371 of file clingo_access.cpp.

◆ set_num_threads()

void fawkes::ClingoAccess::set_num_threads ( const int  threads,
const bool  thread_mode_splitting = false 
)

Sets the number of threads Clingo should use.

Parameters
[in]threadsThe number.
[in]thread_mode_splittingWether splitting should be used.
Warning
This will call reset().
Exceptions
ExceptionIf it is called while solving.
ExceptionIf it is called with threads < 1.

Definition at line 482 of file clingo_access.cpp.

References fawkes::Logger::log_info(), and reset().

◆ solving()

bool fawkes::ClingoAccess::solving ( void  ) const
noexcept

Returns whether the solving process is running.

Returns
true if currently solving, false otherwise

Definition at line 381 of file clingo_access.cpp.

◆ start_solving()

bool fawkes::ClingoAccess::start_solving ( void  )

Starts the solving process, if it isn't already running.

Returns
If the process is started.

Definition at line 391 of file clingo_access.cpp.

References ASP_DBG_TIME, fawkes::Mutex::lock(), fawkes::Logger::log_info(), and fawkes::Mutex::unlock().

◆ start_solving_blocking()

bool fawkes::ClingoAccess::start_solving_blocking ( void  )

Starts the solving process.

If it isn't already running, in a blocking manner, that means it does not start the computation in an asynchronous way.

Returns
true, if the process was started

Definition at line 415 of file clingo_access.cpp.

References ASP_DBG_TIME, fawkes::Mutex::lock(), fawkes::Logger::log_info(), and fawkes::Mutex::unlock().

◆ unregister_finish_callback()

void fawkes::ClingoAccess::unregister_finish_callback ( std::shared_ptr< std::function< void(Clingo::SolveResult)>>  callback)

Unregisters a callback for the event of finishing the solving process.

Parameters
[in]callbackThe callback to unregister.

Definition at line 359 of file clingo_access.cpp.

◆ unregister_model_callback()

void fawkes::ClingoAccess::unregister_model_callback ( std::shared_ptr< std::function< bool(void)>>  callback)

Unregisters a callback for the event of a new model.

Parameters
[in]callbackThe callback to unregister.

Definition at line 336 of file clingo_access.cpp.


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