ruby-minisat 1.14.2 → 2.2.0

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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -21
  3. data/Gemfile +4 -0
  4. data/LICENSE +3 -2
  5. data/README.md +42 -0
  6. data/Rakefile +1 -48
  7. data/examples/shikaku.rb +2 -2
  8. data/ext/minisat/extconf.rb +19 -4
  9. data/ext/minisat/minisat-wrap.cpp +11 -5
  10. data/ext/minisat/minisat.c +17 -3
  11. data/ext/minisat/minisat.h +1 -1
  12. data/minisat/minisat-2.2.0.tar.gz +0 -0
  13. data/minisat/{MiniSat_v1.14 → minisat}/LICENSE +2 -1
  14. data/minisat/minisat/README +24 -0
  15. data/minisat/minisat/core/Dimacs.h +89 -0
  16. data/minisat/minisat/core/Main.cc +192 -0
  17. data/minisat/minisat/core/Solver.cc +923 -0
  18. data/minisat/minisat/core/Solver.h +373 -0
  19. data/minisat/minisat/core/SolverTypes.h +407 -0
  20. data/minisat/minisat/mtl/Alg.h +84 -0
  21. data/minisat/minisat/mtl/Alloc.h +131 -0
  22. data/minisat/minisat/mtl/Heap.h +148 -0
  23. data/minisat/minisat/mtl/IntTypes.h +42 -0
  24. data/minisat/minisat/mtl/Map.h +193 -0
  25. data/minisat/minisat/mtl/Queue.h +69 -0
  26. data/minisat/{MiniSat_v1.14 → minisat/mtl}/Sort.h +14 -47
  27. data/minisat/minisat/mtl/Vec.h +130 -0
  28. data/minisat/minisat/mtl/XAlloc.h +45 -0
  29. data/minisat/minisat/mtl/config.mk +6 -0
  30. data/minisat/minisat/mtl/template.mk +107 -0
  31. data/minisat/minisat/simp/Main.cc +211 -0
  32. data/minisat/minisat/simp/SimpSolver.cc +717 -0
  33. data/minisat/minisat/simp/SimpSolver.h +197 -0
  34. data/minisat/minisat/utils/Options.cc +91 -0
  35. data/minisat/minisat/utils/Options.h +386 -0
  36. data/minisat/minisat/utils/ParseUtils.h +122 -0
  37. data/minisat/minisat/utils/System.cc +95 -0
  38. data/minisat/minisat/utils/System.h +60 -0
  39. data/ruby-minisat.gemspec +21 -0
  40. metadata +94 -75
  41. data/README.rdoc +0 -56
  42. data/minisat/MiniSat_v1.14.2006-Aug-29.src.zip +0 -0
  43. data/minisat/MiniSat_v1.14/Global.h +0 -274
  44. data/minisat/MiniSat_v1.14/Heap.h +0 -100
  45. data/minisat/MiniSat_v1.14/Main.C +0 -244
  46. data/minisat/MiniSat_v1.14/Makefile +0 -88
  47. data/minisat/MiniSat_v1.14/README +0 -30
  48. data/minisat/MiniSat_v1.14/Solver.C +0 -781
  49. data/minisat/MiniSat_v1.14/Solver.h +0 -206
  50. data/minisat/MiniSat_v1.14/Solver.o +0 -0
  51. data/minisat/MiniSat_v1.14/SolverTypes.h +0 -130
  52. data/minisat/MiniSat_v1.14/TODO +0 -73
  53. data/minisat/MiniSat_v1.14/VarOrder.h +0 -96
