Module: Gecode
- Defined in:
- lib/gecoder/interface/binding_changes.rb,
lib/gecoder/bindings.rb,
lib/gecoder/interface/model.rb,
lib/gecoder/interface/branch.rb,
lib/gecoder/interface/search.rb,
lib/gecoder/interface/variables.rb,
lib/gecoder/interface/constraints.rb,
lib/gecoder/interface/enum_wrapper.rb,
lib/gecoder/interface/constraints/int/linear.rb,
lib/gecoder/interface/constraints/bool/boolean.rb,
lib/gecoder/interface/constraints/int_enum/count.rb,
lib/gecoder/interface/constraints/int_enum/distinct.rb,
lib/gecoder/interface/constraints/int_var_constraints.rb,
lib/gecoder/interface/constraints/bool_var_constraints.rb,
lib/gecoder/interface/constraints/int_enum_constraints.rb
Overview
This file adds a small layer on top of the bindings. It alters the allocation of variables so that a single array is allocated in each space which is then used to store variable. The variables themselves are not directly returned, rather they are represented as the index in that store, which allows the variable to be retrieved back given a space.
This layer should be moved to the C++ side instead when possible for better performance.
Defined Under Namespace
Modules: BoolEnumMethods, Constraints, EnumMethods, FixnumEnumMethods, IntEnumMethods, Raw, Util Classes: FreeBoolVar, FreeIntVar, FreeVarBase, MissingConstraintError, Model
Class Method Summary collapse
-
.FreeVar(bound_class, space_bind_method) ⇒ Object
Creates a class for a free variable that can be bound into the specified class using the specified method in a space.
Class Method Details
.FreeVar(bound_class, space_bind_method) ⇒ Object
Creates a class for a free variable that can be bound into the specified class using the specified method in a space.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gecoder/interface/variables.rb', line 23 def Gecode::FreeVar(bound_class, space_bind_method) clazz = Class.new(FreeVarBase) clazz.class_eval <<-"end_method_definitions" # Delegate methods we can't handle to the bound int variable if possible. def method_missing(name, *args) if #{bound_class}.instance_methods.include? name.to_s bind.send(name, *args) else super end end # Binds the int variable to the currently active space of the model, # returning the bound int variable. def bind space = active_space unless @bound_space == space # We have not bound the variable to this space, so we do it now. @bound = space.method(:#{space_bind_method}).call(@index) @bound_space = space end return @bound end def inspect if assigned? "#<#{bound_class} range: \#{val.to_s}>" else "#<#{bound_class} range: \#{min}..\#{max}>" end end end_method_definitions return clazz end |