ruby-cbc 0.3.16 → 0.3.17

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: 20e463b7c62b654cdd7299eccb0a099f3b0e35e7
4
- data.tar.gz: b60149c551f055bc1d1264363291cb62df927164
3
+ metadata.gz: e79f120d60b74959fcc12a548409403d7b310201
4
+ data.tar.gz: 1355dac2bec34a8440ef428d41b42f5b2364e47d
5
5
  SHA512:
6
- metadata.gz: 192219d68fe92f168f9566b1fd4a7d703e36f4bfe048d6f5745eff825f9bab73ad726b597165f7113a26370841949a76624d8bd97f457546d1d505823d444c0d
7
- data.tar.gz: bdd8e5306450aebdc381f66ea9392bc01106ef56a124377ffc6a2d11b4716529cd2f24be8d755c8c8285642b8d8ea80df7066b844a2e7d115dda757a888c9aa9
6
+ metadata.gz: 982e49a7b3126d1f2498cb6977c1cc0d7e3eff40432aa563a54f399c5f727356677f84efd86a07d58b6a3b605641cd7c8e44d79aec3066203d1220eeadcfae1e
7
+ data.tar.gz: 8cc51781cb52dc28a5b89e5ad55cf1ff28c5547d9390975f7107d0cdee927d35a1a0236f9b99a20e9b3e86df789464570582b9030aeff29b12aefd5cb72736c2
@@ -9,6 +9,7 @@ files = %w(
9
9
  model
10
10
  problem
11
11
  version
12
+ ilp/constant
12
13
  ilp/constraint
13
14
  ilp/objective
14
15
  ilp/term
@@ -0,0 +1,49 @@
1
+ module Ilp
2
+ class Constant
3
+ attr_accessor :value
4
+ def initialize(value)
5
+ raise ArgumentError, "Argument is not numeric" unless value.is_a? Numeric
6
+ @value = value
7
+ end
8
+
9
+ def <=(other)
10
+ other >= value
11
+ end
12
+
13
+ def <(other)
14
+ other > value
15
+ end
16
+
17
+ def >=(other)
18
+ other <= value
19
+ end
20
+
21
+ def >(other)
22
+ other < value
23
+ end
24
+
25
+ def ==(other)
26
+ other == value
27
+ end
28
+
29
+ def *(other)
30
+ other * value
31
+ end
32
+
33
+ def +(other)
34
+ other + value
35
+ end
36
+
37
+ def -(other)
38
+ -1 * other + value
39
+ end
40
+
41
+ def to_s
42
+ value.to_s
43
+ end
44
+
45
+ def pretty_print
46
+ value.to_s
47
+ end
48
+ end
49
+ end
@@ -4,8 +4,7 @@ module Ilp
4
4
  GREATER_OR_EQ = :greater_or_eq
5
5
  EQUALS = :equals
6
6
 
7
- attr_reader :terms, :type, :bound
8
- attr_accessor :function_name
7
+ attr_accessor :terms, :type, :bound, :function_name
9
8
 
10
9
  def initialize(terms, type, bound)
11
10
  @terms = terms - bound
@@ -3,7 +3,7 @@ module Ilp
3
3
  MINIMIZE = :min
4
4
  MAXIMIZE = :max
5
5
 
6
- attr_reader :terms, :objective_function
6
+ attr_accessor :terms, :objective_function
7
7
  def initialize(terms, objective_function = MAXIMIZE)
8
8
  @terms = terms
9
9
  @terms = Ilp::Term.new(@terms) if @terms.is_a? Ilp::Var
@@ -1,7 +1,6 @@
1
1
  module Ilp
2
2
  class Term
3
- attr_reader :var
4
- attr_accessor :mult
3
+ attr_accessor :mult, :var
5
4
 
6
5
  def initialize(var, mult = 1)
7
6
  @mult = mult
@@ -28,20 +27,13 @@ module Ilp
28
27
  Ilp::TermArray.new([self]) >= other
29
28
  end
30
29
 
31
- def combine_in(other_term)
32
- return Term.new(var, mult) unless other_term
33
- raise "Terms cannot be combined: #{self} and #{other_term}" unless var.equal? other_term.var
34
- other_term.mult += mult
35
- other_term
36
- end
37
-
38
30
  def *(other)
39
31
  raise ArgumentError, "Argument is not numeric" unless other.is_a? Numeric
40
32
  Ilp::Term.new(@var, @mult * other)
41
33
  end
42
34
 
43
35
  def coerce(num)
44
- [Ilp::TermArray.new([self]), num]
36
+ [Ilp::Constant.new(num), Ilp::TermArray.new([self])]
45
37
  end
46
38
 
47
39
  def to_s
@@ -2,7 +2,7 @@ module Ilp
2
2
  class TermArray
3
3
  extend Forwardable
4
4
 
5
- attr_reader :terms
5
+ attr_accessor :terms
6
6
  def_delegators :@terms, :map, :each, :size
7
7
 
8
8
  def initialize(terms)
@@ -45,8 +45,9 @@ module Ilp
45
45
  when Numeric
46
46
  constant += term
47
47
  when Ilp::Term
48
- variable = term.var
49
- hterms[variable] = term.combine_in(hterms[variable])
48
+ v = term.var
49
+ hterms[v] ||= Ilp::Term.new(v, 0)
50
+ hterms[v].mult += term.mult
50
51
  end
51
52
  end
52
53
  reduced = hterms.map { |_, term| term unless term.mult.zero? }
@@ -68,7 +69,7 @@ module Ilp
68
69
  end
69
70
 
70
71
  def coerce(value)
71
- [value, self]
72
+ [Ilp::Constant.new(value), self]
72
73
  end
73
74
 
74
75
  def to_s
@@ -52,7 +52,7 @@ module Ilp
52
52
  end
53
53
 
54
54
  def coerce(num)
55
- [Ilp::Term.new(self), num]
55
+ [Ilp::Constant.new(num), self]
56
56
  end
57
57
 
58
58
  def to_s
@@ -1,3 +1,3 @@
1
1
  module Cbc
2
- VERSION = "0.3.16"
2
+ VERSION = "0.3.17"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-cbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Verger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,6 +156,7 @@ files:
156
156
  - bin/setup
157
157
  - lib/ruby-cbc.rb
158
158
  - lib/ruby-cbc/conflict_solver.rb
159
+ - lib/ruby-cbc/ilp/constant.rb
159
160
  - lib/ruby-cbc/ilp/constraint.rb
160
161
  - lib/ruby-cbc/ilp/objective.rb
161
162
  - lib/ruby-cbc/ilp/term.rb
@@ -186,8 +187,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  version: '0'
187
188
  requirements: []
188
189
  rubyforge_project:
189
- rubygems_version: 2.5.2
190
+ rubygems_version: 2.5.2.1
190
191
  signing_key:
191
192
  specification_version: 4
192
193
  summary: Wrapper around Cbc Linear Programming Solver
193
194
  test_files: []
195
+ has_rdoc: