or-tools 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/or-tools.rb CHANGED
@@ -18,6 +18,11 @@ require "or_tools/sat_int_var"
18
18
  require "or_tools/solver"
19
19
  require "or_tools/version"
20
20
 
21
+ # solution printers
22
+ require "or_tools/objective_solution_printer"
23
+ require "or_tools/var_array_solution_printer"
24
+ require "or_tools/var_array_and_objective_solution_printer"
25
+
21
26
  # higher level interfaces
22
27
  require "or_tools/basic_scheduler"
23
28
  require "or_tools/seating"
@@ -25,5 +25,9 @@ module ORTools
25
25
  def sum(arr)
26
26
  arr.sum(SatLinearExpr.new)
27
27
  end
28
+
29
+ def inspect
30
+ to_s
31
+ end
28
32
  end
29
33
  end
@@ -9,7 +9,7 @@ module ORTools
9
9
  when BoolVar
10
10
  @response.solution_boolean_value(expr)
11
11
  else
12
- raise "Unsupported type"
12
+ raise "Unsupported type: #{expr.class.name}"
13
13
  end
14
14
  end
15
15
 
@@ -0,0 +1,18 @@
1
+ module ORTools
2
+ class ObjectiveSolutionPrinter < CpSolverSolutionCallback
3
+ attr_reader :solution_count
4
+
5
+ def initialize
6
+ super
7
+ @solution_count = 0
8
+ @start_time = Time.now
9
+ end
10
+
11
+ def on_solution_callback
12
+ current_time = Time.now
13
+ obj = objective_value
14
+ puts "Solution %i, time = %0.2f s, objective = %i" % [@solution_count, current_time - @start_time, obj]
15
+ @solution_count += 1
16
+ end
17
+ end
18
+ end
@@ -14,6 +14,10 @@ module ORTools
14
14
  SatLinearExpr.new([[self, 1], [-other, 1]])
15
15
  end
16
16
 
17
+ def -@
18
+ SatLinearExpr.new([[self, -1]])
19
+ end
20
+
17
21
  # for now
18
22
  def inspect
19
23
  name
@@ -43,10 +43,10 @@ module ORTools
43
43
  case other
44
44
  when SatLinearExpr
45
45
  other.vars
46
- when BoolVar, SatIntVar
46
+ when BoolVar, SatIntVar, Integer
47
47
  [[other, 1]]
48
48
  else
49
- raise ArgumentError, "Unsupported type"
49
+ raise ArgumentError, "Unsupported type: #{other.class.name}"
50
50
  end
51
51
 
52
52
  self.class.new(vars + other_vars.map { |a, b| [a, sign * b] })
@@ -0,0 +1,20 @@
1
+ module ORTools
2
+ class VarArrayAndObjectiveSolutionPrinter < CpSolverSolutionCallback
3
+ attr_reader :solution_count
4
+
5
+ def initialize(variables)
6
+ super()
7
+ @variables = variables
8
+ @solution_count = 0
9
+ @start_time = Time.now
10
+ end
11
+
12
+ def on_solution_callback
13
+ current_time = Time.now
14
+ obj = objective_value
15
+ puts "Solution %i, time = %0.2f s, objective = %i" % [@solution_count, current_time - @start_time, obj]
16
+ puts @variables.map { |v| " %s = %i" % [v.name, value(v)] }.join(" ")
17
+ @solution_count += 1
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module ORTools
2
+ class VarArraySolutionPrinter < CpSolverSolutionCallback
3
+ attr_reader :solution_count
4
+
5
+ def initialize(variables)
6
+ super()
7
+ @variables = variables
8
+ @solution_count = 0
9
+ @start_time = Time.now
10
+ end
11
+
12
+ def on_solution_callback
13
+ current_time = Time.now
14
+ puts "Solution %i, time = %0.2f s" % [@solution_count, current_time - @start_time]
15
+ puts @variables.map { |v| " %s = %i" % [v.name, value(v)] }.join(" ")
16
+ @solution_count += 1
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module ORTools
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: or-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-14 00:00:00.000000000 Z
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -91,8 +91,14 @@ files:
91
91
  - LICENSE.txt
92
92
  - NOTICE.txt
93
93
  - README.md
94
+ - ext/or-tools/assignment.cpp
95
+ - ext/or-tools/bin_packing.cpp
96
+ - ext/or-tools/constraint.cpp
94
97
  - ext/or-tools/ext.cpp
95
98
  - ext/or-tools/extconf.rb
99
+ - ext/or-tools/linear.cpp
100
+ - ext/or-tools/network_flows.cpp
101
+ - ext/or-tools/routing.cpp
96
102
  - ext/or-tools/vendor.rb
97
103
  - lib/or-tools.rb
98
104
  - lib/or_tools/basic_scheduler.rb
@@ -105,6 +111,7 @@ files:
105
111
  - lib/or_tools/int_var.rb
106
112
  - lib/or_tools/knapsack_solver.rb
107
113
  - lib/or_tools/linear_expr.rb
114
+ - lib/or_tools/objective_solution_printer.rb
108
115
  - lib/or_tools/routing_index_manager.rb
109
116
  - lib/or_tools/routing_model.rb
110
117
  - lib/or_tools/sat_int_var.rb
@@ -113,6 +120,8 @@ files:
113
120
  - lib/or_tools/solver.rb
114
121
  - lib/or_tools/sudoku.rb
115
122
  - lib/or_tools/tsp.rb
123
+ - lib/or_tools/var_array_and_objective_solution_printer.rb
124
+ - lib/or_tools/var_array_solution_printer.rb
116
125
  - lib/or_tools/version.rb
117
126
  homepage: https://github.com/ankane/or-tools
118
127
  licenses: