gecoder-with-gecode 0.8.2-mswin32 → 0.8.3-mswin32
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 +14 -0
- data/lib/gecode.dll +0 -0
- data/lib/gecoder/bindings/bindings.rb +104 -46
- data/lib/gecoder/interface/binding_changes.rb +1 -301
- data/lib/gecoder/interface/branch.rb +15 -11
- data/lib/gecoder/interface/constraints.rb +38 -0
- data/lib/gecoder/interface/constraints/bool/boolean.rb +56 -52
- data/lib/gecoder/interface/constraints/bool/channel.rb +1 -16
- data/lib/gecoder/interface/constraints/bool_enum/channel.rb +13 -8
- data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +48 -0
- data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
- data/lib/gecoder/interface/constraints/int/channel.rb +1 -13
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +15 -35
- data/lib/gecoder/interface/constraints/int_enum/extensional.rb +130 -0
- data/lib/gecoder/interface/constraints/set/channel.rb +54 -0
- data/lib/gecoder/interface/constraints/set_enum/channel.rb +37 -6
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +1 -0
- data/lib/gecoder/interface/model.rb +110 -85
- data/lib/gecoder/interface/variables.rb +3 -21
- data/lib/gecoder/version.rb +1 -1
- data/specs/branch.rb +16 -1
- data/specs/constraints/bool_enum_relation.rb +6 -6
- data/specs/constraints/boolean.rb +31 -25
- data/specs/constraints/channel.rb +102 -4
- data/specs/constraints/extensional.rb +185 -2
- data/specs/constraints/reification_sugar.rb +2 -46
- data/specs/model.rb +85 -7
- data/tasks/dependencies.txt +1 -0
- data/vendor/rust/rust/class.rb +33 -35
- data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +1 -1
- data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +10 -1
- metadata +186 -185
- data/example/raw_bindings.rb +0 -44
- data/specs/binding_changes.rb +0 -76
data/CHANGES
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
== Version 0.8.3
|
2
|
+
This release adds regular expression constraints, the last channel
|
3
|
+
constraint and various minor convenience improvements. It also fixes a
|
4
|
+
rather serious bug that occurs when using the latest patchlevels of Ruby
|
5
|
+
1.8.6.
|
6
|
+
|
7
|
+
* [#20888] Fixed a GC bug causing problems with Ruby 1.8.6 at patchlevels around 230.
|
8
|
+
* Boolean constraints can no longer be specified using the form "bool.must == true". Only the "bool.must_be.true" form can now be used.
|
9
|
+
* Added constants in Model that contain the limits of the variables' domains.
|
10
|
+
* The domain when construction arrays and matrices of int variables now default to the same as when creating single variables (the largest possible domain).
|
11
|
+
* Model#branch_on now accepts single variables as well as enums.
|
12
|
+
* Added channel constraints between single set variables and enumerations of boolean variables.
|
13
|
+
* Added integer and boolean regular expression constraints. Thanks goes to Eivind Eklund for providing the idea for the syntax used to specify the regular expressions.
|
14
|
+
|
1
15
|
== Version 0.8.2
|
2
16
|
This release adds search statistics along with some new arithmetic constraints
|
3
17
|
and channel constraints between boolean and integer variables.
|
data/lib/gecode.dll
CHANGED
Binary file
|
@@ -77,7 +77,7 @@ Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "gecode" do |b|
|
|
77
77
|
b.include_header 'gecode/set.hh', Rust::Bindings::HeaderGlobal
|
78
78
|
b.include_header 'gecode/search.hh', Rust::Bindings::HeaderGlobal
|
79
79
|
b.include_header 'gecode/minimodel.hh', Rust::Bindings::HeaderGlobal
|
80
|
-
b.include_header '
|
80
|
+
b.include_header 'gecoder.h', Rust::Bindings::HeaderLocal
|
81
81
|
|
82
82
|
b.add_custom_definition ruby2intargs
|
83
83
|
b.add_custom_definition custom_mark_definitions
|
@@ -351,52 +351,47 @@ Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "gecode" do |b|
|
|
351
351
|
klass.add_method "tuples", "int"
|
352
352
|
end
|
353
353
|
|
354
|
-
ns.add_cxx_class "MBranchingDesc" do |klass|
|
355
|
-
klass.bindname = "BranchingDesc"
|
356
|
-
klass.add_constructor
|
357
|
-
klass.add_method "alternatives", "int"
|
358
|
-
klass.add_method "size", "int"
|
359
|
-
end
|
360
|
-
|
361
354
|
ns.add_cxx_class "MSpace" do |klass|
|
362
355
|
klass.bindname = "Space"
|
363
356
|
klass.function_mark = 'Gecode_MSpace_custom_mark'
|
364
357
|
|
365
358
|
klass.add_constructor
|
366
|
-
|
367
|
-
klass.add_method "debug"
|
368
|
-
|
359
|
+
|
369
360
|
klass.add_method "constrain" do |method|
|
370
361
|
method.add_parameter "Gecode::MSpace*", "s"
|
371
362
|
end
|
372
363
|
|
373
|
-
klass.add_method "
|
374
|
-
method.add_parameter "
|
375
|
-
method.add_parameter "
|
364
|
+
klass.add_method "new_int_var", "int" do |method|
|
365
|
+
method.add_parameter "int", "min"
|
366
|
+
method.add_parameter "int", "max"
|
376
367
|
end
|
377
368
|
|
378
|
-
klass.add_method "
|
379
|
-
method.add_parameter "Gecode::
|
380
|
-
method.add_parameter "char*", "name"
|
369
|
+
klass.add_method "new_int_var", "int" do |method|
|
370
|
+
method.add_parameter "Gecode::IntSet", "domain"
|
381
371
|
end
|
382
|
-
|
383
|
-
klass.add_method "
|
384
|
-
method.add_parameter "Gecode::MSetVarArray *", "x"
|
385
|
-
method.add_parameter "char*", "name"
|
372
|
+
|
373
|
+
klass.add_method "new_bool_var", "int" do |method|
|
386
374
|
end
|
387
|
-
|
388
|
-
klass.add_method "
|
389
|
-
method.add_parameter "
|
375
|
+
|
376
|
+
klass.add_method "new_set_var", "int" do |method|
|
377
|
+
method.add_parameter "Gecode::IntSet", "glb"
|
378
|
+
method.add_parameter "Gecode::IntSet", "lub"
|
379
|
+
method.add_parameter "int", "cardMin"
|
380
|
+
method.add_parameter "int", "cardMax"
|
390
381
|
end
|
391
|
-
|
392
|
-
klass.add_method "
|
393
|
-
method.add_parameter "
|
382
|
+
|
383
|
+
klass.add_method "int_var", "Gecode::IntVar*" do |method|
|
384
|
+
method.add_parameter "int", "id"
|
394
385
|
end
|
395
|
-
|
396
|
-
klass.add_method "
|
397
|
-
method.add_parameter "
|
386
|
+
|
387
|
+
klass.add_method "bool_var", "Gecode::BoolVar*" do |method|
|
388
|
+
method.add_parameter "int", "id"
|
398
389
|
end
|
399
390
|
|
391
|
+
klass.add_method "set_var", "Gecode::SetVar*" do |method|
|
392
|
+
method.add_parameter "int", "id"
|
393
|
+
end
|
394
|
+
|
400
395
|
klass.add_method "clone", "Gecode::MSpace *" do |method|
|
401
396
|
method.add_parameter "bool", "shared"
|
402
397
|
end
|
@@ -411,13 +406,6 @@ Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "gecode" do |b|
|
|
411
406
|
# description method used by rspec, and isn't used directly in the
|
412
407
|
# interface.
|
413
408
|
#klass.add_method "mdescription", "Gecode::MBranchingDesc *", "description"
|
414
|
-
|
415
|
-
klass.add_method "commit" do |method|
|
416
|
-
method.add_parameter "Gecode::MBranchingDesc", "desc" do |param|
|
417
|
-
param.custom_conversion = "ruby2Gecode_MBranchingDescPtr(desc, 1)->ptr()"
|
418
|
-
end
|
419
|
-
method.add_parameter "int", "a"
|
420
|
-
end
|
421
409
|
end
|
422
410
|
|
423
411
|
# The namespace structure doesn't completely mimic Gecode's namespace
|
@@ -659,6 +647,57 @@ Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "gecode" do |b|
|
|
659
647
|
klass.add_method "next", "Gecode::MSpace *"
|
660
648
|
klass.add_method "statistics", "Gecode::Search::Statistics"
|
661
649
|
end
|
650
|
+
|
651
|
+
ns.add_cxx_class "DFA" do |klass|
|
652
|
+
klass.add_constructor
|
653
|
+
end
|
654
|
+
|
655
|
+
ns.add_cxx_class "REG" do |klass|
|
656
|
+
klass.add_constructor
|
657
|
+
|
658
|
+
klass.add_constructor do |method|
|
659
|
+
method.add_parameter "int", "s"
|
660
|
+
end
|
661
|
+
|
662
|
+
klass.add_constructor do |method|
|
663
|
+
method.add_parameter "Gecode::IntArgs&", "x"
|
664
|
+
end
|
665
|
+
|
666
|
+
klass.add_constructor do |method|
|
667
|
+
method.add_parameter "Gecode::REG&", "r"
|
668
|
+
end
|
669
|
+
|
670
|
+
klass.add_operator "+", "Gecode::REG" do |operator|
|
671
|
+
operator.add_parameter "Gecode::REG&", "r"
|
672
|
+
end
|
673
|
+
|
674
|
+
klass.add_operator "+=", "Gecode::REG&" do |operator|
|
675
|
+
operator.add_parameter "Gecode::REG&", "r"
|
676
|
+
end
|
677
|
+
|
678
|
+
klass.add_operator "|", "Gecode::REG" do |operator|
|
679
|
+
operator.add_parameter "Gecode::REG&", "r"
|
680
|
+
end
|
681
|
+
|
682
|
+
klass.add_operator "|=", "Gecode::REG&" do |operator|
|
683
|
+
operator.add_parameter "Gecode::REG&", "r"
|
684
|
+
end
|
685
|
+
|
686
|
+
klass.add_operator "*", "Gecode::REG" do |operator|
|
687
|
+
end
|
688
|
+
|
689
|
+
klass.add_operator "+", "Gecode::REG" do |operator|
|
690
|
+
end
|
691
|
+
|
692
|
+
klass.add_operator "()", "Gecode::REG" do |operator|
|
693
|
+
operator.add_parameter "int", "n"
|
694
|
+
operator.add_parameter "int", "m"
|
695
|
+
end
|
696
|
+
|
697
|
+
klass.add_operator "()", "Gecode::REG" do |operator|
|
698
|
+
operator.add_parameter "int", "n"
|
699
|
+
end
|
700
|
+
end
|
662
701
|
|
663
702
|
# SEARCH NAMESPACE
|
664
703
|
|
@@ -789,7 +828,7 @@ Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "gecode" do |b|
|
|
789
828
|
method.add_parameter "Gecode::MiniModel::LinRel<Gecode::BoolVar>", "e"
|
790
829
|
end
|
791
830
|
|
792
|
-
klass.add_method "post" do |method|
|
831
|
+
klass.add_method "post", "Gecode::BoolVar" do |method|
|
793
832
|
method.add_parameter "Gecode::MSpace *", "home"
|
794
833
|
method.add_parameter "Gecode::IntConLevel", "icl"
|
795
834
|
method.add_parameter "Gecode::PropKind", "pk"
|
@@ -1276,14 +1315,25 @@ Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "gecode" do |b|
|
|
1276
1315
|
func.add_parameter "Gecode::PropKind", "pk"
|
1277
1316
|
end
|
1278
1317
|
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1318
|
+
ns.add_function "extensional", "void" do |func|
|
1319
|
+
func.add_parameter "Gecode::MSpace*", "home"
|
1320
|
+
func.add_parameter "Gecode::MIntVarArray *", "x" do |param|
|
1321
|
+
param.custom_conversion = "*ruby2Gecode_MIntVarArrayPtr(argv[1], 2)->ptr()"
|
1322
|
+
end
|
1323
|
+
func.add_parameter "Gecode::REG", "dfa"
|
1324
|
+
func.add_parameter "Gecode::IntConLevel", "icl"
|
1325
|
+
func.add_parameter "Gecode::PropKind", "pk"
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
ns.add_function "extensional", "void" do |func|
|
1329
|
+
func.add_parameter "Gecode::MSpace*", "home"
|
1330
|
+
func.add_parameter "Gecode::MBoolVarArray *", "x" do |param|
|
1331
|
+
param.custom_conversion = "*ruby2Gecode_MBoolVarArrayPtr(argv[1], 2)->ptr()"
|
1332
|
+
end
|
1333
|
+
func.add_parameter "Gecode::REG", "dfa"
|
1334
|
+
func.add_parameter "Gecode::IntConLevel", "icl"
|
1335
|
+
func.add_parameter "Gecode::PropKind", "pk"
|
1336
|
+
end
|
1287
1337
|
|
1288
1338
|
ns.add_function "bab", "Gecode::MSpace*" do |func|
|
1289
1339
|
func.add_parameter "Gecode::MSpace*", "home"
|
@@ -1765,6 +1815,14 @@ Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "gecode" do |b|
|
|
1765
1815
|
param.custom_conversion = "*ruby2Gecode_MSetVarArrayPtr(argv[2], 3)->ptr()"
|
1766
1816
|
end
|
1767
1817
|
end
|
1818
|
+
|
1819
|
+
ns.add_function "channel" do |func|
|
1820
|
+
func.add_parameter "Gecode::MSpace*", "home"
|
1821
|
+
func.add_parameter "Gecode::MBoolVarArray", "x" do |param|
|
1822
|
+
param.custom_conversion = "*ruby2Gecode_MBoolVarArrayPtr(argv[1], 2)->ptr()"
|
1823
|
+
end
|
1824
|
+
func.add_parameter "Gecode::SetVar", "y"
|
1825
|
+
end
|
1768
1826
|
|
1769
1827
|
ns.add_function "weights" do |func|
|
1770
1828
|
func.add_parameter "Gecode::MSpace*", "home"
|
@@ -1,309 +1,9 @@
|
|
1
|
-
# This file adds a small layer on top of the bindings.
|
2
|
-
# of variables so that a single array is allocated in each space which is then
|
3
|
-
# used to store variable. The variables themselves are not directly returned,
|
4
|
-
# rather they are represented as the index in that store, which allows the
|
5
|
-
# variable to be retrieved back given a space.
|
6
|
-
#
|
7
|
-
# This layer should be moved to the C++ side instead when possible for better
|
8
|
-
# performance.
|
1
|
+
# This file adds a small layer on top of the bindings.
|
9
2
|
module GecodeRaw #:nodoc: all
|
10
3
|
class Space
|
11
|
-
# Creates the specified number of integer variables in the space with the
|
12
|
-
# specified domain. Returns the indices with which they can then be
|
13
|
-
# accessed using int_var. The domain can be given as a Range (trated
|
14
|
-
# specially) or as another enum.
|
15
|
-
def new_int_vars(domain, count = 1)
|
16
|
-
int_var_store.new_vars(domain, count)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Gets the int variable with the specified index, nil if none exists.
|
20
|
-
def int_var(index)
|
21
|
-
int_var_store[index]
|
22
|
-
end
|
23
|
-
|
24
|
-
# Creates the specified number of boolean variables in the space. Returns
|
25
|
-
# the indices with which they can then be accessed using bool_var.
|
26
|
-
def new_bool_vars(count = 1)
|
27
|
-
bool_var_store.new_vars(count)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Gets the bool variable with the specified index, nil if none exists.
|
31
|
-
def bool_var(index)
|
32
|
-
bool_var_store[index]
|
33
|
-
end
|
34
|
-
|
35
|
-
# Creates the specified number of set variables in the space with the
|
36
|
-
# specified domain for greatest lower bound and least upper bound
|
37
|
-
# (specified as either a range or enum). A range for the allowed
|
38
|
-
# cardinality of the set can also be specified, if none is specified, or
|
39
|
-
# nil is given, then the default range (anything) will be used. Returns
|
40
|
-
# the indices with which they can then be accessed using set_var.
|
41
|
-
def new_set_vars(*vars)
|
42
|
-
set_var_store.new_vars(*vars)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Gets the set variable with the specified index, nil if none exists.
|
46
|
-
def set_var(index)
|
47
|
-
set_var_store[index]
|
48
|
-
end
|
49
|
-
|
50
4
|
# Used by Gecode during BAB-search.
|
51
5
|
def constrain(best_so_far_space)
|
52
6
|
Gecode::Model.constrain(self, best_so_far_space)
|
53
7
|
end
|
54
|
-
|
55
|
-
# Refreshes the underlying stores used by the space.
|
56
|
-
def refresh
|
57
|
-
@int_var_store = nil
|
58
|
-
@bool_var_store = nil
|
59
|
-
@set_var_store = nil
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
# Retrieves the store used for integer variables. Creates one if none
|
65
|
-
# exists.
|
66
|
-
def int_var_store
|
67
|
-
# TODO: caching interferes with the variable creation during BAB-search,
|
68
|
-
# find out why.
|
69
|
-
#if @int_var_store.nil?
|
70
|
-
@int_var_store = Gecode::Util::IntVarStore.new(self)
|
71
|
-
#end
|
72
|
-
return @int_var_store
|
73
|
-
end
|
74
|
-
|
75
|
-
# Retrieves the store used for boolean variables. Creates one if none
|
76
|
-
# exists.
|
77
|
-
def bool_var_store
|
78
|
-
#if @bool_var_store.nil?
|
79
|
-
@bool_var_store = Gecode::Util::BoolVarStore.new(self)
|
80
|
-
#end
|
81
|
-
return @bool_var_store
|
82
|
-
end
|
83
|
-
|
84
|
-
# Retrieves the store used for set variables. Creates one if none exists.
|
85
|
-
def set_var_store
|
86
|
-
#if @set_var_store.nil?
|
87
|
-
@set_var_store = Gecode::Util::SetVarStore.new(self)
|
88
|
-
#end
|
89
|
-
return @set_var_store
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
module Gecode
|
95
|
-
# Various utility (mainly used to change the behavior of the raw bindings).
|
96
|
-
module Util #:nodoc: all
|
97
|
-
# Provides common methods to the variable stores. The stores must provide
|
98
|
-
# @next_index, @var_array, @size, ARRAY_IDENTIFIER and #new_storage_array .
|
99
|
-
module VarStoreMethods
|
100
|
-
# Returns the int var with the specified index, nil if none exists.
|
101
|
-
def [](index)
|
102
|
-
if index < 0 or index >= @next_index
|
103
|
-
return nil
|
104
|
-
end
|
105
|
-
return @var_array.at(index)
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
# Grows the store to the new size.
|
111
|
-
def grow(new_size)
|
112
|
-
@var_array.enlargeArray(@space, new_size - @size)
|
113
|
-
@size = new_size
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# A store in which int variables are created and stored.
|
118
|
-
class IntVarStore
|
119
|
-
# Design note: The store used to double its size when it needed to grow
|
120
|
-
# leaving unallocated slots (in rev 16). This was changed to only growing
|
121
|
-
# the amount of space needed because the additional information about which
|
122
|
-
# slot is the next unallocated one could not be encoded without changes to
|
123
|
-
# the bindings (and without that information we can not deduce the store
|
124
|
-
# from the new copy of space). So for additional performance the bindings
|
125
|
-
# should grow the array more than needed (when this is moved to the bindings).
|
126
|
-
|
127
|
-
include VarStoreMethods
|
128
|
-
|
129
|
-
private
|
130
|
-
|
131
|
-
# A string that identifies the array used by the store.
|
132
|
-
ARRAY_IDENTIFIER = 'int_array'
|
133
|
-
|
134
|
-
public
|
135
|
-
|
136
|
-
# Creates a store for the specified space with the specified capacit.
|
137
|
-
def initialize(space)
|
138
|
-
@space = space
|
139
|
-
|
140
|
-
@var_array = space.int_var_array(ARRAY_IDENTIFIER)
|
141
|
-
if @var_array.nil?
|
142
|
-
# Create a new one.
|
143
|
-
@var_array = new_storage_array(0)
|
144
|
-
end
|
145
|
-
|
146
|
-
@size = @var_array.size
|
147
|
-
@next_index = @size
|
148
|
-
end
|
149
|
-
|
150
|
-
# Creates the specified number of integer variables in the space with the
|
151
|
-
# specified domain. Returns the indices with which they can then be
|
152
|
-
# accessed using int_var. The domain can be given as a Range (trated
|
153
|
-
# specially) or as another enum.
|
154
|
-
def new_vars(domain, count = 1)
|
155
|
-
grow(@next_index + count) # See the design note for more information.
|
156
|
-
count.times do |i|
|
157
|
-
if domain.kind_of? Range
|
158
|
-
domain_params = [domain.first, domain.last]
|
159
|
-
elsif domain.kind_of? Enumerable
|
160
|
-
arr = domain.to_a
|
161
|
-
domain_params = [Gecode::Raw::IntSet.new(arr, arr.size)]
|
162
|
-
else
|
163
|
-
raise TypeError, "Expected Enumerable, got #{domain.class}."
|
164
|
-
end
|
165
|
-
|
166
|
-
@var_array[@next_index] = Gecode::Raw::IntVar.new(@space,
|
167
|
-
*domain_params)
|
168
|
-
@next_index += 1
|
169
|
-
end
|
170
|
-
|
171
|
-
((@next_index - count)...@next_index).to_a
|
172
|
-
end
|
173
|
-
|
174
|
-
# Returns the int var with the specified index, nil if none exists.
|
175
|
-
def [](index)
|
176
|
-
if index < 0 or index >= @next_index
|
177
|
-
return nil
|
178
|
-
end
|
179
|
-
return @var_array.at(index)
|
180
|
-
end
|
181
|
-
|
182
|
-
private
|
183
|
-
|
184
|
-
# Creates a new storage array for int variables.
|
185
|
-
def new_storage_array(new_size)
|
186
|
-
arr = Gecode::Raw::IntVarArray.new(@space, new_size)
|
187
|
-
@space.own(arr, ARRAY_IDENTIFIER)
|
188
|
-
return arr
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
# A store in which int variables are created and stored.
|
193
|
-
class BoolVarStore
|
194
|
-
# TODO: can we refactor this better seeing as IntVarStore and BoolVarStore
|
195
|
-
# are similar?
|
196
|
-
|
197
|
-
include VarStoreMethods
|
198
|
-
|
199
|
-
private
|
200
|
-
|
201
|
-
# A string that identifies the array used by the store.
|
202
|
-
ARRAY_IDENTIFIER = 'bool_array'
|
203
|
-
|
204
|
-
public
|
205
|
-
|
206
|
-
# Creates a store for the specified space with the specified capacit.
|
207
|
-
def initialize(space)
|
208
|
-
@space = space
|
209
|
-
|
210
|
-
@var_array = space.bool_var_array(ARRAY_IDENTIFIER)
|
211
|
-
if @var_array.nil?
|
212
|
-
# Create a new one.
|
213
|
-
@var_array = new_storage_array(0)
|
214
|
-
end
|
215
|
-
|
216
|
-
@size = @var_array.size
|
217
|
-
@next_index = @size
|
218
|
-
end
|
219
|
-
|
220
|
-
# Creates the specified number of new bool variables. Returns the indices
|
221
|
-
# of the created variables as an array.
|
222
|
-
def new_vars(count = 1)
|
223
|
-
grow(@next_index + count) # See the design note for more information.
|
224
|
-
count.times do |i|
|
225
|
-
@var_array[@next_index] = Gecode::Raw::BoolVar.new(@space, 0, 1)
|
226
|
-
@next_index += 1
|
227
|
-
end
|
228
|
-
|
229
|
-
((@next_index - count)...@next_index).to_a
|
230
|
-
end
|
231
|
-
|
232
|
-
private
|
233
|
-
|
234
|
-
# Creates a new storage array for bool variables.
|
235
|
-
def new_storage_array(new_size)
|
236
|
-
arr = Gecode::Raw::BoolVarArray.new(@space, new_size)
|
237
|
-
@space.own(arr, ARRAY_IDENTIFIER)
|
238
|
-
return arr
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
# A store in which int variables are created and stored.
|
243
|
-
class SetVarStore
|
244
|
-
include VarStoreMethods
|
245
|
-
|
246
|
-
private
|
247
|
-
|
248
|
-
# A string that identifies the array used by the store.
|
249
|
-
ARRAY_IDENTIFIER = 'set_array'
|
250
|
-
|
251
|
-
public
|
252
|
-
|
253
|
-
# Creates a store for the specified space with the specified capacit.
|
254
|
-
def initialize(space)
|
255
|
-
@space = space
|
256
|
-
|
257
|
-
@var_array = space.set_var_array(ARRAY_IDENTIFIER)
|
258
|
-
if @var_array.nil?
|
259
|
-
# Create a new one.
|
260
|
-
@var_array = new_storage_array(0)
|
261
|
-
end
|
262
|
-
|
263
|
-
@size = @var_array.size
|
264
|
-
@next_index = @size
|
265
|
-
end
|
266
|
-
|
267
|
-
# Creates the specified number of set variables in the space with the
|
268
|
-
# specified domain for greatest lower bound and least upper bound
|
269
|
-
# (specified as either a range or enum). A range for the allowed
|
270
|
-
# cardinality of the set can also be specified, if none is specified, or
|
271
|
-
# nil is given, then the default range (anything) will be used. Returns
|
272
|
-
# the indices with which they can then be accessed using set_var.
|
273
|
-
def new_vars(glb_domain, lub_domain, cardinality_range = nil, count = 1)
|
274
|
-
grow(@next_index + count) # See the design note for more information.
|
275
|
-
|
276
|
-
if cardinality_range.nil?
|
277
|
-
cardinality_range = 0..Gecode::Raw::SetLimits::CARD
|
278
|
-
end
|
279
|
-
|
280
|
-
params = [@space]
|
281
|
-
params << domain_to_args(glb_domain)
|
282
|
-
params << domain_to_args(lub_domain)
|
283
|
-
params << cardinality_range.first << cardinality_range.last
|
284
|
-
count.times do |i|
|
285
|
-
@var_array[@next_index] = Gecode::Raw::SetVar.new(*params.flatten)
|
286
|
-
@next_index += 1
|
287
|
-
end
|
288
|
-
|
289
|
-
((@next_index - count)...@next_index).to_a
|
290
|
-
end
|
291
|
-
|
292
|
-
private
|
293
|
-
|
294
|
-
# Transforms a lub or glb domain given as a fixnum, range or enumeration
|
295
|
-
# into one or more parameters that describe the domain to
|
296
|
-
# Gecode::Raw::SetVar .
|
297
|
-
def domain_to_args(domain)
|
298
|
-
Gecode::Constraints::Util.constant_set_to_int_set(domain)
|
299
|
-
end
|
300
|
-
|
301
|
-
# Creates a new storage array for bool variables.
|
302
|
-
def new_storage_array(new_size)
|
303
|
-
arr = Gecode::Raw::SetVarArray.new(@space, new_size)
|
304
|
-
@space.own(arr, ARRAY_IDENTIFIER)
|
305
|
-
return arr
|
306
|
-
end
|
307
|
-
end
|
308
8
|
end
|
309
9
|
end
|