gecoder-with-gecode 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.rb +38 -0
  9. data/lib/gecoder/interface/constraints/bool/boolean.rb +56 -52
  10. data/lib/gecoder/interface/constraints/bool/channel.rb +1 -16
  11. data/lib/gecoder/interface/constraints/bool_enum/channel.rb +13 -8
  12. data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +48 -0
  13. data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
  14. data/lib/gecoder/interface/constraints/int/channel.rb +1 -13
  15. data/lib/gecoder/interface/constraints/int_enum/channel.rb +15 -35
  16. data/lib/gecoder/interface/constraints/int_enum/extensional.rb +130 -0
  17. data/lib/gecoder/interface/constraints/set/channel.rb +54 -0
  18. data/lib/gecoder/interface/constraints/set_enum/channel.rb +37 -6
  19. data/lib/gecoder/interface/constraints/set_var_constraints.rb +1 -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 +707 -706
  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
@@ -1,44 +0,0 @@
1
- require File.dirname(__FILE__) + '/example_helper'
2
-
3
- # An example of using the raw bindings. Solves the send+more=money problem.
4
-
5
- # Variables
6
- space = Gecode::Raw::Space.new
7
- letters = Gecode::Raw::IntVarArray.new(space, 8, 0, 9)
8
- space.own(letters, 'letters')
9
- s, e, n, d, m, o, r, y = (0..7).to_a.map{ |i| letters.at(i) }
10
-
11
- # Constraints
12
- Gecode::Raw::post(space, (s * 1000 + e * 100 + n * 10 + d +
13
- m * 1000 + o * 100 + r * 10 + e).
14
- equal(m * 10000 + o * 1000 + n * 100 + e * 10 + y ),
15
- Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
16
- Gecode::Raw::rel(space, s, Gecode::Raw::IRT_NQ, 0, Gecode::Raw::ICL_DEF,
17
- Gecode::Raw::PK_DEF)
18
- Gecode::Raw::rel(space, m, Gecode::Raw::IRT_NQ, 0, Gecode::Raw::ICL_DEF,
19
- Gecode::Raw::PK_DEF)
20
- Gecode::Raw::distinct(space, letters, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
21
-
22
- # Branching.
23
- Gecode::Raw::branch(space, letters,
24
- Gecode::Raw::INT_VAR_SIZE_MIN, Gecode::Raw::INT_VAL_MIN)
25
-
26
- # Search
27
- COPY_DIST = 16
28
- ADAPTATION_DIST = 4
29
- dfs = Gecode::Raw::DFS.new(space, COPY_DIST, ADAPTATION_DIST,
30
- Gecode::Raw::Search::Stop.new)
31
-
32
- space = dfs.next
33
- if space.nil?
34
- puts 'Failed'
35
- else
36
- puts 'Solution:'
37
- correct_letters = space.intVarArray('letters')
38
- arr = []
39
- correct_letters.size.times do |i|
40
- arr << correct_letters.at(i).val
41
- end
42
- puts arr.join(' ')
43
- end
44
-
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
-