-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.pl
More file actions
32 lines (25 loc) · 1001 Bytes
/
create.pl
File metadata and controls
32 lines (25 loc) · 1001 Bytes
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
:- [graph, metro_network].
:- new_graph(metro).
% add ertices
add_vertices([]).
add_vertices([[Station|_]|Tail]) :-
add_vertex(metro, Station),
add_vertices(Tail).
% add edges for each couple station which are connected on the line
add_station_edge([_|[]]).
add_station_edge([[Station|_], [Station_2|Distance]|Tail]) :-
add_edge(metro, Station, Station_2, Distance),
add_station_edge([[Station_2|Distance]|Tail]).
/* same work from above, but when the line is reversed, ie way back
this done to get the proper distance for the connection */
add_station_edge_reverse([_|[]]).
add_station_edge_reverse([[Station|Distance], [Station_2|Distance2]|Tail]) :-
add_edge(metro, Station, Station_2, Distance),
add_station_edge_reverse([[Station_2|Distance2]|Tail]).
% creates the metro network, adding edges for each line
create_network :- train(_, List),
add_vertices(List),
add_station_edge(List),
reverse(List, Reverse),
add_station_edge_reverse(Reverse).
:- create_network.