@@ -0,0 +1,122 @@
1
+ /************************************************************************************[ParseUtils.h]
2
+ Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3
+ Copyright (c) 2007-2010, Niklas Sorensson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18
+ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+ **************************************************************************************************/
20
+
21
+ #ifndef Minisat_ParseUtils_h
22
+ #define Minisat_ParseUtils_h
23
+
24
+ #include <stdlib.h>
25
+ #include <stdio.h>
26
+
27
+ #include <zlib.h>
28
+
29
+ namespace Minisat {
30
+
31
+ //-------------------------------------------------------------------------------------------------
32
+ // A simple buffered character stream class:
33
+
34
+ static const int buffer_size = 1048576;
35
+
36
+
37
+ class StreamBuffer {
38
+ gzFile in;
39
+ unsigned char buf[buffer_size];
40
+ int pos;
41
+ int size;
42
+
43
+ void assureLookahead() {
44
+ if (pos >= size) {
45
+ pos = 0;
46
+ size = gzread(in, buf, sizeof(buf)); } }
47
+
48
+ public:
49
+ explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0) { assureLookahead(); }
50
+
51
+ int operator * () const { return (pos >= size) ? EOF : buf[pos]; }
52
+ void operator ++ () { pos++; assureLookahead(); }
53
+ int position () const { return pos; }
54
+ };
55
+
56
+
57
+ //-------------------------------------------------------------------------------------------------
58
+ // End-of-file detection functions for StreamBuffer and char*:
59
+
60
+
61
+ static inline bool isEof(StreamBuffer& in) { return *in == EOF; }
62
+ static inline bool isEof(const char* in) { return *in == '\0'; }
63
+
64
+ //-------------------------------------------------------------------------------------------------
65
+ // Generic parse functions parametrized over the input-stream type.
66
+
67
+
68
+ template<class B>
69
+ static void skipWhitespace(B& in) {
70
+ while ((*in >= 9 && *in <= 13) || *in == 32)
71
+ ++in; }
72
+
73
+
74
+ template<class B>
75
+ static void skipLine(B& in) {
76
+ for (;;){
77
+ if (isEof(in)) return;
78
+ if (*in == '\n') { ++in; return; }
79
+ ++in; } }
80
+
81
+
82
+ template<class B>
83
+ static int parseInt(B& in) {
84
+ int val = 0;
85
+ bool neg = false;
86
+ skipWhitespace(in);
87
+ if (*in == '-') neg = true, ++in;
88
+ else if (*in == '+') ++in;
89
+ if (*in < '0' || *in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
90
+ while (*in >= '0' && *in <= '9')
91
+ val = val*10 + (*in - '0'),
92
+ ++in;
93
+ return neg ? -val : val; }
94
+
95
+
96
+ // String matching: in case of a match the input iterator will be advanced the corresponding
97
+ // number of characters.
98
+ template<class B>
99
+ static bool match(B& in, const char* str) {
100
+ int i;
101
+ for (i = 0; str[i] != '\0'; i++)
102
+ if (in[i] != str[i])
103
+ return false;
104
+
105
+ in += i;
106
+
107
+ return true;
108
+ }
109
+
110
+ // String matching: consumes characters eagerly, but does not require random access iterator.
111
+ template<class B>
112
+ static bool eagerMatch(B& in, const char* str) {
113
+ for (; *str != '\0'; ++str, ++in)
114
+ if (*str != *in)
115
+ return false;
116
+ return true; }
117
+
118
+
119
+ //=================================================================================================
120
+ }
121
+
122
+ #endif
@@ -0,0 +1,95 @@
1
+ /***************************************************************************************[System.cc]
2
+ Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3
+ Copyright (c) 2007-2010, Niklas Sorensson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18
+ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+ **************************************************************************************************/
20
+
21
+ #include "utils/System.h"
22
+
23
+ #if defined(__linux__)
24
+
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+
28
+ using namespace Minisat;
29
+
30
+ // TODO: split the memory reading functions into two: one for reading high-watermark of RSS, and
31
+ // one for reading the current virtual memory size.
32
+
33
+ static inline int memReadStat(int field)
34
+ {
35
+ char name[256];
36
+ pid_t pid = getpid();
37
+ int value;
38
+
39
+ sprintf(name, "/proc/%d/statm", pid);
40
+ FILE* in = fopen(name, "rb");
41
+ if (in == NULL) return 0;
42
+
43
+ for (; field >= 0; field--)
44
+ if (fscanf(in, "%d", &value) != 1)
45
+ printf("ERROR! Failed to parse memory statistics from \"/proc\".\n"), exit(1);
46
+ fclose(in);
47
+ return value;
48
+ }
49
+
50
+
51
+ static inline int memReadPeak(void)
52
+ {
53
+ char name[256];
54
+ pid_t pid = getpid();
55
+
56
+ sprintf(name, "/proc/%d/status", pid);
57
+ FILE* in = fopen(name, "rb");
58
+ if (in == NULL) return 0;
59
+
60
+ // Find the correct line, beginning with "VmPeak:":
61
+ int peak_kb = 0;
62
+ while (!feof(in) && fscanf(in, "VmPeak: %d kB", &peak_kb) != 1)
63
+ while (!feof(in) && fgetc(in) != '\n')
64
+ ;
65
+ fclose(in);
66
+
67
+ return peak_kb;
68
+ }
69
+
70
+ double Minisat::memUsed() { return (double)memReadStat(0) * (double)getpagesize() / (1024*1024); }
71
+ double Minisat::memUsedPeak() {
72
+ double peak = memReadPeak() / 1024;
73
+ return peak == 0 ? memUsed() : peak; }
74
+
75
+ #elif defined(__FreeBSD__)
76
+
77
+ double Minisat::memUsed(void) {
78
+ struct rusage ru;
79
+ getrusage(RUSAGE_SELF, &ru);
80
+ return (double)ru.ru_maxrss / 1024; }
81
+ double MiniSat::memUsedPeak(void) { return memUsed(); }
82
+
83
+
84
+ #elif defined(__APPLE__)
85
+ #include <malloc/malloc.h>
86
+
87
+ double Minisat::memUsed(void) {
88
+ malloc_statistics_t t;
89
+ malloc_zone_statistics(NULL, &t);
90
+ return (double)t.max_size_in_use / (1024*1024); }
91
+
92
+ #else
93
+ double Minisat::memUsed() {
94
+ return 0; }
95
+ #endif
@@ -0,0 +1,60 @@
1
+ /****************************************************************************************[System.h]
2
+ Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3
+ Copyright (c) 2007-2010, Niklas Sorensson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18
+ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+ **************************************************************************************************/
20
+
21
+ #ifndef Minisat_System_h
22
+ #define Minisat_System_h
23
+
24
+ #if defined(__linux__)
25
+ #include <fpu_control.h>
26
+ #endif
27
+
28
+ #include "mtl/IntTypes.h"
29
+
30
+ //-------------------------------------------------------------------------------------------------
31
+
32
+ namespace Minisat {
33
+
34
+ static inline double cpuTime(void); // CPU-time in seconds.
35
+ extern double memUsed(); // Memory in mega bytes (returns 0 for unsupported architectures).
36
+ extern double memUsedPeak(); // Peak-memory in mega bytes (returns 0 for unsupported architectures).
37
+
38
+ }
39
+
40
+ //-------------------------------------------------------------------------------------------------
41
+ // Implementation of inline functions:
42
+
43
+ #if defined(_MSC_VER) || defined(__MINGW32__)
44
+ #include <time.h>
45
+
46
+ static inline double Minisat::cpuTime(void) { return (double)clock() / CLOCKS_PER_SEC; }
47
+
48
+ #else
49
+ #include <sys/time.h>
50
+ #include <sys/resource.h>
51
+ #include <unistd.h>
52
+
53
+ static inline double Minisat::cpuTime(void) {
54
+ struct rusage ru;
55
+ getrusage(RUSAGE_SELF, &ru);
56
+ return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; }
57
+
58
+ #endif
59
+
60
+ #endif
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "ruby-minisat"
4
+ spec.version = "2.2.0"
5
+ spec.authors = ["Yusuke Endoh"]
6
+ spec.email = ["mame@tsg.ne.jp"]
7
+ spec.description = %q{ruby binding for MiniSat, an open-source SAT solver}
8
+ spec.summary = %q{ruby binding for MiniSat, an open-source SAT solver}
9
+ spec.homepage = "http://github.com/mame/ruby-minisat"
10
+ spec.license = "MIT"
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.extensions << 'ext/minisat/extconf.rb'
16
+ spec.require_paths = ["ext/minisat/"]
17
+ spec.rdoc_options = %w[--exclude .*\.o --exclude minisat.so]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ end
metadata CHANGED
@@ -1,36 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-minisat
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 14
8
- - 2
9
- version: 1.14.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Yusuke Endoh
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2010-07-07 00:00:00 +09:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description: ruby binding for MiniSat, which is an open-source SAT solver
22
- email: mame@tsg.ne.jp
11
+ date: 2013-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ruby binding for MiniSat, an open-source SAT solver
42
+ email:
43
+ - mame@tsg.ne.jp
23
44
  executables: []
