Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reference solutions for Assignment 11
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@768 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
140347b
commit 713a491
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
%% Transition relation | ||
|
||
% Prefix | ||
t(X:E,E,X,_). | ||
|
||
% Basic combinator | ||
t(E1+_,E2,X,S) :- t(E1,E2,X,S). | ||
t(_+E1,E2,X,S) :- t(E1,E2,X,S). | ||
|
||
% Composition | ||
t(E1|E2,E3|E2,X,S) :- t(E1,E3,X,S). | ||
t(E1|E2,E1|E3,X,S) :- t(E2,E3,X,S). | ||
|
||
t(E1|E2,E3|E4,tau,S) | ||
:- | ||
t(E1,E3,X1,S), | ||
t(E2,E4,X2,S), | ||
samename(X1,X2). | ||
|
||
% References | ||
t(ref(A),E2,X,S) | ||
:- | ||
member((A,E1),S), | ||
t(E1,E2,X,S). | ||
|
||
% Restriction | ||
t(restrict(E1,L),restrict(E2,L),X,S) | ||
:- | ||
t(E1,E2,X,S), | ||
oklabel(X,L). | ||
|
||
% Relate corresponding names | ||
samename(name(N),coname(N)). | ||
samename(coname(N),name(N)). | ||
|
||
|
||
% Check label to be not restricted | ||
oklabel(tau,_). | ||
oklabel(X,L) :- basename(X,N), \+ member(N,L). | ||
|
||
|
||
% Retrieve basename of name and co-name | ||
basename(name(N),N). | ||
basename(coname(N),N). | ||
|
||
|
||
% Reflexive, transitive closure | ||
tclosure(E,E,[],_). | ||
tclosure(E1,E3,[A|As],S) :- t(E1,E2,A,S), tclosure(E2,E3,As,S). | ||
|
||
|
||
system(As) | ||
:- | ||
S = [ | ||
(jobshop, restrict((ref(hammer)|ref(jobber)),[get,put])) | ||
, (hammer, name(get):name(put):ref(hammer)) | ||
, (jobber, name(job):coname(get):coname(put):coname(done):ref(jobber)) | ||
], | ||
tclosure(ref(jobshop),_,As,S). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
test: | ||
echo "README: type system(As) and see what happens." | ||
swipl -s JobShop.pro | ||
|
||
clean: | ||
rm -rf *~ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
test: | ||
echo "README: type pdate(X) and see what happens." | ||
swipl -s pdate.pro | ||
|
||
clean: | ||
rm -rf *~ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
:- use_module(library(clpfd)). | ||
|
||
pdate(Vars) | ||
:- | ||
Vars = [M1,M2,D1,D2,Y1,Y2,Y3,Y4], | ||
reverse(Vars,Vars), | ||
|
||
% Overall range | ||
Year in 1380..2010, | ||
Month in 1..12, | ||
Day in 1..31, | ||
|
||
% Determine digits by modulo arithmetic | ||
Y1 #= Year / 1000, | ||
Y2 #= (Year - 1000 * Y1) / 100, | ||
Y3 #= (Year - 1000 * Y1 - 100 * Y2) / 10, | ||
Y4 #= Year - 1000 * Y1 - 100 * Y2 - Y3 * 10, | ||
M1 #= Month / 10, | ||
M2 #= Month - M1 * 10, | ||
D1 #= Day / 10, | ||
D2 #= Day - D1 * 10, | ||
|
||
% Check validity | ||
valid(Month,Day). | ||
|
||
valid(N,M) :- M #=< 31, member(N,[1,3,5,7,8,10,12]). | ||
valid(N,M) :- M #=< 30, member(N,[4,6,9,11]). | ||
valid(2,M) :- M #=< 29. % Actually, Feb 29 maps to year 9220... | ||
|
||
/* | ||
?- pdate(X). | ||
X = [0, 1, 0, 2, 2, 0, 1, 0] ; | ||
X = [0, 8, 3, 1, 1, 3, 8, 0] ; | ||
X = [1, 0, 0, 2, 2, 0, 0, 1] ; | ||
false. | ||
*/ |