ClingoBackend#

Implements all basic clingo functionality for single-shot solving.

class ClingoBackend(args)[source]

The ClingoBackend contains the basic clingo functionality for a backend using clingo.

When started it sets up all the arguments provided via the command line, and creates a control object (domain-control) with the provided domain files. It grounds the program and creates an empty UI state.

add_atom(predicate)[source]

Adds an assumption, restarts the control and grounds again

Parameters

predicate (str) – The clingo symbol to be added

clear_atoms()[source]

Removes all atoms and resets the backend (i.e. it regrounds, etc.) and finally updates the model and returns the updated gui as a Json structure.

download(show_prg=None, file_name='clinguin_download.lp', domain_files=True)[source]

Downloads the current state of the backend. All added atoms and assumptions are put together as a list of facts.

Parameters
  • show_prg (_type_, optional) – Program to filter output using show statements. Defaults to None.

  • file_name (str, optional) – The name of the file for the download. Defaults to “clinguin_download.lp”.

  • domain_files (bool, optional) – If the domain files should be included. Defaults to True

next_solution(opt_mode='ignore')[source]

Obtains the next solution. If a no browsing has been started yet, then it calls solve, otherwise it iterates the models in the last call.

Parameters

opt_mode – The clingo optimization mode, bu default is ‘ignore’, to browse only optimal models use ‘optN’

remove_atom(predicate)[source]

Removes an assumption, restarts the control and grounds again

Parameters

predicate (str) – The clingo symbol to be added

restart()[source]

Restarts the backend by initializing parameters, controls, ending the browsing grounding and updating the UI

select()[source]

Select the current solution during browsing. All atoms in the solution are added as atoms in the backend.

update()[source]

Updates the UI and transforms the output into a JSON.

Domain state constructors#

The domain state also inclues domain constructors from the parent class.

ClingoBackend._ds_context()#

Gets the context as facts _clinguin_context(KEY, VALUE)

ClingoBackend._ds_brave()#

Computes brave consequences adds them as predicates _any/1.

It uses a cache that is erased after an operation makes changes in the control.

ClingoBackend._ds_cautious()#

Computes cautious consequences adds them as predicates _all/1.

It uses a cache that is erased after an operation makes changes in the control.

ClingoBackend._ds_model()#

Computes a model if one has not been set yet. When the model is being iterated by the user, the current model is returned. It uses a cache that is erased after an operation makes changes in the control.

ClingoBackend._ds_unsat()#

Adds information about the statisfiablity of the domain control

Includes predicate _clinguin_unsat/0 if the domain control is unsat

ClingoBackend._ds_browsing()#

Adds information about the browsing state

Includes predicate _clinguin_browsing/0 if the user is browsing solutions