gecoder-with-gecode 0.9.0-x86-mswin32-60 → 0.9.1-x86-mswin32-60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +6 -0
- data/README +1 -1
- data/THANKS +18 -0
- data/example/equation_system.rb +3 -1
- data/example/magic_sequence.rb +3 -1
- data/example/queens.rb +3 -1
- data/example/send_more_money.rb +24 -30
- data/example/send_most_money.rb +15 -26
- data/example/square_tiling.rb +3 -1
- data/example/sudoku-set.rb +3 -1
- data/lib/gecode.dll +0 -0
- data/lib/gecoder/bindings.rb +7 -5
- data/lib/gecoder/bindings/bindings.rb +8 -8
- data/lib/gecoder/interface.rb +4 -2
- data/lib/gecoder/interface/binding_changes.rb +1 -1
- data/lib/gecoder/interface/branch.rb +1 -1
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +4 -4
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +2 -2
- data/lib/gecoder/interface/constraints/extensional_regexp.rb +1 -1
- data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +2 -2
- data/lib/gecoder/interface/constraints/int_enum/extensional.rb +5 -5
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +4 -4
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +2 -2
- data/lib/gecoder/interface/constraints/selected_set/select.rb +8 -8
- data/lib/gecoder/interface/constraints/set_enum/{select.rb → element.rb} +10 -10
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +5 -5
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +2 -2
- data/lib/gecoder/interface/{model_sugar.rb → convenience.rb} +19 -4
- data/lib/gecoder/interface/enum_wrapper.rb +1 -1
- data/lib/gecoder/interface/{model.rb → mixin.rb} +93 -60
- data/lib/gecoder/interface/search.rb +23 -22
- data/lib/gecoder/version.rb +1 -1
- data/specs/branch.rb +5 -3
- data/specs/constraints/bool/boolean.rb +3 -1
- data/specs/constraints/bool/linear.rb +3 -1
- data/specs/constraints/bool_enum/bool_enum_relation.rb +3 -1
- data/specs/constraints/bool_enum/channel.rb +3 -1
- data/specs/constraints/fixnum_enum/element.rb +3 -1
- data/specs/constraints/int/arithmetic.rb +3 -1
- data/specs/constraints/int/channel.rb +3 -1
- data/specs/constraints/int/linear.rb +3 -1
- data/specs/constraints/int/linear_properties.rb +3 -1
- data/specs/constraints/int_enum/arithmetic.rb +3 -1
- data/specs/constraints/int_enum/channel.rb +3 -1
- data/specs/constraints/int_enum/count.rb +3 -1
- data/specs/constraints/int_enum/distinct.rb +3 -1
- data/specs/constraints/int_enum/element.rb +3 -1
- data/specs/constraints/int_enum/sort.rb +3 -1
- data/specs/constraints/property_helper.rb +10 -10
- data/specs/constraints/reification_sugar.rb +3 -1
- data/specs/constraints/selected_set/select.rb +6 -5
- data/specs/constraints/selected_set/select_properties.rb +12 -10
- data/specs/constraints/set/channel.rb +3 -1
- data/specs/constraints/set/domain.rb +4 -4
- data/specs/constraints/set/relation.rb +4 -4
- data/specs/constraints/set_enum/channel.rb +3 -1
- data/specs/constraints/set_enum/distinct.rb +3 -1
- data/specs/constraints/set_enum/{select.rb → element.rb} +13 -9
- data/specs/enum_wrapper.rb +1 -1
- data/specs/mixin.rb +78 -0
- data/specs/model.rb +5 -5
- data/specs/search.rb +20 -14
- data/specs/selected_set.rb +3 -3
- data/specs/set_elements.rb +2 -2
- data/tasks/distribution.rake +25 -4
- data/vendor/gecode/win32/lib/{libgecodeint.dll → libWindowsgecodeintWindows.dll} +0 -0
- data/vendor/gecode/win32/lib/{libgecodekernel.dll → libWindowsgecodekernelWindows.dll} +0 -0
- data/vendor/gecode/win32/lib/{libgecodeminimodel.dll → libWindowsgecodeminimodelWindows.dll} +0 -0
- data/vendor/gecode/win32/lib/{libgecodesearch.dll → libWindowsgecodesearchWindows.dll} +0 -0
- data/vendor/gecode/win32/lib/{libgecodeset.dll → libWindowsgecodesetWindows.dll} +0 -0
- data/vendor/gecode/win32/lib/{libgecodesupport.dll → libWindowsgecodesupportWindows.dll} +0 -0
- metadata +20 -17
- data/example/money.rb +0 -36
@@ -5,19 +5,19 @@ module Gecode::IntEnum #:nodoc:
|
|
5
5
|
# constraints defined in IntEnumConstraintReceiver can be placed.
|
6
6
|
#
|
7
7
|
# Enumerations of integer operands can be created either by using
|
8
|
-
# Gecode::
|
8
|
+
# Gecode::Mixin#int_var_array and Gecode::Mixin#int_var_matrix, or
|
9
9
|
# by wrapping an existing enumeration containing IntOperand using
|
10
|
-
# Gecode::
|
10
|
+
# Gecode::Mixin#wrap_enum. The enumerations, no matter how they were
|
11
11
|
# created, all respond to the properties defined by IntEnumOperand.
|
12
12
|
#
|
13
13
|
# ==== Examples
|
14
14
|
#
|
15
15
|
# Produces an array of five int operands with domain 0..9 inside a
|
16
|
-
# problem formulation using Gecode::
|
16
|
+
# problem formulation using Gecode::Mixin#int_var_array:
|
17
17
|
#
|
18
18
|
# int_enum = int_var_array(5, 0..9)
|
19
19
|
#
|
20
|
-
# Uses Gecode::
|
20
|
+
# Uses Gecode::Mixin#wrap_enum inside a problem formulation to create
|
21
21
|
# a IntEnumOperand from an existing enumeration containing the
|
22
22
|
# integer operands +int_operand1+ and +int_operand2+:
|
23
23
|
#
|
@@ -5,7 +5,7 @@ module Gecode::Int #:nodoc:
|
|
5
5
|
# constraints defined in IntConstraintReceiver can be placed.
|
6
6
|
#
|
7
7
|
# Integer operands can be created either by using
|
8
|
-
# Gecode::
|
8
|
+
# Gecode::Mixin#int_var et al, or by using properties that produce
|
9
9
|
# integer operands. The operands, no matter how they were created,
|
10
10
|
# all respond to the properties defined by IntOperand.
|
11
11
|
#
|
@@ -13,7 +13,7 @@ module Gecode::Int #:nodoc:
|
|
13
13
|
#
|
14
14
|
# Produces a single integer operand (more specifically an IntVar) with
|
15
15
|
# domain 0..9 inside a problem formulation, using
|
16
|
-
# Gecode::
|
16
|
+
# Gecode::Mixin#int_var:
|
17
17
|
#
|
18
18
|
# int_operand = int_var(0..9)
|
19
19
|
#
|
@@ -7,7 +7,7 @@ module Gecode::SelectedSet
|
|
7
7
|
# # The union of all sets selected by +set_enum[set]+.
|
8
8
|
# set_enum[set].union
|
9
9
|
def union
|
10
|
-
|
10
|
+
Element::SelectedSetUnionOperand.new(model, self)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Produces a SetOperand representing the selected sets' intersection.
|
@@ -36,7 +36,7 @@ module Gecode::SelectedSet
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
Element::SelectedSetIntersectionOperand.new(model, self, universe)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -59,11 +59,11 @@ module Gecode::SelectedSet
|
|
59
59
|
end
|
60
60
|
|
61
61
|
@params.update Gecode::Set::Util.decode_options(options)
|
62
|
-
@model.add_constraint
|
62
|
+
@model.add_constraint Element::DisjointConstraint.new(@model, @params)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
module
|
66
|
+
module Element #:nodoc:
|
67
67
|
class SelectedSetUnionOperand < Gecode::Set::ShortCircuitEqualityOperand #:nodoc:
|
68
68
|
def initialize(model, selected_set)
|
69
69
|
super model
|
@@ -76,7 +76,7 @@ module Gecode::SelectedSet
|
|
76
76
|
set_operand.must_be.subset_of enum.upper_bound_range
|
77
77
|
end
|
78
78
|
|
79
|
-
Gecode::Raw::
|
79
|
+
Gecode::Raw::elementsUnion(@model.active_space,
|
80
80
|
enum.to_set_enum.bind_array, indices.to_set_var.bind,
|
81
81
|
set_operand.to_set_var.bind)
|
82
82
|
end
|
@@ -97,11 +97,11 @@ module Gecode::SelectedSet
|
|
97
97
|
# is the universe.
|
98
98
|
|
99
99
|
if universe.nil?
|
100
|
-
Gecode::Raw::
|
100
|
+
Gecode::Raw::elementsInter(@model.active_space,
|
101
101
|
enum.to_set_enum.bind_array, indices.to_set_var.bind,
|
102
102
|
set_operand.to_set_var.bind)
|
103
103
|
else
|
104
|
-
Gecode::Raw::
|
104
|
+
Gecode::Raw::elementsInter(@model.active_space,
|
105
105
|
enum.to_set_enum.bind_array, indices.to_set_var.bind,
|
106
106
|
set_operand.to_set_var.bind,
|
107
107
|
Gecode::Util.constant_set_to_int_set(universe))
|
@@ -112,7 +112,7 @@ module Gecode::SelectedSet
|
|
112
112
|
class DisjointConstraint < Gecode::Constraint #:nodoc:
|
113
113
|
def post
|
114
114
|
enum, indices = @params[:lhs].to_selected_set
|
115
|
-
Gecode::Raw.
|
115
|
+
Gecode::Raw.elementsDisjoint(@model.active_space,
|
116
116
|
enum.to_set_enum.bind_array, indices.to_set_var.bind)
|
117
117
|
end
|
118
118
|
end
|
@@ -7,14 +7,14 @@ module Gecode::SetEnum
|
|
7
7
|
mod.module_eval do
|
8
8
|
# Now we enter the module SetEnumOperands is mixed into.
|
9
9
|
class << self
|
10
|
-
alias_method :
|
10
|
+
alias_method :pre_set_element_included, :included
|
11
11
|
def included(mod) #:nodoc:
|
12
12
|
mod.module_eval do
|
13
13
|
# Now we enter the module that the module possibly defining #[]
|
14
14
|
# is mixed into.
|
15
15
|
if instance_methods.include?('[]') and
|
16
|
-
not instance_methods.include?('
|
17
|
-
alias_method :
|
16
|
+
not instance_methods.include?('pre_set_element_access')
|
17
|
+
alias_method :pre_set_element_access, :[]
|
18
18
|
end
|
19
19
|
|
20
20
|
# Produces a SetOperand representing the i:th set
|
@@ -38,27 +38,27 @@ module Gecode::SetEnum
|
|
38
38
|
# Hook in an element constraint if a operand is used for array
|
39
39
|
# access.
|
40
40
|
if vars.first.respond_to? :to_int_var
|
41
|
-
|
41
|
+
Element::ElementSetOperand.new(
|
42
42
|
model, self, vars.first)
|
43
43
|
elsif vars.first.respond_to? :to_set_var
|
44
44
|
Gecode::SelectedSet::SelectedSetOperand.new(
|
45
45
|
self, vars.first)
|
46
46
|
else
|
47
|
-
if respond_to? :
|
48
|
-
|
47
|
+
if respond_to? :pre_set_element_access
|
48
|
+
pre_set_element_access(*vars)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
pre_set_element_included(mod)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
module
|
61
|
-
class
|
60
|
+
module Element #:nodoc:
|
61
|
+
class ElementSetOperand < Gecode::Set::ShortCircuitEqualityOperand #:nodoc:
|
62
62
|
def initialize(model, enum_op, position_int_op)
|
63
63
|
super model
|
64
64
|
@enum = enum_op
|
@@ -71,7 +71,7 @@ module Gecode::SetEnum
|
|
71
71
|
set_operand.must_be.subset_of enum.upper_bound_range
|
72
72
|
end
|
73
73
|
|
74
|
-
Gecode::Raw::
|
74
|
+
Gecode::Raw::element(@model.active_space, enum.bind_array,
|
75
75
|
@position.to_int_var.bind, set_operand.to_set_var.bind)
|
76
76
|
end
|
77
77
|
end
|
@@ -5,20 +5,20 @@ module Gecode::SetEnum #:nodoc:
|
|
5
5
|
# constraints defined in SetEnumConstraintReceiver can be placed.
|
6
6
|
#
|
7
7
|
# Enumerations of set operands can be created either by using
|
8
|
-
# Gecode::
|
8
|
+
# Gecode::Mixin#set_var_array and Gecode::Mixin#set_var_matrix, or
|
9
9
|
# by wrapping an existing enumeration containing SetOperand using
|
10
|
-
# Gecode::
|
10
|
+
# Gecode::Mixin#wrap_enum. The enumerations, no matter how they were
|
11
11
|
# created, all respond to the properties defined by SetEnumOperand.
|
12
12
|
#
|
13
13
|
# ==== Examples
|
14
14
|
#
|
15
15
|
# Produces an array of five set operands, with greatest lower bound
|
16
16
|
# {0} and least upper bound {0, 1, 2}, inside a problem formulation
|
17
|
-
# using Gecode::
|
17
|
+
# using Gecode::Mixin#set_var_array:
|
18
18
|
#
|
19
19
|
# set_enum = set_var_array(5, 0, 1..2)
|
20
20
|
#
|
21
|
-
# Uses Gecode::
|
21
|
+
# Uses Gecode::Mixin#wrap_enum inside a problem formulation to create
|
22
22
|
# a SetEnumOperand from an existing enumeration containing the
|
23
23
|
# set operands +set_operand1+ and +set_operand2+:
|
24
24
|
#
|
@@ -80,5 +80,5 @@ end
|
|
80
80
|
|
81
81
|
require 'gecoder/interface/constraints/set_enum/channel'
|
82
82
|
require 'gecoder/interface/constraints/set_enum/distinct'
|
83
|
-
require 'gecoder/interface/constraints/set_enum/
|
83
|
+
require 'gecoder/interface/constraints/set_enum/element'
|
84
84
|
require 'gecoder/interface/constraints/set_enum/operation'
|
@@ -4,7 +4,7 @@ module Gecode::Set #:nodoc:
|
|
4
4
|
# A SetOperand is a combination of operands on which the
|
5
5
|
# constraints defined in SetConstraintReceiver can be placed.
|
6
6
|
#
|
7
|
-
# Set operands can be created either by using Gecode::
|
7
|
+
# Set operands can be created either by using Gecode::Mixin#set_var et
|
8
8
|
# al, or by using properties that produce set operands. The operands,
|
9
9
|
# no matter how they were created, all respond to the properties
|
10
10
|
# defined by SetOperand.
|
@@ -13,7 +13,7 @@ module Gecode::Set #:nodoc:
|
|
13
13
|
#
|
14
14
|
# Produces a single set operand (more specifically a SetVar), with
|
15
15
|
# greatest lower bound {0} and least upper bound {0, 1, 2}, inside a
|
16
|
-
# problem formulation, using Gecode::
|
16
|
+
# problem formulation, using Gecode::Mixin#set_var:
|
17
17
|
#
|
18
18
|
# set_operand = set_var(0, 0..2)
|
19
19
|
#
|
@@ -1,4 +1,11 @@
|
|
1
1
|
module Gecode
|
2
|
+
# A convenient class that just includes Gecode::Mixin. Can be useful
|
3
|
+
# when you don't want to create your own class that mixes in
|
4
|
+
# Gecode::Mixin.
|
5
|
+
class Model
|
6
|
+
include Gecode::Mixin
|
7
|
+
end
|
8
|
+
|
2
9
|
# Provides a convenient way to construct a model and then find a
|
3
10
|
# solution. The model constructed uses the specified block as
|
4
11
|
# initialization method. The first solution to the model is then
|
@@ -12,7 +19,9 @@ module Gecode
|
|
12
19
|
#
|
13
20
|
# is equivalent to
|
14
21
|
#
|
15
|
-
# class Foo
|
22
|
+
# class Foo
|
23
|
+
# include Gecode::Mixin
|
24
|
+
#
|
16
25
|
# def initialize
|
17
26
|
# # Do something
|
18
27
|
# end
|
@@ -35,7 +44,9 @@ module Gecode
|
|
35
44
|
#
|
36
45
|
# is equivalent to
|
37
46
|
#
|
38
|
-
# class Foo
|
47
|
+
# class Foo
|
48
|
+
# include Gecode::Mixin
|
49
|
+
#
|
39
50
|
# def initialize
|
40
51
|
# # Do something
|
41
52
|
# end
|
@@ -58,7 +69,9 @@ module Gecode
|
|
58
69
|
#
|
59
70
|
# is equivalent to
|
60
71
|
#
|
61
|
-
# class Foo
|
72
|
+
# class Foo
|
73
|
+
# include Gecode::Mixin
|
74
|
+
#
|
62
75
|
# def initialize
|
63
76
|
# # Do something
|
64
77
|
# end
|
@@ -73,8 +86,10 @@ module Gecode
|
|
73
86
|
# Creates an instance of a class that subclasses Model and uses the
|
74
87
|
# specified block as initialization method.
|
75
88
|
def self.create_model(&block)
|
76
|
-
model = Class.new
|
89
|
+
model = Class.new
|
77
90
|
model.class_eval do
|
91
|
+
include Gecode::Mixin
|
92
|
+
|
78
93
|
def initialize(&init_block) #:nodoc:
|
79
94
|
instance_eval &init_block
|
80
95
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module Gecode
|
2
|
-
#
|
2
|
+
# Mixin contains the base functionality needed to formulate problems.
|
3
3
|
#
|
4
4
|
# == Formulating problems
|
5
5
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# Problems are formulated by building a model that represents the
|
7
|
+
# problem. A model is a class that mixes in Mixin and uses its
|
8
|
+
# functionality to define variables and constraints that describe the
|
9
|
+
# problem. Below is an example of a model that formulates the problem
|
10
|
+
# of finding a solution to the following equation system.
|
9
11
|
#
|
10
12
|
# Equation system:
|
11
13
|
# x + y = z
|
@@ -13,7 +15,9 @@ module Gecode
|
|
13
15
|
# 0 <= x,y,z <= 9
|
14
16
|
#
|
15
17
|
# Model:
|
16
|
-
# class EquationProblem
|
18
|
+
# class EquationProblem
|
19
|
+
# include Gecode::Mixin
|
20
|
+
#
|
17
21
|
# attr :vars
|
18
22
|
#
|
19
23
|
# def initialize
|
@@ -97,7 +101,9 @@ module Gecode
|
|
97
101
|
# Additionally one can use "foo_is_an ..." to create an accessor of
|
98
102
|
# name foo, without having to use instance variables. The above
|
99
103
|
# problem becomes
|
100
|
-
# class EquationProblem
|
104
|
+
# class EquationProblem
|
105
|
+
# include Gecode::Mixin
|
106
|
+
#
|
101
107
|
# def initialize
|
102
108
|
# x, y, z = vars_is_an int_var_array(3, 0..9)
|
103
109
|
#
|
@@ -108,7 +114,7 @@ module Gecode
|
|
108
114
|
# end
|
109
115
|
# end
|
110
116
|
#
|
111
|
-
|
117
|
+
module Mixin
|
112
118
|
# The largest integer allowed in the domain of an integer variable.
|
113
119
|
MAX_INT = Gecode::Raw::IntLimits::MAX
|
114
120
|
# The smallest integer allowed in the domain of an integer variable.
|
@@ -221,7 +227,7 @@ module Gecode
|
|
221
227
|
# The space returned by this method should never be stored, it should be
|
222
228
|
# rerequested from the model every time that it's needed.
|
223
229
|
def active_space #:nodoc:
|
224
|
-
unless @
|
230
|
+
unless @gecoder_mixin_allow_space_access
|
225
231
|
raise 'Space access is restricted and the permission to access the ' +
|
226
232
|
'space has not been given.'
|
227
233
|
end
|
@@ -253,63 +259,90 @@ module Gecode
|
|
253
259
|
# We store the old value so that nested calls don't become a problem, i.e.
|
254
260
|
# access is allowed as long as one call to this method is still on the
|
255
261
|
# stack.
|
256
|
-
old = @
|
257
|
-
@
|
262
|
+
old = @gecoder_mixin_allow_space_access
|
263
|
+
@gecoder_mixin_allow_space_access = true
|
258
264
|
res = yield
|
259
|
-
@
|
265
|
+
@gecoder_mixin_allow_space_access = old
|
260
266
|
return res
|
261
267
|
end
|
262
268
|
|
263
269
|
# Starts tracking a variable that depends on the space. All variables
|
264
270
|
# created should call this method for their respective models.
|
265
271
|
def track_variable(variable) #:nodoc:
|
266
|
-
(@
|
272
|
+
(@gecoder_mixin_variables ||= []) << variable
|
267
273
|
end
|
268
274
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
275
|
+
def self.included(mod)
|
276
|
+
mod.class_eval do
|
277
|
+
alias_method :pre_gecoder_method_missing, :method_missing
|
278
|
+
# Wraps method missing to handle #foo_is_a and #foo_is_an .
|
279
|
+
#
|
280
|
+
# "<variable_name>_is_a <variable>" or "<variable_name>_is_an
|
281
|
+
# <variable>", # replacing "<variable_name>" with the variable's
|
282
|
+
# name and "<variable>" with the variable, adds an instance
|
283
|
+
# variable and accessor with the specified name.
|
284
|
+
#
|
285
|
+
# The method also returns the variable given.
|
286
|
+
#
|
287
|
+
# ==== Example
|
288
|
+
#
|
289
|
+
# # Add an instance variable and accessor named "foo" that return
|
290
|
+
# # the integer variable.
|
291
|
+
# foo_is_an int_var(0..9)
|
292
|
+
#
|
293
|
+
# # Add an instance variable and accessor named "bar" that return
|
294
|
+
# # the boolean variable array.
|
295
|
+
# bar_is_a bool_var_array(2)
|
296
|
+
def method_missing(method, *args)
|
297
|
+
name = method.to_s
|
298
|
+
if name =~ /._is_an?$/
|
299
|
+
name.sub!(/_is_an?$/, '')
|
300
|
+
unless args.size == 1
|
301
|
+
raise ArgumentError,
|
302
|
+
"Wrong number of argmuments (#{args.size} for 1)."
|
303
|
+
end
|
304
|
+
if respond_to? name
|
305
|
+
raise ArgumentError, "Method with name #{name} already exists."
|
306
|
+
end
|
307
|
+
if instance_variable_defined? "@#{name}"
|
308
|
+
raise ArgumentError,
|
309
|
+
"Instance variable with name @#{name} already exists."
|
310
|
+
end
|
311
|
+
|
312
|
+
# We use the meta class to avoid defining the variable in all
|
313
|
+
# other instances of the class.
|
314
|
+
eval <<-"end_eval"
|
315
|
+
@#{name} = args.first
|
316
|
+
class <<self
|
317
|
+
attr :#{name}
|
318
|
+
end
|
319
|
+
end_eval
|
320
|
+
return args.first
|
321
|
+
else
|
322
|
+
pre_gecoder_method_missing(method, *args)
|
323
|
+
end
|
300
324
|
end
|
325
|
+
alias_method :mixin_method_missing, :method_missing
|
301
326
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
327
|
+
def self.method_added(method)
|
328
|
+
if method == :method_missing && !@redefining_method_missing
|
329
|
+
# The class that is mixing in the mixin redefined method
|
330
|
+
# missing. Redefine method missing again to combine the two
|
331
|
+
# definitions.
|
332
|
+
@redefining_method_missing = true
|
333
|
+
class_eval do
|
334
|
+
alias_method :mixee_method_missing, :method_missing
|
335
|
+
def combined_method_missing(*args)
|
336
|
+
begin
|
337
|
+
mixin_method_missing(*args)
|
338
|
+
rescue NoMethodError => e
|
339
|
+
mixee_method_missing(*args)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
alias_method :method_missing, :combined_method_missing
|
343
|
+
end
|
308
344
|
end
|
309
|
-
|
310
|
-
return args.first
|
311
|
-
else
|
312
|
-
super
|
345
|
+
end
|
313
346
|
end
|
314
347
|
end
|
315
348
|
|
@@ -419,19 +452,19 @@ module Gecode
|
|
419
452
|
|
420
453
|
# Retrieves the base from which searches are made.
|
421
454
|
def base_space
|
422
|
-
@
|
455
|
+
@gecoder_mixin_base_space ||= Gecode::Raw::Space.new
|
423
456
|
end
|
424
457
|
|
425
458
|
# Retrieves the currently selected space, the one which constraints and
|
426
459
|
# variables should be bound to.
|
427
460
|
def selected_space
|
428
|
-
return @
|
461
|
+
return @gecoder_mixin_active_space unless @gecoder_mixin_active_space.nil?
|
429
462
|
self.active_space = base_space
|
430
463
|
end
|
431
464
|
|
432
465
|
# Retrieves the space that should be used for variable creation.
|
433
466
|
def variable_creation_space
|
434
|
-
@
|
467
|
+
@gecoder_mixin_variable_creation_space || selected_space
|
435
468
|
end
|
436
469
|
|
437
470
|
# Executes any interactions with Gecode still waiting in the queue
|
@@ -444,10 +477,10 @@ module Gecode
|
|
444
477
|
end
|
445
478
|
|
446
479
|
# Switches the active space used (the space from which variables are read
|
447
|
-
# and to which constraints are posted). @
|
448
|
-
# assigned directly.
|
480
|
+
# and to which constraints are posted). @gecoder_mixin_active_space
|
481
|
+
# should never be assigned directly.
|
449
482
|
def active_space=(new_space)
|
450
|
-
@
|
451
|
-
end
|
483
|
+
@gecoder_mixin_active_space = new_space
|
484
|
+
end
|
452
485
|
end
|
453
486
|
end
|