or-tools 0.13.1 → 0.14.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.
@@ -0,0 +1,29 @@
1
+ module ORTools
2
+ module Variable
3
+ include ExpressionMethods
4
+
5
+ def inspect
6
+ name
7
+ end
8
+
9
+ def vars
10
+ @vars ||= [self]
11
+ end
12
+ end
13
+
14
+ class MPVariable
15
+ include Variable
16
+ end
17
+
18
+ class SatIntVar
19
+ include Variable
20
+ end
21
+
22
+ class SatBoolVar
23
+ include Variable
24
+ end
25
+
26
+ class RoutingIntVar
27
+ include Variable
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module ORTools
2
- VERSION = "0.13.1"
2
+ VERSION = "0.14.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.13.1
4
+ version: 0.14.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: 2024-10-06 00:00:00.000000000 Z
11
+ date: 2024-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.3'
19
+ version: 4.3.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: '4.3'
26
+ version: 4.3.3
27
27
  description:
28
28
  email: andrew@ankane.org
29
29
  executables: []
@@ -42,36 +42,33 @@ files:
42
42
  - ext/or-tools/ext.h
43
43
  - ext/or-tools/extconf.rb
44
44
  - ext/or-tools/linear.cpp
45
+ - ext/or-tools/math_opt.cpp
45
46
  - ext/or-tools/network_flows.cpp
46
47
  - ext/or-tools/routing.cpp
47
48
  - ext/or-tools/vendor.rb
48
49
  - lib/or-tools.rb
49
50
  - lib/or_tools/basic_scheduler.rb
50
- - lib/or_tools/bool_var.rb
51
51
  - lib/or_tools/comparison.rb
52
- - lib/or_tools/comparison_operators.rb
53
52
  - lib/or_tools/constant.rb
54
53
  - lib/or_tools/cp_model.rb
55
54
  - lib/or_tools/cp_solver.rb
56
55
  - lib/or_tools/cp_solver_solution_callback.rb
57
- - lib/or_tools/int_var.rb
56
+ - lib/or_tools/expression.rb
58
57
  - lib/or_tools/knapsack_solver.rb
59
- - lib/or_tools/linear_constraint.rb
60
- - lib/or_tools/linear_expr.rb
61
- - lib/or_tools/mp_variable.rb
58
+ - lib/or_tools/math_opt/model.rb
59
+ - lib/or_tools/math_opt/variable.rb
62
60
  - lib/or_tools/objective_solution_printer.rb
63
- - lib/or_tools/product_cst.rb
61
+ - lib/or_tools/product.rb
64
62
  - lib/or_tools/routing_index_manager.rb
65
63
  - lib/or_tools/routing_model.rb
66
- - lib/or_tools/sat_int_var.rb
67
- - lib/or_tools/sat_linear_expr.rb
68
64
  - lib/or_tools/seating.rb
69
65
  - lib/or_tools/solver.rb
70
66
  - lib/or_tools/sudoku.rb
71
- - lib/or_tools/sum_array.rb
72
67
  - lib/or_tools/tsp.rb
68
+ - lib/or_tools/utils.rb
73
69
  - lib/or_tools/var_array_and_objective_solution_printer.rb
74
70
  - lib/or_tools/var_array_solution_printer.rb
71
+ - lib/or_tools/variable.rb
75
72
  - lib/or_tools/version.rb
76
73
  homepage: https://github.com/ankane/or-tools-ruby
77
74
  licenses:
@@ -92,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
89
  - !ruby/object:Gem::Version
93
90
  version: '0'
94
91
  requirements: []
95
- rubygems_version: 3.5.16
92
+ rubygems_version: 3.5.22
96
93
  signing_key:
97
94
  specification_version: 4
98
95
  summary: Operations research tools for Ruby
