Fawkes API
Fawkes Development Version
|
A wrapper around the clingo control, to control the solving process. More...
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... | |
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.
Definition at line 38 of file clingo_access.h.
Debug levels, higher levels include the lower values.
Definition at line 42 of file clingo_access.h.
fawkes::ClingoAccess::ClingoAccess | ( | Logger * | logger, |
const std::string & | log_component | ||
) |
Constructor.
[in] | logger | The used logger. |
[in] | log_component | The logging component. |
Definition at line 304 of file clingo_access.cpp.
fawkes::ClingoAccess::~ClingoAccess | ( | void | ) |
Destructor.
Definition at line 319 of file clingo_access.cpp.
|
inline |
Assign external value.
atom | external atom |
value | value to assign |
Definition at line 82 of file clingo_access.h.
Referenced by free_external().
bool fawkes::ClingoAccess::assign_external | ( | const Clingo::Symbol & | atom, |
const Clingo::TruthValue | value | ||
) |
Assigns an external value.
[in] | atom | The atom to assign. |
[in] | value | The assigned value. |
Definition at line 612 of file clingo_access.cpp.
References ASP_DBG_EXTERNALS, and fawkes::Logger::log_info().
bool fawkes::ClingoAccess::cancel_solving | ( | void | ) |
Stops the solving process, if it is running.
Definition at line 443 of file clingo_access.cpp.
References ASP_DBG_TIME, and fawkes::Logger::log_info().
Referenced by reset().
ClingoAccess::DebugLevel_t fawkes::ClingoAccess::debug_level | ( | ) | const |
Get current debug level.
Definition at line 522 of file clingo_access.cpp.
|
inline |
Release external value.
atom | external atom |
Definition at line 88 of file clingo_access.h.
References assign_external().
bool fawkes::ClingoAccess::ground | ( | const Clingo::PartSpan & | parts | ) |
Grounds a program part.
[in] | parts | The parts to ground. |
Definition at line 568 of file clingo_access.cpp.
References ASP_DBG_PROGRAMS, ASP_DBG_TIME, and fawkes::Logger::log_info().
bool fawkes::ClingoAccess::load_file | ( | const std::string & | path | ) |
Loads a file in the solver.
[in] | path | The path of the file. |
Definition at line 551 of file clingo_access.cpp.
References fawkes::Logger::log_info().
Clingo::SymbolVector fawkes::ClingoAccess::model_symbols | ( | void | ) | const |
Returns a copy of the last symbols found.
Definition at line 540 of file clingo_access.cpp.
|
noexcept |
Returns how many threads Clingo should use.
Definition at line 513 of file clingo_access.cpp.
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.
[in] | callback | The callback to register. |
Definition at line 352 of file clingo_access.cpp.
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.
[in] | callback | The callback to register. |
Definition at line 330 of file clingo_access.cpp.
bool fawkes::ClingoAccess::release_external | ( | const Clingo::Symbol & | atom | ) |
Releases an external value.
[in] | atom | The atom to release. |
Definition at line 642 of file clingo_access.cpp.
References ASP_DBG_EXTERNALS, and fawkes::Logger::log_info().
bool fawkes::ClingoAccess::reset | ( | void | ) |
Tries to reset Clingo.
That means deletes the control object and creates a new one.
Definition at line 463 of file clingo_access.cpp.
References cancel_solving(), and fawkes::Logger::log_warn().
Referenced by set_num_threads().
void fawkes::ClingoAccess::set_debug_level | ( | ClingoAccess::DebugLevel_t | log_level | ) |
Set debug level.
log_level | new debug level |
Definition at line 531 of file clingo_access.cpp.
void fawkes::ClingoAccess::set_ground_callback | ( | Clingo::GroundCallback && | callback | ) |
Sets the ground callback, to implement custom functions.
[in,out] | callback | The callback, will be moved. |
Definition at line 376 of file clingo_access.cpp.
void fawkes::ClingoAccess::set_num_threads | ( | const int | threads, |
const bool | thread_mode_splitting = false |
||
) |
Sets the number of threads Clingo should use.
[in] | threads | The number. |
[in] | thread_mode_splitting | Wether splitting should be used. |
Definition at line 487 of file clingo_access.cpp.
References fawkes::Logger::log_info(), and reset().
|
noexcept |
Returns whether the solving process is running.
Definition at line 386 of file clingo_access.cpp.
bool fawkes::ClingoAccess::start_solving | ( | void | ) |
Starts the solving process, if it isn't already running.
Definition at line 396 of file clingo_access.cpp.
References ASP_DBG_TIME, fawkes::Mutex::lock(), fawkes::Logger::log_info(), and fawkes::Mutex::unlock().
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.
Definition at line 420 of file clingo_access.cpp.
References ASP_DBG_TIME, fawkes::Mutex::lock(), fawkes::Logger::log_info(), and fawkes::Mutex::unlock().
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.
[in] | callback | The callback to unregister. |
Definition at line 364 of file clingo_access.cpp.
void fawkes::ClingoAccess::unregister_model_callback | ( | std::shared_ptr< std::function< bool(void)>> | callback | ) |
Unregisters a callback for the event of a new model.
[in] | callback | The callback to unregister. |
Definition at line 341 of file clingo_access.cpp.