24
-
25
- extensions:
45
+ extensions:
26
46
  - ext/minisat/extconf.rb
27
- extra_rdoc_files:
28
- - LICENSE
29
- - README.rdoc
30
- files:
47
+ extra_rdoc_files: []
48
+ files:
31
49
  - .gitignore
50
+ - Gemfile
32
51
  - LICENSE
33
- - README.rdoc
52
+ - README.md
34
53
  - Rakefile
35
54
  - VERSION
36
55
  - examples/compat18.rb
@@ -53,62 +72,62 @@ files:
53
72
  - ext/minisat/minisat-wrap.cpp
54
73
  - ext/minisat/minisat.c
55
74
  - ext/minisat/minisat.h
56
- - minisat/MiniSat_v1.14.2006-Aug-29.src.zip
57
- - minisat/MiniSat_v1.14/Global.h
58
- - minisat/MiniSat_v1.14/Heap.h
59
- - minisat/MiniSat_v1.14/LICENSE
60
- - minisat/MiniSat_v1.14/Main.C
61
- - minisat/MiniSat_v1.14/Makefile
62
- - minisat/MiniSat_v1.14/README
63
- - minisat/MiniSat_v1.14/Solver.C
64
- - minisat/MiniSat_v1.14/Solver.h
65
- - minisat/MiniSat_v1.14/Solver.o
66
- - minisat/MiniSat_v1.14/SolverTypes.h
67
- - minisat/MiniSat_v1.14/Sort.h
68
- - minisat/MiniSat_v1.14/TODO
69
- - minisat/MiniSat_v1.14/VarOrder.h
75
+ - minisat/minisat-2.2.0.tar.gz
76
+ - minisat/minisat/LICENSE
77
+ - minisat/minisat/README
78
+ - minisat/minisat/core/Dimacs.h
79
+ - minisat/minisat/core/Main.cc
80
+ - minisat/minisat/core/Solver.cc
81
+ - minisat/minisat/core/Solver.h
82
+ - minisat/minisat/core/SolverTypes.h
83
+ - minisat/minisat/mtl/Alg.h
84
+ - minisat/minisat/mtl/Alloc.h
85
+ - minisat/minisat/mtl/Heap.h
86
+ - minisat/minisat/mtl/IntTypes.h
87
+ - minisat/minisat/mtl/Map.h
88
+ - minisat/minisat/mtl/Queue.h
89
+ - minisat/minisat/mtl/Sort.h
90
+ - minisat/minisat/mtl/Vec.h
91
+ - minisat/minisat/mtl/XAlloc.h
92
+ - minisat/minisat/mtl/config.mk
93
+ - minisat/minisat/mtl/template.mk
94
+ - minisat/minisat/simp/Main.cc
95
+ - minisat/minisat/simp/SimpSolver.cc
96
+ - minisat/minisat/simp/SimpSolver.h
97
+ - minisat/minisat/utils/Options.cc
98
+ - minisat/minisat/utils/Options.h
99
+ - minisat/minisat/utils/ParseUtils.h
100
+ - minisat/minisat/utils/System.cc
101
+ - minisat/minisat/utils/System.h
102
+ - ruby-minisat.gemspec
70
103
  - test/test_minisat.rb
