potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
589 stars 79 forks source link

understanding how to format an lp input graph file for clingo #502

Closed aymeric75 closed 5 days ago

aymeric75 commented 1 month ago

Here is the begining of a .lp file that I am trying to run:


% Suggested call
% clingo -t 6 --sat-prepro=2 --time-limit=7200 <this-solver> <graph-files>
% Constants and options
#const num_predicates = 12.
#const max_action_arity = 3.
#const null_arg = (null,).
#const opt_equal_objects = 0. % Allow same obj as argument for grounded actions
#const opt_allow_negative_precs = 1. % Allow for negative preconditions
#const opt_fill = 1. % Fill in missing negative valuations for primitive predicates
#const opt_symmetries = 1. % Some (simple) symmetry breaking

% Input Instances defined by instance/1, and graphs by tlabel/3 and node/2
% O2D features defined by feature/1, f_arity/2, f_static/2, fval/3, and fval/4
nullary(F) :- feature(F), f_arity(F,1), 1 { fval(I,(F,null_arg),0..1) }. % Explicit zero_arity predicates
nullary(F) :- feature(F), f_arity(F,1), 1 { fval(I,(F,null_arg),S,0..1) : node(I,S) }. % Explicit zero_arity predicates
p_arity(F,N) :- feature(F), f_arity(F,N), not nullary(F). % Explicit zero_arity predicates
p_arity(F,0) :- nullary(F). % Explicit zero_arity predicates
:- p_arity(F,N), nullary(F), N > 0.

I am trying to understand how the input file should be formatted. Here is an example of such a format from what I understood so far

instance(1)

node(1, 1)
node(1, 2)

tlabel(1, (1, 2), 0)

feature(shape)
f_arity(shape, 2)
f_static(1, shape)

Now, I am wondering how to ground the fval/3 and fval/4 predicates, for instance, for the "shape" predicate, would the following work ? fval(1, (shape, null_arg), 1) it would mean something like: the "shape" predicate is always true on instance 1

Finally, in the code shown above what does 0..1 means (in fval(I,(F,null_arg),0..1)) ?

Thanks a lot

rkaminsk commented 1 month ago

It's hard to help you here because we do not know what the encoding is supposed to do. It looks like a part of something complex. Maybe ask the author of the encoding for help?

rkaminsk commented 1 month ago

Your questions are also very basic. Maybe you should read some introductory material about ASP. You could check out our guide or the book Answer Set Programming by Vladimir Lifschitz. There is also a free draft available.