Esempio n. 1
0
conn = connect('buses.db')
curs = conn.cursor()

curs.execute("select * from stops")

stops = []

for row in curs:
    code = row[0]
    name = row[1]
    x = row[2]
    y = row[3]

    stops.append(((x, y), code, name))

tree = kdtree(stops)
#tree.dump(3)

#searchrange(tree,(55.9014167786,-4),(55.916,-3.224),2)

#testloc=(55.952545,-3.200546)
#nearest = searchnearest(tree,testloc)
#print "The nearest is ",nearest, distance(nearest.location[0],testloc)

# Snap route points to stops
curs.execute("select * from points")
for row in curs:
    route, chain, x, y, stop, dist = row
    pointloc = (x, y)
    stop = searchnearest(tree, pointloc)
    stoploc, code, name = stop.location
Esempio n. 2
0
conn = connect('buses.db')
curs = conn.cursor()

curs.execute("select * from stops")

stops=[]

for row in curs:
    code=row[0]
    name=row[1]
    x=row[2]
    y=row[3]

    stops.append(((x,y),code,name))

tree=kdtree(stops)

def recordnumgenerator():
    num=0
    while 1:
        yield num
        num+=1

# Header - 8 bytes - 'bus1', integer root pos

f=file("stops.dat","wb")
f.seek(8,os.SEEK_SET)
recordnumgen=recordnumgenerator()
rootpos=tree.write(f,recordnumgen)
f.seek(0,os.SEEK_SET)
print rootpos ," root"
       first mapping
       
For each column not in the mapping the nearest neighbor that IS in the mapping
is identified and a new mapping is printed in which such columns are mapped to
the same symbol as said nearest neighbor.

"""

import sys
from math import *

from kdtree import *

inf = float( "inf" )

k = kdtree()
points = []
points_to_labels = dict()

# Read the mapping
mapping = {}
for line in open( sys.argv[1] ):
    fields = line.split()
    mapping[ fields[0] ] = fields[1]

# Read the ancestral distributions associated with that mapping
for line in open( sys.argv[2] ):
    if line.startswith( '#' ):
        continue
    fields = line.split()
    label = fields[0]
Esempio n. 4
0

def result(string, empty):
    _input = []
    query = string.split(',')
    for i in range(8):
        _input.append(int(query[i]))

    start_time = time.time()
    result = empty.search_nn([
        _input[0], _input[1], _input[2], _input[3], _input[4], _input[5],
        _input[6], _input[7]
    ])

    T = "%s seconds" % (time.time() - start_time)
    a = str(result)
    b = a.split('(')
    distance = b[2].split(',')[9].split(')')[0]
    d = b[2].split(')')[0].split(',')[0:8]
    coordinate = "" + d[0] + ',' + d[1] + ',' + d[2] + ',' + d[3] + ',' + d[
        4] + ',' + d[5] + ',' + d[6] + ',' + d[7]
    index = b[2].split(')')[0].split(',')[8]
    str1 = "The nearest neighbor point's coordinate is : " + coordinate
    str2 = "The time cost of kdtree is : " + T
    str3 = "The distance between query point and neareast point is : " + distance
    return [str1, str2, str3]


kdtree('itemset.txt')
result('1,2,3,4,5,6,7,8')