Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about how to do something #538

Open
Abderos opened this issue Feb 21, 2025 · 2 comments
Open

Question about how to do something #538

Abderos opened this issue Feb 21, 2025 · 2 comments
Labels

Comments

@Abderos
Copy link

Abderos commented Feb 21, 2025

  • 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.

@rkaminsk
Copy link
Member

  • 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.

@Abderos
Copy link
Author

Abderos commented Feb 22, 2025

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants