gecoder 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGES +17 -2
  2. data/README +7 -1
  3. data/Rakefile +4 -0
  4. data/lib/gecoder/interface/constraints/bool/boolean.rb +1 -4
  5. data/lib/gecoder/interface/constraints/int/arithmetic.rb +77 -0
  6. data/lib/gecoder/interface/constraints/int/domain.rb +50 -0
  7. data/lib/gecoder/interface/constraints/int/linear.rb +12 -44
  8. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +72 -0
  9. data/lib/gecoder/interface/constraints/int_enum/channel.rb +32 -0
  10. data/lib/gecoder/interface/constraints/int_enum/count.rb +90 -0
  11. data/lib/gecoder/interface/constraints/int_enum/distinct.rb +3 -8
  12. data/lib/gecoder/interface/constraints/int_enum/element.rb +75 -0
  13. data/lib/gecoder/interface/constraints/int_enum/equality.rb +31 -0
  14. data/lib/gecoder/interface/constraints/int_enum/sort.rb +104 -0
  15. data/lib/gecoder/interface/constraints/int_enum_constraints.rb +6 -0
  16. data/lib/gecoder/interface/constraints/int_var_constraints.rb +2 -0
  17. data/lib/gecoder/interface/constraints/reifiable_constraints.rb +21 -0
  18. data/lib/gecoder/interface/constraints.rb +57 -6
  19. data/lib/gecoder/interface/enum_matrix.rb +64 -0
  20. data/lib/gecoder/interface/enum_wrapper.rb +33 -5
  21. data/lib/gecoder/interface/model.rb +36 -6
  22. data/lib/gecoder/interface.rb +1 -0
  23. data/lib/gecoder/version.rb +4 -0
  24. data/lib/gecoder.rb +1 -0
  25. data/specs/binding_changes.rb +72 -0
  26. data/specs/bool_var.rb +20 -0
  27. data/specs/branch.rb +104 -0
  28. data/specs/constraints/arithmetic.rb +227 -0
  29. data/specs/constraints/boolean.rb +132 -0
  30. data/specs/constraints/channel.rb +55 -0
  31. data/specs/constraints/constraint_helper.rb +48 -0
  32. data/specs/constraints/constraints.rb +28 -0
  33. data/specs/constraints/count.rb +99 -0
  34. data/specs/constraints/distinct.rb +99 -0
  35. data/specs/constraints/domain.rb +56 -0
  36. data/specs/constraints/element.rb +128 -0
  37. data/specs/constraints/equality.rb +30 -0
  38. data/specs/constraints/linear.rb +166 -0
  39. data/specs/constraints/reification_sugar.rb +92 -0
  40. data/specs/constraints/relation.rb +72 -0
  41. data/specs/constraints/sort.rb +173 -0
  42. data/specs/enum_matrix.rb +43 -0
  43. data/specs/enum_wrapper.rb +100 -0
  44. data/specs/int_var.rb +108 -0
  45. data/specs/model.rb +84 -0
  46. data/specs/search.rb +157 -0
  47. data/specs/spec_helper.rb +63 -0
  48. data/specs/tmp +135 -0
  49. data/tasks/all_tasks.rb +1 -0
  50. data/tasks/distribution.rake +64 -0
  51. data/tasks/rcov.rake +17 -0
  52. data/tasks/specs.rake +16 -0
  53. data/tasks/svn.rake +11 -0
  54. data/tasks/website.rake +58 -0
  55. data/vendor/rust/include/rust_conversions.hh +1 -2
  56. metadata +53 -2
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../lib/gecoder'
2
+
3
+ module CustomVarMatchers
4
+ class HaveDomain
5
+ def initialize(expected)
6
+ @expected = expected.to_a
7
+ end
8
+
9
+ def matches?(target)
10
+ @target = target
11
+ return false unless @target.size == @expected.size
12
+ @expected.each do |element|
13
+ return false unless @target.in(element)
14
+ end
15
+ return true
16
+ end
17
+
18
+ def failure_message
19
+ "expected #{@target.inspect} to have domain #{@expected.inspect}"
20
+ end
21
+
22
+ def negative_failure_message
23
+ "expected #{@target.inspect} not to have domain #{@expected.inspect}"
24
+ end
25
+ end
26
+
27
+ # Tests whether a variable has the expected domain.
28
+ def have_domain(expected)
29
+ HaveDomain.new(expected)
30
+ end
31
+
32
+ class IsAlias
33
+ def initialize(expected)
34
+ @expected = expected.to_a
35
+ end
36
+
37
+ def matches?(target)
38
+ @target = target
39
+ return false unless @target.size == @expected.size
40
+ @expected.each do |element|
41
+ return false unless @target.in(element)
42
+ end
43
+ return true
44
+ end
45
+
46
+ def failure_message
47
+ "expected #{@target.inspect} to be an alias of #{@expected.inspect}"
48
+ end
49
+
50
+ def negative_failure_message
51
+ "expected #{@target.inspect} not to be an alias of #{@expected.inspect}"
52
+ end
53
+ end
54
+
55
+ # Tests whether a method with a specified name is the alias of another.
56
+ def is_alias_of(expected)
57
+ HaveDomain.new(expected)
58
+ end
59
+ end
60
+
61
+ Spec::Runner.configure do |config|
62
+ config.include(CustomVarMatchers)
63
+ end
data/specs/tmp ADDED
@@ -0,0 +1,135 @@
1
+ Idea: Write constraints in separate modules and then include the modules in
2
+ the respective place.
3
+
4
+
5
+ =begin
6
+ it 'should handle relation with integer variables' do
7
+ fail
8
+ end
9
+
10
+ it 'should handle propagation strength domain' do
11
+ fail
12
+ end
13
+
14
+ it 'should handle propagation strength val' do
15
+ fail
16
+ end
17
+
18
+ it 'should handle propagation strength range' do
19
+ fail
20
+ end
21
+
22
+ it 'should raise error for unknown propagation strengths' do
23
+ fail
24
+ end
25
+
26
+ it 'should handle reification' do
27
+ fail
28
+ end
29
+ =end
30
+
31
+ =begin
32
+ it 'should handle variables as right hand side' do
33
+ (@x + @y).must == @z
34
+ sol = @model.solution
35
+ x = sol.x.val
36
+ y = sol.y.val
37
+ z = sol.z.val
38
+ (x + y).should equal(z)
39
+ end
40
+
41
+ it 'should handle multiplication with a constant' do
42
+ Gecode::Raw.should_receive(:linear).once.with(@model.active_space,
43
+ an_instance_of(Gecode::Raw::IntVarArray), Gecode::Raw::IRT_EQ, 1,
44
+ Gecode::Raw::ICL_DEF).and_return{ |s, arr, irt, res, strength| arr }
45
+ ((10*@x + @y).must == 1).should contain_vars_with_domains(@x_dom, @y_dom)
46
+ end
47
+
48
+ it 'should handle addition with a constant' do
49
+
50
+ end
51
+
52
+ it 'should handle relation...' do
53
+
54
+ end
55
+ =end
56
+
57
+
58
+
59
+ module CustomVarMatchers
60
+ class ContainVarsWithDomains
61
+ def initialize(*expected_domains)
62
+ @expected_domains = expected_domains
63
+ end
64
+
65
+ def matches?(target)
66
+ @target = target
67
+ return false unless @target.kind_of? Gecode::Raw::IntVarArray
68
+ return false unless @target.size == @expected_domains.size
69
+ @target.size do |i|
70
+ var = @target.at(i)
71
+ detected = @expected_domains.detect do |domain|
72
+ variable_has_domain?(var, domain)
73
+ end
74
+ unless detected.nil?
75
+ @expected_domains.delete(@expected_domains.index(detected))
76
+ else
77
+ return false
78
+ end
79
+ end
80
+ return true
81
+ end
82
+
83
+ def failure_message
84
+ "expected #{@target.inspect} to contain variables with domains " +
85
+ @expected_vars.inspect
86
+ end
87
+
88
+ def negative_failure_message
89
+ "expected #{@target.inspect} to not contain variables with domains " +
90
+ @expected_vars.inspect
91
+ end
92
+
93
+ private
94
+
95
+ def variable_has_domain?(target, expected)
96
+ return false unless target.size == expected.size
97
+ expected.each do |element|
98
+ return false unless target.in(element)
99
+ end
100
+ return true
101
+ end
102
+ end
103
+
104
+ # Tests whether an integer variables array contains variables with the
105
+ # expected domains (in any order given).
106
+ def contain_domains(expected)
107
+ ContainVarsWithDomains.new(expected)
108
+ end
109
+ end
110
+
111
+ Spec::Runner.configure do |config|
112
+ config.include(CustomVarMatchers)
113
+ end
114
+
115
+
116
+
117
+
118
+ Left:
119
+ * Sorted
120
+ * Arithmetic
121
+
122
+
123
+ xs.occurrences_of(y).must == z
124
+ xs.occurrences_of(3).must >= 5
125
+ xs.count(y).must == z
126
+ xs.number_of(y).must == z
127
+
128
+
129
+ ys.sorted.must == xs
130
+ ys.sorted_with(zs).must == xs
131
+
132
+ ys.sort.must == xs
133
+ ys.must_be.xs.sorted
134
+ ys.must_be.sort(xs)
135
+ ys.sort.must_be.xs
@@ -0,0 +1 @@
1
+ Dir["#{File.dirname(__FILE__)}/*.rake"].each { |ext| load ext }
@@ -0,0 +1,64 @@
1
+ require 'lib/gecoder/version'
2
+
3
+ PKG_NAME = 'gecoder'
4
+ PKG_VERSION = GecodeR::VERSION
5
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
6
+
7
+ desc 'Generate RDoc'
8
+ rd = Rake::RDocTask.new do |rdoc|
9
+ rdoc.rdoc_dir = "#{File.dirname(__FILE__)}/../doc/output/rdoc"
10
+ rdoc.options << '--title' << 'Gecode/R' << '--line-numbers' << '--inline-source' << '--main' << 'README'
11
+ rdoc.rdoc_files.include('README', 'lib/**/*.rb')
12
+ end
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = PKG_NAME
16
+ s.version = GecodeR::VERSION
17
+ s.summary = 'Ruby interface to Gecode, an environment for constraint programming.'
18
+
19
+ s.files = FileList[
20
+ '[A-Z]*',
21
+ 'lib/**/*.rb',
22
+ 'examples/**/*',
23
+ 'src/**/*',
24
+ 'vendor/**/*',
25
+ 'tasks/**/*',
26
+ 'specs/**/*',
27
+ 'ext/*'
28
+ ].to_a
29
+ s.require_path = 'lib'
30
+ s.extensions << 'ext/extconf.rb'
31
+
32
+ s.has_rdoc = true
33
+ s.rdoc_options = rd.options
34
+ s.extra_rdoc_files = rd.rdoc_files
35
+
36
+ s.autorequire = 'gecoder'
37
+ s.author = ["Gecode/R Development Team"]
38
+ s.email = "gecoder-devel@rubyforge.org"
39
+ s.homepage = "http://gecoder.rubyforge.org"
40
+ s.rubyforge_project = "gecoder"
41
+ end
42
+
43
+ desc 'Generate Gem'
44
+ Rake::GemPackageTask.new(spec) do |pkg|
45
+ pkg.need_zip = true
46
+ pkg.need_tar = true
47
+ end
48
+
49
+ desc "Publish packages on RubyForge"
50
+ task :publish_packages => [:verify_user, :package] do
51
+ release_files = FileList[
52
+ "pkg/#{PKG_FILE_NAME}.gem",
53
+ "pkg/#{PKG_FILE_NAME}.tgz",
54
+ "pkg/#{PKG_FILE_NAME}.zip"
55
+ ]
56
+ require 'meta_project'
57
+ require 'rake/contrib/xforge'
58
+
59
+ Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |xf|
60
+ xf.user_name = ENV['RUBYFORGE_USER']
61
+ xf.files = release_files.to_a
62
+ xf.release_name = "Gecode/R #{PKG_VERSION}"
63
+ end
64
+ end
data/tasks/rcov.rake ADDED
@@ -0,0 +1,17 @@
1
+ require 'spec/rake/spectask'
2
+ require 'spec/rake/verify_rcov'
3
+
4
+ RCOV_DIR = "#{File.dirname(__FILE__)}/../doc/output/coverage"
5
+
6
+ desc "Run all specs with rcov"
7
+ Spec::Rake::SpecTask.new(:rcov) do |t|
8
+ t.spec_files = FileList['specs/**/*.rb']
9
+ t.rcov = true
10
+ t.rcov_opts = ['--exclude examples', '--exclude specs']
11
+ t.rcov_dir = RCOV_DIR
12
+ end
13
+
14
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |t|
15
+ t.threshold = 100.0
16
+ t.index_html = "#{RCOV_DIR}/index.html"
17
+ end
data/tasks/specs.rake ADDED
@@ -0,0 +1,16 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ spec_files = FileList['specs/**/*.rb']
4
+
5
+ desc 'Run all specs'
6
+ Spec::Rake::SpecTask.new('specs') do |t|
7
+ t.spec_opts = ["--format", "specdoc"]
8
+ t.libs = ['lib']
9
+ t.spec_files = spec_files
10
+ end
11
+
12
+ desc 'Generate an rspec html report'
13
+ Spec::Rake::SpecTask.new('spec_html') do |t|
14
+ t.spec_files = spec_files
15
+ t.spec_opts = ['--format html:doc/output/rspec.html','--backtrace']
16
+ end
data/tasks/svn.rake ADDED
@@ -0,0 +1,11 @@
1
+ require 'lib/gecoder/version'
2
+
3
+ desc "Tag the release in svn"
4
+ task :tag do
5
+ from = `svn info`.match(/Repository Root: (.*)/n)[1] + '/trunk'
6
+ to = from.gsub(/trunk/, "tags/gecoder-#{GecodeR::VERSION}")
7
+
8
+ puts "Creating tag in SVN"
9
+ tag_cmd = "svn cp #{from} #{to} -m \"Tag release Gecode/R #{GecodeR::VERSION}\""
10
+ `#{tag_cmd}` ; raise "ERROR: #{tag_cmd}" unless $? == 0
11
+ end
@@ -0,0 +1,58 @@
1
+ require 'rake/contrib/rubyforgepublisher'
2
+
3
+ desc 'Regenerates the contents of the website'
4
+ task :website do
5
+ Rake::Task[:clobber].invoke
6
+ mkdir 'doc/output'
7
+ begin
8
+ Rake::Task[:spec_html].invoke
9
+ rescue
10
+ # The task will fail unless all specs pass, we want it to continue.
11
+ end
12
+ Rake::Task[:rdoc].invoke
13
+ begin
14
+ Rake::Task[:rcov].invoke
15
+ rescue
16
+ # The task will fail unless all specs pass, we want it to continue.
17
+ end
18
+ WebsiteRakeHelpers.webgen
19
+ end
20
+
21
+ desc 'Removes generated documentation'
22
+ task :clobber do
23
+ WebsiteRakeHelpers.clobber
24
+ end
25
+
26
+ task :verify_user do
27
+ raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
28
+ end
29
+
30
+ desc "Uploads the website to RubyForge"
31
+ task :publish_website => [:verify_user, :website] do
32
+ publisher = Rake::SshDirPublisher.new(
33
+ "#{ENV['RUBYFORGE_USER']}@rubyforge.org",
34
+ "/var/www/gforge-projects/gecoder",
35
+ "doc/output"
36
+ )
37
+ publisher.upload
38
+ end
39
+
40
+ module WebsiteRakeHelpers
41
+ module_function
42
+
43
+ # Remove generated documentation.
44
+ def clobber
45
+ rm_rf 'doc/output'
46
+ end
47
+
48
+ # Generates the website with webgen.
49
+ def webgen
50
+ Dir.chdir 'doc' do
51
+ output = nil
52
+ IO.popen('webgen 2>&1') do |io|
53
+ output = io.read
54
+ end
55
+ raise "ERROR while running webgen: #{output}" if output =~ /ERROR/n || $? != 0
56
+ end
57
+ end
58
+ end
@@ -67,8 +67,7 @@ static inline VALUE cxx2ruby(double val) {
67
67
  static inline int *ruby2intArray(VALUE rval, int argn = -1) {
68
68
  int i;
69
69
  RArray *array = RARRAY(rval);
70
- // int *ret = new int(array->len);
71
- int ret[array->len];
70
+ int* ret = (int*)malloc(array->len*sizeof(int)); // FIXME: Leak!!!
72
71
  for(i = 0; i < array->len; i++)
73
72
  {
74
73
  ret[i] = NUM2INT(array->ptr[i]);
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: gecoder
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-06-26 00:00:00 +02:00
6
+ version: 0.4.0
7
+ date: 2007-07-03 00:00:00 +02:00
8
8
  summary: Ruby interface to Gecode, an environment for constraint programming.
9
9
  require_paths:
10
10
  - lib
@@ -37,6 +37,7 @@ files:
37
37
  - lib/gecoder.rb
38
38
  - lib/gecoder/interface.rb
39
39
  - lib/gecoder/bindings.rb
40
+ - lib/gecoder/version.rb
40
41
  - lib/gecoder/interface/search.rb
41
42
  - lib/gecoder/interface/model.rb
42
43
  - lib/gecoder/interface/constraints.rb
@@ -44,13 +45,22 @@ files:
44
45
  - lib/gecoder/interface/branch.rb
45
46
  - lib/gecoder/interface/enum_wrapper.rb
46
47
  - lib/gecoder/interface/variables.rb
48
+ - lib/gecoder/interface/enum_matrix.rb
47
49
  - lib/gecoder/interface/constraints/reifiable_constraints.rb
48
50
  - lib/gecoder/interface/constraints/bool_var_constraints.rb
49
51
  - lib/gecoder/interface/constraints/int_var_constraints.rb
50
52
  - lib/gecoder/interface/constraints/int_enum_constraints.rb
51
53
  - lib/gecoder/interface/constraints/bool/boolean.rb
52
54
  - lib/gecoder/interface/constraints/int/linear.rb
55
+ - lib/gecoder/interface/constraints/int/domain.rb
56
+ - lib/gecoder/interface/constraints/int/arithmetic.rb
53
57
  - lib/gecoder/interface/constraints/int_enum/distinct.rb
58
+ - lib/gecoder/interface/constraints/int_enum/equality.rb
59
+ - lib/gecoder/interface/constraints/int_enum/channel.rb
60
+ - lib/gecoder/interface/constraints/int_enum/element.rb
61
+ - lib/gecoder/interface/constraints/int_enum/count.rb
62
+ - lib/gecoder/interface/constraints/int_enum/sort.rb
63
+ - lib/gecoder/interface/constraints/int_enum/arithmetic.rb
54
64
  - lib/gecoder/bindings/bindings.rb
55
65
  - vendor/rust
56
66
  - vendor/rust/test
@@ -111,6 +121,37 @@ files:
111
121
  - vendor/rust/rust/templates/ClassDeclarations.rusttpl
112
122
  - vendor/rust/rust/templates/MethodInitBinding.rusttpl
113
123
  - vendor/rust/rust/templates/CxxMethodStub.rusttpl
124
+ - tasks/rcov.rake
125
+ - tasks/all_tasks.rb
126
+ - tasks/specs.rake
127
+ - tasks/distribution.rake
128
+ - tasks/website.rake
129
+ - tasks/svn.rake
130
+ - specs/search.rb
131
+ - specs/model.rb
132
+ - specs/tmp
133
+ - specs/branch.rb
134
+ - specs/binding_changes.rb
135
+ - specs/spec_helper.rb
136
+ - specs/enum_wrapper.rb
137
+ - specs/int_var.rb
138
+ - specs/constraints
139
+ - specs/bool_var.rb
140
+ - specs/enum_matrix.rb
141
+ - specs/constraints/linear.rb
142
+ - specs/constraints/relation.rb
143
+ - specs/constraints/distinct.rb
144
+ - specs/constraints/constraint_helper.rb
145
+ - specs/constraints/constraints.rb
146
+ - specs/constraints/boolean.rb
147
+ - specs/constraints/reification_sugar.rb
148
+ - specs/constraints/domain.rb
149
+ - specs/constraints/equality.rb
150
+ - specs/constraints/channel.rb
151
+ - specs/constraints/element.rb
152
+ - specs/constraints/count.rb
153
+ - specs/constraints/sort.rb
154
+ - specs/constraints/arithmetic.rb
114
155
  - ext/missing.h
115
156
  - ext/extconf.rb
116
157
  - ext/vararray.cpp
@@ -130,6 +171,7 @@ extra_rdoc_files:
130
171
  - lib/gecoder.rb
131
172
  - lib/gecoder/interface.rb
132
173
  - lib/gecoder/bindings.rb
174
+ - lib/gecoder/version.rb
133
175
  - lib/gecoder/interface/search.rb
134
176
  - lib/gecoder/interface/model.rb
135
177
  - lib/gecoder/interface/constraints.rb
@@ -137,13 +179,22 @@ extra_rdoc_files:
137
179
  - lib/gecoder/interface/branch.rb
138
180
  - lib/gecoder/interface/enum_wrapper.rb
139
181
  - lib/gecoder/interface/variables.rb
182
+ - lib/gecoder/interface/enum_matrix.rb
140
183
  - lib/gecoder/interface/constraints/reifiable_constraints.rb
141
184
  - lib/gecoder/interface/constraints/bool_var_constraints.rb
142
185
  - lib/gecoder/interface/constraints/int_var_constraints.rb
143
186
  - lib/gecoder/interface/constraints/int_enum_constraints.rb
144
187
  - lib/gecoder/interface/constraints/bool/boolean.rb
145
188
  - lib/gecoder/interface/constraints/int/linear.rb
189
+ - lib/gecoder/interface/constraints/int/domain.rb
190
+ - lib/gecoder/interface/constraints/int/arithmetic.rb
146
191
  - lib/gecoder/interface/constraints/int_enum/distinct.rb
192
+ - lib/gecoder/interface/constraints/int_enum/equality.rb
193
+ - lib/gecoder/interface/constraints/int_enum/channel.rb
194
+ - lib/gecoder/interface/constraints/int_enum/element.rb
195
+ - lib/gecoder/interface/constraints/int_enum/count.rb
196
+ - lib/gecoder/interface/constraints/int_enum/sort.rb
197
+ - lib/gecoder/interface/constraints/int_enum/arithmetic.rb
147
198
  - lib/gecoder/bindings/bindings.rb
148
199
  executables: []
149
200