Move tour, LOG and LOGN in utils, add vertices_from_set
This commit is contained in:
parent
43201caf9b
commit
dd1fe6569e
3 changed files with 34 additions and 23 deletions
23
ants.py
23
ants.py
|
|
@ -5,27 +5,8 @@ import math
|
|||
import random
|
||||
from collections import Counter
|
||||
import shortpath
|
||||
|
||||
|
||||
def LOG( *args ):
|
||||
"""Print something on stderr and flush"""
|
||||
for msg in args:
|
||||
sys.stderr.write( str(msg) )
|
||||
sys.stderr.write(" ")
|
||||
sys.stderr.flush()
|
||||
|
||||
|
||||
def LOGN( *args ):
|
||||
"""Print something on stdeer, with a trailing new line, and flush"""
|
||||
LOG( *args )
|
||||
LOG("\n")
|
||||
|
||||
|
||||
def tour(lst):
|
||||
# consecutive pairs in lst + last-to-first element
|
||||
for a,b in zip(lst, lst[1:] + [lst[0]]):
|
||||
yield (a,b)
|
||||
|
||||
from utils import tour
|
||||
from utils import LOG,LOGN
|
||||
|
||||
def euclidian_distance( ci, cj, graph = None):
|
||||
return math.sqrt( float(ci[0] - cj[0])**2 + float(ci[1] - cj[1])**2 )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue