예제 #1
0
파일: test_sa.py 프로젝트: sparkiegeek/TSP
def test_kirkpatrick_cooling():
    start_temp = 1
    rate = 0.9
    coooling_schedule = sa.kirkpatrick_cooling(start_temp, rate)
    assert coooling_schedule.next() == start_temp
    assert coooling_schedule.next() == start_temp * rate
    assert coooling_schedule.next() == start_temp * rate * rate
    assert coooling_schedule.next() == start_temp * rate * rate * rate
예제 #2
0
파일: plots.py 프로젝트: udemirezen/TSP
import matplotlib

matplotlib.use("TkAgg")

from pylab import *
import sys
from sa import P, kirkpatrick_cooling

if sys.argv[1] == "P":
    coords = [x * 0.1 for x in range(0, 100)]

    plot(coords, [P(x, 0, 1) for x in coords], "b-")
    xlabel("difference")
    ylabel("probability")

    show()
else:
    cooling = kirkpatrick_cooling(100, 0.9)
    coords = range(0, 100)

    plot(coords, [t for i, t in zip(coords, cooling)], "b-")
    xlabel("time")
    ylabel("temperature")

    show()