示例#1
0
    tour.insertNearest(b)
    tour.insertNearest(c)
    tour.insertNearest(d)
except:
    print("insertNearest not implemented according to API")
finally:
    print("Initial score for insertNearest: " + str(score) + "/1.0")

totalScore += score

# 7. insertSmallest()
score = 0.0
tour = Tour()
try:
    # first check to see if it is implemented
    tour.insertSmallest(a)
    score += 1
    # next insert three more points
    tour.insertSmallest(b)
    tour.insertSmallest(c)
    tour.insertSmallest(d)
except:
    print("insertSmallest not implemented according to API")
finally:
    print("Initial score for insertSmallest: " + str(score) + "/1.0")

totalScore += score

# Now test all methods together using client programs
inOrderScore = 0.0
nearestScore = 0.0
示例#2
0
        
# get dimensions
w = int(lines[0])
h = int(lines[1])
StdDraw.setCanvasSize(768, 768)
StdDraw.setXscale(0, w)
StdDraw.setYscale(0, h)

# turn on animation mode
StdDraw.show(0)

# run in order insertion heuristic
tour = Tour()
for i in range (2, len(lines),2):
    x = float(lines[i])
    y = float(lines[i+1])
    p = Point(x, y)
    tour.insertSmallest(p)
    if delay > -1:
        StdDraw.clear()
        tour.draw()
        StdDraw.show(delay)

# draw to standard draw
tour.draw()
StdDraw.show(5000)

# print tour to standard output
print("Tour distance = " + str(tour.distance()))
tour.show()