Prolog - STACLP EN PROLOG

 
Vista:

STACLP EN PROLOG

Publicado por oswaldo (1 intervención) el 04/05/2011 00:16:11
hola que tal espero en este foro me puedan ayudar lo que pasa es que tengo un problema con un tema llamado "STACLP" se refiere a espacio-tiempo estos dos terminos que los maneja todo el tiempo, la situacion es que debo hacer un programa en prolog que indique las reglas y restricciones que marca el documento esta un poco extraño pero debo hacer unas consultas y no se ni como hacerlo espero puedan ayudarme.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
:- auto_table.
% auto_table if in: http://www.cs.sunysb.edu/~sbprolog/manual1/node31.html
 
demo(true).
demo(((B1,Alfa1,Beta1),(B2,Alfa2,Beta2))) :-
                     demo((B1,Alfa1,Beta1)),
                     demo((B2,Alfa2,Beta2)).
 
demo((A,Alfa,Beta)) :- contR(Alfa,Delta),
                       contT(Beta,Gama),
                       clause1((A,Delta,Gama),B),
                       demo(B).
 
demo((A,Alfap,Betap)) :- une(Alfa1,Beta1,Alfa2,Beta2,Alfa,Beta),
                         contR(Alfap,Alfa),
                         contT(Betap,Beta),
                         clause1((A,Alfa1,Beta1),B),
                         demo(B),
                         demo((A,Alfa2,Beta2)).
 
clause1((A,Alfa,Beta),B) :- claus((A,Alfa,Beta),B),
                            validaR(Alfa), validaT(Beta).
 
validaR(thr(X1,Y1,X2,Y2)) :- nonvar(X1), nonvar(Y1), nonvar(X2), nonvar(Y2).
validaR(inr(X1,Y1,X2,Y2)) :- nonvar(X1), nonvar(Y1), nonvar(X2), nonvar(Y2).
 
validaT(th(S1,S2)) :- nonvar(S1), nonvar(S2).
validaT(in(S1,S2)) :- nonvar(S1), nonvar(S2).
 
/*SPACE-TIME o TIME SPACE */
/*THR overlap Y E-T*/
une(thr(X1,X2,Y1,Y2),th(T1,T2),
    thr(X1,X2,Z1,Z2),th(T1,T2),
    thr(X1,X2,Y1,Z2),th(T1,T2)) :- claus((_,thr(X1,X2,Y1,Y2),th(T1,T2)),true),
				   claus((_,thr(X1,X2,Z1,Z2),th(T1,T2)),true),
				   Y1=<Z1, Z1=<Y2, Y2=<Z2.
 
/*THR overlap X E-T*/
une(thr(X1,X2,Y1,Y2),th(T1,T2),
    thr(Z1,Z2,Y1,Y2),th(T1,T2),
    thr(X1,Z2,Y1,Y2),th(T1,T2)) :- claus((_,thr(X1,X2,Y1,Y2),th(T1,T2)),true),
				   claus((_,thr(Z1,Z2,Y1,Y2),th(T1,T2)),true),
                                   X1=<Z1, Z1=<X2, X2=<Z2.
 
/*THR overlap  time  E-T*/
une(thr(X1,X2,Y1,Y2),th(S1,S2),
    thr(X1,X2,Y1,Y2),th(R1,R2),
    thr(X1,X2,Y1,Y2),th(S1,R2)) :- claus((_,thr(X1,X2,Y1,Y2),th(S1,S2)),true),
                                   claus((_,thr(X1,X2,Y1,Y2),th(R1,R2)),true),
                                   S1=<R1, R1=<S2, S2=<R2.
 
/*INR overlap  time  E-T*/
une(inr(X1,X2,Y1,Y2),th(S1,S2),
    inr(X1,X2,Y1,Y2),th(R1,R2),
    inr(X1,X2,Y1,Y2),th(S1,R2)) :- claus((_,inr(X1,X2,Y1,Y2),th(S1,S2)),true),
				       claus((_,inr(X1,X2,Y1,Y2),th(R1,R2)),true),
                                       S1=<R1, R1=<S2, S2=<R2.
 
/*IN overlap region Y  T-E*/
une(in(T1,T2),thr(X1,X2,Y1,Y2),
    in(T1,T2),thr(X1,X2,Z1,Z2),
    in(T1,T2),thr(X1,X2,Y1,Z2)) :- claus((_,in(T1,T2),thr(X1,X2,Y1,Y2)),true),
	       		           claus((_,in(T1,T2),thr(X1,X2,Z1,Z2)),true),
                                       Y1=<Z1, Z1=<Y2, Y2=<Z2.
 
/*IN overlap region X  T-E*/
une(in(T1,T2),thr(X1,X2,Y1,Y2),
    in(T1,T2),thr(Z1,Z2,Y1,Y2),
    in(T1,T2),thr(X1,Z2,Y1,Y2)) :- claus((_,in(T1,T2),thr(X1,X2,Y1,Y2)),true),
				       claus((_,in(T1,T2),thr(Z1,Z2,Y1,Y2)),true),
                                       X1=<Z1, Z1=<X2, X2=<Z2.
