changeset 15:d9aa5e25859c draft

main: use CLI args to select the algorithm to use Also return maxplan from brute_force() so it can be used in main() with the same API as greedy().
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Wed, 11 Mar 2015 16:47:17 -0400
parents a72cf3c7c976
children 4c23cfdeaa5f
files optim.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/optim.py
+++ b/optim.py
@@ -135,7 +135,7 @@
         except InvalidPlan:
             pass
 
-    return maxcapital
+    return maxcapital, maxplan
 
 def greedy(case):
     """Greedy algorithm, considering each machine only once, in decreasing
@@ -168,7 +168,11 @@
     args = process_options()
     cases = parseinput(args.file)
     for (number, case) in enumerate(cases):
-        maxcapital = brute_force(case)
+        if args.greedy:
+            solver = greedy
+        if args.brute_force:
+            solver = brute_force
+        maxcapital, plan = solver(case)
         print "Case %d: %d" % (number + 1, maxcapital)
 
 if __name__ == "__main__":