%
% ECLiPSe sample code
% Author: Joachim Schimpf
% Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/
%
% Traffic lights (CSPLib problem 16, see http://csplib.org/Problems/prob016)
%
% Specification:
% Consider a four way traffic junction with eight traffic lights.
% Four of the traffic lights are for the vehicles and can be
% represented by the variables V1 to V4 with domains {r,ry,g,y} (for
% red, red-yellow, green and yellow).  The other four traffic lights
% are for the pedestrians and can be represented by the variables P1
% to P4 with domains {r,g}.  The constraints on these variables can be
% modelled by quaternary constraints on (Vi, Pi, Vj, Pj ) for
% 1<=i<=4, j=(1+i)mod 4 which allow just the tuples
% {(r,r,g,g), (ry,r,y,r), (g,g,r,r), (y,r,ry,r)}.
%
% We are interested in the set of all globally consistent 8-tuples
% (which reflects the evolution of the traffic light sequence).
%
%
% Sample run:
%     % eclipse -f traffic_lights_table.ecl -e main
%     [g, g, r, r, g, g, r, r]
%     [r, r, g, g, r, r, g, g]
%     [ry, r, y, r, ry, r, y, r]
%     [y, r, ry, r, y, r, ry, r]
%
% Using symbolic domains and a generalized propagation table constraint
%

:- lib(sd).             % symbolic domain solver
:- lib(propia).         % generalized propagation

main :-
length(Xs, 8),
Xs &:: [r,ry,y,g],
append(Xs, Xs, XsXs),
(
for(_,1,4),
fromto(XsXs, [Vi,Pi,Vj,Pj|XsXs1], [Vj,Pj|XsXs1], _)
do
allowed(Vi,Pi,Vj,Pj) infers sd      % domain propagation
),
labeling(Xs),   % search
writeln(Xs),
fail.

allowed(r, r,g ,g).
allowed(ry,r,y ,r).
allowed(g, g,r ,r).
allowed(y, r,ry,r).
{"ft_lang_label":"__label__en","ft_lang_prob":0.7086032,"math_prob":0.9626886,"size":1572,"snap":"2022-27-2022-33","text_gpt3_token_len":536,"char_repetition_ratio":0.1179847,"word_repetition_ratio":0.0,"special_character_ratio":0.34033078,"punctuation_ratio":0.29382715,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97423,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-07T16:02:58Z\",\"WARC-Record-ID\":\"<urn:uuid:3674ebef-f840-466c-9be8-56bc31217ab3>\",\"Content-Length\":\"6787\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:66ee29e3-6c5a-404f-9de8-9bc2716d6b2e>\",\"WARC-Concurrent-To\":\"<urn:uuid:8172493a-3b1e-490b-b740-cd6c3d9086f2>\",\"WARC-IP-Address\":\"138.251.20.160\",\"WARC-Target-URI\":\"https://www.csplib.org/Problems/prob016/models/traffic_lights_table.ecl.html\",\"WARC-Payload-Digest\":\"sha1:LTJFZCDVKEJIKEATL7GNWIT3UU2QCOTJ\",\"WARC-Block-Digest\":\"sha1:S6VSXXG7DYEGSFLUQP4EZNWRLOYKQDV5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882570651.49_warc_CC-MAIN-20220807150925-20220807180925-00067.warc.gz\"}"}