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 +4 -4
- data/lib/ruby-cbc.rb +1 -0
- data/lib/ruby-cbc/ilp/constant.rb +49 -0
- data/lib/ruby-cbc/ilp/constraint.rb +1 -2
- data/lib/ruby-cbc/ilp/objective.rb +1 -1
- data/lib/ruby-cbc/ilp/term.rb +2 -10
- data/lib/ruby-cbc/ilp/term_array.rb +5 -4
- data/lib/ruby-cbc/ilp/var.rb +1 -1
- data/lib/ruby-cbc/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e79f120d60b74959fcc12a548409403d7b310201
|
4
|
+
data.tar.gz: 1355dac2bec34a8440ef428d41b42f5b2364e47d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 982e49a7b3126d1f2498cb6977c1cc0d7e3eff40432aa563a54f399c5f727356677f84efd86a07d58b6a3b605641cd7c8e44d79aec3066203d1220eeadcfae1e
|
7
|
+
data.tar.gz: 8cc51781cb52dc28a5b89e5ad55cf1ff28c5547d9390975f7107d0cdee927d35a1a0236f9b99a20e9b3e86df789464570582b9030aeff29b12aefd5cb72736c2
|
data/lib/ruby-cbc.rb
CHANGED
@@ -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
|
data/lib/ruby-cbc/ilp/term.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Ilp
|
2
2
|
class Term
|
3
|
-
|
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])
|
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
|
-
|
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
|
-
|
49
|
-
hterms[
|
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
|
data/lib/ruby-cbc/ilp/var.rb
CHANGED
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.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:
|
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:
|