Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/set_enum_constraints.rb | 84 | 28 | 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 # A module containing constraints that have enumerations of set operands as |
2 # left hand side. |
3 module Gecode::SetEnum #:nodoc: |
4 # A SetEnumOperand is a enumeration of SetOperand on which the |
5 # constraints defined in SetEnumConstraintReceiver can be placed. |
6 # |
7 # Enumerations of set operands can be created either by using |
8 # Gecode::Mixin#set_var_array and Gecode::Mixin#set_var_matrix, or |
9 # by wrapping an existing enumeration containing SetOperand using |
10 # Gecode::Mixin#wrap_enum. The enumerations, no matter how they were |
11 # created, all respond to the properties defined by SetEnumOperand. |
12 # |
13 # ==== Examples |
14 # |
15 # Produces an array of five set operands, with greatest lower bound |
16 # {0} and least upper bound {0, 1, 2}, inside a problem formulation |
17 # using Gecode::Mixin#set_var_array: |
18 # |
19 # set_enum = set_var_array(5, 0, 1..2) |
20 # |
21 # Uses Gecode::Mixin#wrap_enum inside a problem formulation to create |
22 # a SetEnumOperand from an existing enumeration containing the |
23 # set operands +set_operand1+ and +set_operand2+: |
24 # |
25 # set_enum = wrap_enum([set_operand1, set_operand2]) |
26 # |
27 #-- |
28 # Classes that mix in SetEnumOperand must define #model and |
29 # #to_set_enum . |
30 module SetEnumOperand |
31 include Gecode::Operand |
32 |
33 def method_missing(method, *args) #:nodoc: |
34 if Gecode::SetEnum::Dummy.instance_methods.include? method.to_s |
35 # Delegate to the set enum. |
36 to_set_enum.method(method).call(*args) |
37 else |
38 super |
39 end |
40 end |
41 |
42 private |
43 |
44 def construct_receiver(params) |
45 Gecode::SetEnum::SetEnumConstraintReceiver.new(@model, params) |
46 end |
47 end |
48 |
49 # SetEnumConstraintReceiver contains all constraints that can be |
50 # placed on a SetEnumOperand. |
51 # |
52 # Constraints are placed by calling SetEnumOperand#must (or any other |
53 # of the variations defined in Operand), which produces a |
54 # SetEnumConstraintReceiver from which the desired constraint can be used. |
55 # |
56 # ==== Examples |
57 # |
58 # Constrains +set_enum+ to channel +int_enum+ by using |
59 # SetEnumConstraintReceiver#channel: |
60 # |
61 # set_enum.must.channel set_enum |
62 # |
63 # Constrains each pair of set operands in +set_enum+ to at most share |
64 # one element. Also constrains each set to have size 17. Uses |
65 # SetEnumConstraintReceiver#at_most_share_one_element. |
66 # |
67 # set_enum.must.at_most_share_one_element(:size => 17) |
68 # |
69 class SetEnumConstraintReceiver < Gecode::ConstraintReceiver |
70 # Raises TypeError unless the left hand side is a set enum operand. |
71 def initialize(model, params) #:nodoc: |
72 super |
73 |
74 unless params[:lhs].respond_to? :to_set_enum |
75 raise TypeError, 'Must have set enum operand as left hand side.' |
76 end |
77 end |
78 end |
79 end |
80 |
81 require 'gecoder/interface/constraints/set_enum/channel' |
82 require 'gecoder/interface/constraints/set_enum/distinct' |
83 require 'gecoder/interface/constraints/set_enum/element' |
84 require 'gecoder/interface/constraints/set_enum/operation' |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0