rulp 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2294411951f1ca37ef2ffe418a7b28ee3af92a9
4
- data.tar.gz: 800d2fb52a1f6dba2f671bf026b0696eeada97e2
3
+ metadata.gz: 51fa526dd152f836d5b5e6f4658352847828fa8e
4
+ data.tar.gz: 0858e2314d40ee7d7ac6e085634bfeb064d1d9f2
5
5
  SHA512:
6
- metadata.gz: c34eb327344222dbde5e0184aeda3dd35c0f809666c80641e787859821085c8a7d0d5f6d33065c700d86ff989713d651c3f2b4273e089e8878aa2f06b20009c0
7
- data.tar.gz: a947a74465255076740c4c8ea459a12546c5bacc7f5234410f6bf516bfcc42d640f9fbbfd2b6d6e5c6c3e9450009fa0dd0950212c9736108f5bdd3b2ede44ad5
6
+ metadata.gz: 5c0fdb11528ae4ce52edf332902b0941fc4c298c2a06d21f41b11da96d8d8216e7f495a96a47587dd0588563981ed656af74468dcc06b9cd7be5f27682fc5363
7
+ data.tar.gz: 6603c3523a9a755eef88ad563d71ab27282a37cc539edcb733a765cefdf0c4f57e81c74308d57af5b2f7d099e662a95523ed9a511b77e0a15a5495b197b72d6a
@@ -13,9 +13,11 @@ class Expressions
13
13
  end
14
14
 
15
15
  def to_s
16
- @expressions.map{|expression|
17
- [expression.operand < 0 ? " " : " + ", expression.to_s]
18
- }.flatten[1..-1].join("")
16
+ as_str = @expressions[0].to_s[3..-1]
17
+ (@expressions.length - 1).times do |i|
18
+ as_str << @expressions[i + 1].to_s
19
+ end
20
+ as_str
19
21
  end
20
22
 
21
23
  def variables
@@ -100,13 +102,15 @@ class Fragment
100
102
  end
101
103
 
102
104
  def to_s
103
- case @operand
104
- when -1
105
- "-#{@lv}"
106
- when 1
107
- "#{@lv}"
108
- else
109
- "#{@operand} #{@lv}"
105
+ @as_str ||= begin
106
+ case @operand
107
+ when -1
108
+ " - #{@lv}"
109
+ when 1
110
+ " + #{@lv}"
111
+ else
112
+ " + #{@operand} #{@lv}"
113
+ end
110
114
  end
111
115
  end
112
116
  end
@@ -74,9 +74,13 @@ module Rulp
74
74
  end
75
75
 
76
76
  def [](*constraints)
77
+ "Got constraints".log(:info)
77
78
  constraints.flatten!
79
+ "Flattened constraints".log(:info)
78
80
  @constraints.concat(constraints)
79
- @variables.merge(constraints.map(&:variables).flatten)
81
+ "Joint constraints".log(:info)
82
+ @variables.merge(constraints.flat_map(&:variables).uniq)
83
+ "Extracted variables".log(:info)
80
84
  self
81
85
  end
82
86
 
@@ -98,14 +102,12 @@ module Rulp
98
102
  end
99
103
 
100
104
  def constraints
101
- constraints_str = @constraints.map.with_index{|constraint, i|
102
- " c#{i}: #{constraint}"
103
- }.join("\n").strip
104
- if constraints_str.empty?
105
- "0 #{@variables.first} = 0"
106
- else
107
- " #{constraints_str}"
108
- end
105
+ return "0 #{@variables.first} = 0" if @constraints.length == 0
106
+ constraints_str = " "
107
+ @constraints.each.with_index{|constraint, i|
108
+ constraints_str << " c#{i}: #{constraint}\n"
109
+ }
110
+ constraints_str
109
111
  end
110
112
 
111
113
  def integers
@@ -137,10 +139,10 @@ module Rulp
137
139
  filename = get_output_filename
138
140
  solver = SOLVERS[type].new(filename, options)
139
141
 
140
- "Writing problem".log(:info)
141
- IO.write(filename, self)
142
+ "Writing problem".log(:info)
143
+ IO.write(filename, self)
142
144
 
143
- `open #{filename}` if options[:open_definition]
145
+ `open #{filename}` if options[:open_definition]
144
146
 
145
147
  "Solving problem".log(:info)
146
148
  _, time = _profile{ solver.solve }
@@ -3,6 +3,7 @@ module Rulp
3
3
  def initialize(name, args)
4
4
  @name = name
5
5
  @args = args
6
+ @identifier = "#{self.name}#{self.args.join("_")}"
6
7
  raise StandardError.new("Variable with the name #{self} of a different type (#{LV::names_table[self.to_s].class}) already exists") if LV::names_table[self.to_s]
7
8
  LV::names_table[self.to_s] = self
8
9
  end
@@ -22,7 +23,7 @@ module Rulp
22
23
  end
23
24
 
24
25
  def to_s
25
- "#{self.name}#{self.args.join("_")}"
26
+ @identifier
26
27
  end
27
28
  end
28
29
  end
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.15
4
+ version: 0.0.16
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-07-31 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple Ruby LP description DSL
14
14
  email: wc@pico.net.nz