module Gecode::Util::Extensional
A module that contains utility-methods for extensional constraints.
Public Instance Methods
parse_regexp(regexp)
click to toggle source
Parses a regular expression over the integer domain, returning an instance of Gecode::REG .
Pseudo-BNF of the integer regexp representation: regexp ::= <Fixnum> | <TrueClass> | <FalseClass> | <Gecode::Raw::REG>
| [<regexp>, ...]
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/extensional_regexp.rb, line 65 def parse_regexp(regexp) # Check the involved types. unless regexp.kind_of? Enumerable regexp = [regexp] end regexp.to_a.flatten.each do |element| unless element.kind_of?(Fixnum) or element.kind_of?(Gecode::Raw::REG) or element.kind_of?(TrueClass) or element.kind_of?(FalseClass) raise TypeError, "Can't translate #{element.class} into integer or boolean regexp." end end # Convert it into a regexp. internal_parse_regexp(regexp) end
perform_tuple_checks(tuples, expected_size) { |tuple| ... }
click to toggle source
Checks that the specified enumeration is an enumeration containing one or more tuples of the specified size. It also allows the caller to define additional tests by providing a block, which is given each tuple. If a test fails then an appropriate error is raised.
# File doc/tmp/rdoc_dev/gecoder/interface/constraints.rb, line 442 def perform_tuple_checks(tuples, expected_size, &additional_test) unless tuples.respond_to?(:each) raise TypeError, 'Expected an enumeration with tuples, got ' + "#{tuples.class}." end if tuples.empty? raise ArgumentError, 'One or more tuples must be specified.' end tuples.each do |tuple| unless tuple.respond_to?(:each) raise TypeError, 'Expected an enumeration containing enumeraions, ' + "got #{tuple.class}." end unless tuple.size == expected_size raise ArgumentError, 'All tuples must be of the same size as the ' + 'number of operands in the array.' end yield tuple end end