rulp 0.0.43 → 0.0.45

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d68bde7a38b8bf0a62ead7589727428da3ca212d
4
- data.tar.gz: 19deb3f77fffeece80b35ca0ed00825fbe5fca4d
2
+ SHA256:
3
+ metadata.gz: 58a47250456efb480a41ea21a923355242c38c27d1e9eb04d17782493a51b083
4
+ data.tar.gz: e7b05a98c43d57035049cd1b2537fd3ecb42792e08114d8dd0729229092e96ac
5
5
  SHA512:
6
- metadata.gz: 76162b58a10cd20302f53f413b38c1e2795fc1b63f26fe5e1f6851efc79eefd5e3dd62b17db606e136290e7ade442dbadc596e5a69ebdb8f4be7d8cf8edfdd3f
7
- data.tar.gz: 5c2341e5a8bdbab7f941b9e699e226b0db0ca2d90c7d891a447451a6928b0e068bbf9e69eee013a9d8bf25b55424e3bce98ab1910c812041b9a3aa9a1bef9db7
6
+ metadata.gz: d12655f339c1095d9bc5f3c4620829965e3375ae4025fceeaea0438d97e6f334bdc0b727e0ac975d03ef8b688da4775c6c34cc9b56c0885cfa6fe38cd757d2dc
7
+ data.tar.gz: 9a3bd500cabd00c9118ff81cd79da588d629f5ee5788eae993d986161cd2ce3da715965534491f3d088b202154e53f124f7053dea671df606b028db96e24cdb4
@@ -1,5 +1,4 @@
1
- require_relative './array_extensions'
2
1
  require_relative './kernel_extensions'
3
2
  require_relative './object_extensions'
4
3
  require_relative './file_extensions'
5
- require_relative './os_extensions'
4
+ require_relative './os_extensions'
@@ -18,17 +18,15 @@ module Kernel
18
18
  alias_method :old_method_missing, :method_missing
19
19
  def method_missing(value, *args)
20
20
  method_name = "#{value}" rescue ""
21
- start = method_name[0]
22
- if (start <= "Z" && start >= "A")
23
- case method_name[-1]
24
- when "b"
25
- method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
21
+ if ("A".."Z").cover?(method_name[0])
22
+ if method_name.end_with?(BV.suffix)
23
+ method_name = method_name.chomp(BV.suffix).chomp("_")
26
24
  return BV.definition(method_name, args)
27
- when "i"
28
- method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
25
+ elsif method_name.end_with?(IV.suffix)
26
+ method_name = method_name.chomp(IV.suffix).chomp("_")
29
27
  return IV.definition(method_name, args)
30
- when "f"
31
- method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)]
28
+ elsif method_name.end_with?(LV.suffix)
29
+ method_name = method_name.chomp(LV.suffix).chomp("_")
32
30
  return LV.definition(method_name, args)
33
31
  end
34
32
  end
@@ -14,13 +14,13 @@ class << Object
14
14
  alias_method :old_const_missing, :const_missing
15
15
  def const_missing(value)
16
16
  method_name = "#{value}".split("::")[-1] rescue ""
