summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-12-17 22:39:48 +0100
committerGuillaume Seguin <guillaume@segu.in>2007-12-17 22:39:48 +0100
commitb61fe8845f198f7f1a6c88b3bc8d3ba9539289f2 (patch)
treef32b0eecddf4f6e1093e69de37fd7c06052b6648
parent9a5334dbf056dbbb2872944ea480b2645914e8cf (diff)
downloadtsp-b61fe8845f198f7f1a6c88b3bc8d3ba9539289f2.tar.gz
tsp-b61fe8845f198f7f1a6c88b3bc8d3ba9539289f2.tar.bz2
* Add need_init property to Algo class
This property specifies whether or not an initial path is needed
-rwxr-xr-xtsp.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/tsp.py b/tsp.py
index eabcdb8..8eeb24d 100755
--- a/tsp.py
+++ b/tsp.py
@@ -244,6 +244,7 @@ class Algo:
'''Base class for algorithm, please extend me!'''
context = None
+ need_init = True
def __init__ (self, context):
'''Initialize object'''
@@ -393,19 +394,21 @@ the current settings) and run the algorithm on it until the stop () function
is called.'''
if not self.runner:
self.update_best (path = None)
- if self.init == INIT_GREEDY_BEST:
- for i in self.context.map:
- if self.terminate:
- return
- path = self.context.nearest_neighbours (start = i)
- if not best or path.length < best.length:
- self.best = path
- elif self.init == INIT_GREEDY:
- self.best = self.context.nearest_neighbours ()
- else:
- self.best = self.context.random_path ()
- self.update_best (path = self.best)
- self.runner = self.algo.run (self.best)
+ if self.algo.need_init:
+ if self.init == INIT_GREEDY_BEST:
+ for i in self.context.map:
+ if self.terminate:
+ return
+ path = self.context.nearest_neighbours (start = i)
+ if not best or path.length < best.length:
+ self.best = path
+ elif self.init == INIT_GREEDY:
+ self.best = self.context.nearest_neighbours ()
+ else:
+ self.best = self.context.random_path ()
+ self.update_best (path = self.best)
+ self.runner = self.algo.run (self.best)
+ self.runner = self.algo.run ()
while not self.terminate:
path = self.runner.next ()
if not self.best or path.length < self.best.length: