Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/set/operation.rb | 118 | 60 | 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::Set |
2 module SetOperand |
3 # Produces a new SetOperand representing the union between this operand |
4 # and +set_operand_or_constant_set+. |
5 # |
6 # ==== Examples |
7 # |
8 # # The union between +set1+ and +set2+. |
9 # set1.union set2 |
10 # |
11 # # The union between +set+ and {1, 3, 5}. |
12 # set.union [1,3,5] |
13 def union(set_operand_or_constant_set) |
14 set_operation(:union, set_operand_or_constant_set) |
15 end |
16 |
17 # Produces a new SetOperand representing the disjoint union between |
18 # this operand and +set_operand_or_constant_set+. The disjoint union |
19 # is the union of the disjoint parts of the sets. |
20 # |
21 # ==== Examples |
22 # |
23 # # The disjoint union between +set1+ and +set2+. |
24 # set1.disjoint_union set2 |
25 # |
26 # # The disjoint union between +set+ and {1, 3, 5}. |
27 # set.disjoint_union [1,3,5] |
28 def disjoint_union(set_operand_or_constant_set) |
29 set_operation(:disjoint_union, set_operand_or_constant_set) |
30 end |
31 |
32 # Produces a new SetOperand representing the intersection between |
33 # this operand and +set_operand_or_constant_set+. |
34 # |
35 # ==== Examples |
36 # |
37 # # The intersection between +set1+ and +set2+. |
38 # set1.intersection set2 |
39 # |
40 # # The intersection between +set+ and {1, 3, 5}. |
41 # set.intersection [1,3,5] |
42 def intersection(set_operand_or_constant_set) |
43 set_operation(:intersection, set_operand_or_constant_set) |
44 end |
45 |
46 # Produces a new SetOperand representing this operand minus |
47 # +set_operand_or_constant_set+. |
48 # |
49 # ==== Examples |
50 # |
51 # # +set1+ minus +set2+. |
52 # set1.minus set2 |
53 # |
54 # # +set+ minus {1, 3, 5}. |
55 # set.minus [1,3,5] |
56 def minus(set_operand_or_constant_set) |
57 set_operation(:minus, set_operand_or_constant_set) |
58 end |
59 |
60 private |
61 |
62 # Produces the SetOperand resulting from +operator+ applied to this |
63 # operand and +operand2+. |
64 def set_operation(operator, operand2) |
65 unless operand2.respond_to? :to_set_var or |
66 Gecode::Util::constant_set?(operand2) |
67 raise TypeError, 'Expected set operand or constant set as ' + |
68 "operand, got \#{operand2.class}." |
69 end |
70 |
71 return Operation::OperationSetOperand.new(model, self, operator, |
72 operand2) |
73 end |
74 end |
75 |
76 # A module that gathers the classes and modules used in operation constraints. |
77 module Operation #:nodoc: |
78 class OperationSetOperand < Gecode::Set::ShortCircuitRelationsOperand #:nodoc: |
79 def initialize(model, op1, operator, op2) |
80 super model |
81 @op1 = op1 |
82 @op2 = op2 |
83 @operator = operator |
84 end |
85 |
86 def relation_constraint(relation, set_operand_or_constant_set, params) |
87 relation_type = |
88 Gecode::Util::SET_RELATION_TYPES[relation] |
89 |
90 operation = Gecode::Util::SET_OPERATION_TYPES[@operator] |
91 params.update(:rhs => set_operand_or_constant_set, |
92 :relation_type => relation_type, :op1 => @op1, :op2 => @op2, |
93 :operation => operation) |
94 OperationConstraint.new(model, params) |
95 end |
96 end |
97 |
98 class OperationConstraint < Gecode::Constraint #:nodoc: |
99 def post |
100 op1, op2, operation, relation, rhs, negate = @params.values_at(:op1, |
101 :op2, :operation, :relation_type, :rhs, :negate) |
102 |
103 op1, op2, rhs = [op1, op2, rhs].map do |expression| |
104 # The expressions can either be set operands or constant sets, |
105 # convert them appropriately. |
106 if expression.respond_to? :to_set_var |
107 expression.to_set_var.bind |
108 else |
109 Gecode::Util::constant_set_to_int_set(expression) |
110 end |
111 end |
112 |
113 Gecode::Raw::rel(@model.active_space, op1, operation, op2, |
114 relation, rhs) |
115 end |
116 end |
117 end |
118 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0