Example #1
0
def main():
    random.seed(38272932)
    points = getrandompoints(
        30, 1000, (0.0, 0.0), None,
        30, 600,
        30, 200,
        30, 50
    )
    # mix them up for a specified amount of time
    imax = len(points) - 1
    st = time.time()
    random.seed(time.time())
    print('rendering output image of nodes..')
    tga = TGAImage(1000, 1000)
    tga.drawpoints(points)
    tga.save('test.tga')
    print('mixing initial node list..')
    random.shuffle(points)
    #while time.time() - st < 10:
    #    a = random.randint(0, imax)
    #    b = random.randint(0, imax)
    #    tmp = points[a]
    #    points[a] = points[b]
    #    points[b] = tmp
    print('starting solver..')
    st = time.time()
    path = solve(points)
    tt = time.time() - st
    if len(path) < len(points):
        raise Exception('All points must be included in the path.')

    td = getpathdistance(points, path)

    print('total-distance:   %.2f' % td)
    print('time-taken:       %.2f' % tt)