1 module Gecode::IntEnum |

2 class IntEnumConstraintReceiver |

3 # Constrains all operands in the enumeration to be equal. |

4 # Neither negation nor reification is supported. |

5 # |

6 # ==== Examples |

7 # |

8 # # Constrains all operands in +int_enum+ to be equal. |

9 # int_enum.must_be.equal |

10 def equal(options = {}) |

11 if @params[:negate] |

12 # The best we could implement it as from here would be a bunch of |

13 # reified pairwise inequality constraints. |

14 raise Gecode::MissingConstraintError, 'A negated equality is not ' + |

15 'implemented.' |

16 end |

17 unless options[:reify].nil? |

18 raise ArgumentError, 'Reification is not supported by the equality ' + |

19 'constraint.' |

20 end |

21 |

22 @model.add_constraint Equality::EqualityConstraint.new(@model, |

23 @params.update(Gecode::Util.decode_options(options))) |

24 end |

25 end |

26 |

27 # A module that gathers the classes and modules used in equality constraints. |

28 module Equality #:nodoc: |

29 class EqualityConstraint < Gecode::Constraint #:nodoc: |

30 def post |

31 Gecode::Raw::rel(@model.active_space, |

32 @params[:lhs].to_int_enum.bind_array, |

33 Gecode::Raw::IRT_EQ, *propagation_options) |

34 end |

35 end |

36 end |

37 end |