Class: KnapsackSolver::CLI
- Inherits:
-
Object
- Object
- KnapsackSolver::CLI
- Defined in:
- lib/knapsack_solver/cli.rb
Overview
This class implements a command-line interface for the 0/1 knapsack problem solver.
Constant Summary collapse
- RESULTS_FILNEMAE_SUFFIX =
Suffix of a text file which will containg results of dataset solving (price, knapsack things presence, cpu time, wall clock time, relative_error).
'.results'.freeze
- STATS_FILNEMAE_SUFFIX =
Suffix of a text file which will containg statistic data (average price, execution times, relative error)
'.stats'.freeze
Class Method Summary collapse
-
.print_results(results, stats, options, args) ⇒ Object
Prints output of datasets solving.
-
.run(args) ⇒ Object
Processes command-line arguments.
Class Method Details
.print_results(results, stats, options, args) ⇒ Object
Prints output of datasets solving. Results and statistics are printed to stdout or to a text files. Graphs of statistic values can be created.
42 43 44 45 46 47 |
# File 'lib/knapsack_solver/cli.rb', line 42 def self.print_results(results, stats, , args) OutputPrinter.new(args, RESULTS_FILNEMAE_SUFFIX, results).print([:output_dir]) OutputPrinter.new(args, STATS_FILNEMAE_SUFFIX, stats).print([:output_dir]) return unless [:graphs_dir] GraphPrinter.new(args, stats, [:graphs_dir]).print end |
.run(args) ⇒ Object
Processes command-line arguments. If no option is given, converts arabic number to roman number and prints it to stdout.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/knapsack_solver/cli.rb', line 24 def self.run(args) = CliOptionParser.parse(args) return if .nil? datasets = args.each_with_object([]) do |file, sets| sets << Dataset.parse(File.new(file)) end s = Solver.new(, datasets) results = s.run print_results(results, s.stats(results), , args) end |