rulp 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yzk4NWFlMmYwMGQ0ZDFjZTUxMmEwNzlkNDAwZmQ4MDU3YWY2Zjg5Mg==
4
+ YWVhZGY3OGVlMTcyMjUxOWJhMTdiN2FjOWJjMzRmYzBmYjFkZWU1MA==
5
5
  data.tar.gz: !binary |-
6
- MDI3Y2E5MjdhNTY2M2FiZDBhZGMzZTg4MzU2ZDRiMzgyOGFmZTIzMA==
6
+ MmVkYjg0M2E4NzMxNTU2ZjM5OWUwYzBlOGVjZGNjNDE0MDJjYjBiZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTg0OTJlNjhiMGJkNjdlM2U1ZTQ0ZGMyMTkwMTc0ZmI5NjliZjIzM2M3NjE1
10
- N2VlNTBiNDBjZmIwOTA5MWI2OGEzZjhkYzYyMmFkOTkzNWM5YTg5OWUzNTc3
11
- ZmUwY2U0ODM0ZmJhNTdiNjY2M2JjZDNhNzI0MTJmZDllMDY4Y2Q=
9
+ OGY1MjkwYmExY2YwYzUwOTM0ZGI5NjM3NDNkZTAwYWRiOTk5MGMwYmE3YzU5
10
+ YTEyODRkMDVhMTM5YTFkODBhZDQyZjk4ODlmODFiZTliZjhkZWExMWE2ZTBh
11
+ N2IwMzVmZDMwNGM3OTJhZjQ1NmE3ODQ1ZjI4ODc4NjVmNDFkMWU=
12
12
  data.tar.gz: !binary |-
13
- MzU4YjQxNzkzNTRlMmU0NzMyNTIyNGQ0NmE1ODM1YzU0NmYyYzFiZmM2YzI1
14
- YmI2MTFkNWZmMzJjZWFmZjY0ZTAzODVmNTEwZTk5MDlkYjBhMmZhNzg1NzZm
15
- NzFhNTllMTM1MTIwNmJmMDk3MGYyNTRmZGY5ZGMyM2U5YWI2ZjA=
13
+ MjJiOTA5N2NiNGJhOTY4ZmI0MTg2ZjY0MWMxOWQ4NDAzZGMyMWNhNWM3NmQ3
14
+ NjE4YjFkYjZiNmYzMmRlYzM5ZjhmZWNkOTM0ZWZjODYxZDFhMTViYWRmZDlm
15
+ ZDQ0NzM0MGYxNmRkNjVlOGVmODBmYjI3ZmMzNzdiZGI3NDhmZmM=
@@ -22,14 +22,14 @@ module Kernel
22
22
  if (start <= "Z" && start >= "A")
23
23
  case method_name[-1]
24
24
  when "b"
25
- method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)] + args.join("_")
26
- return BV.send(method_name)
25
+ method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
26
+ return BV.send(method_name, args)
27
27
  when "i"
28
- method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)] + args.join("_")
29
- return IV.send(method_name)
28
+ method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
29
+ return IV.send(method_name, args)
30
30
  when "f"
31
- method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)] + args.join("_")
32
- return LV.send(method_name)
31
+ method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
32
+ return LV.send(method_name, args)
33
33
  end
34
34
  end
35
35
  old_method_missing(value, *args)
data/lib/rulp/lv.rb CHANGED
@@ -4,17 +4,17 @@
4
4
  # These are constructed dynamically by using the special Capitalised variable declaration syntax.
5
5
  ##
6
6
  class LV
7
- attr_reader :name
7
+ attr_reader :name, :args
8
8
  attr_accessor :lt, :lte, :gt, :gte, :value
9
9
  include Rulp::Bounds
10
10
  include Rulp::Initializers
11
11
 
12
12
  def to_proc
13
- ->(index){ send(self.meth(index)) }
13
+ ->(index){ send(self.meth, index) }
14
14
  end
15
15
 
