or-tools 0.13.1 → 0.14.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +27 -0
- data/ext/or-tools/constraint.cpp +29 -50
- data/ext/or-tools/ext.cpp +2 -0
- data/ext/or-tools/extconf.rb +8 -2
- data/ext/or-tools/linear.cpp +10 -9
- data/ext/or-tools/math_opt.cpp +179 -0
- data/ext/or-tools/routing.cpp +13 -27
- data/lib/or-tools.rb +29 -18
- data/lib/or_tools/comparison.rb +7 -10
- data/lib/or_tools/constant.rb +16 -13
- data/lib/or_tools/cp_model.rb +8 -8
- data/lib/or_tools/cp_solver_solution_callback.rb +3 -3
- data/lib/or_tools/expression.rb +85 -0
- data/lib/or_tools/math_opt/model.rb +54 -0
- data/lib/or_tools/math_opt/variable.rb +15 -0
- data/lib/or_tools/product.rb +32 -0
- data/lib/or_tools/solver.rb +28 -15
- data/lib/or_tools/utils.rb +107 -0
- data/lib/or_tools/variable.rb +29 -0
- data/lib/or_tools/version.rb +1 -1
- metadata +11 -14
- data/lib/or_tools/bool_var.rb +0 -9
- data/lib/or_tools/comparison_operators.rb +0 -9
- data/lib/or_tools/int_var.rb +0 -5
- data/lib/or_tools/linear_constraint.rb +0 -50
- data/lib/or_tools/linear_expr.rb +0 -85
- data/lib/or_tools/mp_variable.rb +0 -11
- data/lib/or_tools/product_cst.rb +0 -35
- data/lib/or_tools/sat_int_var.rb +0 -29
- data/lib/or_tools/sat_linear_expr.rb +0 -59
- data/lib/or_tools/sum_array.rb +0 -23
data/lib/or_tools/mp_variable.rb
DELETED
data/lib/or_tools/product_cst.rb
DELETED
@@ -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
|
data/lib/or_tools/sat_int_var.rb
DELETED
@@ -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
|
data/lib/or_tools/sum_array.rb
DELETED
@@ -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
|