I am trying to solve a CLP problem in SWI-Prolog. The task is very similar to the zebra problem. There are a total of 25 variables with the domains between 1 to 5. So the related variables will get the same tags. (The program is written in hungarian.)
I want the output to show not only the labels assigned to the variables, but the related variables in a table. Is there a way to do this?
% Constraint Logic Programming
:- use_module(library(clpfd)).
:- use_module(library(lists)).
% Your program goes here
egyetemista(X, All):-
All = [Egressy,Fenyvesi,Gallyas,Jeney,Vadkerti,
Edina, Frida, Gabriella, Jozsef, Vince,
Budapest,Debrecen,Miskolc,Pecs,Szeged,
Biologia,Informatika,Jog,Kemia,Magyar],
All ins 1..5,
all_different([Egressy,Fenyvesi,Gallyas,Jeney,Vadkerti]),
all_different([Edina, Frida, Gabriella, Jozsef, Vince]),
all_different([Budapest,Debrecen,Miskolc,Pecs,Szeged]),
all_different([Biologia,Informatika,Jog,Kemia,Magyar]),
Fenyvesi #= Jog,
Fenyvesi #\= Debrecen,
Fenyvesi #\= Jozsef,
Fenyvesi #\= Vince,
Jozsef #\= Gallyas,
Jozsef #\= Biologia,
Jozsef #= Budapest,
Vadkerti #= Gabriella,
Vadkerti #\= Kemia,
Vadkerti #\= Szeged,
Gabriella #\= Kemia,
Gabriella #\= Szeged,
Kemia #= Szeged,
Jeney #= Pecs,
Jeney #\= Vince,
Frida #= Magyar,
Edina #= Egressy #\ Edina #= Miskolc,
Informatika #\= Edina,
Informatika #\= Frida,
Informatika #\= Gabriella,
labeling([], All),
%Szak:
nth0(N, All, Szeged),
nth0(N, All, X).
%egyetemista(X, All)
If you run the program like this, the output is: All = [1, 2, 3, 4, 5, 2, 4, 5, 1, 3, 1, 5, 2, 4, 3, 5, 1, 2, 3, 4], X = 3
Which means that the label assigned to the variable 'Szeged' is 3, and the associated variables are obtained by substituting variables from the All list that also have a label of 3 on the output. So, for example, the first row of the table could be: 'gallyas vince szeged kemia'
Thank you so much in advance.