gecoder 0.8.2 → 0.8.3

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.
Files changed (38) hide show
  1. data/CHANGES +14 -0
  2. data/ext/gecoder.cpp +181 -0
  3. data/ext/gecoder.h +94 -0
  4. data/ext/vararray.cpp +3 -3
  5. data/lib/gecoder/bindings/bindings.rb +104 -46
  6. data/lib/gecoder/interface/binding_changes.rb +1 -301
  7. data/lib/gecoder/interface/branch.rb +15 -11
  8. data/lib/gecoder/interface/constraints/bool/boolean.rb +56 -52
  9. data/lib/gecoder/interface/constraints/bool/channel.rb +1 -16
  10. data/lib/gecoder/interface/constraints/bool_enum/channel.rb +13 -8
  11. data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +48 -0
  12. data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
  13. data/lib/gecoder/interface/constraints/int/channel.rb +1 -13
  14. data/lib/gecoder/interface/constraints/int_enum/channel.rb +15 -35
  15. data/lib/gecoder/interface/constraints/int_enum/extensional.rb +130 -0
  16. data/lib/gecoder/interface/constraints/set/channel.rb +54 -0
  17. data/lib/gecoder/interface/constraints/set_enum/channel.rb +37 -6
  18. data/lib/gecoder/interface/constraints/set_var_constraints.rb +1 -0
  19. data/lib/gecoder/interface/constraints.rb +38 -0
  20. data/lib/gecoder/interface/model.rb +110 -85
  21. data/lib/gecoder/interface/variables.rb +3 -21
  22. data/lib/gecoder/version.rb +1 -1
  23. data/specs/branch.rb +16 -1
  24. data/specs/constraints/bool_enum_relation.rb +6 -6
  25. data/specs/constraints/boolean.rb +31 -25
  26. data/specs/constraints/channel.rb +102 -4
  27. data/specs/constraints/extensional.rb +185 -2
  28. data/specs/constraints/reification_sugar.rb +2 -46
  29. data/specs/model.rb +85 -7
  30. data/tasks/dependencies.txt +1 -0
  31. data/vendor/rust/rust/class.rb +33 -35
  32. data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +1 -1
  33. data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +10 -1
  34. metadata +185 -184
  35. data/example/raw_bindings.rb +0 -44
  36. data/ext/missing.cpp +0 -328
  37. data/ext/missing.h +0 -120
  38. data/specs/binding_changes.rb +0 -76
