rulp 0.0.29 → 0.0.32

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: 09720b9d7a5928c65f128a799c5bfd65a1f7faa1
4
- data.tar.gz: f0a7e222e69add27ce719461ebbc95bac26f8061
3
+ metadata.gz: 7d2c9a6eeda7ec471a82cd94ec79672cb7e913f3
4
+ data.tar.gz: 2b829c2e34f3c3f570918032b3936aa54d9c8507
5
5
  SHA512:
6
- metadata.gz: b850be5ea33feb7209b15a5b77af3dc53cd7a286936502178d747c3a906ef7aebf3a1c35949ec3cda9c9f9bc6b2461779b32c39e97cf732c7d5d547aad2165d7
7
- data.tar.gz: a5314cb33474f9116733237c94887bb9d8d2aef3536e4f6a398d57ac1b39d3995d508e8840cd61c5c47aac670bad40d4d2378e8b3e8e636d235eb34deb245364
6
+ metadata.gz: d374b099370168788b3b667e29c30035d40b89d88dffd765fa77d337a6ae6af00002ec5340f5d308567aedd14680f1277db6144dea6c52babe658095244c7aad
7
+ data.tar.gz: 1661630baad3f122d45fc6e35bfc8cce755ae36b42b52f2f5dae444cd8e02d18caf5435857729ae5348de8cafc9bb93fd87c0ef40c9ddfff2701226eb9a12761
@@ -23,13 +23,13 @@ module Kernel
23
23
  case method_name[-1]
24
24
  when "b"
25
25
  method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
26
- return BV.send(method_name, args)
26
+ return BV.definition(method_name, args)
27
27
  when "i"
28
28
  method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
29
- return IV.send(method_name, args)
29
+ return IV.definition(method_name, args)
30
30
  when "f"
31
31
  method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
32
- return LV.send(method_name, args)
32
+ return LV.definition(method_name, args)
33
33
  end
34
34
  end
35
35
  old_method_missing(value, *args)
@@ -16,11 +16,11 @@ class << Object
16
16
  method_name = "#{value}".split("::")[-1] rescue ""
17
17
  if (("A".."Z").include?(method_name[0]))
18
18
  if(method_name.end_with?("b"))
