0

I am totally new in asp. I need to create a group of teams. Each group must consist of 3 randomly chosen teams. A team can be in only one group.

Thanks in advance. Here is my code

team(fener;galata;besik;van;adana;mardin).

neq(X,Y) :- X!=Y,team(X),team(Y).

count(C) :- C = #count{ T : team(T)}.

C/3 {group(X,Y,Z):team(X),team(Y),team(Z), neq(X,Y),neq(X,Z),neq(Z,Y) } C/3 :- count(C).

#show group/3.

a possible output could be

group(fener;besik;van) group(galata;mardin;adana)
Ismail Sahin
  • 2,640
  • 5
  • 31
  • 58

2 Answers2

1

The output you want is not possible:

group(a;b;c).

implies:

group(a). group(b). group(c).

A possible output would be:

group(a,b,c).

But ASP is not really friendly with variable arguments atoms, or list elements as parameters. A simpler output to manage would be:

group(1,a). group(1,b). group(1,c).

And this is very easy to generate, and allows us to avoid the costly #count:

% Data
#const nb_group=2.
group(1..nb_group).
team(fener;galata;besik;van;adana;mardin).

% Assign 3 teams to each group
3{ group(G,T): team(T) }3 :- group(G).

% Two (almost) equilavent constraints:
1{ group(G,T): group(G) }1:- team(T).  % a team is in only one group
OR
:- team(T) ; not group(_,T).  % a team has no group
aluriak
  • 5,559
  • 2
  • 26
  • 39
  • Are you sure that the group(a;b;c) output is not possible, please try my answer to see if it is. I might have some logical errors but here it is. – Ismail Sahin Apr 29 '18 at 20:10
  • Since you want two differentiated groups, you would lost the information. Try run clingo on `group(a;b;c). group(d;e;f).`. Can you determine which letter belong to which group ? – aluriak Apr 30 '18 at 10:17
  • 1
    On the other hand, your answer use `group(a,b,c)`. To quote my own answer: *ASP is not really friendly with variable arguments atoms, or list elements as parameters*. That's the reason i propose another way to go. – aluriak Apr 30 '18 at 10:21
0

I think, have found the solution.

team(fener;galata;besik;van;adana;mardin).

neq(X,Y) :- X!=Y,team(X),team(Y).

count(C) :- C = #count{ T : team(T)}.

C/3 {group(X,Y,Z):team(X),team(Y),team(Z), neq(X,Y),neq(X,Z),neq(Z,Y) } C/3 :- count(C).

exist_in_group(T) :- group(T,_,_).
exist_in_group(T) :- group(_,T,_).
exist_in_group(T) :- group(_,_,T).

:- team(T), not exist_in_group(T).

#show group/3.

The output:

clingo version 5.0.0
Solving...
Answer: 1
group(besik,fener,adana) group(galata,mardin,van)
SATISFIABLE

Models       : 1+
Calls        : 1
Time         : 0.011s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time     : 0.000s
Ismail Sahin
  • 2,640
  • 5
  • 31
  • 58