Beispiel #1
0
def tryP0(areaPoly=None, t=60):
    fig = plt.figure()
    lst = [0.5, 0.6, 0.7, 0.8]
    data = []
    best = None
    globalOrigin = (596250, 6727996)
    Rini = gr.SqGridGraph(areaPoly=areaPoly, globalOrigin=globalOrigin)
    R = copy.deepcopy(Rini)
    ref = simplified_bruteForce(R)
    print "cost:", cf.totalCost(ref)
    for index, p0 in enumerate(lst):
        R = copy.deepcopy(Rini)
        R, tries = stochastic_several(R, t=t / float(len(lst)), probListGen=ProbListGen(p0, 15))
        if not best or R.cost < best.cost:
            best = R
        data.append(tries)
    mi = min([min(tries) for tries in data] + [ref.cost])
    ma = max([max(tries) for tries in data] + [ref.cost])
    for index, p0 in enumerate(lst):
        ax = fig.add_subplot("%d1%d" % (len(lst), index + 1))
        ax.plot(data[index], "o")
        ax.plot([0, len(data[index])], [ref.cost, ref.cost], "r")  # reference
        ax.set_title("p0=%.1f" % p0)
        ax.set_ylabel("cost")
        ax.set_ylim(mi - 10, ma + 10)
        ax.set_xticklabels([])
    fig = plt.figure()
    ax = fig.add_subplot(111)
    print "best cost:", best.cost
    best.draw(ax=ax)
Beispiel #2
0
def best(areaPoly=None, t=60):
    """
	time - how long we should look for a better solution
	"""
    globalOrigin = 596250, 6727996
    R = gr.SqGridGraph(areaPoly=areaPoly, globalOrigin=globalOrigin)
    # R=simplified_bruteForce(R,aCap=0.2, anim=True)
    R, tries = stochastic_several(R, t=t)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    print "best cost:", R.cost
    R.draw(ax=ax)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(tries, "o")
    ax.set_ylim(0, max(tries) + 100)