Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/int_enum/distinct.rb | 64 | 35 | 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::IntEnum |
2 class IntEnumConstraintReceiver |
3 # Constrains all integer operands in the enumeration to be distinct |
4 # (different). The constraint can also be used with constant |
5 # offsets, so that the operands, with specified offsets added, must |
6 # be distinct. |
7 # |
8 # The constraint does not support negation nor reification. |
9 # |
10 # ==== Examples |
11 # |
12 # # Constrains all operands in +int_enum+ to be assigned different |
13 # # values. |
14 # int_enum.must_be.distinct |
15 # |
16 # # The same as above, but also selects that the strength +domain+ should |
17 # # be used. |
18 # int_enum.must_be.distinct(:strength => :domain) |
19 # |
20 # # Uses the offset to constrain that no number may be the previous number |
21 # # incremented by one. |
22 # numbers = int_var_array(8, 0..9) |
23 # numbers.must_be.distinct(:offsets => (1..numbers.size).to_a.reverse) |
24 def distinct(options = {}) |
25 if @params[:negate] |
26 # The best we could implement it as from here would be a bunch of |
27 # reified pairwise equality constraints. |
28 raise Gecode::MissingConstraintError, 'A negated distinct is not ' + |
29 'implemented.' |
30 end |
31 unless options[:reify].nil? |
32 raise ArgumentError, 'Reification is not supported by the distinct ' + |
33 'constraint.' |
34 end |
35 |
36 if options.has_key? :offsets |
37 offsets = options.delete(:offsets) |
38 unless offsets.kind_of? Enumerable |
39 raise TypeError, 'Expected Enumerable as offsets, got ' + |
40 "#{offsets.class}." |
41 end |
42 @params[:offsets] = offsets |
43 end |
44 @model.add_constraint Distinct::DistinctConstraint.new(@model, |
45 @params.update(Gecode::Util.decode_options(options))) |
46 end |
47 end |
48 |
49 # A module that gathers the classes and modules used in distinct constraints. |
50 module Distinct #:nodoc: |
51 class DistinctConstraint < Gecode::Constraint #:nodoc: |
52 def post |
53 # Bind lhs. |
54 @params[:lhs] = @params[:lhs].to_int_enum.bind_array |
55 |
56 # Fetch the parameters to Gecode. |
57 params = @params.values_at(:offsets, :lhs) |
58 params.delete_if{ |x| x.nil? } |
59 params.concat propagation_options |
60 Gecode::Raw::distinct(@model.active_space, *params) |
61 end |
62 end |
63 end |
64 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0