from layout import Layout from tools import plot_layout, plot_energies file_paths = ['star.txt', 'square.txt', 'star++.txt', 'dog.txt'] for file_path in file_paths: # read the file into your layout class layout = Layout(file_path) # run the normal layout for 1000 iterations and store the total energies energies_normal = layout.layout(1000) # plot the normal layout plot_layout(layout, '') # run the simulated annealing layout for 1000 iterations and store the total energies energiesSA = layout.simulated_annealing_layout(1000) # plot the simulated annealing layout plot_layout(layout, '') # plot the total energies of the normal layout and the simulated annealing layout plot_energies(energies_normal, '', '') plot_energies(energiesSA, '', '')
from layout import Layout from tools import plot_layout, plot_energies energy1 = [] energy2 = [] nets = ["star.txt", "square.txt", "star++.txt", "dog.txt"] for name in nets: print("creating layout for " + name + " ...") temp_layout = Layout(name) Layout.init_positions(temp_layout) e1 = Layout.layout(temp_layout, 1000) # save energy energy1.append(e1) plot_layout(temp_layout, name + "; final energy: " + float(e1[999]).__str__()) e2 = Layout.simulated_annealing_layout(temp_layout, 1000) # save energy energy2.append(e2) plot_layout( temp_layout, "simulated annealing for " + name + "; final energy: " + float(e2[999]).__str__()) plot_energies([energy1[0], energy2[0]], ["force directed", "simulated annealing"], "energy plot for star.txt")