ruby-cbc 0.3.13 → 0.3.14

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: 272b8de4efdc665ae9bee9f0ee6f772d57c7c59a
4
- data.tar.gz: 95bf23cd92a5d1c42b79c1a70fdab508e71ed1c3
3
+ metadata.gz: d514718856124b2c3fc5e3e09fdabfd2f2d59595
4
+ data.tar.gz: b092657bba86b6994f7064beb80ae43f95b11677
5
5
  SHA512:
6
- metadata.gz: 244b5f78ce28e5551a91a585a0fa62059c4858229e65a168f70ad7a11a28a219c5d4421f821f68efc9db77e57ff2f608486135fb222643a60b3a3e5029e0d5f7
7
- data.tar.gz: f1afc4bc47beeee8df16c89557f86d08af93d5a9fee67035f4e22c63b6e918c08c0259f74bf39ad54a74cf75f02911cb614a0942270f13a4de3175518f4f4628
6
+ metadata.gz: daebded03c047f67704f9e9f955b83bccc204637a1448712a0a5c349d7913fe5da4513cce2fe0944b8e5eebc8c38989310594d31098203375e1132c8437b00b7
7
+ data.tar.gz: b52e132ab1cfc3db2df67ca2129e02d44458db05f889c27b8d4e109808338419e65b4a9d83f27fb9cfaa1d99d2a492d7d9976d4203dc0ff0e00e3ef7500242de
@@ -1,14 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "cbc"
4
+ require "ruby-cbc"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
10
+ require "pry"
11
+ Pry.start
@@ -9,7 +9,6 @@ files = %w(
9
9
  model
10
10
  problem
11
11
  version
12
- ilp/constant
13
12
  ilp/constraint
14
13
  ilp/objective
15
14
  ilp/term
@@ -4,7 +4,8 @@ module Ilp
4
4
  GREATER_OR_EQ = :greater_or_eq
5
5
  EQUALS = :equals
6
6
 
7
- attr_accessor :terms, :type, :bound, :function_name
7
+ attr_reader :terms, :type, :bound
8
+ attr_accessor :function_name
8
9
 
9
10
  def initialize(terms, type, bound)
10
11
  @terms = terms - bound
@@ -24,7 +25,7 @@ module Ilp
24
25
  SIGN_TO_STRING = {
25
26
  LESS_OR_EQ => "<=",
26
27
  GREATER_OR_EQ => ">=",
27
- EQUALS => "=="
28
+ EQUALS => "="
28
29
  }
29
30
 
30
31
  def to_s
@@ -3,7 +3,7 @@ module Ilp
3
3
  MINIMIZE = :min
4
4
  MAXIMIZE = :max
5
5
 
6
- attr_accessor :terms, :objective_function
6
+ attr_reader :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,6 +1,7 @@
1
1
  module Ilp
2
2
  class Term
3
- attr_accessor :mult, :var
3
+ attr_reader :var
4
+ attr_accessor :mult
4
5
 
5
6
  def initialize(var, mult = 1)
6
7
  @mult = mult
@@ -27,6 +28,13 @@ module Ilp
27
28
  Ilp::TermArray.new([self]) >= other
28
29
  end
29
30
 
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
+
30
38
  def *(other)
31
39
  raise ArgumentError, "Argument is not numeric" unless other.is_a? Numeric
32
40
  Ilp::Term.new(@var, @mult * other)
@@ -2,7 +2,7 @@ module Ilp
2
2
  class TermArray
3
3
  extend Forwardable
4
4
 
5
- attr_accessor :terms
5
+ attr_reader :terms
6
6
  def_delegators :@terms, :map, :each, :size
7
7
 
8
8
  def initialize(terms)
@@ -45,9 +45,8 @@ module Ilp
45
45
  when Numeric
46
46
  constant += term
47
47
  when Ilp::Term
48
- v = term.var
49
- hterms[v] ||= Ilp::Term.new(v, 0)
50
- hterms[v].mult += term.mult
48
+ variable = term.var
49
+ hterms[variable] = term.combine_in(hterms[variable])
51
50
  end
52
51
  end
53
52
  reduced = hterms.map { |_, term| term unless term.mult.zero? }
@@ -69,7 +68,7 @@ module Ilp
69
68
  end
70
69
 
71
70
  def coerce(value)
72
- [Ilp::Constant.new(value), self]
71
+ [value, self]
73
72
  end
74
73
 
75
74
  def to_s
@@ -1,3 +1,3 @@
1
1
  module Cbc
2
- VERSION = "0.3.13"
2
+ VERSION = "0.3.14"
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.13
4
+ version: 0.3.14
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-05-23 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,7 +156,6 @@ 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
160
159
  - lib/ruby-cbc/ilp/constraint.rb
161
160
  - lib/ruby-cbc/ilp/objective.rb
162
161
  - lib/ruby-cbc/ilp/term.rb
@@ -1,49 +0,0 @@
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