Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|

lib/gecoder/interface/constraints/reifiable_constraints.rb | 78 |
49 |
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 |

2 # Base class for all reifiable constraints. |

3 class ReifiableConstraint < Constraint #:nodoc: |

4 # Gets the reification operand of the constraint, nil if none exists. |

5 def reification_var |

6 @params[:reif] |

7 end |

8 |

9 # Sets the reification operand of the constraint, nil if none should be |

10 # used. |

11 def reification_var=(new_var) |

12 @params[:reif] = new_var |

13 end |

14 |

15 # Produces a disjunction of two reifiable constraints, producing a new |

16 # reifiable constraint. |

17 def |(constraint) |

18 with_reification_operands(constraint) do |b1, b2| |

19 # Create the disjunction constraint. |

20 (b1 | b2).must_be.true |

21 end |

22 end |

23 |

24 # Produces a conjunction of two reifiable constraints, producing a new |

25 # reifiable constraint. |

26 def &(constraint) |

27 with_reification_operands(constraint) do |b1, b2| |

28 # Create the conjunction constraint. |

29 (b1 & b2).must_be.true |

30 end |

31 end |

32 |

33 private |

34 |

35 # Yields two boolean operands to the specified block. The first one |

36 # is self's reification operand and the second one is the |

37 # reification operand of the specified constraint. Reuses |

38 # reification operands if possible, otherwise creates new ones. |

39 def with_reification_operands(constraint, &block) |

40 raise TypeError unless constraint.kind_of? ReifiableConstraint |

41 |

42 # Set up the reification operands, using existing operands if they |

43 # exist. |

44 con1_holds = self.reification_var |

45 con2_holds = constraint.reification_var |

46 if con1_holds.nil? |

47 con1_holds = @model.bool_var |

48 self.reification_var = con1_holds |

49 end |

50 if con2_holds.nil? |

51 con2_holds = @model.bool_var |

52 constraint.reification_var = con2_holds |

53 end |

54 yield(con1_holds, con2_holds) |

55 end |

56 |

57 # If called the negation of the constraint will be handled using the |

58 # reification operand. This means that the post method (which has to be |

59 # defined prior to calling this method) doesn't have to bother about |

60 # negation. |

61 def self.negate_using_reification |

62 class_eval do |

63 alias_method :post_without_negation, :post |

64 |

65 def post |

66 if @params[:negate] |

67 if @params[:reif].nil? |

68 # Create a reification variable if none exists. |

69 @params[:reif] = @model.bool_var |

70 end |

71 @params[:reif].must_be.false |

72 end |

73 post_without_negation |

74 end |

75 end |

76 end |

77 end |

78 end |

Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0