Class: ORTools::VarArrayAndObjectiveSolutionPrinter

Inherits:
CpSolverSolutionCallback show all
Defined in:
lib/or_tools/var_array_and_objective_solution_printer.rb

Instance Attribute Summary collapse

Attributes inherited from CpSolverSolutionCallback

#response

Instance Method Summary collapse

Methods inherited from CpSolverSolutionCallback

#objective_value, #value

Constructor Details

#initialize(variables) ⇒ VarArrayAndObjectiveSolutionPrinter

Returns a new instance of VarArrayAndObjectiveSolutionPrinter.



5
6
7
8
9
10
# File 'lib/or_tools/var_array_and_objective_solution_printer.rb', line 5

def initialize(variables)
  super()
  @variables = variables
  @solution_count = 0
  @start_time = Time.now
end

Instance Attribute Details

#solution_countObject (readonly)

Returns the value of attribute solution_count.



3
4
5
# File 'lib/or_tools/var_array_and_objective_solution_printer.rb', line 3

def solution_count
  @solution_count
end

Instance Method Details

#on_solution_callbackObject



12
13
14
15
16
17
18
# File 'lib/or_tools/var_array_and_objective_solution_printer.rb', line 12

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]
  puts @variables.map { |v| "  %s = %i" % [v.name, value(v)] }.join(" ")
  @solution_count += 1
end