/* SPACE */
 
/* THR */
/*THR <= E-T */ contR(thr(X1,X2,Y1,Y2),thr(X1p,X2p,Y1p,Y2p) ) :-
                          nonvar(X1),nonvar(X2),nonvar(Y1),nonvar(Y2),
                          nonvar(X1p),nonvar(X2p),nonvar(Y1p),nonvar(Y2p),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/*THR <=*/ contR(thr((X1,X2,Y1,Y2)),thr(X1p,X2p,Y1p,Y2p) ) :-
                          nonvar(X1),nonvar(X2),nonvar(Y1),nonvar(Y2),
                          claus((_,thr(X1p,X2p,Y1p,Y2p),_),true),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/*THR <= E-T  ultima */ contR(thr(X1,X2,Y1,Y2),thr(X1p,X2p,Y1p,Y2p) ) :-
                          nonvar(X1),nonvar(X2),nonvar(Y1),nonvar(Y2),
                          claus((_,thr(X1p,X2p,Y1p,Y2p),_),true),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/*THR <=  */  contR(thr((X1,X2,Y1,Y2)),thr(X1,X2,Y1,Y2) ) :-
                          var(X1),var(X2),var(Y1),var(Y2),
                          claus((_,thr(X1,X2,Y1,Y2),_),true).
 
/*THR <=  E-T */  contR(thr((X1,X2,Y1,Y2)),thr(X1p,X2p,Y1p,Y2p) ) :-
                          var(X1),var(X2),var(Y1),var(Y2),
                          nonvar(X1p),nonvar(X2p),nonvar(Y1p),nonvar(Y2p),
                          claus((_,thr(X1,X2,Y1,Y2),_),true),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/* INR*/
/*INR <= E-T */ contR(inr(X1p,X2p,Y1p,Y2p),inr(X1,X2,Y1,Y2)) :-
                          nonvar(X1p),nonvar(X2p),nonvar(Y1p),nonvar(Y2p),
                          nonvar(X1),nonvar(X2),nonvar(Y1),nonvar(Y2),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/*INR <= */ contR(inr((X1p,X2p,Y1p,Y2p)),inr(X1,X2,Y1,Y2)) :-
                          nonvar(X1p),nonvar(X2p),nonvar(Y1p),nonvar(Y2p),
                          claus((_,inr(X1,X2,Y1,Y2),_),true),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/*INR <= E-T ultima */ contR(inr(X1p,X2p,Y1p,Y2p),inr(X1,X2,Y1,Y2)) :-
                          nonvar(X1p),nonvar(X2p),nonvar(Y1p),nonvar(Y2p),
                          claus((_,inr(X1,X2,Y1,Y2),_),true),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/*INR <=*/  contR(inr((X1,X2,Y1,Y2)),inr(X1,X2,Y1,Y2)) :-
                          var(X1),var(X2),var(Y1),var(Y2),
                          claus((_,inr(X1,X2,Y1,Y2),_),true).
 
/*INR <= E-T */ contR(inr((X1p,X2p,Y1p,Y2p)),inr(X1,X2,Y1,Y2)) :-
                          var(X1p),var(X2p),var(Y1p),var(Y2p),
                          nonvar(X1),nonvar(X2),nonvar(Y1),nonvar(Y2),
                          claus((_,inr(X1p,X2p,Y1p,Y2p),_),true),
                          X1p=<X1, X1=<X2, X2=<X2p, Y1p=<Y1, Y1=<Y2, Y2=<Y2p.
 
/* TIME */
/*TH <= T-E */ contT(th(S1,S2),th(R1,R2)) :-
                          nonvar(S1),nonvar(S2),
                          nonvar(R1),nonvar(R2), /*write(uno), */
                          R1=<S1, S1=<S2, S2=<R2.
 
/*TH <=*/ contT(th((S1,S2)),th(R1,R2)) :-
                          nonvar(S1),nonvar(S2),
                          claus((_,_,th(R1,R2)),true),
                          R1=<S1, S1=<S2, S2=<R2.
 
/*TH <= T-E ultima */ contT(th(S1,S2),th(R1,R2)) :-
                          nonvar(S1),nonvar(S2),
                          claus((_,_,th(R1,R2)),true),
                          R1=<S1, S1=<S2, S2=<R2.
 
/*TH <= */ contT(th((S1,S2)),th(S1,S2)) :-
                          var(S1),var(S2),
                          claus((_,_,th(S1,S2)),true).
 
/*TH <= T-E */ contT(th((S1,S2)),th(R1,R2)) :-
                          var(S1),var(S2),
                          nonvar(R1),nonvar(R2),
                          claus((_,_,th(S1,S2)),true),
                          R1=<S1, S1=<S2, S2=<R2.
 
/*  the next two clausules are the link between IN and TH annotations */
/* IN <= TH */ contT(in(R1,R2),th(S1,S2)) :-
                          nonvar(R1),nonvar(R2),
                          claus((_,_,th(S1,S2)),true),
                          R1=<S1,S1=<R2,R1=<R2,R2=<S2,S1=<S2.
 