data/ext/missing.cpp DELETED
@@ -1,328 +0,0 @@
1
- /**
2
- * Gecode/R, a Ruby interface to Gecode.
3
- * Copyright (C) 2007 The Gecode/R development team.
4
- *
5
- * This library is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU Lesser General Public
7
- * License as published by the Free Software Foundation; either
8
- * version 2.1 of the License, or (at your option) any later version.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public
16
- * License along with this library; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- **/
19
-
20
- #include "missing.h"
21
- #include "gecode.hh"
22
-
23
- #include <iostream>
24
- #include <map>
25
-
26
- namespace Gecode {
27
-
28
- struct MBranchingDesc::Private
29
- {
30
- const Gecode::BranchingDesc *ptr;
31
- };
32
-
33
- MBranchingDesc::MBranchingDesc() : d(new Private)
34
- {
35
-
36
- }
37
-
38
- MBranchingDesc::~MBranchingDesc()
39
- {
40
- delete d;
41
- }
42
-
43
- void MBranchingDesc::setPtr(const Gecode::BranchingDesc *desc)
44
- {
45
- d->ptr = desc;
46
- }
47
-
48
- const Gecode::BranchingDesc *MBranchingDesc::ptr() const
49
- {
50
- return d->ptr;
51
- }
52
-
53
- int MBranchingDesc::alternatives() const
54
- {
55
- if(d->ptr) return d->ptr->alternatives();
56
-
57
- return -1;
58
- }
59
-
60
- int MBranchingDesc::size() const
61
- {
62
- if(d->ptr) return d->ptr->size();
63
-
64
- return -1;
65
- }
66
-
67
-
68
- /////////////////////////////////////
69
-
70
- struct ltstr
71
- {
72
- bool operator()(const char* s1, const char* s2) const
73
- {
74
- return strcmp(s1, s2) < 0;
75
- }
76
- };
77
-
78
- typedef std::map<const char *, MIntVarArray *, ltstr> IntVarArrays;
79
- typedef std::map<const char *, MBoolVarArray *, ltstr> BoolVarArrays;
80
- typedef std::map<const char *, MSetVarArray *, ltstr> SetVarArrays;
81
-
82
- struct MSpace::Private
83
- {
84
- Private()
85
- {
86
- description = new MBranchingDesc;;
87
- }
88
-
89
- ~Private()
90
- {
91
- // {
92
- // IntVarArrays::iterator it, eend = intArrays.end();
93
- //
94
- // for(it = intArrays.begin(); it != eend; it++)
95
- // {
96
- // delete (*it).second;
97
- // }
98
- // }
99
- // {
100
- // SetVarArrays::iterator it, eend = setArrays.end();
101
- //
102
- // for(it = setArrays.begin(); it != eend; it++)
103
- // {
104
- // delete (*it).second;
105
- // }
106
- // }
107
- //
108
- // {
109
- // BoolVarArrays::iterator it, eend = boolArrays.end();
110
- //
111
- // for(it = boolArrays.begin(); it != eend; it++)
112
- // {
113
- // delete (*it).second;
114
- // }
115
- // }
116
-
117
- delete description;
118
- }
119
-
120
- IntVarArrays intArrays;
121
- BoolVarArrays boolArrays;
122
- SetVarArrays setArrays;
123
-
124
- MBranchingDesc *description;
125
- };
126
-
127
- MSpace::MSpace() : d(new Private())
128
- {
129
- }
130
-
131
- MSpace::MSpace(MSpace& s, bool share) : Gecode::Space(share, s), d(new Private)
132
- {
133
- {
134
- IntVarArrays::iterator it, eend = s.d->intArrays.end();
135
-
136
- for(it = s.d->intArrays.begin(); it != eend; it++)
137
- {
138
- Gecode::MIntVarArray *iva = new Gecode::MIntVarArray(this, (*it).second->ptr()->size());
139
-
140
- iva->ptr()->update(this, share, *(*it).second->ptr() );
141
-
142
- own(iva, (*it).first);
143
- }
144
- }
145
- {
146
- BoolVarArrays::iterator it, eend = s.d->boolArrays.end();
147
-
148
- for(it = s.d->boolArrays.begin(); it != eend; it++)
149
- {
150
- Gecode::MBoolVarArray *bva = new Gecode::MBoolVarArray(this, (*it).second->ptr()->size());
151
-
152
- bva->ptr()->update(this, share, *(*it).second->ptr() );
153
-
154
- own(bva, (*it).first);
155
- }
156
- }
157
- {
158
- SetVarArrays::iterator it, eend = s.d->setArrays.end();
159
-
160
- for(it = s.d->setArrays.begin(); it != eend; it++)
161
- {
162
- Gecode::MSetVarArray *sva = new Gecode::MSetVarArray(this, (*it).second->ptr()->size());
163
- sva->ptr()->update(this, share, *(*it).second->ptr() );
164
-
165
- own(sva, (*it).first);
166
- }
167
- }
168
- }
169
-
170
-
171
-
172
- MSpace::~MSpace()
173
- {
174
- delete d;
175
- }
176
-
177
- Gecode::Space *MSpace::copy(bool share)
178
- {
179
- return new MSpace(*this,share);
180
- }
181
-
182
- void MSpace::own(Gecode::MIntVarArray *iva, const char *name)
183
- {
184
- d->intArrays[name] = iva;
185
- }
186
-
187
- void MSpace::own(Gecode::MBoolVarArray *bva, const char *name)
188
- {
189
- d->boolArrays[name] = bva;
190
- }
191
-
192
- void MSpace::own(Gecode::MSetVarArray *sva, const char *name)
193
- {
194
- d->setArrays[name] = sva;
195
- }
196
-
197
- void MSpace::gc_mark()
198
- {
199
- {
200
- IntVarArrays::iterator it, eend = d->intArrays.end();
201
- for(it = d->intArrays.begin(); it != eend; it++)
202
- {
203
- rb_gc_mark(Rust_gecode::cxx2ruby((*it).second));
204
- }
205
- }
206
- {
207
- BoolVarArrays::iterator it, eend = d->boolArrays.end();
208
- for(it = d->boolArrays.begin(); it != eend; it++)
209
- {
210
- rb_gc_mark(Rust_gecode::cxx2ruby((*it).second));
211
- }
212
- }
213
- {
214
- SetVarArrays::iterator it, eend = d->setArrays.end();
215
- for(it = d->setArrays.begin(); it != eend; it++)
216
- {
217
- rb_gc_mark(Rust_gecode::cxx2ruby((*it).second));
218
- }
219
- }
220
- }
221
-
222
- // For BAB.
223
- void MSpace::constrain(MSpace* s)
224
- {
225
- // Call Ruby's constrain.
226
- rb_funcall(Rust_gecode::cxx2ruby(this), rb_intern("constrain"), 1,
227
- Rust_gecode::cxx2ruby(s, false));
228
- }
229
-
230
- Gecode::MIntVarArray *MSpace::intVarArray(const char *name) const
231
- {
232
- if ( d->intArrays.find(name) == d->intArrays.end() ) return 0;
233
- return d->intArrays[name];
234
- }
235
-
236
- Gecode::MBoolVarArray *MSpace::boolVarArray(const char *name ) const
237
- {
238
- if ( d->boolArrays.find(name) == d->boolArrays.end() ) return 0;
239
- return d->boolArrays[name];
240
- }
241
-
242
- Gecode::MSetVarArray *MSpace::setVarArray(const char *name ) const
243
- {
244
- if ( d->setArrays.find(name) == d->setArrays.end() ) return 0;
245
- return d->setArrays[name];
246
- }
247
-
248
- Gecode::MBranchingDesc *MSpace::mdescription()
249
- {
250
- if(!this->failed() || !d->description->ptr() )
251
- {
252
- d->description->setPtr(this->description());
253
- }
254
- return d->description;
255
- }
256
-
257
- void MSpace::debug()
258
- {
259
- std::cout << "DEBUG: "<< d->intArrays["default"]->ptr()->size() << std::endl;
260
- }
261
-
262
-
263
- // DFS
264
- MDFS::MDFS(MSpace *space, unsigned int c_d, unsigned int a_d, Search::Stop* st) : Gecode::Search::DFS(space, c_d, a_d, st, sizeof(space))
265
- {
266
- }
267
-
268
- MDFS::~MDFS()
269
- {
270
- }
271
-
272
-
273
- // BAB
274
- MBAB::MBAB(MSpace *space, const Search::Options &o) : Gecode::BAB<MSpace>(space, o)
275
- {
276
- }
277
-
278
- MBAB::~MBAB()
279
- {
280
- }
281
-
282
- namespace Search {
283
-
284
- // Stop
285
-
286
- struct MStop::Private
287
- {
288
- Gecode::Search::TimeStop *ts;
289
- Gecode::Search::FailStop *fs;
290
- };
291
-
292
- MStop::MStop() : d(new Private)
293
- {
294
- d->ts = 0;
295
- d->fs = 0;
296
- }
297
-
298
- MStop::MStop(int fails, int time) : d(new Private)
299
- {
300
- d->ts = new Search::TimeStop(time);
301
- d->fs = new Search::FailStop(fails);
302
- }
303
-
304
- MStop::~MStop()
305
- {
306
- }
307
-
308
- bool MStop::stop(const Gecode::Search::Statistics &s)
309
- {
310
- if (!d->fs || d->ts)
311
- return false;
312
- return d->fs->stop(s) || d->ts->stop(s);
313
- }
314
-
315
- Gecode::Search::Stop* MStop::create(int fails, int time)
316
- {
317
- if (fails < 0 && time < 0) return 0;
318
- if (fails < 0) return new Search::TimeStop( time );
319
-
320
- if (time < 0) return new Search::FailStop(fails);
321
-
322
- return new MStop(fails, time);
323
- }
324
-
325
-
326
- }
327
-
328
- }
data/ext/missing.h DELETED
@@ -1,120 +0,0 @@
1
- /**
2
- * Gecode/R, a Ruby interface to Gecode.
3
- * Copyright (C) 2007 The Gecode/R development team.
4
- *
5
- * This library is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU Lesser General Public
7
- * License as published by the Free Software Foundation; either
8
- * version 2.1 of the License, or (at your option) any later version.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public
16
- * License along with this library; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- **/
19
-
20
- #ifndef __MISSING_CLASSES_H
21
- #define __MISSING_CLASSES_H
22
-
23
- #include <ruby.h>
24
-
25
- #include <gecode/kernel.hh>
26
- #include <gecode/int.hh>
27
- #include <gecode/search.hh>
28
- #include <gecode/minimodel.hh>
29
- #include <gecode/set.hh>
30
-
31
- #include "vararray.h"
32
-
33
- namespace Gecode {
34
-
35
- class MBranchingDesc
36
- {
37
- public:
38
- MBranchingDesc();
39
- ~MBranchingDesc();
40
-
41
- void setPtr(const Gecode::BranchingDesc *);
42
- const Gecode::BranchingDesc *ptr() const;
43
-
44
- int alternatives() const;
45
- int size() const;
46
-
47
- private:
48
- struct Private;
49
- Private *const d;
50
- };
51
-
52
- class MSpace : public Space
53
- {
54
- public:
55
- MSpace();
56
- explicit MSpace(MSpace& s, bool share=true);
57
- ~MSpace();
58
- Gecode::Space *copy(bool share);
59
-
60
- void own(Gecode::MIntVarArray *iva, const char *name);
61
- void own(Gecode::MBoolVarArray *bva, const char *name);
62
- void own(Gecode::MSetVarArray *sva, const char *name);
63
-
64
- void gc_mark();
65
-
66
- void constrain(MSpace* s);
67
-
68
- Gecode::MIntVarArray *intVarArray(const char *name ) const;
69
- Gecode::MBoolVarArray *boolVarArray(const char *name ) const;
70
- Gecode::MSetVarArray *setVarArray(const char *name) const;
71
-
72
- Gecode::MBranchingDesc *mdescription();
73
-
74
- void debug();
75
-
76
- private:
77
- struct Private;
78
- Private *const d;
79
- };
80
-
81
- class MDFS : public Gecode::Search::DFS
82
- {
83
- public:
84
- MDFS(MSpace *space, unsigned int c_d, unsigned int a_d, Search::Stop* st = 0);
85
- ~MDFS();
86
- };
87
- class MBAB : public Gecode::BAB<MSpace>
88
- {
89
- public:
90
- MBAB(MSpace* space, const Search::Options &o);
91
- ~MBAB();
92
- };
93
-
94
- namespace Search {
95
- class MStop : public Gecode::Search::Stop
96
- {
97
- private:
98
- MStop(int fails, int time);
99
-
100
- public:
101
- MStop();
102
- ~MStop();
103
-
104
- bool stop (const Gecode::Search::Statistics &s);
105
- static Gecode::Search::Stop* create(int fails, int time);
106
-
107
-
108
- private:
109
- struct Private;
110
- Private *const d;
111
- };
112
-
113
- }
114
-
115
-
116
- }
117
-
118
- #endif
119
-
120
-
@@ -1,76 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe 'Space', :shared => true do
4
- it 'should give different indices when creating int variables' do
5
- @space.new_int_vars([0, 17]).should_not equal(@space.new_int_vars([0, 17]))
6
- end
7
-
8
- it 'should give different indices when creating bool variables' do
9
- @space.new_bool_vars().should_not equal(@space.new_bool_vars())
10
- end
11
-
12
- it 'should give different indices when creating multiple int variables' do
13
- @space.new_int_vars([0, 17], 17).uniq.size.should equal(17)
14
- end
15
-
16
- it 'should give different indices when creating multiple bool variables' do
17
- @space.new_bool_vars(17).uniq.size.should equal(17)
18
- end
19
-
20
- it 'should not return nil for created int variables' do
21
- @space.new_int_vars([0, 17], 4).each do |i|
22
- @space.int_var(i).should_not be_nil
23
- end
24
- end
25
-
26
- it 'should not return nil for created int variables' do
27
- @space.new_bool_vars(4).each do |i|
28
- @space.bool_var(i).should_not be_nil
29
- end
30
- end
31
-
32
- it 'should return nil when requesting int variables with negative indices' do
33
- @space.int_var(-1).should be_nil
34
- end
35
-
36
- it 'should return nil when requesting bool variables with negative indices' do
37
- @space.bool_var(-1).should be_nil
38
- end
39
-
40
- it 'should raise an error if given a domain of incorrect type' do
41
- lambda{ @space.new_int_vars(17) }.should raise_error(TypeError)
42
- end
43
- end
44
-
45
- describe Gecode::Raw::Space, ' (new)' do
46
- before do
47
- @space = Gecode::Raw::Space.new
48
- end
49
-
50
- it 'should return nil when requesting int variables' do
51
- @space.int_var(0).should be_nil
52
- end
53
-
54
- it 'should return nil when requesting bool variables' do
55
- @space.bool_var(0).should be_nil
56
- end
57
-
58
- it_should_behave_like 'Space'
59
- end
60
-
61
- describe Gecode::Raw::Space, ' (with items)' do
62
- before do
63
- @space = Gecode::Raw::Space.new
64
- @first = @space.new_int_vars([1, 4]).first
65
- @second = @space.new_int_vars([-5, 5]).first
66
- end
67
-
68
- it_should_behave_like 'Space'
69
-
70
- it 'should give int variables with the correct domains' do
71
- @space.int_var(@first).min.should equal(1)
72
- @space.int_var(@first).max.should equal(4)
73
- @space.int_var(@second).min.should equal(-5)
74
- @space.int_var(@second).max.should equal(5)
75
- end
76
- end