opl 2.2.0 → 2.3.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 (2) hide show
  1. data/lib/opl.rb +17 -4
  2. metadata +2 -2
data/lib/opl.rb CHANGED
@@ -12,10 +12,14 @@ require "rglpk"
12
12
  #should return an error message
13
13
 
14
14
  #2.4
15
- #way more comprehensive test suite of functionality so far
15
+ #catch this error for sum() in forall()
16
+ #"forall(i in (0..2), sum(j in (0..2), x[i][j] = 1))"
17
+ #should be:
18
+ #"forall(i in (0..2), sum(j in (0..2), x[i][j]) = 1)"
16
19
 
17
20
  #3.0
18
21
  #multiple level sub notation e.g. x[1][[3]]
22
+ #why would one use that notation rather than x[1][3]???
19
23
 
20
24
  #3.1
21
25
  #make sure extreme cases of foralls and sums
@@ -183,16 +187,25 @@ class OPL
183
187
  def self.forall(text)
184
188
  #in: "i in (0..2), x[i] <= 5"
185
189
  #out: ["x[0] <= 5", "x[1] <= 5", "x[2] <= 5"]
190
+ helper = self
186
191
  text = text.sub_paren_with_array
187
192
  if ((text.gsub(" ","")).scan(/\]\,/).size) + ((text.gsub(" ","")).scan(/\)\,/).size) != text.gsub(" ","").scan(/in/).size
188
193
  raise "The following forall() constraint is incorrectly formatted: #{text}. Please see the examples in test.rb for forall() constraints. I suspect you are missing a comma somewhere."
189
194
  end
190
195
  final_constraints = []
191
- indices = text.scan(/[a-z] in/).map{|sc|sc[0]}
192
- values = text.scan(/\s\[[\-\s\d+,]+\]/).map{|e|e.gsub(" ", "").scan(/[\-\d]+/)}
196
+ if text.include?("sum")
197
+ indices = text.split("sum")[0].scan(/[a-z] in/).map{|sc|sc[0]}
198
+ values = text.split("sum")[0].scan(/\s\[[\-\s\d+,]+\]/).map{|e|e.gsub(" ", "").scan(/[\-\d]+/)}
199
+ else
200
+ indices = text.scan(/[a-z] in/).map{|sc|sc[0]}
201
+ values = text.scan(/\s\[[\-\s\d+,]+\]/).map{|e|e.gsub(" ", "").scan(/[\-\d]+/)}
202
+ end
203
+ #TODO: the indices and values should only be those
204
+ #of the forall(), not of any sum() that is
205
+ #inside the forall()
193
206
  index_value_pairs = indices.zip(values)
194
207
  variable = text.scan(/[a-z]\[/)[0].gsub("[","")
195
- value_combinations = self.mass_product(values)
208
+ value_combinations = helper.mass_product(values)
196
209
  value_combinations.each_index do |vc_index|
197
210
  value_combination = value_combinations[vc_index]
198
211
  value_combination = [value_combination] unless value_combination.is_a?(Array)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-12 00:00:00.000000000 Z
12
+ date: 2013-10-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Built on top of the rglpk gem for linear programming, this gem is meant
15
15
  to give you a beautifully simple way to formulate your linear or mixed integer program.