def generateAStarPlotWithLines(n): """ Generates a plot. :param n: # of random problems to test algorithm on. """ colors = ['r', 'g', 'b', 'm', 'c'] heuristics = [h0, h1, h2, h3, h4] plt.figure() plt.xlabel("Problem number") plt.ylabel("Complexity") H0_Y = [] H1_Y = [] H2_Y = [] H3_Y = [] H4_Y = [] for i in range(int(n)): p = generateRandomProblem() H0_Y.append(sum(S.astar(p, h0)[1:])) H1_Y.append(sum(S.astar(p, h1)[1:])) H2_Y.append(sum(S.astar(p, h2)[1:])) H3_Y.append(sum(S.astar(p, h3)[1:])) H4_Y.append(sum(S.astar(p, h4)[1:])) plt.plot([x for x in range(1, n + 1)], H0_Y, marker='o', linestyle='-', color='r') plt.plot([x for x in range(1, n + 1)], H1_Y, marker='o', linestyle='-', color='g') plt.plot([x for x in range(1, n + 1)], H2_Y, marker='o', linestyle='-', color='b') plt.plot([x for x in range(1, n + 1)], H3_Y, marker='o', linestyle='-', color='m') plt.plot([x for x in range(1, n + 1)], H4_Y, marker='o', linestyle='-', color='c') plt.legend(('H1', 'H2', 'H3', 'H4', 'H5')) plt.show()
def generateAStarPlot(n): """ Generates a plot. :param n: # of random problems to test algorithm on. """ colors = ['r', 'g', 'b', 'm', 'c'] heuristics = [h0, h1, h2, h3, h4] plt.figure() plt.xlabel("Problem number") plt.ylabel("Complexity") H_ALL = [] X = [] for i in range(int(n)): p = generateRandomProblem() results = [S.astar(p, h)[1:] for h in heuristics] H_Y = [] for j in range(len(results)): y = sum(results[j]) H_Y.append(y) #X.append(i) plt.plot([1, 2, 3, 4, 5], H_Y, marker='o', linestyle='-', color=colors[j]) plt.legend(('H1', 'H2', 'H3', 'H4', 'H5')) # plt.plot(X, H_Y[1], marker='o', linestyle='-', color='g', label='H2') # plt.plot(X, H_Y[2], marker='o', linestyle='-', color='b', label='H3') # plt.plot(X, H_Y[3], marker='o', linestyle='-', color='y', label='H4') # plt.plot(X, H_Y[4], marker='o', linestyle='-', color='m', label='H5') plt.show()