71
- has_rdoc: true
72
104
  homepage: http://github.com/mame/ruby-minisat
73
- licenses: []
74
-
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
75
108
  post_install_message:
76
- rdoc_options:
77
- - --charset=UTF-8
78
- require_paths:
79
- - lib
80
- required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- segments:
94
- - 0
95
- version: "0"
109
+ rdoc_options:
110
+ - --exclude
111
+ - .*\.o
112
+ - --exclude
113
+ - minisat.so
114
+ require_paths:
115
+ - ext/minisat/
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
96
126
  requirements: []
97
-
98
127
  rubyforge_project:
99
- rubygems_version: 1.3.7
128
+ rubygems_version: 2.0.2
100
129
  signing_key:
101
- specification_version: 3
102
- summary: ruby binding for MiniSat, which is an open-source SAT solver
103
- test_files:
130
+ specification_version: 4
131
+ summary: ruby binding for MiniSat, an open-source SAT solver
132
+ test_files:
104
133
  - test/test_minisat.rb
105
- - examples/compat18.rb
106
- - examples/shikaku.rb
107
- - examples/kakuro.rb
108
- - examples/example2.rb
109
- - examples/example.rb
110
- - examples/numberlink.rb
111
- - examples/lonely7.rb
112
- - examples/slitherlink.rb
113
- - examples/sudoku.rb
114
- - examples/nonogram.rb