(no subject)

MUSAJADAKISS at aol.com MUSAJADAKISS at aol.com
Sat Dec 16 07:17:34 EST 2000


please can you help me in completing this to search for a route using a* 
algorithim 
the file will be in text written and stored in notepad plase i will be glad 
if it is done as soon as you can thank you very much
Amsterdam:
    Berlin,650
    Brussels,197
    Calais,367
    Cologne,256
    Edinburgh,1093
    Hamburg,447
    Paris,510
Athens:
    Sofia,828
Belfast:
    Cork,416
    Dublin,167
    Kilkenny,277
Berlin:
    Edinburgh,1696
    Hamburg,285
    Prague,345
    Rostock,222
    Stuttgart,629
    Warsaw,606
Budapest:
    Burcharest,852
    Prague,537
    Sofia,790
    Vienna,242
Cork:
    Kilkenny,148
Dublin:
    Cork,259
    Kilkenny,119
    Edinburgh,346
Edinburgh:
    Copenhagen,479
Hamburg:
    Rostock,175
    Stuttgart,659
Istanbul:
    Athens,1145
    Burcharest,690
    Sofia,550
London:
    Brussels,333
    Dublin,430
    Cologne,508
    Edinburgh,608
    Paris,399
Madrid:
    Bercelona,617
    Lisbon,651
    Paris,1280
Munich:
    Berlin,594
    Cologne,580
    Frankfurt,398
    Paris,810
    Prague,388
    Vienna,430
Oslo:
    Copenhagen,590
    Hamburg,900
    stocholm,530
Paris:
    Brussels,320
    Cologne,495
Prague:
    Frankfurt,512
    Hamburg,652
    Oslo,1350
    Warsaw,616
    Vienna,295
Rome:
    Athens,1140
    Milan,606
Vienna:
    Berlin,640
    Warsaw,727
Warsaw:
    Moscow,1245
Zurich:
    Milan,292
    Munich,303
    Paris,592
    Vienna,743

this is the pprogramme the hueristic distance is not measured but you can use 
any distance you want
 
import sys, os
import string

##  global vars :
citysign = ':'
NL = '\n'
alphanum = string.letters + string.digits


## Main program
#
def main():
        "TUBEREAD : Main line!"

        global  citysign, NL
        args = sys.argv[:]          ##  gets command-line arguments
        na = len(args)
        print args[0],"[version 1.0]"
        print "command-line args. =",na
        if na < 2:
                print "normal usage:  python tuberead.py <textfile>"
                args.append(raw_input("please give input textfile name: "))
                
        na = len(args)
        
        textname = args[1]
        textfile =  open(textname,"r")
    if textfile == None:
                print "Can't open file:",textname
        
        lc = 0 ; sc = 0
        lines = {}  ##  empty dictionary (station names)
        citylist = []  ##  empty list (line names)
    thisline = "Zonk"
    citydic = {}
    
        while 1:
      textline = textfile.readline()
      if not textline:  break
      name = string.capwords(string.strip(textline))
      sc = sc + 1
      if citysign in name:
          newline = 1
          print "city = ", name
          thiscity = string.replace(name,citysign,'')
          if not citydic.has_key(thiscity):
              citydic[thiscity] = []
          ##  citylist.append(thiscity)
      else:
          x = string.split(name,',')
          ##print x
          c = x[0]
          ##print c
          if not citydic.has_key(c):
              lc = lc + 1
              citydic[c] = []
          d = eval(x[1])
          t1 = (c,d)
          citydic[thiscity].append(t1)
          ##  also append symmetric link :
          t2 = (thiscity,d)
          citydic[c].append(t2)
          
    citylist = citydic.keys()
    citylist.sort()
        print citylist
    print
    print len(citylist),"distinct cities read from textfile."
    print
    ## print citydic
    ##  I/O from user
    while 1:
        sn = raw_input("Enter city name: ")
        sn = string.strip(sn)
        if len(sn) < 1:  break  ##  user hits CRLF to quit loop
        sd = raw_input("Enter destination city name: ")
        if len(sd) < 1:  break  ##  user hits CRLF to quit loop     
        sl = citydic.get(sn,[])
        ra = len(sl)
        st = citydic.get(sd,[])
        mu = len(st)
        print sn,sl,ra
        print sd,st,mu
                
        
    return 0
        
        
            ##  do search

            ##  show result to user


##  Call main and attempt to honour exit status:
try:
    main()
except KeyboardInterrupt:
    sys.exit(1)




More information about the Python-list mailing list