From 35d9475033669385ca84a5f72730ef68b5dbc082 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Sat, 22 Mar 2014 18:23:22 +0100 Subject: [PATCH] Refactor naming scheme --- README => README.md | 0 ant_colony.py => ants.py | 4 ++-- run_all.py | 16 ++++++++-------- path.py => shortpath.py | 0 graph.py => utils.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) rename README => README.md (100%) rename ant_colony.py => ants.py (99%) rename path.py => shortpath.py (100%) rename graph.py => utils.py (86%) diff --git a/README b/README.md similarity index 100% rename from README rename to README.md diff --git a/ant_colony.py b/ants.py similarity index 99% rename from ant_colony.py rename to ants.py index e233311..a0f2aa4 100644 --- a/ant_colony.py +++ b/ants.py @@ -4,7 +4,7 @@ import sys import math import random from collections import Counter -import path +import shortpath def LOG( *args ): @@ -31,7 +31,7 @@ def euclidian_distance( ci, cj, graph = None): return math.sqrt( float(ci[0] - cj[0])**2 + float(ci[1] - cj[1])**2 ) def graph_distance( ci, cj, graph ): - p,c = path.astar( graph, ci, cj ) + p,c = shortpath.astar( graph, ci, cj ) return c diff --git a/run_all.py b/run_all.py index 58e6cdd..46c19ee 100755 --- a/run_all.py +++ b/run_all.py @@ -3,9 +3,9 @@ import sys import turtle import lindenmayer -import graph -import ant_colony -import path +import utils +import ants +import shortpath import uberplot import matplotlib.pyplot as plot @@ -39,7 +39,7 @@ with open("penrose_%i.segments" % depth, "w") as fd: fd.write( str(penrose) ) print "Convert the segment list into an adjacency list graph" -G = graph.graph( penrose.segments ) +G = utils.adjacency_from_set( penrose.segments ) print "Solve the TSP with an Ant Colony Algorithm" @@ -52,13 +52,13 @@ w_local_phero = 0.1 c_greed = 0.9 w_history = 1.0 -best,phero = ant_colony.search( G, max_it, num_ants, decay, w_heur, w_local_phero, w_history, c_greed, cost_func = ant_colony.graph_distance ) +best,phero = ants.search( G, max_it, num_ants, decay, w_heur, w_local_phero, w_history, c_greed, cost_func = ants.graph_distance ) print "Transform the resulting nodes permutation into a path on the graph" # by finding the shortest path between two cities. traj = [] -for start,end in ant_colony.tour(best["permutation"]): - p,c = path.astar( G, start, end ) +for start,end in ants.tour(best["permutation"]): + p,c = shortpath.astar( G, start, end ) traj += p print "traj",len(traj) @@ -83,7 +83,7 @@ for i in phero: # uberplot.scatter_segments( ax, seg, color="red", alpha=0.5, linewidth=nph ) # best tour -uberplot.plot_segments( ax, ant_colony.tour(traj), color="red", alpha=0.9, linewidth=3 ) +uberplot.plot_segments( ax, ants.tour(traj), color="red", alpha=0.9, linewidth=3 ) # tesselation tcol = "black" diff --git a/path.py b/shortpath.py similarity index 100% rename from path.py rename to shortpath.py diff --git a/graph.py b/utils.py similarity index 86% rename from graph.py rename to utils.py index d33a934..c7e9eec 100644 --- a/graph.py +++ b/utils.py @@ -1,5 +1,5 @@ -def graph( segments ): +def adjacency_from_set( segments ): graph = {} for start,end in segments: graph[start] = graph.get( start, [] )