Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/int/arithmetic.rb | 150 | 101 | 100.00%
|
100.00%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 module Gecode::Int |
2 module IntOperand |
3 # Produces an IntOperand representing the absolute value of this |
4 # operand. |
5 # |
6 # ==== Examples |
7 # |
8 # # The absolute value of +int_op+. |
9 # int_op.abs |
10 def abs |
11 Arithmetic::IntAbsOperand.new(@model, self) |
12 end |
13 |
14 # Produces an IntOperand representing this operand squared. |
15 # |
16 # ==== Examples |
17 # |
18 # # The value of +int_op*int_op+. |
19 # int_op.squared |
20 def squared |
21 Arithmetic::IntSquaredOperand.new(@model, self) |
22 end |
23 |
24 # Produces an IntOperand representing the square root of this |
25 # operand rounded down. |
26 # |
27 # ==== Examples |
28 # |
29 # # The square root of +int_op+, rounded down. |
30 # int_op.square_root |
31 def square_root |
32 Arithmetic::IntSquareRootOperand.new(@model, self) |
33 end |
34 alias_method :sqrt, :square_root |
35 |
36 |
37 alias_method :pre_arith_mult, :* |
38 |
39 # Produces a new IntOperand representing this operand times |
40 # +int_operand+. |
41 # |
42 # ==== Examples |
43 # |
44 # # The value of +int_op1+ times +int_op2+. |
45 # int_op1 * int_op2 |
46 def *(int_operand) |
47 if int_operand.respond_to? :to_int_var |
48 Arithmetic::IntMultOperand.new(@model, self, int_operand) |
49 else |
50 pre_arith_mult(int_operand) |
51 end |
52 end |
53 end |
54 |
55 # A module that gathers the classes and modules used by arithmetic |
56 # constraints. |
57 module Arithmetic #:nodoc: |
58 class IntAbsOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc: |
59 def initialize(model, int_op) |
60 super model |
61 @int = int_op |
62 end |
63 |
64 def constrain_equal(int_operand, constrain, propagation_options) |
65 int_op = @int.to_int_var |
66 if constrain |
67 bounds = [int_op.min.abs, int_op.max.abs] |
68 bounds << 0 if int_op.min < 0 |
69 int_operand.must_be.in bounds.min..bounds.max |
70 end |
71 |
72 Gecode::Raw::abs(@model.active_space, int_op.to_int_var.bind, |
73 int_operand.to_int_var.bind, *propagation_options) |
74 end |
75 end |
76 |
77 class IntMultOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc: |
78 def initialize(model, op1, op2) |
79 super model |
80 @op1 = op1 |
81 @op2 = op2 |
82 end |
83 |
84 def constrain_equal(int_operand, constrain, propagation_options) |
85 int_op1, int_op2 = @op1.to_int_var, @op2.to_int_var |
86 if constrain |
87 a_min = int_op1.min; a_max = int_op1.max |
88 b_min = int_op2.min; b_max = int_op2.max |
89 products = [a_min*b_min, a_min*b_max, a_max*b_min, a_max*b_max] |
90 int_operand.must_be.in products.min..products.max |
91 end |
92 |
93 Gecode::Raw::mult(@model.active_space, int_op1.to_int_var.bind, |
94 int_op2.to_int_var.bind, int_operand.to_int_var.bind, |
95 *propagation_options) |
96 end |
97 end |
98 |
99 class IntSquaredOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc: |
100 def initialize(model, int_op) |
101 super model |
102 @int = int_op |
103 end |
104 |
105 def constrain_equal(int_operand, constrain, propagation_options) |
106 int_op = @int.to_int_var |
107 if constrain |
108 min = int_op.min; max = int_op.max |
109 products = [min*max, min*min, max*max] |
110 int_operand.must_be.in products.min..products.max |
111 end |
112 |
113 Gecode::Raw::sqr(@model.active_space, int_op.to_int_var.bind, |
114 int_operand.to_int_var.bind, *propagation_options) |
115 end |
116 end |
117 |
118 class IntSquareRootOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc: |
119 def initialize(model, int_op) |
120 super model |
121 @int = int_op |
122 end |
123 |
124 def constrain_equal(int_operand, constrain, propagation_options) |
125 int_op = @int.to_int_var |
126 if constrain |
127 max = int_op.max |
128 if max < 0 |
129 # The left hand side does not have a real valued square root. |
130 upper_bound = 0 |
131 else |
132 upper_bound = Math.sqrt(max).floor; |
133 end |
134 |
135 min = int_op.min |
136 if min < 0 |
137 lower_bound = 0 |
138 else |
139 lower_bound = Math.sqrt(min).floor; |
140 end |
141 |
142 int_operand.must_be.in lower_bound..upper_bound |
143 end |
144 |
145 Gecode::Raw::sqrt(@model.active_space, int_op.to_int_var.bind, |
146 int_operand.to_int_var.bind, *propagation_options) |
147 end |
148 end |
149 end |
150 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0