ruby-cbc 0.3.13 → 0.3.14
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 +4 -4
- data/bin/console +3 -6
- data/lib/ruby-cbc.rb +0 -1
- data/lib/ruby-cbc/ilp/constraint.rb +3 -2
- data/lib/ruby-cbc/ilp/objective.rb +1 -1
- data/lib/ruby-cbc/ilp/term.rb +9 -1
- data/lib/ruby-cbc/ilp/term_array.rb +4 -5
- data/lib/ruby-cbc/version.rb +1 -1
- metadata +2 -3
- data/lib/ruby-cbc/ilp/constant.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d514718856124b2c3fc5e3e09fdabfd2f2d59595
|
4
|
+
data.tar.gz: b092657bba86b6994f7064beb80ae43f95b11677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daebded03c047f67704f9e9f955b83bccc204637a1448712a0a5c349d7913fe5da4513cce2fe0944b8e5eebc8c38989310594d31098203375e1132c8437b00b7
|
7
|
+
data.tar.gz: b52e132ab1cfc3db2df67ca2129e02d44458db05f889c27b8d4e109808338419e65b4a9d83f27fb9cfaa1d99d2a492d7d9976d4203dc0ff0e00e3ef7500242de
|
data/bin/console
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
data/lib/ruby-cbc.rb
CHANGED
@@ -4,7 +4,8 @@ module Ilp
|
|
4
4
|
GREATER_OR_EQ = :greater_or_eq
|
5
5
|
EQUALS = :equals
|
6
6
|
|
7
|
-
|
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
|
data/lib/ruby-cbc/ilp/term.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Ilp
|
2
2
|
class Term
|
3
|
-
|
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
|
-
|
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
|
-
|
49
|
-
hterms[
|
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
|
-
[
|
71
|
+
[value, self]
|
73
72
|
end
|
74
73
|
|
75
74
|
def to_s
|
data/lib/ruby-cbc/version.rb
CHANGED
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.
|
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-
|
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
|