Module: Gecode::Util
- Defined in:
- lib/gecoder/interface/constraints.rb,
lib/gecoder/interface/enum_matrix.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Extensional, MatrixEnumMethods Classes: EnumMatrix
Constant Summary collapse
- PROPAGATION_STRENGTHS =
Maps the name used in options to the value used in Gecode for propagation strengths.
{ :default => Gecode::Raw::ICL_DEF, :value => Gecode::Raw::ICL_VAL, :bounds => Gecode::Raw::ICL_BND, :domain => Gecode::Raw::ICL_DOM }
- PROPAGATION_KINDS =
Maps the name used in options to the value used in Gecode for propagation kinds.
{ :default => Gecode::Raw::PK_DEF, :speed => Gecode::Raw::PK_SPEED, :memory => Gecode::Raw::PK_MEMORY, }
- RELATION_TYPES =
Maps the names of the methods to the corresponding integer relation type in Gecode.
{ :== => Gecode::Raw::IRT_EQ, :<= => Gecode::Raw::IRT_LQ, :< => Gecode::Raw::IRT_LE, :>= => Gecode::Raw::IRT_GQ, :> => Gecode::Raw::IRT_GR }
- NEGATED_RELATION_TYPES =
The same as above, but negated.
{ :== => Gecode::Raw::IRT_NQ, :<= => Gecode::Raw::IRT_GR, :< => Gecode::Raw::IRT_GQ, :>= => Gecode::Raw::IRT_LE, :> => Gecode::Raw::IRT_LQ }
- SET_RELATION_TYPES =
Maps the names of the methods to the corresponding set relation type in Gecode.
{ :== => Gecode::Raw::SRT_EQ, :superset => Gecode::Raw::SRT_SUP, :subset => Gecode::Raw::SRT_SUB, :disjoint => Gecode::Raw::SRT_DISJ, :complement => Gecode::Raw::SRT_CMPL }
- NEGATED_SET_RELATION_TYPES =
The same as above, but negated.
{ :== => Gecode::Raw::SRT_NQ }
- SET_OPERATION_TYPES =
Maps the names of the methods to the corresponding set operation type in Gecode.
{ :union => Gecode::Raw::SOT_UNION, :disjoint_union => Gecode::Raw::SOT_DUNION, :intersection => Gecode::Raw::SOT_INTER, :minus => Gecode::Raw::SOT_MINUS }
- COMPARISON_ALIASES =
Various method aliases for comparison methods. Maps the original (symbol) name to an array of aliases.
{ :== => [:equal, :equal_to], :> => [:greater, :greater_than], :>= => [:greater_or_equal, :greater_than_or_equal_to], :< => [:less, :less_than], :<= => [:less_or_equal, :less_than_or_equal_to] }
- SET_ALIASES =
{ :== => [:equal, :equal_to], :superset => [:superset_of], :subset => [:subset_of], :disjoint => [:disjoint_with], :complement => [:complement_of] }
Class Method Summary collapse
-
.constant_set?(expression) ⇒ Boolean
Checks whether the specified expression is regarded as a constant set.
-
.constant_set_to_int_set(constant_set) ⇒ Object
Converts the different ways to specify constant sets in the interface to an instance of Gecode::Raw::IntSet.
-
.constant_set_to_params(constant_set) ⇒ Object
Converts the different ways to specify constant sets in the interface to the form that the set should be represented in Gecode (possibly multiple paramters. The different forms accepted are: * Single instance of Fixnum (singleton set). * Range (set containing all numbers in range), treated differently from other enumerations. * Enumeration of integers (set contaning all numbers in set)..
-
.decode_options(options) ⇒ Object
Decodes the common options to constraints: strength, kind and reification.
-
.extract_propagation_options(params) ⇒ Object
Extracts an array of the values selected for the standard propagation options (propagation strength and propagation kind) from the hash of parameters given.
Class Method Details
.constant_set?(expression) ⇒ Boolean
Checks whether the specified expression is regarded as a constant set. Returns true if it is, false otherwise.
407 408 409 410 411 412 413 414 415 |
# File 'lib/gecoder/interface/constraints.rb', line 407 def constant_set?(expression) return ( expression.kind_of?(Range) && # It's a range. expression.first.kind_of?(Fixnum) && expression.last.kind_of?(Fixnum)) || expression.kind_of?(Fixnum) || # It's a single fixnum. (expression.kind_of?(Enumerable) && # It's an enum of fixnums. expression.all?{ |e| e.kind_of? Fixnum }) end |
.constant_set_to_int_set(constant_set) ⇒ Object
Converts the different ways to specify constant sets in the interface to an instance of Gecode::Raw::IntSet. The different forms accepted are:
-
Single instance of Fixnum (singleton set).
-
Range (set containing all numbers in range), treated differently from other enumerations.
-
Enumeration of integers (set contaning all numbers in set).
390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/gecoder/interface/constraints.rb', line 390 def constant_set_to_int_set(constant_set) unless constant_set?(constant_set) raise TypeError, "Expected a constant set, got: #{constant_set}." end if constant_set.kind_of? Range return Gecode::Raw::IntSet.new(constant_set.first, constant_set.last) elsif constant_set.kind_of? Fixnum return Gecode::Raw::IntSet.new([constant_set], 1) else constant_set = constant_set.to_a return Gecode::Raw::IntSet.new(constant_set, constant_set.size) end end |
.constant_set_to_params(constant_set) ⇒ Object
Converts the different ways to specify constant sets in the interface to the form that the set should be represented in Gecode (possibly multiple paramters. The different forms accepted are:
-
Single instance of Fixnum (singleton set).
-
Range (set containing all numbers in range), treated differently from other enumerations.
-
Enumeration of integers (set contaning all numbers in set).
369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/gecoder/interface/constraints.rb', line 369 def constant_set_to_params(constant_set) unless constant_set?(constant_set) raise TypeError, "Expected a constant set, got: #{constant_set}." end if constant_set.kind_of? Range return constant_set.first, constant_set.last elsif constant_set.kind_of? Fixnum return constant_set else constant_set = constant_set.to_a return Gecode::Raw::IntSet.new(constant_set, constant_set.size) end end |
.decode_options(options) ⇒ Object
Decodes the common options to constraints: strength, kind and reification. Returns a hash with up to three values. :strength is the strength that should be used for the constraint, :kind is the propagation kind that should be used, and :reif is the (bound) boolean operand that should be used for reification. The decoded options are removed from the hash (so in general the hash will be consumed in the process).
Raises ArgumentError if an unrecognized option is found in the specified hash. Or if an unrecognized strength is given. Raises TypeError if the reification operand is not a boolean operand.
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/gecoder/interface/constraints.rb', line 331 def () # Propagation strength. strength = .delete(:strength) || :default unless PROPAGATION_STRENGTHS.include? strength raise ArgumentError, "Unrecognized propagation strength #{strength}." end # Propagation kind. kind = .delete(:kind) || :default unless PROPAGATION_KINDS.include? kind raise ArgumentError, "Unrecognized propagation kind #{kind}." end # Reification. reif_var = .delete(:reify) unless reif_var.nil? or reif_var.respond_to? :to_bool_var raise TypeError, 'Only boolean operands may be used for reification.' end # Check for unrecognized options. unless .empty? raise ArgumentError, 'Unrecognized constraint option: ' + .keys.first.to_s end return { :strength => PROPAGATION_STRENGTHS[strength], :kind => PROPAGATION_KINDS[kind], :reif => reif_var } end |
.extract_propagation_options(params) ⇒ Object
Extracts an array of the values selected for the standard propagation options (propagation strength and propagation kind) from the hash of parameters given. The options are returned in the order that they are given when posting constraints to Gecode.
421 422 423 |
# File 'lib/gecoder/interface/constraints.rb', line 421 def (params) params.values_at(:strength, :kind) end |