Smith Dhumbumroong avatar Smith Dhumbumroong committed d03f2dd

Simplify the code base

Comments (0)

Files changed (2)

     best_cand = None
     best_cand_score = 0
 
-    # define data structures used by graph plotter module
-    hist_best_cand_scores = []
-    hist_loser_cand_scores = []
-    hist_pvector = []
-
     # initialize the probability vector
     pvector = init_pvector(clength)
 
-    console_output.print_greeting_message(clength, pop_size)
-
     # print the initial probability vector if the user wishes
     if show_pvector:
         console_output.print_init_pvector(pvector)
 
+    if args.plot_graph:
+        # define data structures used by graph plotter module
+        hist_best_cand_scores = []
+        hist_loser_cand_scores = []
+        hist_pvector = []
+
     # the main loop
     for g in xrange(1, max_iter + 1):
         # use the probability vector to generate candidates
         best_cand = winner[0]
         best_cand_score = winner[1]
 
-        # populate data structures used by graph plotter module
-        hist_best_cand_scores.append(winner[1])
-        hist_loser_cand_scores.append(loser[1])
-
-        # clone the state of the probability vector in the current generation
-        cur_gen_pvector = list(pvector) 
-        hist_pvector.append(cur_gen_pvector)
-
         # print the current generation status to the console
         console_output.print_gen_status(g, winner[0], winner[1],
                                         loser[0], loser[1], pvector,
                                         show_loser, show_pvector)
 
+        if args.plot_graph:
+            # populate data structures used by graph plotter module
+            hist_best_cand_scores.append(winner[1])
+            hist_loser_cand_scores.append(loser[1])
+
+            # clone the state of the probability vector in the current generation
+            cur_gen_pvector = list(pvector) 
+            hist_pvector.append(cur_gen_pvector)
+
+    console_output.print_greeting_message(clength, pop_size)
+
     # print the final result
     console_output.print_final_result(max_iter,
                                       best_cand, 
                                       best_cand_score, 
-                                      pvector)
-
-    return hist_best_cand_scores, hist_loser_cand_scores, hist_pvector
+                                      pvector,
+                                      clength,
+                                      pop_size)
+    if args.plot_graph:
+        return hist_best_cand_scores, hist_loser_cand_scores, hist_pvector
+    else:
+        return
 
 # our C-like "main function"
 if __name__ == "__main__":

console_output.py

     else:
         print "================="
 
-def print_final_result(max_iter, best_cand, best_cand_score, pvector):
+def print_final_result(max_iter, best_cand, best_cand_score, pvector,
+                       clength, pop_size):
     print """
 Done!
 
+==========
+The Setup:
+==========
+Chromosome length: {4}
+Population size: {5}
+
 ===========
 The Results
 ===========
 
 The final state of the probability vector is:
 {3}
-""".format(max_iter, best_cand_score, best_cand, pvector)
+""".format(max_iter, best_cand_score, best_cand, pvector, clength, pop_size)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.