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 +4 -4
- data/lib/extensions/kernel_extensions.rb +3 -3
- data/lib/extensions/object_extensions.rb +3 -3
- data/lib/rulp/constraint.rb +2 -0
- data/lib/rulp/expression.rb +8 -13
- data/lib/rulp/lv.rb +17 -36
- data/lib/rulp/rulp.rb +12 -7
- data/lib/rulp/rulp_bounds.rb +2 -0
- data/lib/rulp/rulp_initializers.rb +1 -0
- data/lib/solvers/scip.rb +1 -1
- data/lib/solvers/solver.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d2c9a6eeda7ec471a82cd94ec79672cb7e913f3
|
4
|
+
data.tar.gz: 2b829c2e34f3c3f570918032b3936aa54d9c8507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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.
|
19
|
+
return BV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
|
20
20
|
elsif(method_name.end_with?("i"))
|
21
|
-
return IV.
|
21
|
+
return IV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
|
22
22
|
elsif(method_name.end_with?("f"))
|
23
|
-
return LV.
|
23
|
+
return LV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
old_const_missing(value)
|
data/lib/rulp/constraint.rb
CHANGED
data/lib/rulp/expression.rb
CHANGED
@@ -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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
109
|
-
|
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
|
data/lib/rulp/lv.rb
CHANGED
@@ -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
|
-
|
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.
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
data/lib/rulp/rulp.rb
CHANGED
@@ -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
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
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
|
data/lib/rulp/rulp_bounds.rb
CHANGED
@@ -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
|
data/lib/solvers/scip.rb
CHANGED
data/lib/solvers/solver.rb
CHANGED
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.
|
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-
|
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
|