/* if IN then TH in the same time point */
               contT(th(S1,S2),in(S1,S2)) :-
                          nonvar(S1),nonvar(S2),
                          claus((_,_,in(S1,S2)),true),
                          S1=S2, S2=R1, R1=R2.
/* --------------  */
 
/*in <= T-E */ contT(in(R1,R2),in(S1,S2)) :-
                          nonvar(R1),nonvar(R2),
                          nonvar(S1),nonvar(S2),
                          R1=<S1, S1=<S2, S2=<R2.
 
/*in <=*/ contT(in((R1,R2)),in(S1,S2)) :-
                          nonvar(R1),nonvar(R2),
                          claus((_,_,in(S1,S2)),true),
                          R1=<S1, S1=<S2, S2=<R2.
 
/*in <= T-E ultima */ contT(in(R1,R2),in(S1,S2)) :-
                          nonvar(R1),nonvar(R2),
                          claus((_,_,in(S1,S2)),true),
                          R1=<S1, S1=<S2, S2=<R2.
 
/*in <=*/ contT(in((R1,R2)),in(R1,R2)) :-
                          var(R1),var(R2),
                          claus((_,_,in(R1,R2)),true).
 
/*in <= T-E */ contT(in((R1,R2)),in(S1,S2)) :-
			  var(R1),var(R2),
                          nonvar(S1),nonvar(S2),
                          claus((_,_,in(R1,R2)),true),
                          R1=<S1, S1=<S2, S2=<R2.
 
 
 
/* FACTS */
 
 
claus(person(monica,jurnalist),true ).
claus((does(monica,play),inr(600,1500,1200,1400),th(1200,1300)),true).
claus((does(monica,eat),inr(600,1000,1000,1100),th(1100,1200)),true).
claus((does(monica,ski),thr(500,2000,1400,2000),th(1300,1600)),true).
 
claus(person(panfila,jurnalist),true ).
claus((does(panfila,play),in(1200,1300),thr(600,1500,1200,1400)),true).
claus((does(panfila,eat),in(1100,1200),thr(600,1000,1000,1100)),true).
claus((does(panfila,ski),in(1300,1600),thr(500,2000,1400,2000)),true).
 
claus(person(john,tourist),true).
claus((does(john,eat),inr(600,1000,1000,1100),th(1100,1200)),true ).
claus((does(john,ski),thr(500,2000,1400,2000),th(1200,1500)),true).
 
claus(person(hilda,tourist),true).
claus((does(hilda,eat),inr(600,1000,1000,1100),in(1100,1200)),true).
claus((does(hilda,run),inr(520,2000,1400,2000),th(1500,1700)),true).
 
claus((resort(terrance), thr(500,2000,1000,1400), th(0000,2400)),true).
claus((resort(skia), thr(500,2000,1400,2000), th(0000,2400)),true).
 
 
/* EXAMPLE OF QUERIES (you have to comment the actual query and uncomment the next query
 before load the program */
 
/* setof(P,demo((does(P,eat),inr(_),th(_))),L). */
 
/* s(R) :- demo((does(hilda,_),inr(R),in(1500,1700))).  */
 
/*s(R,I) :- demo(((does(monica,_),thr(R),th(I)),(resort(skia),thr(R),th(_)))).  */
/*s(R) :- demo((does(hilda,_),inr(R),in(0800,1200))).*/
/*s(A,R,I) :- demo(((does(monica,A),inr(R),th(I)),(resort(terrance),thr(R),th(_)))),write(R),write(I). */
 
		  /*s(R,I) :- demo(((does(monica,eat),inr(R),th(I)),(does(hilda,eat),inr(R),in(I)),
         (does(john,eat),inr(R),th(I)),(resort(terrance),thr(R),th(_)))).*/
/*s(R,I,R1) :- demo(((does(john,_),inr(R),th(I)),(does(monica,_),inr(R1),th(I)),
           (resort(terrance),thr(R1),th(_)))),write(R),write(R1),write(I).*/
/* s(R,I) :- demo((
                  (does(monica,eat),inr(R),th(I)),
                  (does(hilda,eat),inr(R),in(I)),
                  (does(john,eat),inr(R),in(I)),
                  (resort(terrance),thr(R),th(_))
                 )).                 */
 
/* Facts about volcano zone */
 
claus(transport(bus1,people),true).
claus(transport(bus2,people),true).
 
claus((does(bus1,parking),inr(3,3,4,4),th(10,12)),true).
claus((does(bus2,working),inr(3,4,4,7),th(10,12)),true).
claus((does(bus1,working),inr(1,2,2,3),in(12,17)),true).
claus((does(bus1,loading),thr(1,2,1,2),th(13,14)),true).
 
claus((town(huejotzingo),thr(3,4,4,7), th(0,24)),true).
claus((town(calpan), thr(1,2,2,3), th(0,24)),true).
 
/*s(X,R) :- demo((
      (does(X,loading),inr(R),in(12,15)),
      (town(calpan),thr(R),in(_))

    )).*/
 
/*s(X,R) :- demo((does(bus2,X),inr(R),in(9,12))).*/
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder