gecoder 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/COPYING +17 -0
  2. data/LGPL-LICENSE +458 -0
  3. data/README +20 -0
  4. data/Rakefile +6 -0
  5. data/ext/extconf.rb +29 -0
  6. data/ext/missing.cpp +295 -0
  7. data/ext/missing.h +116 -0
  8. data/ext/vararray.cpp +312 -0
  9. data/ext/vararray.h +146 -0
  10. data/lib/gecoder.rb +4 -0
  11. data/lib/gecoder/bindings.rb +7 -0
  12. data/lib/gecoder/bindings/bindings.rb +2055 -0
  13. data/lib/gecoder/interface.rb +6 -0
  14. data/lib/gecoder/interface/binding_changes.rb +111 -0
  15. data/lib/gecoder/interface/branch.rb +102 -0
  16. data/lib/gecoder/interface/constraints.rb +10 -0
  17. data/lib/gecoder/interface/constraints/distinct.rb +15 -0
  18. data/lib/gecoder/interface/constraints/linear.rb +158 -0
  19. data/lib/gecoder/interface/constraints/relation.rb +76 -0
  20. data/lib/gecoder/interface/enum_wrapper.rb +64 -0
  21. data/lib/gecoder/interface/model.rb +130 -0
  22. data/lib/gecoder/interface/search.rb +23 -0
  23. data/vendor/rust/README +28 -0
  24. data/vendor/rust/bin/cxxgenerator.rb +93 -0
  25. data/vendor/rust/include/rust_checks.hh +115 -0
  26. data/vendor/rust/include/rust_conversions.hh +103 -0
  27. data/vendor/rust/rust.rb +67 -0
  28. data/vendor/rust/rust/attribute.rb +51 -0
  29. data/vendor/rust/rust/bindings.rb +172 -0
  30. data/vendor/rust/rust/class.rb +334 -0
  31. data/vendor/rust/rust/constants.rb +48 -0
  32. data/vendor/rust/rust/container.rb +110 -0
  33. data/vendor/rust/rust/cppifaceparser.rb +129 -0
  34. data/vendor/rust/rust/cwrapper.rb +72 -0
  35. data/vendor/rust/rust/cxxclass.rb +98 -0
  36. data/vendor/rust/rust/element.rb +81 -0
  37. data/vendor/rust/rust/enum.rb +63 -0
  38. data/vendor/rust/rust/function.rb +407 -0
  39. data/vendor/rust/rust/namespace.rb +61 -0
  40. data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
  41. data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
  42. data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
  43. data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
  44. data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
  45. data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
  46. data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
  47. data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
  48. data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +91 -0
  49. data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
  50. data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +12 -0
  51. data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
  52. data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
  53. data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
  54. data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
  55. data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
  56. data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
  57. data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
  58. data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
  59. data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +5 -0
  60. data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
  61. data/vendor/rust/rust/type.rb +98 -0
  62. data/vendor/rust/test/Makefile +4 -0
  63. data/vendor/rust/test/constants.rb +35 -0
  64. data/vendor/rust/test/cppclass.cc +40 -0
  65. data/vendor/rust/test/cppclass.hh +63 -0
  66. data/vendor/rust/test/cppclass.rb +59 -0
  67. data/vendor/rust/test/cwrapper.c +74 -0
  68. data/vendor/rust/test/cwrapper.h +41 -0
  69. data/vendor/rust/test/cwrapper.rb +56 -0
  70. data/vendor/rust/test/dummyclass.hh +31 -0
  71. data/vendor/rust/test/lib/extension-test.rb +98 -0
  72. data/vendor/rust/test/test-constants.rb +43 -0
  73. data/vendor/rust/test/test-cppclass.rb +82 -0
  74. data/vendor/rust/test/test-cwrapper.rb +77 -0
  75. metadata +144 -0
data/README ADDED
@@ -0,0 +1,20 @@
1
+ == Gecode/R
2
+
3
+ Gecode/R is a Ruby interface to Gecode, an open, free and efficient environment
4
+ for developing constraint-based systems and applications.
5
+
6
+ == Installation
7
+
8
+ Gecode/R requires Gecode 1.3.1, which can be downloaded from
9
+ http://www.gecode.org/download.html . See
10
+ http://www.gecode.org/gecode-doc-latest/PageComp.html for the installation
11
+ instructions.
12
+
13
+ === Installing from gem
14
+
15
+ gem install gecoder
16
+
17
+ === Building the gem
18
+
19
+ rake gem
20
+ gem install pkg/gecoder-0.x.gem
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ require 'tasks/all_tasks'
data/ext/extconf.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'mkmf'
2
+ require 'pathname'
3
+
4
+ # Find the Gecode libraries.
5
+ find_library("gecodeint", "" )
6
+ find_library("gecodekernel", "")
7
+ find_library("gecodeminimodel", "")
8
+ find_library("gecodesearch", "")
9
+ find_library("gecodeset", "")
10
+
11
+ # Set up some important locations.
12
+ ROOT = Pathname.new(File.dirname(__FILE__) + '/..').realpath
13
+ RUST_INCLUDES = "#{ROOT}/vendor/rust/include"
14
+ BINDINGS_DIR = "#{ROOT}/lib/gecoder/bindings"
15
+ EXT_DIR = "#{ROOT}/ext"
16
+ ORIGINAL_DIR = Pathname.new('.').realpath
17
+
18
+ cppflags = "-I#{RUST_INCLUDES} -I#{EXT_DIR}"
19
+ with_cppflags(cppflags) {
20
+ find_header("rust_conversions.hh", RUST_INCLUDES)
21
+ find_header("rust_checks.hh", RUST_INCLUDES)
22
+ }
23
+
24
+ # Load the specification of the bindings. This creates the headers in the
25
+ # current directory.
26
+ load "#{BINDINGS_DIR}/bindings.rb"
27
+
28
+ # Create the makefile.
29
+ create_makefile("gecode")
data/ext/missing.cpp ADDED
@@ -0,0 +1,295 @@
1
+ /** Copyright (c) 2007, David Cuadrado <krawek@gmail.com>
2
+ * All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * 1. Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * 2. Redistributions in binary form must reproduce the above copyright
10
+ * notice, this list of conditions and the following disclaimer in the
11
+ * documentation and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
17
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23
+ * POSSIBILITY OF SUCH DAMAGE.
24
+ **/
25
+
26
+ #include "missing.h"
27
+
28
+ #include <iostream>
29
+ #include <map>
30
+
31
+ namespace Gecode {
32
+
33
+ struct MBranchingDesc::Private
34
+ {
35
+ const Gecode::BranchingDesc *ptr;
36
+ };
37
+
38
+ MBranchingDesc::MBranchingDesc() : d(new Private)
39
+ {
40
+
41
+ }
42
+
43
+ MBranchingDesc::~MBranchingDesc()
44
+ {
45
+ delete d;
46
+ }
47
+
48
+ void MBranchingDesc::setPtr(const Gecode::BranchingDesc *desc)
49
+ {
50
+ d->ptr = desc;
51
+ }
52
+
53
+ const Gecode::BranchingDesc *MBranchingDesc::ptr() const
54
+ {
55
+ return d->ptr;
56
+ }
57
+
58
+ int MBranchingDesc::alternatives() const
59
+ {
60
+ if(d->ptr) return d->ptr->alternatives();
61
+
62
+ return -1;
63
+ }
64
+
65
+ int MBranchingDesc::size() const
66
+ {
67
+ if(d->ptr) return d->ptr->size();
68
+
69
+ return -1;
70
+ }
71
+
72
+
73
+ /////////////////////////////////////
74
+
75
+ struct ltstr
76
+ {
77
+ bool operator()(const char* s1, const char* s2) const
78
+ {
79
+ return strcmp(s1, s2) < 0;
80
+ }
81
+ };
82
+
83
+ typedef std::map<const char *, MIntVarArray *, ltstr> IntVarArrays;
84
+ typedef std::map<const char *, MBoolVarArray *, ltstr> BoolVarArrays;
85
+ typedef std::map<const char *, MSetVarArray *, ltstr> SetVarArrays;
86
+
87
+ struct MSpace::Private
88
+ {
89
+ Private()
90
+ {
91
+ description = new MBranchingDesc;;
92
+ }
93
+
94
+ ~Private()
95
+ {
96
+ // {
97
+ // IntVarArrays::iterator it, eend = intArrays.end();
98
+ //
99
+ // for(it = intArrays.begin(); it != eend; it++)
100
+ // {
101
+ // delete (*it).second;
102
+ // }
103
+ // }
104
+ // {
105
+ // SetVarArrays::iterator it, eend = setArrays.end();
106
+ //
107
+ // for(it = setArrays.begin(); it != eend; it++)
108
+ // {
109
+ // delete (*it).second;
110
+ // }
111
+ // }
112
+ //
113
+ // {
114
+ // BoolVarArrays::iterator it, eend = boolArrays.end();
115
+ //
116
+ // for(it = boolArrays.begin(); it != eend; it++)
117
+ // {
118
+ // delete (*it).second;
119
+ // }
120
+ // }
121
+
122
+ delete description;
123
+ }
124
+
125
+ IntVarArrays intArrays;
126
+ BoolVarArrays boolArrays;
127
+ SetVarArrays setArrays;
128
+
129
+ MBranchingDesc *description;
130
+ };
131
+
132
+ MSpace::MSpace() : d(new Private())
133
+ {
134
+ }
135
+
136
+ MSpace::MSpace(MSpace& s, bool share) : Gecode::Space(share, s), d(new Private)
137
+ {
138
+ {
139
+ IntVarArrays::iterator it, eend = s.d->intArrays.end();
140
+
141
+ for(it = s.d->intArrays.begin(); it != eend; it++)
142
+ {
143
+ Gecode::MIntVarArray *iva = new Gecode::MIntVarArray(this, (*it).second->ptr()->size());
144
+
145
+ iva->ptr()->update(this, share, *(*it).second->ptr() );
146
+
147
+ own(iva, (*it).first);
148
+ }
149
+ }
150
+ {
151
+ BoolVarArrays::iterator it, eend = s.d->boolArrays.end();
152
+
153
+ for(it = s.d->boolArrays.begin(); it != eend; it++)
154
+ {
155
+ Gecode::MBoolVarArray *bva = new Gecode::MBoolVarArray;
156
+
157
+ bva->ptr()->update(this, share, *(*it).second->ptr() );
158
+
159
+ own(bva, (*it).first);
160
+ }
161
+ }
162
+ {
163
+ SetVarArrays::iterator it, eend = s.d->setArrays.end();
164
+
165
+ for(it = s.d->setArrays.begin(); it != eend; it++)
166
+ {
167
+ Gecode::MSetVarArray *sva = new Gecode::MSetVarArray;
168
+ sva->ptr()->update(this, share, *(*it).second->ptr() );
169
+
170
+ own(sva, (*it).first);
171
+ }
172
+ }
173
+ }
174
+
175
+
176
+
177
+ MSpace::~MSpace()
178
+ {
179
+ delete d;
180
+ }
181
+
182
+ Gecode::Space *MSpace::copy(bool share)
183
+ {
184
+ return new MSpace(*this,share);
185
+ }
186
+
187
+ void MSpace::own(Gecode::MIntVarArray *iva, const char *name)
188
+ {
189
+ d->intArrays[name] = iva;
190
+ }
191
+
192
+ void MSpace::own(Gecode::MBoolVarArray *bva, const char *name)
193
+ {
194
+ d->boolArrays[name] = bva;
195
+ }
196
+
197
+ void MSpace::own(Gecode::MSetVarArray *sva, const char *name)
198
+ {
199
+ d->setArrays[name] = sva;
200
+ }
201
+
202
+ Gecode::MIntVarArray *MSpace::intVarArray(const char *name) const
203
+ {
204
+ if ( d->intArrays.find(name) == d->intArrays.end() ) return 0;
205
+ return d->intArrays[name];
206
+ }
207
+
208
+ Gecode::MBoolVarArray *MSpace::boolVarArray(const char *name ) const
209
+ {
210
+ if ( d->boolArrays.find(name) == d->boolArrays.end() ) return 0;
211
+ return d->boolArrays[name];
212
+ }
213
+
214
+ Gecode::MSetVarArray *MSpace::setVarArray(const char *name ) const
215
+ {
216
+ if ( d->setArrays.find(name) == d->setArrays.end() ) return 0;
217
+ return d->setArrays[name];
218
+ }
219
+
220
+
221
+ Gecode::MBranchingDesc *MSpace::mdescription()
222
+ {
223
+ if(!this->failed() || !d->description->ptr() )
224
+ {
225
+ d->description->setPtr(this->description());
226
+ }
227
+ return d->description;
228
+ }
229
+
230
+ void MSpace::debug()
231
+ {
232
+ std::cout << "DEBUG: "<< d->intArrays["default"]->ptr()->size() << std::endl;
233
+ }
234
+
235
+
236
+ // DFS
237
+ 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))
238
+ {
239
+ }
240
+
241
+ MDFS::~MDFS()
242
+ {
243
+ }
244
+
245
+
246
+ namespace Search {
247
+
248
+ // Stop
249
+
250
+ struct MStop::Private
251
+ {
252
+ Gecode::Search::TimeStop *ts;
253
+ Gecode::Search::FailStop *fs;
254
+ };
255
+
256
+ MStop::MStop() : d(new Private)
257
+ {
258
+ d->ts = 0;
259
+ d->fs = 0;
260
+ }
261
+
262
+ MStop::MStop(int fails, int time) : d(new Private)
263
+ {
264
+ d->ts = new Search::TimeStop(time);
265
+ d->fs = new Search::FailStop(fails);
266
+ }
267
+
268
+ MStop::~MStop()
269
+ {
270
+ }
271
+
272
+ bool MStop::stop(const Gecode::Search::Statistics &s)
273
+ {
274
+ if (!d->fs || d->ts)
275
+ return false;
276
+ return d->fs->stop(s) || d->ts->stop(s);
277
+ }
278
+
279
+ Gecode::Search::Stop* MStop::create(int fails, int time)
280
+ {
281
+ if (fails < 0 && time < 0) return 0;
282
+ if (fails < 0) return new Search::TimeStop( time );
283
+
284
+ if (time < 0) return new Search::FailStop(fails);
285
+
286
+ return new MStop(fails, time);
287
+ }
288
+
289
+
290
+ }
291
+
292
+ }
293
+
294
+
295
+
data/ext/missing.h ADDED
@@ -0,0 +1,116 @@
1
+ /** Copyright (c) 2007, David Cuadrado <krawek@gmail.com>
2
+ * All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * 1. Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * 2. Redistributions in binary form must reproduce the above copyright
10
+ * notice, this list of conditions and the following disclaimer in the
11
+ * documentation and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
17
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23
+ * POSSIBILITY OF SUCH DAMAGE.
24
+ **/
25
+
26
+ #ifndef __MISSING_CLASSES_H
27
+ #define __MISSING_CLASSES_H
28
+
29
+ #include <ruby.h>
30
+
31
+ #include <gecode/kernel.hh>
32
+ #include <gecode/int.hh>
33
+ #include <gecode/search.hh>
34
+ #include <gecode/minimodel.hh>
35
+ #include <gecode/set.hh>
36
+
37
+ #include "vararray.h"
38
+
39
+ namespace Gecode {
40
+
41
+ class MBranchingDesc
42
+ {
43
+ public:
44
+ MBranchingDesc();
45
+ ~MBranchingDesc();
46
+
47
+ void setPtr(const Gecode::BranchingDesc *);
48
+ const Gecode::BranchingDesc *ptr() const;
49
+
50
+ int alternatives() const;
51
+ int size() const;
52
+
53
+ private:
54
+ struct Private;
55
+ Private *const d;
56
+ };
57
+
58
+ class MSpace : public Space
59
+ {
60
+ public:
61
+ MSpace();
62
+ explicit MSpace(MSpace& s, bool share=true);
63
+ ~MSpace();
64
+ Gecode::Space *copy(bool share);
65
+
66
+ void own(Gecode::MIntVarArray *iva, const char *name);
67
+ void own(Gecode::MBoolVarArray *bva, const char *name);
68
+ void own(Gecode::MSetVarArray *sva, const char *name);
69
+
70
+ Gecode::MIntVarArray *intVarArray(const char *name ) const;
71
+ Gecode::MBoolVarArray *boolVarArray(const char *name ) const;
72
+ Gecode::MSetVarArray *setVarArray(const char *name) const;
73
+
74
+ Gecode::MBranchingDesc *mdescription();
75
+
76
+ void debug();
77
+
78
+ private:
79
+ struct Private;
80
+ Private *const d;
81
+ };
82
+
83
+ class MDFS : public Gecode::Search::DFS
84
+ {
85
+ public:
86
+ MDFS(MSpace *space, unsigned int c_d, unsigned int a_d, Search::Stop* st = 0);
87
+ ~MDFS();
88
+ };
89
+
90
+ namespace Search {
91
+ class MStop : public Gecode::Search::Stop
92
+ {
93
+ private:
94
+ MStop(int fails, int time);
95
+
96
+ public:
97
+ MStop();
98
+ ~MStop();
99
+
100
+ bool stop (const Gecode::Search::Statistics &s);
101
+ static Gecode::Search::Stop* create(int fails, int time);
102
+
103
+
104
+ private:
105
+ struct Private;
106
+ Private *const d;
107
+ };
108
+
109
+ }
110
+
111
+
112
+ }
113
+
114
+ #endif
115
+
116
+