Interact with a running search.
A clingo_solve_handle_t objects can be used for both synchronous and asynchronous search, as well as iteratively receiving models and solve results.
For an example showing how to solve asynchronously, see solve-async.c.
◆ clingo_solve_event_callback_t
Callback function called during search to notify when the search is finished or a model is ready.
If a (non-recoverable) clingo API function fails in this callback, it must return false. In case of errors not related to clingo, set error code clingo_error_unknown and return false to stop solving with an error.
- Attention
- If the search is finished, the model is NULL.
- Parameters
-
[in] | model | the current model |
[in] | data | user data of the callback |
[in] | goon | can be set to false to stop solving |
- Returns
- whether the call was successful
- See also
- clingo_control_solve()
◆ clingo_solve_handle_t
◆ clingo_solve_event_type
Enumeration of solve events.
Enumerator |
---|
clingo_solve_event_type_model | Issued if a model is found.
|
clingo_solve_event_type_finish | Issued if the search has completed.
|
◆ clingo_solve_mode
Enumeration of solve modes.
Enumerator |
---|
clingo_solve_mode_async | Enable non-blocking search.
|
clingo_solve_mode_yield | Yield models in calls to clingo_solve_handle_model.
|
◆ clingo_solve_handle_cancel()
Stop the running search and block until done.
- Parameters
-
- Returns
- whether the call was successful; might set one of the following error codes:
◆ clingo_solve_handle_close()
◆ clingo_solve_handle_get()
Get the next solve result.
Blocks until the result is ready. When yielding partial solve results can be obtained, i.e., when a model is ready, the result will be satisfiable but neither the search exhausted nor the optimality proven.
- Parameters
-
[in] | handle | the target |
[out] | result | the solve result |
- Returns
- whether the call was successful; might set one of the following error codes:
- Examples:
- ast.c, backend.c, configuration.c, control.c, model.c, propagator.c, solve-async.c, statistics.c, and theory-atoms.c.
◆ clingo_solve_handle_model()
◆ clingo_solve_handle_resume()
◆ clingo_solve_handle_wait()
CLINGO_VISIBILITY_DEFAULT void clingo_solve_handle_wait |
( |
clingo_solve_handle_t * |
handle, |
|
|
double |
timeout, |
|
|
bool * |
result |
|
) |
| |
Wait for the specified amount of time to check if the next result is ready.
If the time is set to zero, this function can be used to poll if the search is still active. If the time is negative, the function blocks until the search is finished.
- Parameters
-
[in] | handle | the target |
[in] | timeout | the maximum time to wait |
[out] | result | whether the search has finished |