Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/selected_set/select.rb | 120 | 82 | 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::SelectedSet |
2 class SelectedSetOperand |
3 # Produces a SetOperand representing the selected sets' union. |
4 # |
5 # ==== Examples |
6 # |
7 # # The union of all sets selected by +set_enum[set]+. |
8 # set_enum[set].union |
9 def union |
10 Element::SelectedSetUnionOperand.new(model, self) |
11 end |
12 |
13 # Produces a SetOperand representing the selected sets' intersection. |
14 # The option :with can be used to enumerate the elements in the |
15 # universe. |
16 # |
17 # ==== Examples |
18 # |
19 # # The intersection of all sets selected by +set_enum[set]+. |
20 # set_enum[set].intersection |
21 # |
22 # # The same intersection as above, but with [3,5,7] as universe. |
23 # set_enum[set].intersection(:with => [3,5,7]) |
24 def intersection(options = {}) |
25 universe = nil |
26 unless options.empty? |
27 unless options.size == 1 and options.has_key?(:with) |
28 raise ArgumentError, "Expected option key :with, got #{options.keys}." |
29 else |
30 universe = options[:with] |
31 unless universe.kind_of?(Enumerable) and |
32 universe.all?{ |element| element.kind_of? Fixnum } |
33 raise TypeError, "Expected the universe to be specified as " + |
34 "an enumeration of fixnum, got #{universe.class}." |
35 end |
36 end |
37 end |
38 |
39 Element::SelectedSetIntersectionOperand.new(model, self, universe) |
40 end |
41 end |
42 |
43 class SelectedSetConstraintReceiver |
44 # Constrains the selected sets to be pairwise disjoint. |
45 # |
46 # ==== Examples |
47 # |
48 # # Constrains all sets selected by +set_enum[set]+ to be pairwise |
49 # # disjoint. |
50 # set_enum[set].must_be.disjoint |
51 def disjoint(options = {}) |
52 if @params[:negate] |
53 raise Gecode::MissingConstraintError, 'A negated disjoint constraint ' + |
54 'is not implemented.' |
55 end |
56 if options.has_key? :reify |
57 raise ArgumentError, 'The disjoint constraint does not support the ' + |
58 'reification option.' |
59 end |
60 |
61 @params.update Gecode::Set::Util.decode_options(options) |
62 @model.add_constraint Element::DisjointConstraint.new(@model, @params) |
63 end |
64 end |
65 |
66 module Element #:nodoc: |
67 class SelectedSetUnionOperand < Gecode::Set::ShortCircuitEqualityOperand #:nodoc: |
68 def initialize(model, selected_set) |
69 super model |
70 @selected_set = selected_set |
71 end |
72 |
73 def constrain_equal(set_operand, constrain, propagation_options) |
74 enum, indices = @selected_set.to_selected_set |
75 if constrain |
76 set_operand.must_be.subset_of enum.upper_bound_range |
77 end |
78 |
79 Gecode::Raw::elementsUnion(@model.active_space, |
80 enum.to_set_enum.bind_array, indices.to_set_var.bind, |
81 set_operand.to_set_var.bind) |
82 end |
83 end |
84 |
85 class SelectedSetIntersectionOperand < Gecode::Set::ShortCircuitEqualityOperand #:nodoc: |
86 def initialize(model, selected_set, universe) |
87 super model |
88 @selected_set = selected_set |
89 @universe = universe |
90 end |
91 |
92 def constrain_equal(set_operand, constrain, propagation_options) |
93 enum, indices = @selected_set.to_selected_set |
94 universe = @universe |
95 |
96 # We can't do any useful constraining here since the empty intersection |
97 # is the universe. |
98 |
99 if universe.nil? |
100 Gecode::Raw::elementsInter(@model.active_space, |
101 enum.to_set_enum.bind_array, indices.to_set_var.bind, |
102 set_operand.to_set_var.bind) |
103 else |
104 Gecode::Raw::elementsInter(@model.active_space, |
105 enum.to_set_enum.bind_array, indices.to_set_var.bind, |
106 set_operand.to_set_var.bind, |
107 Gecode::Util.constant_set_to_int_set(universe)) |
108 end |
109 end |
110 end |
111 |
112 class DisjointConstraint < Gecode::Constraint #:nodoc: |
113 def post |
114 enum, indices = @params[:lhs].to_selected_set |
115 Gecode::Raw.elementsDisjoint(@model.active_space, |
116 enum.to_set_enum.bind_array, indices.to_set_var.bind) |
117 end |
118 end |
119 end |
120 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0