19
- return BV.send(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
19
+ return BV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
20
20
  elsif(method_name.end_with?("i"))
21
- return IV.send(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
21
+ return IV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
22
22
  elsif(method_name.end_with?("f"))
23
- return LV.send(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
23
+ return LV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
24
24
  end
25
25
  end
26
26
  old_const_missing(value)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ##
2
4
  # An LP Expression constraint. A mathematical expression of which the result
3
5
  # must be constrained in some way.
@@ -8,10 +8,6 @@ class Expressions
8
8
  @expressions = expressions
9
9
  end
10
10
 
11
- def +(other)
12
- return Expressions.new(@expressions + [other])
13
- end
14
-
15
11
  def to_s
16
12
  as_str = @expressions[0].to_s[3..-1]
17
13
  (@expressions.length - 1).times do |i|
@@ -45,9 +41,11 @@ class Expressions
45
41
  end
46
42
 
47
43
  def self.[](value)
48
- return Expressions.new([Fragment.new(value, 1)]) if value.kind_of?(LV)
49
- return Expressions.new([value]) if value.kind_of?(Fragment)
50
- return value if value.kind_of?(Expressions)
44
+ case value
45
+ when LV then Expressions.new([Fragment.new(value, 1)])
46
+ when Fragment then Expressions.new([value])
47
+ when Expressions then value
48
+ end
51
49
  end
52
50
 
53
51
  def evaluate
@@ -104,12 +102,9 @@ class Fragment
104
102
  def to_s
105
103
  @as_str ||= begin
106
104
  case @operand
107
- when -1
108
- " - #{@lv}"
109
- when 1
110
- " + #{@lv}"
111
- else
112
- " + #{@operand} #{@lv}"
105
+ when -1 then " - #{@lv}"
106
+ when 1 then " + #{@lv}"
107
+ else " + #{@operand} #{@lv}"
113
108
  end
114
109
  end
115
110
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ##
2
4
  # An LP Variable. Used as arguments in LP Expressions.
3
5
  # The subtypes BV and IV represent Binary and Integer variables.
@@ -5,7 +7,9 @@
5
7
  ##
6
8
  class LV
7
9
  attr_reader :name, :args
8
- attr_accessor :lt, :lte, :gt, :gte, :value
10
+ attr_writer :value
11
+ attr_accessor :lt, :lte, :gt, :gte
12
+
9
13
  include Rulp::Bounds
10
14
  include Rulp::Initializers
11
15
 
@@ -21,32 +25,15 @@ class LV
21
25
  "f"
22
26
  end
23
27
 
24
- def self.method_missing(name, *args)
25
- return self.definition(name, args)
26
- end
27
-
28
- def self.const_missing(name)
29
- return self.definition(name)
30
- end
31
-
32
- def self.definition(name, args)
28
+ def self.definition(name, *args)
33
29
  identifier = "#{name}#{args.join("_")}"
34
- self.class.send(:define_method, identifier){|index=nil|
35
- if index
36
- self.definition(name, index)
37
- else
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
47
- end
48
- }
49
- return self.send(identifier) || self.new(name, args)
30
+ defined = LV::names_table["#{identifier}"]
31
+ case defined
32
+ when self then defined
33
+ when nil then self.new(name, args)
34
+ else raise StandardError.new("ERROR:\n#{name} was already defined as a variable of type #{defined.class}."+
35
+ "You are trying to redefine it as a variable of type #{self}")
36
+ end
50
37
  end
51
38
 
52
39
  def * (numeric)
@@ -68,12 +55,10 @@ class LV
68
55
 
69
56
  def value
70
57
  return nil unless @value
71
- if self.class == BV
72
- return @value.round(2) == 1
73
- elsif self.class == IV
74
- return @value
75
- else
76
- @value
58
+ case self
59
+ when BV then @value.round(2) == 1
60
+ when IV then @value
61
+ else @value
77
62
  end
78
63
  end
79
64
 
@@ -81,10 +66,6 @@ class LV
81
66
  value ? value : false
82
67
  end
83
68
 
84
- def selected?
85
- value?
86
- end
87
-
88
69
  def inspect
89
70
  "#{name}#{args.join("-")}(#{suffix})[#{value.nil? ? 'undefined' : value }]"
90
71
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "rulp_bounds"
2
4
  require_relative "rulp_initializers"
3
5
  require_relative "lv"
@@ -84,13 +86,14 @@ module Rulp
84
86
 
85
87
  class Problem
86
88
 
87
- attr_accessor :result, :trace
89
+ attr_accessor :result, :trace, :lp_file
88
90
 
89
91
  def initialize(objective, objective_expression)
90
92
  @objective = objective
91
93
  @variables = Set.new
92
94
  @objective_expression = objective_expression.kind_of?(LV) ? 1 * objective_expression : objective_expression
93
95
  @variables.merge(@objective_expression.variables)
96
+ @lp_file = nil
94
97
  @constraints = []
95
98
  end
96
99
 
@@ -124,11 +127,9 @@ module Rulp
124
127
 
125
128
  def constraints
126
129
  return "0 #{@variables.first} = 0" if @constraints.length == 0
127
- constraints_str = " "
128
- @constraints.each.with_index{|constraint, i|
129
- constraints_str << " c#{i}: #{constraint}\n"
130
- }
131
- constraints_str
130
+ @constraints.each.with_index.map{|constraint, i|
131
+ " c#{i}: #{constraint}\n"
132
+ }.join
132
133
  end
133
134
 
134
135
  def integers
@@ -187,7 +188,11 @@ module Rulp
187
188
  raise "Solve failed: all units undefined"
188
189
  end
189
190
 
190
- solver.remove_lp_file if options[:remove_lp_file]
191
+ if options[:remove_lp_file]
192
+ solver.remove_lp_file
193
+ else
194
+ self.lp_file = solver.filename
195
+ end
191
196
  solver.remove_sol_file if options[:remove_sol_file]
192
197
 
193
198
  self.result = @objective_expression.evaluate
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rulp
2
4
  module Bounds
3
5
 
@@ -3,6 +3,7 @@ module Rulp
3
3
  def initialize(name, args)
4
4
  @name = name
5
5
  @args = args
6
+ @value = nil
6
7
  @identifier = "#{self.name}#{self.args.join("_")}"
7
8
  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]
8
9
  LV::names_table[self.to_s] = self
@@ -17,7 +17,7 @@ class Scip < Solver
17
17
  end
18
18
 
19
19
  def settings_file
20
- existing_settings = if File.exists?("./scip.set")
20
+ existing_settings = if File.exist?("./scip.set")
21
21
  IO.read("./scip.set")
22
22
  else
23
23
  ""
@@ -1,5 +1,5 @@
1
1
  class Solver
2
- attr_reader :options, :outfile
2
+ attr_reader :options, :outfile, :filename
3
3
  attr_accessor :unsuccessful
4
4
 
5
5
  def initialize(filename, options)
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.29
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple Ruby LP description DSL
14
14
  email: wc@pico.net.nz