or-tools 0.3.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,34 +3,43 @@ require "fileutils"
3
3
  require "net/http"
4
4
  require "tmpdir"
5
5
 
6
- version = "7.8.7959"
6
+ version = "9.0.9048"
7
7
 
8
8
  if RbConfig::CONFIG["host_os"] =~ /darwin/i
9
- filename = "or-tools_MacOsX-10.15.6_v#{version}.tar.gz"
10
- checksum = "8d1d92105e962fab2fd7bde5843b711334a9f246dc22c51d41281898dbc1f69d"
9
+ filename = "or-tools_MacOsX-11.2.3_v#{version}.tar.gz"
10
+ checksum = "adf73a00d4ec49558b67be5ce3cfc8f30268da2253b35feb11d0d40700550bf6"
11
11
  else
12
12
  os = %x[lsb_release -is].chomp rescue nil
13
13
  os_version = %x[lsb_release -rs].chomp rescue nil
14
14
  if os == "Ubuntu" && os_version == "20.04"
15
15
  filename = "or-tools_ubuntu-20.04_v#{version}.tar.gz"
16
- checksum = "40018cd573305cec76e12ff87e84d4ec18ce0823f265e4d75625bf3aefdea7c9"
16
+ checksum = "5565343c1c310d2885a40ce850ae7e3468299b3fee97ae8eed8425ce06bd4960"
17
17
  elsif os == "Ubuntu" && os_version == "18.04"
18
18
  filename = "or-tools_ubuntu-18.04_v#{version}.tar.gz"
19
- checksum = "6e53e1a7b82b65b928617b9dce663778c5200de9366ad948948597dc763b1943"
20
- elsif os == "Ubuntu" && os_version == "16.04"
21
- filename = "or-tools_ubuntu-16.04_v#{version}.tar.gz"
22
- checksum = "182cd4e2a1d2f29a9a81f2f90cb3e05cf1c0731c1a1e94c471d79a74dc09fff0"
19
+ checksum = "08cf548d0179f7fa814bb7458be94cd1b8a3de14985e6a9faf6118a1d8571539"
23
20
  elsif os == "Debian" && os_version == "10"
24
- filename = "or-tools_debian-10_v#{version}.tar.gz "
25
- checksum = "87dd294237095a7fea466c47789802b0a66c664fa1f79e6bbb2cd36323b409ca"
21
+ filename = "or-tools_debian-10_v#{version}.tar.gz"
22
+ checksum = "063fb1d8765ae23b0bb25b9c561e904532713416fe0458f7db45a0f72190eb50"
26
23
  elsif os == "CentOS" && os_version == "8"
27
24
  filename = "or-tools_centos-8_v#{version}.tar.gz"
28
- checksum = "4e61bf2994fc767da1b4fd073f554c944d2c811609df4bc1afa6a2d876c05bb4"
25
+ checksum = "c98212ed4fc699d8ae70c1f53cd1d8dacd28e52970336fab5b86dedf7406f215"
26
+ elsif os == "CentOS" && os_version == "7"
27
+ filename = "or-tools_centos-7_v#{version}.tar.gz"
28
+ checksum = "b992bda4614bbc703583b0e9edcd2ade54bacfb9909399b20c8aa95ff7197d68"
29
29
  else
30
+ platform =
31
+ if Gem.win_platform?
32
+ "Windows"
33
+ elsif os || os_version
34
+ "#{os} #{os_version}"
35
+ else
36
+ "Unknown"
37
+ end
38
+
30
39
  # there is a binary download for Windows
31
40
  # however, it's compiled with Visual Studio rather than MinGW (which RubyInstaller uses)
32
41
  raise <<~MSG
33
- Binary installation not available for this platform.
42
+ Binary installation not available for this platform: #{platform}
34
43
 
35
44
  Build the OR-Tools C++ library from source, then run:
36
45
  bundle config build.or-tools --with-or-tools-dir=/path/to/or-tools
@@ -44,7 +53,9 @@ url = "https://github.com/google/or-tools/releases/download/v#{short_version}/#{
44
53
 
45
54
  $stdout.sync = true
46
55
 
47
- def download_file(url, download_path)
56
+ def download_file(url, download_path, redirects = 0)
57
+ raise "Too many redirects" if redirects > 10
58
+
48
59
  uri = URI(url)
49
60
  location = nil
50
61
 
@@ -73,7 +84,7 @@ def download_file(url, download_path)
73
84
  end
74
85
 
75
86
  # outside of Net::HTTP block to close previous connection
76
- download_file(location, download_path) if location
87
+ download_file(location, download_path, redirects + 1) if location
77
88
  end
78
89
 
79
90
  # download
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
@@ -29,6 +29,10 @@ module ORTools
29
29
  @response.status
30
30
  end
31
31
 
32
+ def sufficient_assumptions_for_infeasibility
33
+ @response.sufficient_assumptions_for_infeasibility
34
+ end
35
+
32
36
  def parameters
33
37
  @parameters ||= SatParameters.new
34
38
  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.3.4"
2
+ VERSION = "0.5.0"
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.3.4
4
+ version: 0.5.0
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-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -16,72 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake-compiler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '5'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '5'
26
+ version: '3'
83
27
  description:
84
- email: andrew@chartkick.com
28
+ email: andrew@ankane.org
85
29
  executables: []
86
30
  extensions:
87
31
  - ext/or-tools/extconf.rb
@@ -91,8 +35,14 @@ files:
91
35
  - LICENSE.txt
92
36
  - NOTICE.txt
93
37
  - README.md
38
+ - ext/or-tools/assignment.cpp
39
+ - ext/or-tools/bin_packing.cpp
40
+ - ext/or-tools/constraint.cpp
94
41
  - ext/or-tools/ext.cpp
95
42
  - ext/or-tools/extconf.rb
43
+ - ext/or-tools/linear.cpp
44
+ - ext/or-tools/network_flows.cpp
45
+ - ext/or-tools/routing.cpp
96
46
  - ext/or-tools/vendor.rb
97
47
  - lib/or-tools.rb
98
48
  - lib/or_tools/basic_scheduler.rb
@@ -105,6 +55,7 @@ files:
105
55
  - lib/or_tools/int_var.rb
106
56
  - lib/or_tools/knapsack_solver.rb
107
57
  - lib/or_tools/linear_expr.rb
58
+ - lib/or_tools/objective_solution_printer.rb
108
59
  - lib/or_tools/routing_index_manager.rb
109
60
  - lib/or_tools/routing_model.rb
110
61
  - lib/or_tools/sat_int_var.rb
@@ -113,6 +64,8 @@ files:
113
64
  - lib/or_tools/solver.rb
114
65
  - lib/or_tools/sudoku.rb
115
66
  - lib/or_tools/tsp.rb
67
+ - lib/or_tools/var_array_and_objective_solution_printer.rb
68
+ - lib/or_tools/var_array_solution_printer.rb
116
69
  - lib/or_tools/version.rb
117
70
  homepage: https://github.com/ankane/or-tools
118
71
  licenses:
@@ -126,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
79
  requirements:
127
80
  - - ">="
128
81
  - !ruby/object:Gem::Version
129
- version: '2.4'
82
+ version: '2.6'
130
83
  required_rubygems_version: !ruby/object:Gem::Requirement
131
84
  requirements:
132
85
  - - ">="