16
- def meth(*args)
17
- "#{self.name}#{args.join("_")}_#{self.suffix}"
16
+ def meth
17
+ "#{self.name}_#{self.suffix}"
18
18
  end
19
19
 
20
20
  def suffix
@@ -22,26 +22,31 @@ class LV
22
22
  end
23
23
 
24
24
  def self.method_missing(name, *args)
25
- return self.definition( "#{name}#{args.join("_")}" )
25
+ return self.definition(name, args)
26
26
  end
27
27
 
28
28
  def self.const_missing(name)
29
29
  return self.definition(name)
30
30
  end
31
31
 
32
- def self.definition(name)
33
- self.class.send(:define_method, name){
34
- defined = LV::names_table["#{name}"]
35
- if defined && defined.class != self
36
- raise StandardError.new("ERROR:\n#{name} was already defined as a variable of type #{defined.class}."+
37
- "You are trying to redefine it as a variable of type #{self}")
38
- elsif(!defined)
39
- self.new(name)
32
+ def self.definition(name, args)
33
+ identifier = "#{name}#{args.join("_")}"
34
+ self.class.send(:define_method, identifier){|index=nil|
35
+ if index
36
+ self.definition(name, index)
40
37
  else
41
- defined
38
+ defined = LV::names_table["#{identifier}"]
39
+ if defined && defined.class != self
40
+ raise StandardError.new("ERROR:\n#{name} was already defined as a variable of type #{defined.class}."+
41
+ "You are trying to redefine it as a variable of type #{self}")
42
+ elsif(!defined)
43
+ self.new(name, args)
44
+ else
45
+ defined
46
+ end
42
47
  end
43
48
  }
44
- return self.send(name) || self.new(name)
49
+ return self.send(identifier) || self.new(name, args)
45
50
  end
46
51
 
47
52
  def * (numeric)
@@ -73,7 +78,7 @@ class LV
73
78
  end
74
79
 
75
80
  def inspect
76
- "#{name}(#{suffix})[#{value || 'undefined'}]"
81
+ "#{name}#{args.join("-")}(#{suffix})[#{value || 'undefined'}]"
77
82
  end
78
83
  end
79
84
 
@@ -1,9 +1,10 @@
1
1
  module Rulp
2
2
  module Initializers
3
- def initialize(name)
4
- raise StandardError.new("Variable with the name #{name} of a different type (#{LV::names_table[name].class}) already exists") if LV::names_table["#{name}"]
5
- LV::names_table["#{name}"] = self
3
+ def initialize(name, args)
6
4
  @name = name
5
+ @args = args
6
+ 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
+ LV::names_table[self.to_s] = self
7
8
  end
8
9
 
9
10
  def self.included(base)
@@ -21,7 +22,7 @@ module Rulp
21
22
  end
22
23
 
23
24
  def to_s
24
- "#{self.name}"
25
+ "#{self.name}#{self.args.join("_")}"
25
26
  end
26
27
  end
27
28
  end
data/lib/solvers/cbc.rb CHANGED
@@ -17,7 +17,7 @@ class Cbc < Solver
17
17
  vars_by_name[cols[1].to_s] = cols[2].to_f
18
18
  end
19
19
  variables.each do |var|
20
- var.value = vars_by_name[var.name.to_s].to_f
20
+ var.value = vars_by_name[var.to_s].to_f
21
21
  end
22
22
  return objective
23
23
  end
data/lib/solvers/scip.rb CHANGED
@@ -23,7 +23,7 @@ class Scip < Solver
23
23
  vars_by_name[cols[0].to_s] = cols[1].to_f
24
24
  end
25
25
  variables.each do |var|
26
- var.value = vars_by_name[var.name.to_s].to_f
26
+ var.value = vars_by_name[var.to_s].to_f
27
27
  end
28
28
 
29
29
  return objective
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.5
4
+ version: 0.0.6
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-03-03 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple Ruby LP description DSL
14
14
  email: wc@pico.net.nz