```    1% Simple illustration of the automatic extraction of modes
2%       in Aleph using Michalski's trains problem.
3% To run do the following:
6%       c. induce_modes.
7% Tighter or looser chaining is achieved by changing the
8% value of the mode_overlap_threshold parameter
```

?- `induce_modes(Modes)`. */

```   15:-use_module(library(aleph)).   16:- if(current_predicate(use_rendering/1)).   17:- use_rendering(prolog).   18:- endif.   19:- aleph.   20:- aleph_set(i,2).   21:- aleph_set(clauselength,4).   22:- aleph_set(mode_overlap_threshold,0.95).   23
24% commented out -- Aleph has to learn these (or some approximation to them)
25% :- modeh(1,eastbound(+train)).
26% :- modeb(1,short(+car)).
27% :- modeb(1,closed(+car)).
28% :- modeb(1,long(+car)).
29% :- modeb(1,open_car(+car)).
30% :- modeb(1,double(+car)).
31% :- modeb(1,jagged(+car)).
32% :- modeb(1,shape(+car,#shape)).
34% :- modeb(1,wheels(+car,#int)).
35% :- modeb(*,has_car(+train,-car)).
36
37:- determination(eastbound/1,short/1).   38:- determination(eastbound/1,closed/1).   39:- determination(eastbound/1,long/1).   40:- determination(eastbound/1,open_car/1).   41:- determination(eastbound/1,double/1).   42:- determination(eastbound/1,jagged/1).   43:- determination(eastbound/1,shape/2).   44:- determination(eastbound/1,wheels/2).   45:- determination(eastbound/1,has_car/2).   46:- determination(eastbound/1,load/3).   47
48% type definitions
49car(car_11).  car(car_12).  car(car_13).  car(car_14).
50car(car_21).  car(car_22).  car(car_23).
51car(car_31).  car(car_32).  car(car_33).
52car(car_41).  car(car_42).  car(car_43).  car(car_44).
53car(car_51).  car(car_52).  car(car_53).
54car(car_61).  car(car_62).
55car(car_71).  car(car_72).  car(car_73).
56car(car_81).  car(car_82).
57car(car_91).  car(car_92).  car(car_93).  car(car_94).
58car(car_101).  car(car_102).
59
60shape(elipse).  shape(hexagon).  shape(rectangle).  shape(u_shaped).
61shape(triangle). shape(circle). shape(nil).
62
63train(east1).  train(east2).  train(east3).  train(east4).  train(east5).
64train(west6).  train(west7).  train(west8).  train(west9).  train(west10).
65
66% eastbound train 1
67short(car_12).		% 0
68closed(car_12).		% 1
69long(car_11).		% 2
70long(car_13).
71short(car_14).
72open_car(car_11).		% 3
73% infront(east1,car_11).
74% infront(car_11,car_12).
75% infront(car_12,car_13).
76% infront(car_13,car_14).
77open_car(car_13).
78open_car(car_14).
79shape(car_11,rectangle). % 4,5
80shape(car_12,rectangle).
81shape(car_13,rectangle).
82shape(car_14,rectangle).
87wheels(car_11,2).	  % 9,10
88wheels(car_12,2).
89wheels(car_13,3).
90wheels(car_14,2).
91has_car(east1,car_11). % 11,12
92has_car(east1,car_12).
93has_car(east1,car_13).
94has_car(east1,car_14).
95
96% eastbound train 2
97has_car(east2,car_21).
98has_car(east2,car_22).
99has_car(east2,car_23).
100% infront(east2,car_21).
101% infront(car_21,car_22).
102% infront(car_22,car_23).
103short(car_21).
104short(car_22).
105short(car_23).
106shape(car_21,u_shaped).
107shape(car_22,u_shaped).
108shape(car_23,rectangle).
109open_car(car_21).
110open_car(car_22).
111closed(car_23).
115wheels(car_21,2).
116wheels(car_22,2).
117wheels(car_23,2).
118
119% eastbound train 3
120has_car(east3,car_31).
121has_car(east3,car_32).
122has_car(east3,car_33).
123% infront(east3,car_31).
124% infront(car_31,car_32).
125% infront(car_32,car_33).
126short(car_31).
127short(car_32).
128long(car_33).
129shape(car_31,rectangle).
130shape(car_32,hexagon).
131shape(car_33,rectangle).
132open_car(car_31).
133closed(car_32).
134closed(car_33).
138wheels(car_31,2).
139wheels(car_32,2).
140wheels(car_33,3).
141
142% eastbound train 4
143has_car(east4,car_41).
144has_car(east4,car_42).
145has_car(east4,car_43).
146has_car(east4,car_44).
147% infront(east4,car_41).
148% infront(car_41,car_42).
149% infront(car_42,car_43).
150% infront(car_43,car_44).
151short(car_41).
152short(car_42).
153short(car_43).
154short(car_44).
155shape(car_41,u_shaped).
156shape(car_42,rectangle).
157shape(car_43,elipse).
158shape(car_44,rectangle).
159double(car_42).
160open_car(car_41).
161open_car(car_42).
162closed(car_43).
163open_car(car_44).
168wheels(car_41,2).
169wheels(car_42,2).
170wheels(car_43,2).
171wheels(car_44,2).
172
173% eastbound train 5
174has_car(east5,car_51).
175has_car(east5,car_52).
176has_car(east5,car_53).
177% infront(east5,car_51).
178% infront(car_51,car_52).
179% infront(car_52,car_53).
180short(car_51).
181short(car_52).
182short(car_53).
183shape(car_51,rectangle).
184shape(car_52,rectangle).
185shape(car_53,rectangle).
186double(car_51).
187open_car(car_51).
188closed(car_52).
189closed(car_53).
193wheels(car_51,2).
194wheels(car_52,3).
195wheels(car_53,2).
196
197% westbound train 6
198has_car(west6,car_61).
199has_car(west6,car_62).
200% infront(west6,car_61).
201% infront(car_61,car_62).
202long(car_61).
203short(car_62).
204shape(car_61,rectangle).
205shape(car_62,rectangle).
206closed(car_61).
207open_car(car_62).
210wheels(car_61,2).
211wheels(car_62,2).
212
213% westbound train 7
214has_car(west7,car_71).
215has_car(west7,car_72).
216has_car(west7,car_73).
217% infront(west7,car_71).
218% infront(car_71,car_72).
219% infront(car_72,car_73).
220short(car_71).
221short(car_72).
222long(car_73).
223shape(car_71,rectangle).
224shape(car_72,u_shaped).
225shape(car_73,rectangle).
226double(car_71).
227open_car(car_71).
228open_car(car_72).
229jagged(car_73).
233wheels(car_71,2).
234wheels(car_72,2).
235wheels(car_73,2).
236
237% westbound train 8
238has_car(west8,car_81).
239has_car(west8,car_82).
240% infront(west8,car_81).
241% infront(car_81,car_82).
242long(car_81).
243short(car_82).
244shape(car_81,rectangle).
245shape(car_82,u_shaped).
246closed(car_81).
247open_car(car_82).
250wheels(car_81,3).
251wheels(car_82,2).
252
253% westbound train 9
254has_car(west9,car_91).
255has_car(west9,car_92).
256has_car(west9,car_93).
257has_car(west9,car_94).
258% infront(west9,car_91).
259% infront(car_91,car_92).
260% infront(car_92,car_93).
261% infront(car_93,car_94).
262short(car_91).
263long(car_92).
264short(car_93).
265short(car_94).
266shape(car_91,u_shaped).
267shape(car_92,rectangle).
268shape(car_93,rectangle).
269shape(car_94,u_shaped).
270open_car(car_91).
271jagged(car_92).
272open_car(car_93).
273open_car(car_94).
278wheels(car_91,2).
279wheels(car_92,2).
280wheels(car_93,2).
281wheels(car_94,2).
282
283% westbound train 10
284has_car(west10,car_101).
285has_car(west10,car_102).
286% infront(west10,car_101).
287% infront(car_101,car_102).
288short(car_101).
289long(car_102).
290shape(car_101,u_shaped).
291shape(car_102,rectangle).
292open_car(car_101).
293open_car(car_102).
296wheels(car_101,2).
297wheels(car_102,2).
298
299
300% cost(_,[P,N|_],Cost):-
301	% Cost is 1-(P+1)/(P+N+2).
302%
303%
304% :- aleph_set(refine,user).
305%
306% refine(false,eastbound(X)):- !.
307% refine(Clause,Clause1):-
309%
313	% !,
316	% !,
319
320% %
321% refine(false,(eastbound(X):-has_car(X,Y),short(Y),closed(Y))).
322% refine(false,eastbound(X)).
323% refine(eastbound(X),(eastbound(X):-has_car(X,Y))).
324% refine(eastbound(X),(eastbound(X):-has_car(X,Y),short(Y))).
325% refine((eastbound(X):-has_car(X,Y),short(Y)),(eastbound(X):-has_car(X,Y),short(Y),closed(Y))).
326
327% :- aleph_set(portray_literals,true).
328% :- aleph_set(portray_search,true).
329
330% :- [portray].
331/*
332portray(eastbound(A)):-
333	write('Train '), write(A),
334	write(' is eastbound').
335
336portray(has_car(A,B)):-
337	write('train '), write(A),
338	write(' has a car '), write(B).
339
340portray(short(B)):-
341	write('car '), write(B),
342	write(' is short').
343
344portray(closed(B)):-
345	write('car '), write(B),
346	write(' is closed').
347
348portray(long(B)):-
349	write('car '), write(B),
350	write(' is long').
351
352portray(open_car(B)):-
353	write('car '), write(B),
354	write(' is open').
355
356portray(double(B)):-
357	write('car '), write(B),
358	write(' is double-walled').
359
360portray(jagged(B)):-
361	write('car '), write(B),
362	write(' has a jagged roof').
363
364portray(shape(B,C)):-
365	write('car '), write(B),
366	write(' is '), write(C), write('-shaped').
367
368portray(wheels(B,C)):-
369	write('car '), write(B),
370	write(' has '), write(C),
371	write(' wheels').
372
374	write('car '), write(B),
375	write(' has '), write(D),
376	write(' '), write(C), write('-shaped load(s)').
377
378*/
379
380:-end_bg.  381:-begin_in_pos.  382eastbound(east1).
383eastbound(east2).
384eastbound(east3).
385eastbound(east4).
386eastbound(east5).
387
388% eastbound(east1).
389% eastbound(east2).
390% eastbound(east3).
391% eastbound(east4).
392% eastbound(east5).
393% eastbound(east1).
394% eastbound(east2).
395% eastbound(east3).
396% eastbound(east4).
397% eastbound(east5).
398% eastbound(east1).
399% eastbound(east1).
400% eastbound(east1).
401% eastbound(east1).
402% eastbound(east1).
403% eastbound(east1).
404% eastbound(east1).
405% eastbound(east1).
406% eastbound(east1).
407% eastbound(east1).
408% eastbound(east1).
409% eastbound(east1).
410% eastbound(east1).
411% eastbound(east1).
412% eastbound(east1).
413% eastbound(east1).
414% eastbound(east1).
415% eastbound(east1).
416% eastbound(east1).
417% eastbound(east1).
418% eastbound(east1).
419% eastbound(east2).
420% eastbound(east3).
421% eastbound(east4).
422% eastbound(east5).
423% eastbound(east2).
424% eastbound(east3).
425% eastbound(east4).
426% eastbound(east5).
427% eastbound(east2).
428% eastbound(east3).
429% eastbound(east4).
430% eastbound(east5).
431% eastbound(east2).
432% eastbound(east3).
433% eastbound(east4).
434% eastbound(east5).
435% eastbound(east2).
436% eastbound(east3).
437% eastbound(east4).
438% eastbound(east5).
439% eastbound(east2).
440% eastbound(east3).
441% eastbound(east4).
442% eastbound(east5).
443% eastbound(east2).
444% eastbound(east3).
445% eastbound(east4).
446% eastbound(east5).
447% eastbound(east2).
448% eastbound(east3).
449% eastbound(east4).
450% eastbound(east5).
451% eastbound(east2).
452% eastbound(east3).
453% eastbound(east4).
454% eastbound(east5).
455% eastbound(east2).
456% eastbound(east3).
457% eastbound(east4).
458% eastbound(east5).
459% eastbound(east2).
460% eastbound(east3).
461% eastbound(east4).
462% eastbound(east5).
463% eastbound(east2).
464% eastbound(east3).
465% eastbound(east4).
466% eastbound(east5).
467% eastbound(east2).
468% eastbound(east3).
469% eastbound(east4).
470% eastbound(east5).
471% eastbound(east2).
472% eastbound(east3).
473% eastbound(east4).
474% eastbound(east5).
475% eastbound(east2).
476% eastbound(east3).
477% eastbound(east4).
478% eastbound(east5).
479% eastbound(east2).
480% eastbound(east3).
481% eastbound(east4).
482% eastbound(east5).
483% eastbound(east2).
484% eastbound(east3).
485% eastbound(east4).
486% eastbound(east5).
487% eastbound(east2).
488% eastbound(east3).
489% eastbound(east4).
490% eastbound(east5).
491% eastbound(east2).
492% eastbound(east3).
493% eastbound(east4).
494% eastbound(east5).
495% eastbound(east2).
496% eastbound(east3).
497% eastbound(east4).
498% eastbound(east5).
499% eastbound(east2).
500% eastbound(east3).
501% eastbound(east4).
502% eastbound(east5).
503:-end_in_pos.  504
505:-begin_in_neg.  506
507eastbound(west6).
508eastbound(west7).
509eastbound(west8).
510eastbound(west9).
511eastbound(west10).
512
513%westbound(east1).
514%westbound(east2).
515%westbound(east3).
516%westbound(east4).
517%westbound(east5).
518:-end_in_neg.```