or-tools 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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