Class: ORTools::ObjectiveSolutionPrinter
- Inherits:
-
CpSolverSolutionCallback
- Object
- CpSolverSolutionCallback
- ORTools::ObjectiveSolutionPrinter
- Defined in:
- lib/or_tools/objective_solution_printer.rb
Instance Attribute Summary collapse
-
#solution_count ⇒ Object
readonly
Returns the value of attribute solution_count.
Attributes inherited from CpSolverSolutionCallback
Instance Method Summary collapse
-
#initialize ⇒ ObjectiveSolutionPrinter
constructor
A new instance of ObjectiveSolutionPrinter.
- #on_solution_callback ⇒ Object
Methods inherited from CpSolverSolutionCallback
Constructor Details
#initialize ⇒ ObjectiveSolutionPrinter
Returns a new instance of ObjectiveSolutionPrinter.
5 6 7 8 9 |
# File 'lib/or_tools/objective_solution_printer.rb', line 5 def initialize super @solution_count = 0 @start_time = Time.now end |
Instance Attribute Details
#solution_count ⇒ Object (readonly)
Returns the value of attribute solution_count.
3 4 5 |
# File 'lib/or_tools/objective_solution_printer.rb', line 3 def solution_count @solution_count end |
Instance Method Details
#on_solution_callback ⇒ Object
11 12 13 14 15 16 |
# File 'lib/or_tools/objective_solution_printer.rb', line 11 def on_solution_callback current_time = Time.now obj = objective_value puts "Solution %i, time = %0.2f s, objective = %i" % [@solution_count, current_time - @start_time, obj] @solution_count += 1 end |