示例#1
0
# get dimensions
w = int(lines[0])
h = int(lines[1])
StdDraw.setCanvasSize(w, h)
StdDraw.setXscale(0, w)
StdDraw.setYscale(0, h)

# turn on animation mode
StdDraw.show(0)

# run nearest 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.insertNearest(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()
示例#2
0
    score += 2
except:
    print("draw not implemented according to API")
finally:
    print("Score for draw: " + str(score) + "/2.0")
    print("NOTE: You should see a window with a square drawn in it.")
    print("      Points may be subtracted if this doesn't appear.")

totalScore += score

# 6. insertNearest()
score = 0.0
tour = Tour()
try:
    # first check to see if it is implemented
    tour.insertNearest(a)
    score += 1
    # next insert three more points
    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()