def main(): '''Read a 0-1 knapsack problem instance from a file and solve it.''' if len(sys.argv) < 2: print "Usage: main.py FILE" return problem = knapsack.get_problem_from_file(sys.argv[1]) solutions.solve(problem)
print solution print def get_solvers(problem): '''Factory function to create solvers for this problem.''' solvers = [] #balk if the size is too big. if problem.size() < 25: solvers.append(BruteForceBinaryKnapsackSolver(problem)) solvers.append(BranchAndBoundBinaryKnapsackSolver(problem)) solvers.append(GeneticAlgorithmBinaryKnapsackSolver(problem)) return solvers def solve(problem): '''Solves the problem with several algorithms.''' solvers = get_solvers(problem) print problem for solver in solvers: solve_and_print(solver) if __name__ == "__main__": KNAPSACK_PROBLEM = \ knapsack.get_problem_from_file("../data/10_instance.txt") solve(KNAPSACK_PROBLEM)