@@ -36,7 +36,7 @@ def random_vector(minmax):
36
36
37
37
return random_vector
38
38
39
- def search (search_space , max_iter , show_log = True ):
39
+ def search (search_space , max_iter , output_format = "human" ):
40
40
best = None
41
41
42
42
for i in range (max_iter ):
@@ -47,7 +47,9 @@ def search(search_space, max_iter, show_log=True):
47
47
if best is None or candidate ['cost' ] < best ['cost' ]:
48
48
best = candidate
49
49
50
- if show_log :
50
+ if output_format == "csv" :
51
+ print ("%s,%s" % (i , best ["cost" ]))
52
+ else :
51
53
print ("Iteration " + str (i ) + ": best = " + str (best ['cost' ]))
52
54
53
55
return best
@@ -59,11 +61,10 @@ def search(search_space, max_iter, show_log=True):
59
61
60
62
# algorithm configuration
61
63
max_iter = 100
62
- show_log = decide ()
63
- best = search (search_space , max_iter , show_log )
64
+ output_format = decide ()
65
+ best = search (search_space , max_iter , output_format )
64
66
65
- # execute the algorithm
66
- if show_log :
67
- print ("Done. Best Solution: cost = " + str (best ['cost' ]) + ", v = " + str (best ['vector' ]))
67
+ if output_format == "csv" :
68
+ print ("%s,%s" % (best ["cost" ], "," .join ([str (i ) for i in best ["vector" ]])))
68
69
else :
69
- print (best [" cost" ] )
70
+ print ("Done. Best Solution: cost = " + str ( best [' cost' ]) + ", v = " + str ( best [ 'vector' ]) )
0 commit comments