17
- if (("A".."Z").include?(method_name[0]))
18
- if(method_name.end_with?("b"))
19
- return BV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
20
- elsif(method_name.end_with?("i"))
21
- return IV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
22
- elsif(method_name.end_with?("f"))
23
- return LV.definition(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
17
+ if ("A".."Z").cover?(method_name[0])
18
+ if method_name.end_with?(BV.suffix)
19
+ return BV.definition(method_name.chomp(BV.suffix).chomp("_"))
20
+ elsif method_name.end_with?(IV.suffix)
21
+ return IV.definition(method_name.chomp(IV.suffix).chomp("_"))
22
+ elsif method_name.end_with?(LV.suffix)
23
+ return LV.definition(method_name.chomp(LV.suffix).chomp("_"))
24
24
  end
25
25
  end
26
26
  old_const_missing(value)
data/lib/rulp/lv.rb CHANGED
@@ -21,8 +21,12 @@ class LV
21
21
  "#{self.name}_#{self.suffix}"
22
22
  end
23
23
 
24
+ def self.suffix
25
+ ENV['RULP_LV_SUFFIX'] || "f"
26
+ end
27
+
24
28
  def suffix
25
- "f"
29
+ self.class.suffix
26
30
  end
27
31
 
28
32
  def self.definition(name, *args)
@@ -74,12 +78,13 @@ class LV
74
78
  end
75
79
 
76
80
  class BV < LV;
77
- def suffix
78
- "b"
81
+ def self.suffix
82
+ ENV['RULP_BV_SUFFIX'] || "b"
79
83
  end
80
84
  end
85
+
81
86
  class IV < LV;
82
- def suffix
83
- "i"
87
+ def self.suffix
88
+ ENV['RULP_IV_SUFFIX'] || "i"
84
89
  end
85
- end
90
+ end
data/lib/rulp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rulp
2
- VERSION = '0.0.43'
2
+ VERSION = '0.0.45'
3
3
  end
data/lib/solvers/cbc.rb CHANGED
@@ -7,7 +7,8 @@ class Cbc < Solver
7
7
  end
8
8
  command %= [
9
9
  options[:gap] ? "ratio #{options[:gap]}":"",
10
- options[:node_limit] ? "maxN #{options[:node_limit]}":""
10
+ options[:node_limit] ? "maxN #{options[:node_limit]}":"",
11
+ options[:time_limit] ? "seconds #{options[:time_limit]}":""
11
12
  ]
12
13
 
13
14
  exec(command)
data/lib/solvers/glpk.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  class Glpk < Solver
2
2
  def solve
3
3
  command = "#{executable} --lp #{@filename} %s --cuts --output #{@outfile}"
4
- command %= options[:gap] ? "--mipgap #{options[:gap]}" : ""
4
+ command %= [
5
+ options[:gap] ? "--mipgap #{options[:gap]}" : "",
6
+ options[:time_limit] ? "--tmlim #{options[:time_limit]}" : ""
7
+ ]
5
8
  exec(command)
6
9
  end
7
10
 
@@ -4,6 +4,7 @@ class Gurobi < Solver
4
4
  command %= [
5
5
  options[:gap] ? "MipGap=#{options[:gap]}":"",
6
6
  options[:node_limit] ? "NodeLimit=#{options[:node_limit]}":"",
7
+ options[:time_limit] ? "TimeLimit=#{options[:time_limit]}":"",
7
8
  ENV['RULP_GUROBI_CMD_ARGS'] ? ENV['RULP_GUROBI_CMD_ARGS'] : ''
8
9
  ]
9
10
  exec(command)
data/lib/solvers/scip.rb CHANGED
@@ -28,6 +28,9 @@ class Scip < Solver
28
28
  if options[:gap]
29
29
  existing_settings += "\nlimits/gap = #{options[:gap]}"
30
30
  end
31
+ if options[:time_limit]
32
+ existing_settings += "\nlimits/time = #{options[:time_limit]}"
33
+ end
31
34
 
32
35
  settings_file = get_settings_filename
33
36
  IO.write(settings_file, existing_settings)
data/test/test_boolean.rb CHANGED
@@ -8,8 +8,8 @@ require_relative 'test_helper'
8
8
  class BooleanTest < Minitest::Test
9
9
  def setup
10
10
  @items = 30.times.map(&Shop_Item_b)
11
- items_count = @items.sum
12
- @items_costs = @items.map{|item| item * Random.rand(1.0...5.0)}.sum
11
+ items_count = @items.inject(:+)
12
+ @items_costs = @items.map{|item| item * Random.rand(1.0...5.0)}.inject(:+)
13
13
 
14
14
  @problem =
15
15
  Rulp::Min( @items_costs ) [
@@ -8,8 +8,8 @@ require_relative 'test_helper'
8
8
  class InfeasibleTest < Minitest::Test
9
9
  def setup
10
10
  @items = 30.times.map(&Shop_Item_b)
11
- items_count = @items.sum
12
- @items_costs = @items.map{|item| item * Random.rand(1.0...5.0)}.sum
11
+ items_count = @items.inject(:+)
12
+ @items_costs = @items.map{|item| item * Random.rand(1.0...5.0)}.inject(:+)
13
13
 
14
14
  @problem =
15
15
  Rulp::Min( @items_costs ) [
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.43
4
+ version: 0.0.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-27 00:00:00.000000000 Z
11
+ date: 2024-03-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple Ruby LP description DSL
14
14
  email: wc@pico.net.nz
@@ -18,7 +18,6 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - bin/rulp
21
- - lib/extensions/array_extensions.rb
22
21
  - lib/extensions/extensions.rb
23
22
  - lib/extensions/file_extensions.rb
24
23
  - lib/extensions/kernel_extensions.rb
@@ -45,10 +44,10 @@ files:
45
44
  - test/test_infeasible.rb
46
45
  - test/test_save_to_file.rb
47
46
  - test/test_simple.rb
48
- homepage:
47
+ homepage:
49
48
  licenses: []
50
49
  metadata: {}
51
- post_install_message:
50
+ post_install_message:
52
51
  rdoc_options: []
53
52
  require_paths:
54
53
  - lib
@@ -63,9 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
62
  - !ruby/object:Gem::Version
64
63
  version: '0'
65
64
  requirements: []
66
- rubyforge_project:
67
- rubygems_version: 2.5.1
68
- signing_key:
65
+ rubygems_version: 3.5.6
66
+ signing_key:
69
67
  specification_version: 4
70
68
  summary: Ruby Linear Programming
71
69
  test_files:
@@ -1,5 +0,0 @@
1
- class Array
2
- def sum
3
- self.inject(:+)
4
- end
5
- end