clingo icon indicating copy to clipboard operation
clingo copied to clipboard

Question about how to do something

Open Abderos opened this issue 1 year ago • 2 comments

  • I wondered if there is a way to pick numbers from a set quickly like in:
#const n = 2000.

available(0..n).
n(0..5).
#count { M:q(N,M):available(M) } == 1:- n(N).
#show q/2.

This approach works but it is very slow since i create so many rules !

  • I also wondered how if i have something like:
q(0,node,a).
q(0,connect,y).
q(0,connect,z).
q(0,connect,p).
q(1,node,b).
q(1,connect,q).
available(0..n).

Would it be possible to spawn things incrementally like the remaining node that should connect to node a ?: q(2,node,y) q(3,node,z) q(4,node,p) q(5,node,q) and where the order of the derivations isn't important.

I am not sure it make sense to try to do this like this with clingo, however i thank you in advance.

Abderos avatar Feb 21 '25 00:02 Abderos

  • I wondered if there is a way to pick numbers from a set quickly like in:
#const n = 2000.

available(0..n).
n(0..5).
#count { M:q(N,M):available(M) } == 1:- n(N).
#show q/2.

This approach works but it is very slow since i create so many rules !

This program should create 5 (rather large rules) rules. If you really need to choose from the 5x2000 atoms, then there is not much you can do in a system like clingo.

It looks a bit like you have 5 variables and want to assign numbers between 0 and 2000 to them. There is the option to use a logarithmic encoding but those are not nice to write and also have scaling issues. You could also try a constraint solver or maybe an ILP solver. As for constraint solvers, we have the clingcon system, which accepts programs like this:

&dom { 0..2000 } = q(N) :- N=1..5.
* I also wondered how if i have something like:
q(0,node,a).
q(0,connect,y).
q(0,connect,z).
q(0,connect,p).
q(1,node,b).
q(1,connect,q).
available(0..n).

Would it be possible to spawn things incrementally like the remaining node that should connect to node a ?: q(2,node,y) q(3,node,z) q(4,node,p) q(5,node,q) and where the order of the derivations isn't important.

I am not sure it make sense to try to do this like this with clingo, however i thank you in advance.

I cannot follow here.

rkaminsk avatar Feb 22 '25 19:02 rkaminsk

Thank you for answering. I will definitely check clingcon but thinking about it i think my question is clearer this way:

q(0,node,a).
q(0,connect,y).
q(0,connect,z).
q(0,connect,p).
q(1,node,b).
q(1,connect,q).
available(0..n).

I tried:

#count { M:q(M,node,X):available(M) } ==1:- q(N,A,X)
:- q(M,node,X), q(M,node,Y), X!=Y.

To generate dynamically on new element when something like q(NewUniqueNumber,node,Z) :- q(N,node,A), q(M,node,B), some_relation(A,B,Z). triggers.

But it seemed that using an aggregate like this generate too many rules.

If i have numbers like this n(0;4;5;7) and m(a;c;e;g), they have the same cardinality so,

can i with obtain only {q(0,a) q(4,c) q(5,e) q(7,g)} not using aggregate, using the natural order on the natural number and on the arguments names ? Thus i wouldn't need an aggregate.

But it seems the problem is already solved with something like &dom { 0..2000 } = q(N) :- N=1..5 !

Abderos avatar Feb 22 '25 23:02 Abderos