Skip to content

Commit

Permalink
Cleaned up code some more, removed an if statement in progmon, added …
Browse files Browse the repository at this point in the history
…type error to try except statement
  • Loading branch information
Susan Redmond authored and Susan Redmond committed Jan 10, 2019
1 parent 7281c40 commit b21043a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
55 changes: 25 additions & 30 deletions gastop/progmon.py
Expand Up @@ -110,8 +110,7 @@ def progress_monitor(self, current_gen, population):
Returns:
Nothing
"""
try: #if being called by utilities you dont want to do this block

try:
fitscore = [i.fitness_score for i in population]
fitscore_min = fitscore[0]
fitscore_median = np.median(fitscore)
Expand All @@ -124,8 +123,7 @@ def progress_monitor(self, current_gen, population):
# Store population stats:
for j in range(5):
self.pop_progress['Generation '+str(current_gen+1)][dict_headings[j]] = pop_stats[j]

except:
except TypeError: # population has no len when called from save_gif
fitscore = population.fitness_score
fitscore_min = fitscore
best_truss = population
Expand All @@ -134,26 +132,27 @@ def progress_monitor(self, current_gen, population):
# store initial min fitscore (should be worst) for plotting box
self.pop_start = fitscore_min

if self.progress_fitness and self.progress_truss:


# Fitness score plot
self.ax1.scatter(current_gen+1.0, fitscore_min,c=[[0, 0, 0]]) # change c to be 2D array?
[txt.set_visible(False) for txt in self.ax1.texts] #clear old text box
plot_text = self.ax1.text(self.num_gens, self.pop_start, round(
fitscore_min, 3), bbox=dict(facecolor='white', alpha=1),horizontalalignment='right')

# Truss plot
self.ax3.cla()
best_truss.plot(domain=self.domain, loads = self.loads,
fixtures=self.fixtures, ax=self.ax3, fig=self.fig)

plot_text3d = self.ax3.text(self.domain[1][0]-1.0, self.domain[1][1]-1.0, self.domain[1]
[2], "Iteration: " + str(current_gen+1.0), bbox=dict(facecolor='white', alpha=1))

plt.pause(0.001)

elif self.progress_fitness:
# if self.progress_fitness and self.progress_truss:
#
#
# # Fitness score plot
# self.ax1.scatter(current_gen+1.0, fitscore_min,c=[[0, 0, 0]]) # change c to be 2D array?
#
# [txt.set_visible(False) for txt in self.ax1.texts] #clear old text box
# self.ax1.text(self.num_gens, self.pop_start, round(
# fitscore_min, 3), bbox=dict(facecolor='white', alpha=1),horizontalalignment='right')
#
# # Truss plot
# self.ax3.cla()
# best_truss.plot(domain=self.domain, loads = self.loads,
# fixtures=self.fixtures, ax=self.ax3, fig=self.fig)
#
# self.ax3.text(self.domain[1][0]-1.0, self.domain[1][1]-1.0, self.domain[1][2],
# "Iteration: " + str(current_gen+1.0), bbox=dict(facecolor='white', alpha=1))
#
# plt.pause(0.001)

if self.progress_fitness:

self.ax1.scatter(current_gen+1.0, fitscore_min,
c=[[0, 0, 0]])
Expand All @@ -164,17 +163,13 @@ def progress_monitor(self, current_gen, population):

plt.pause(0.001)

elif self.progress_truss:
if self.progress_truss:

self.ax3.cla()
best_truss.plot(domain=self.domain, loads = self.loads,
fixtures=self.fixtures, ax=self.ax3, fig=self.fig)

plot_text = self.ax3.text(self.domain[1][0]-1.0, self.domain[1][1]-1.0, self.domain[1]
[2], "Iteration: " + str(current_gen+1.0), bbox=dict(facecolor='white', alpha=1))
plot_text._bbox_patch._mutation_aspect = 0.1
plot_text.get_bbox_patch().set_boxstyle("square", pad=1)

plt.pause(0.001)
#self.fig.savefig('animation/truss_evo_iter' +
# str(current_gen) + '.png')
plt.pause(0.001)
4 changes: 2 additions & 2 deletions gastop/utilities.py
Expand Up @@ -188,8 +188,8 @@ def transform(section, key):
loads = config['general']['loads']
fixtures = config['general']['fixtures']

progress_fitness = config['monitor_params']['progress_fitness'] # sfr
progress_truss = config['monitor_params']['progress_truss'] # sfr
#progress_fitness = config['monitor_params']['progress_fitness'] # sfr
#progress_truss = config['monitor_params']['progress_truss'] # sfr

if loads.ndim < 3:
loads = np.reshape(loads, (loads.shape + (1,)))
Expand Down
20 changes: 20 additions & 0 deletions junk/susan_scratch.py
Expand Up @@ -20,6 +20,26 @@
#plt.ylabel('convergence')
#plt.xlabel('iteration')

# if self.progress_fitness and self.progress_truss:
#
#
# # Fitness score plot
# self.ax1.scatter(current_gen+1.0, fitscore_min,c=[[0, 0, 0]]) # change c to be 2D array?
#
# [txt.set_visible(False) for txt in self.ax1.texts] #clear old text box
# self.ax1.text(self.num_gens, self.pop_start, round(
# fitscore_min, 3), bbox=dict(facecolor='white', alpha=1),horizontalalignment='right')
#
# # Truss plot
# self.ax3.cla()
# best_truss.plot(domain=self.domain, loads = self.loads,
# fixtures=self.fixtures, ax=self.ax3, fig=self.fig)
#
# self.ax3.text(self.domain[1][0]-1.0, self.domain[1][1]-1.0, self.domain[1][2],
# "Iteration: " + str(current_gen+1.0), bbox=dict(facecolor='white', alpha=1))
#
# plt.pause(0.001)

def run(self):
y = counter(10)
print(y)
Expand Down

0 comments on commit b21043a

Please sign in to comment.