Created
September 28, 2021 10:24
-
-
Save k3ut0i/0657d0bd6c36c41f12f3cd0a53be0206 to your computer and use it in GitHub Desktop.
A simple FD example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subject(t1, math). | |
subject(t2, math). | |
subject(t2, english). | |
subject(t3, sports). | |
subject(t3, art). | |
subject(t3, english). | |
subject(t4, math). | |
subject(t4, art). | |
subject(t5, sports). | |
subject(t5, math). | |
subject(t5, english). | |
hours(math, 12). | |
hours(english, 8). | |
hours(art, 4). | |
hours(sport, 2). | |
p(A, B, A-B). | |
filterS(_, [], []). | |
filterS(S, [_-S-X|Xs], [X|Ys]) :- !, filterS(S, Xs, Ys). | |
filterS(S, [_|Xs], Ys) :- filterS(S, Xs, Ys). | |
% findall(T-S, subject(T, S), X), length(X, N), length(Y, N), fd_domain(Y, 2, 3), maplist(pair, X, Y, Z). | |
%% constraint_subject_hours(Subject, L) :- | |
%% hours(Subject, H), | |
%% filterS(Subject, L, Vars), | |
%% fd_domain(Vars,0,3). | |
% A direct modelling of the specific problem | |
soln(X) :- | |
X = [T1M, T2M, T2E, T3S, T3A, T3E, T4M, T4A, T5S, T5M, T5E], | |
fd_domain(X, 0, 10), | |
%% subject constraints | |
T1M + T2M + T4M + T5M #= 12, | |
T2E + T3E + T5E #= 8, | |
T4A + T3A #= 4, | |
T3S + T5S #= 2, | |
fd_domain(T, 0, 10), | |
T #=< T1M, T1M #=< T+1, | |
T #=< T2M + T2E, T2M + T2E #=< T+1, | |
T #=< T3S + T3E + T3A, T3S + T3E + T3A #=< T+1, | |
T #=< T4M + T4A, T4M + T4A #=< T+1, | |
T #=< T5S + T5M + T5E, T5S + T5M + T5E #=< T+1, | |
fd_labeling(X). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment