diff --git a/topfarm/cost_models/dummy.py b/topfarm/cost_models/dummy.py index 55f8db8b7257f17d6daccc4a80fd9e4336503b7b..caa9fe69b17c2f55f51a80eb3ec90a3d9c6619b0 100644 --- a/topfarm/cost_models/dummy.py +++ b/topfarm/cost_models/dummy.py @@ -57,8 +57,8 @@ class DummyCost(ExplicitComponent): J['cost', 'turbineY'] = (2 * y - 2 * np.array(self.optimal)[:, 1]) class DummyCostPlotComp(PlotComp): - def __init__(self, optimal): - super().__init__() + def __init__(self, optimal, memory=10): + super().__init__(memory) self.optimal = optimal def init_plot(self, boundary): diff --git a/topfarm/plotting.py b/topfarm/plotting.py index fbe716555902f8897243b37a01011fa2f75118b9..a5981293a8d1d9f382264dae0c17581c12345cca 100644 --- a/topfarm/plotting.py +++ b/topfarm/plotting.py @@ -9,10 +9,9 @@ class PlotComp(ExplicitComponent): """ colors = ['b', 'r', 'm', 'c', 'g', 'y', 'orange', 'indigo', 'grey'] * 100 - def __init__(self, memory=10, plot_every=5): + def __init__(self, memory=10): ExplicitComponent.__init__(self) self.memory = memory - self.plot_every = plot_every self.history = [] self.counter = 0 @@ -47,20 +46,17 @@ class PlotComp(ExplicitComponent): x = inputs['turbineX'] y = inputs['turbineY'] cost = inputs['cost'] - if self.history: - self.history = [(x.copy(), y.copy())] + self.history[:self.memory] - else: - self.history = [(x.copy(), y.copy())] - if self.counter % self.plot_every == 0: - boundary = inputs['boundary'] - self.init_plot(boundary) - plt.title(cost) - - history_arr = np.array(self.history) - for i, c, x_, y_ in zip(range(len(x)), self.colors, x, y): - plt.plot(history_arr[:, 0, i], history_arr[:, 1, i], '.-', color=c, lw=1) - plt.plot(x_, y_, 'o', color=c, ms=5) - plt.plot(x_, y_, 'x' + 'k', ms=4) - - plt.pause(.01) + self.history = [(x.copy(), y.copy())] + self.history[:self.memory] + + boundary = inputs['boundary'] + self.init_plot(boundary) + plt.title(cost) + + history_arr = np.array(self.history) + for i, c, x_, y_ in zip(range(len(x)), self.colors, x, y): + plt.plot(history_arr[:, 0, i], history_arr[:, 1, i], '.-', color=c, lw=1) + plt.plot(x_, y_, 'o', color=c, ms=5) + plt.plot(x_, y_, 'x' + 'k', ms=4) + + plt.pause(.01) self.counter += 1