@@ -1,9 +0,0 @@
1
- module ORTools
2
- class BoolVar
3
- include ComparisonOperators
4
-
5
- def *(other)
6
- SatLinearExpr.new([[self, other]])
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module ORTools
2
- module ComparisonOperators
3
- ["==", "!=", ">", ">=", "<", "<="].each do |operator|
4
- define_method(operator) do |other|
5
- Comparison.new(operator, self, other)
6
- end
7
- end
8
- end
9
- end
@@ -1,5 +0,0 @@
1
- module ORTools
2
- class IntVar
3
- include ComparisonOperators
4
- end
5
- end
@@ -1,50 +0,0 @@
1
- module ORTools
2
- class LinearConstraint
3
- attr_reader :expr, :lb, :ub
4
-
5
- def initialize(expr, lb, ub)
6
- @expr = expr
7
- @lb = lb
8
- @ub = ub
9
- end
10
-
11
- def to_s
12
- if @lb > -Float::INFINITY && @ub < Float::INFINITY
13
- if @lb == @ub
14
- "#{@expr} == #{@lb}"
15
- else
16
- "#{@lb} <= #{@expr} <= #{@ub}"
17
- end
18
- elsif @lb > -Float::INFINITY
19
- "#{@expr} >= #{@lb}"
20
- elsif @ub < Float::INFINITY
21
- "#{@expr} <= #{@ub}"
22
- else
23
- "Trivial inequality (always true)"
24
- end
25
- end
26
-
27
- def inspect
28
- "#<#{self.class.name} #{to_s}>"
29
- end
30
-
31
- def extract(solver)
32
- coeffs = @expr.coeffs
33
- constant = coeffs.delete(OFFSET_KEY) || 0.0
34
- lb = -solver.infinity
35
- ub = solver.infinity
36
- if @lb > -Float::INFINITY
37
- lb = @lb - constant
38
- end
39
- if @ub < Float::INFINITY
40
- ub = @ub - constant
41
- end
42
-
43
- constraint = solver.constraint(lb, ub)
44
- coeffs.each do |v, c|
45
- constraint.set_coefficient(v, c.to_f)
46
- end
47
- constraint
48
- end
49
- end
50
- end
@@ -1,85 +0,0 @@
1
- module ORTools
2
- class LinearExpr
3
- def solution_value
4
- coeffs.sum { |var, coeff| var.solution_value * coeff }
5
- end
6
-
7
- def coeffs
8
- coeffs = Hash.new(0.0)
9
- stack = [[1.0, self]]
10
- while stack.any?
11
- current_multiplier, current_expression = stack.pop
12
-
13
- # skip empty LinearExpr for backwards compatibility
14
- next if current_expression.instance_of?(LinearExpr)
15
-
16
- current_expression.add_self_to_coeff_map_or_stack(coeffs, current_multiplier, stack)
17
- end
18
- coeffs
19
- end
20
-
21
- def +(expr)
22
- SumArray.new([self, expr])
23
- end
24
-
25
- def -(expr)
26
- SumArray.new([self, -expr])
27
- end
28
-
29
- def *(other)
30
- if is_a?(Constant)
31
- ProductCst.new(other, @val)
32
- else
33
- ProductCst.new(self, other)
34
- end
35
- end
36
-
37
- def /(cst)
38
- ProductCst.new(self, 1.0 / other)
39
- end
40
-
41
- def -@
42
- ProductCst.new(self, -1)
43
- end
44
-
45
- def ==(arg)
46
- if arg.is_a?(Numeric)
47
- LinearConstraint.new(self, arg, arg)
48
- else
49
- LinearConstraint.new(self - arg, 0.0, 0.0)
50
- end
51
- end
52
-
53
- def >=(arg)
54
- if arg.is_a?(Numeric)
55
- LinearConstraint.new(self, arg, Float::INFINITY)
56
- else
57
- LinearConstraint.new(self - arg, 0.0, Float::INFINITY)
58
- end
59
- end
60
-
61
- def <=(arg)
62
- if arg.is_a?(Numeric)
63
- LinearConstraint.new(self, -Float::INFINITY, arg)
64
- else
65
- LinearConstraint.new(self - arg, -Float::INFINITY, 0.0)
66
- end
67
- end
68
-
69
- def to_s
70
- "(empty)"
71
- end
72
-
73
- def inspect
74
- "#<#{self.class.name} #{to_s}>"
75
- end
76
-
77
- def coerce(other)
78
- if other.is_a?(Numeric)
79
- [Constant.new(other), self]
80
- else
81
- raise TypeError, "#{self.class} can't be coerced into #{other.class}"
82
- end
83
- end
84
- end
85
- end
@@ -1,11 +0,0 @@
1
- module ORTools
2
- class MPVariable < LinearExpr
3
- def add_self_to_coeff_map_or_stack(coeffs, multiplier, stack)
4
- coeffs[self] += multiplier
5
- end
6
-
7
- def to_s
8
- name
9
- end
10
- end
11
- end
@@ -1,35 +0,0 @@
1
- module ORTools
2
- class ProductCst < LinearExpr
3
- attr_reader :expr, :coef
4
-
5
- def initialize(expr, coef)
6
- @expr = cast_to_lin_exp(expr)
7
- # TODO improve message
8
- raise TypeError, "expected numeric" unless coef.is_a?(Numeric)
9
- @coef = coef
10
- end
11
-
12
- def to_s
13
- if @coef == -1
14
- "-#{@expr}"
15
- else
16
- expr = @expr.to_s
17
- if expr.include?("+") || expr.include?("-")
18
- expr = "(#{expr})"
19
- end
20
- "#{@coef} * #{expr}"
21
- end
22
- end
23
-
24
- def add_self_to_coeff_map_or_stack(coeffs, multiplier, stack)
25
- current_multiplier = multiplier * @coef
26
- if current_multiplier
27
- stack << [current_multiplier, @expr]
28
- end
29
- end
30
-
31
- def cast_to_lin_exp(v)
32
- v.is_a?(Numeric) ? Constant.new(v) : v
33
- end
34
- end
35
- end
@@ -1,29 +0,0 @@
1
- module ORTools
2
- class SatIntVar
3
- include ComparisonOperators
4
-
5
- def *(other)
6
- SatLinearExpr.new([[self, other]])
7
- end
8
-
9
- def +(other)
10
- SatLinearExpr.new([[self, 1], [other, 1]])
11
- end
12
-
13
- def -(other)
14
- SatLinearExpr.new([[self, 1], [-other, 1]])
15
- end
16
-
17
- def -@
18
- SatLinearExpr.new([[self, -1]])
19
- end
20
-
21
- def to_s
22
- name
23
- end
24
-
25
- def inspect
26
- "#<#{self.class.name} #{to_s}>"
27
- end
28
- end
29
- end
@@ -1,59 +0,0 @@
1
- module ORTools
2
- class SatLinearExpr
3
- include ComparisonOperators
4
-
5
- attr_reader :vars
6
-
7
- def initialize(vars = [])
8
- @vars = vars
9
- end
10
-
11
- def +(other)
12
- add(other, 1)
13
- end
14
-
15
- def -(other)
16
- add(other, -1)
17
- end
18
-
19
- def *(other)
20
- if vars.size == 1
21
- self.class.new([[vars[0][0], vars[0][1] * other]])
22
- else
23
- raise ArgumentError, "Multiplication not allowed here"
24
- end
25
- end
26
-
27
- def to_s
28
- vars.map do |v|
29
- k = v[0]
30
- k = k.respond_to?(:name) ? k.name : k.to_s
31
- if v[1] == 1
32
- k
33
- else
34
- "#{k} * #{v[1]}"
35
- end
36
- end.join(" + ").sub(" + -", " - ")
37
- end
38
-
39
- def inspect
40
- "#<#{self.class.name} #{to_s}>"
41
- end
42
-
43
- private
44
-
45
- def add(other, sign)
46
- other_vars =
47
- case other
48
- when SatLinearExpr
49
- other.vars
50
- when BoolVar, SatIntVar, Integer
51
- [[other, 1]]
52
- else
53
- raise ArgumentError, "Unsupported type: #{other.class.name}"
54
- end
55
-
56
- self.class.new(vars + other_vars.map { |a, b| [a, sign * b] })
57
- end
58
- end
59
- end
@@ -1,23 +0,0 @@
1
- module ORTools
2
- class SumArray < LinearExpr
3
- attr_reader :array
4
-
5
- def initialize(array)
6
- @array = array.map { |v| cast_to_lin_exp(v) }
7
- end
8
-
9
- def add_self_to_coeff_map_or_stack(coeffs, multiplier, stack)
10
- @array.reverse_each do |arg|
11
- stack << [multiplier, arg]
12
- end
13
- end
14
-
15
- def cast_to_lin_exp(v)
16
- v.is_a?(Numeric) ? Constant.new(v) : v
17
- end
18
-
19
- def to_s
20
- "#{@array.map(&:to_s).reject { |v| v == "0" }.join(" + ")}".gsub(" + -", " - ")
21
- end
22
- end
23
- end