Example #1
0
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
Example #2
0
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()