Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graph Routing Question

Status
Not open for further replies.

bumperboy2000

Programmer
Oct 20, 2011
1
0
0
SG
Hi guys. I'm currently doing a module on programming languages. I have an assignment which requires graph traversal, finding out the 3 shortest paths from one train station to another. There're interchanges for changing of train lines.

The station diagram is depicted here:
I have come up with an adjacency list of stations, without definition whether it's an interchange or not. As for progressing from there, I'm dumbfounded by how this language works. Could anyone lead me in the correct direction as to solve this problem?

User input: beginning station AND end station
Program output: shortest path 1, shortest path 2, shortest path 3

The paths require printing of each station's name throughout the whole path.

These are the lines of arcs I have come up with in an adjacency-list manner.

Thanks a million! :D

arcs(jookoon,[pioneer]).
arcs(pioneer,[jookoon,boonlay]).
arcs(boonlay,[pioneer,lakeside]).
arcs(lakeside,[boonlay,chinesegarden]).
arcs(chinesegarden,[lakeside,jurongeast]).
arcs(jurongeast,[chinesegarden,clementi,bukitbatok]).
arcs(clementi,[jurongeast,dover]).
arcs(dover,[clementi,buonavista]).
arcs(buonavista,[dover,commonwealth]).
arcs(commonwealth,[buonavista,queenstown]).
arcs(queenstown,[commonwealth,redhill]).
arcs(redhill,[queenstown,tiongbahru]).
arcs(tiongbahru,[redhill,outrampark]).
arcs(outrampark,[tiongbahru,tanjongpagar,harbourfront,chinatown]).
arcs(tanjongpagar,[outrampark,rafflesplace]).
arcs(rafflesplace,[tanjongpagar,cityhall,marinabay]).
arcs(cityhall,[rafflesplace,dhobyghaut,bugis]).
arcs(bugis,[cityhall,lavender]).
arcs(lavender,[bugis,kallang]).
arcs(kallang,[lavender,aljunied]).
arcs(aljunied,[kallang,payalebar]).
arcs(payalebar,[aljunied,eunos,dakota,macpherson]).
arcs(eunos,[payalebar,kembangan]).
arcs(kembangan,[eunos,bedok]).
arcs(bedok,[kembangan,tanahmerah]).
arcs(tanahmerah,[bedok,simei,expo]).
arcs(simei,[tanahmerah,tampines]).
arcs(tampines,[simei,pasirris]).
arcs(pasirris,[tampines]).
arcs(expo,[tanahmerah,changiairport]).
arcs(changiairport,[expo]).
arcs(bukitbatok,[jurongeast,bukitgombak]).
arcs(bukitgombak,[bukitbatok,choachukang]).
arcs(choachukang,[bukitgombak,yewtee]).
arcs(yewtee,[choachukang,kranji]).
arcs(kranji,[yewtee,marsiling]).
arcs(marsiling,[kranji,woodlands]).
arcs(woodlands,[marsiling,admiralty]).
arcs(admiralty,[woodlands,sembawang]).
arcs(sembawang,[admiralty,yishun]).
arcs(yishun,[sembawang,khatib]).
arcs(khatib,[yishun,yiochukang]).
arcs(yiochukang,[khatib,angmokio]).
arcs(angmokio,[yiochukang,bishan]).
arcs(bishan,[angmokio,braddell,marymount,lorongchuan]).
arcs(braddell,[bishan,toapayoh]).
arcs(toapayoh,[braddell,novena]).
arcs(novena,[toapayoh,newton]).
arcs(newton,[novena,orchard]).
arcs(orchard,[newton,somerset]).
arcs(somerset,[orchard,dhobyghaut]).
arcs(dhobyghaut,[somerset,cityhall,clarkequay,littleindia,brasbasah]).
arcs(marinabay,[rafflesplace]).
arcs(harbourfront,[outrampark]).
arcs(chinatown,[outrampark,clarkequay]).
arcs(clarkequay,[dhobyghaut,chinatown]).
arcs(littleindia,[dhobyghaut,farrerpark]).
arcs(farrerpark,[littleindia,boonkeng]).
arcs(boonkeng,[farrerpark,potongpasir]).
arcs(potongpasir,[boonkeng,woodleigh]).
arcs(woodleigh,[potongpasir,serangoon]).
arcs(serangoon,[woodleigh,kovan,bartley,lorongchuan]).
arcs(kovan,[serangoon,hougang]).
arcs(hougang,[kovan,buangkok]).
arcs(buangkok,[hougang,sengkang]).
arcs(sengkang,[buangkok,punggol]).
arcs(punggol,[sengkang]).
arcs(marymount,[bishan]).
arcs(lorongchuan,[bishan,serangoon]).
arcs(bartley,[taiseng,serangoon]).
arcs(taiseng,[bartley,macpherson]).
arcs(macpherson,[taiseng,payalebar]).
arcs(dakota,[mountbatten,payalebar]).
arcs(mountbatten,[dakota,stadium]).
arcs(stadium,[mountbatten,nicollhighway]).
arcs(nicollhighway,[stadium,promenade]).
arcs(promenade,[nicollhighway,esplanade]).
arcs(esplanade,[promenade,brasbasah]).
arcs(brasbasah,[esplanade,dhobyghaut]).
 
Generally, a graph is described with nodes eg, not arcs(pioneer,[jookoon,boonlay]). but arc(pioneer, jookoon), and arc(pioneer, boonlay).
Now, searching in this forum, you should find the answer of your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top