rulp 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzYxYzBjMTNmYmFhN2MxY2MwOGVmZTgzZmEzNTBlZTczMzAzODg4YQ==
5
- data.tar.gz: !binary |-
6
- OGYxNzNjODE3YmJmMWVjYzU5MjFhOWM2NTg2OWQ2ZTY2MTI3ZTEyYg==
2
+ SHA1:
3
+ metadata.gz: e2294411951f1ca37ef2ffe418a7b28ee3af92a9
4
+ data.tar.gz: 800d2fb52a1f6dba2f671bf026b0696eeada97e2
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YTZhMmIyYjdkMGZhNzFjM2VkNDBjNjZkOTBjYWU1YjNjMmQzOGRiMDUxNWZm
10
- MmQwNmJkZWIzZjczMjU3YTAzNTc4NjFlYTgzNWIyMjIxYTI3ODM4ZDkwNTcy
11
- Y2Y1N2RjM2I4N2U4YzFmNjVhYzI0N2FkMzAwZGIyMzBmNzY0Nzk=
12
- data.tar.gz: !binary |-
13
- YzllNGI2NTQxZDcyNGU0OWQxYjg0MjM4NjY5YTRlNDFkMWYzZTU0NDMzODFj
14
- NjRiYzc3Njc5NjAwZWEwZDBjYzg3NGU3ZjNkNGM1MDdlM2EwY2NjOWQzOGI1
15
- ZmU5YWFlNjM5MDI5N2ZlZDFkZWE5ZDIyNjk0MGNmZTdhOTQyODM=
6
+ metadata.gz: c34eb327344222dbde5e0184aeda3dd35c0f809666c80641e787859821085c8a7d0d5f6d33065c700d86ff989713d651c3f2b4273e089e8878aa2f06b20009c0
7
+ data.tar.gz: a947a74465255076740c4c8ea459a12546c5bacc7f5234410f6bf516bfcc42d640f9fbbfd2b6d6e5c6c3e9450009fa0dd0950212c9736108f5bdd3b2ede44ad5
data/lib/rulp.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  STDOUT.sync = true
2
+ require 'pry'
2
3
  require_relative 'rulp/rulp'
data/lib/rulp/lv.rb CHANGED
@@ -77,9 +77,19 @@ class LV
77
77
  end
78
78
  end
79
79
 
80
+ def value?
81
+ value ? value : false
82
+ end
83
+
84
+ def selected?
85
+ value?
86
+ end
87
+
80
88
  def inspect
81
89
  "#{name}#{args.join("-")}(#{suffix})[#{value || 'undefined'}]"
82
90
  end
91
+
92
+ alias_method :selected?, :value?
83
93
  end
84
94
 
85
95
  class BV < LV;
data/lib/rulp/rulp.rb CHANGED
@@ -4,7 +4,7 @@ require_relative "lv"
4
4
  require_relative "constraint"
5
5
  require_relative "expression"
6
6
 
7
- require_relative "../solvers/solvers"
7
+ require_relative "../solvers/solver"
8
8
  require_relative "../extensions/extensions"
9
9
  require_relative "../helpers/log"
10
10
 
@@ -74,6 +74,7 @@ module Rulp
74
74
  end
75
75
 
76
76
  def [](*constraints)
77
+ constraints.flatten!
77
78
  @constraints.concat(constraints)
78
79
  @variables.merge(constraints.map(&:variables).flatten)
79
80
  self
@@ -136,10 +137,10 @@ module Rulp
136
137
  filename = get_output_filename
137
138
  solver = SOLVERS[type].new(filename, options)
138
139
 
139
- "Writing problem".log(:info)
140
- IO.write(filename, self)
140
+ "Writing problem".log(:info)
141
+ IO.write(filename, self)
141
142
 
142
- `open #{filename}` if options[:open_definition]
143
+ `open #{filename}` if options[:open_definition]
143
144
 
144
145
  "Solving problem".log(:info)
145
146
  _, time = _profile{ solver.solve }
@@ -161,6 +162,16 @@ module Rulp
161
162
  to_s
162
163
  end
163
164
 
165
+ def write(output)
166
+ output.puts "#{@objective}"
167
+ output.puts " obj: #{@objective_expression}"
168
+ output.puts "Subject to"
169
+ output.puts "#{constraints}"
170
+ output.puts "Bounds"
171
+ output.puts "#{bounds}#{integers}#{bits}"
172
+ output.puts "End"
173
+ end
174
+
164
175
  def to_s
165
176
  %Q(
166
177
  #{' '*0}#{@objective}
data/lib/solvers/cbc.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  class Cbc < Solver
2
-
3
- #maxN
4
-
5
2
  def solve
6
3
  if options[:parallel]
7
4
  command = "#{executable} #{@filename} %s %s threads 8 branch solution #{@outfile}"
@@ -28,6 +28,25 @@ class Solver
28
28
  def self.exists?
29
29
  return `which #{self.executable}`.length != 0
30
30
  end
31
+
32
+ def next_pipe
33
+ filename = "./tmp/_rulp_pipe"
34
+ file_index = 1
35
+ file_index += 1 while File.exists?("#{filename}_#{file_index}")
36
+ pipe = "#{filename}_#{file_index}"
37
+ `mkfifo #{pipe}`
38
+ pipe
39
+ end
40
+
41
+ def with_pipe(pipe)
42
+ output = open(pipe, 'w+')
43
+ thread = Thread.new{
44
+ yield output
45
+ output.flush
46
+ }
47
+ return thread, output
48
+ end
49
+
31
50
  end
32
51
 
33
52
  require_relative 'cbc'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rulp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-09 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple Ruby LP description DSL
14
14
  email: wc@pico.net.nz
@@ -36,7 +36,7 @@ files:
36
36
  - lib/solvers/glpk.rb
37
37
  - lib/solvers/gurobi.rb
38
38
  - lib/solvers/scip.rb
39
- - lib/solvers/solvers.rb
39
+ - lib/solvers/solver.rb
40
40
  - test/test_basic_suite.rb
41
41
  - test/test_boolean.rb
42
42
  - test/test_helper.rb
@@ -51,17 +51,17 @@ require_paths:
51
51
  - lib
52
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ! '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
- rubygems_version: 2.3.0
64
+ rubygems_version: 2.2.2
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Ruby Linear Programming