ruby-cbc 0.3.0 → 0.3.1
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/conflict_solver.rb +11 -6
- data/lib/ruby-cbc/model.rb +2 -2
- data/lib/ruby-cbc/problem.rb +9 -8
- data/lib/ruby-cbc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c35ac50e1d6033308676657596808d43ee1562
|
4
|
+
data.tar.gz: 93ae6e4aa7b33bd8f17585d6a6ac20d671054e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68893fc94cab781da6b5728f9e26752161394c252b9b558162c0fa2926bf4458ec47a7585c6c61e51d0e8dc849f26f8590fa86f63904d25dde1cd206f6f1d7a0
|
7
|
+
data.tar.gz: afa5911247b564e559025151f816351e9f9b3871de8922fdb4db50faa8e01f3abc522e960ae58bf6300eb829c2ebbd47ef62a39c7d0e5dabb81af9748ee992e0
|
@@ -8,24 +8,29 @@ module Cbc
|
|
8
8
|
|
9
9
|
# Assuming there is a conflict
|
10
10
|
def find_conflict
|
11
|
+
continuous = is_continuous_conflict?
|
11
12
|
conflict_set = []
|
12
13
|
all_constraints = @model.constraints.to_a
|
13
14
|
loop do
|
14
15
|
m = Model.new
|
15
16
|
m.vars = @model.vars
|
16
17
|
m.enforce(conflict_set)
|
17
|
-
return conflict_set if infeasible?(m)
|
18
|
+
return conflict_set if infeasible?(m, continuous: continuous)
|
18
19
|
|
19
|
-
constraint = first_failing(conflict_set, all_constraints)
|
20
|
+
constraint = first_failing(conflict_set, all_constraints, continuous: continuous)
|
20
21
|
return conflict_set if !constraint
|
21
22
|
|
22
23
|
conflict_set << constraint
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
27
|
+
def is_continuous_conflict?
|
28
|
+
infeasible?(@model, continuous: true)
|
29
|
+
end
|
30
|
+
|
26
31
|
private
|
27
32
|
# finds the first constraint from constraints that makes the problem infeasible
|
28
|
-
def first_failing(conflict_set, constraints)
|
33
|
+
def first_failing(conflict_set, constraints, continuous: false)
|
29
34
|
min_nb_constraints = 1
|
30
35
|
max_nb_constraints = constraints.count + 1
|
31
36
|
|
@@ -36,7 +41,7 @@ module Cbc
|
|
36
41
|
|
37
42
|
nb_constraints = (max_nb_constraints + min_nb_constraints) / 2
|
38
43
|
m.enforce(constraints.take(nb_constraints))
|
39
|
-
if infeasible?(m)
|
44
|
+
if infeasible?(m, continuous: continuous)
|
40
45
|
max_nb_constraints = nb_constraints
|
41
46
|
else
|
42
47
|
min_nb_constraints = nb_constraints
|
@@ -50,8 +55,8 @@ module Cbc
|
|
50
55
|
return nil
|
51
56
|
end
|
52
57
|
|
53
|
-
def infeasible?(model)
|
54
|
-
problem = model
|
58
|
+
def infeasible?(model, continuous: false)
|
59
|
+
problem = Problem.new(model, continuous: continuous)
|
55
60
|
problem.solve
|
56
61
|
problem.proven_infeasible?
|
57
62
|
end
|
data/lib/ruby-cbc/model.rb
CHANGED
@@ -25,11 +25,11 @@ module Cbc
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def bin_var(name: nil)
|
28
|
-
var(Ilp::Var::BINARY_KIND,
|
28
|
+
var(Ilp::Var::BINARY_KIND, 0..1, name)
|
29
29
|
end
|
30
30
|
|
31
31
|
def bin_var_array(length, names: nil)
|
32
|
-
array_var(length, Ilp::Var::BINARY_KIND,
|
32
|
+
array_var(length, Ilp::Var::BINARY_KIND, 0..1, names)
|
33
33
|
end
|
34
34
|
|
35
35
|
def cont_var(range = nil, name: nil)
|
data/lib/ruby-cbc/problem.rb
CHANGED
@@ -3,7 +3,7 @@ module Cbc
|
|
3
3
|
|
4
4
|
attr_reader :model
|
5
5
|
|
6
|
-
def initialize(model)
|
6
|
+
def initialize(model, continuous: false)
|
7
7
|
|
8
8
|
@int_arrays = []
|
9
9
|
@double_arrays = []
|
@@ -71,14 +71,15 @@ module Cbc
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
model.vars.each_with_index do |v, idx|
|
74
|
-
|
75
|
-
when Ilp::Var::INTEGER_KIND
|
76
|
-
Cbc_wrapper.Cbc_setInteger(@cbc_model, idx)
|
77
|
-
when Ilp::Var::BINARY_KIND
|
78
|
-
Cbc_wrapper.Cbc_setInteger(@cbc_model, idx)
|
79
|
-
v.bounds = 0..1
|
80
|
-
when Ilp::Var::CONTINUOUS_KIND
|
74
|
+
if continuous
|
81
75
|
Cbc_wrapper.Cbc_setContinuous(@cbc_model, idx)
|
76
|
+
else
|
77
|
+
case v.kind
|
78
|
+
when Ilp::Var::INTEGER_KIND, Ilp::Var::BINARY_KIND
|
79
|
+
Cbc_wrapper.Cbc_setInteger(@cbc_model, idx)
|
80
|
+
when Ilp::Var::CONTINUOUS_KIND
|
81
|
+
Cbc_wrapper.Cbc_setContinuous(@cbc_model, idx)
|
82
|
+
end
|
82
83
|
end
|
83
84
|
Cbc_wrapper.Cbc_setColLower(@cbc_model, idx, v.lower_bound) unless v.lower_bound.nil?
|
84
85
|
Cbc_wrapper.Cbc_setColUpper(@cbc_model, idx, v.upper_bound) unless v.upper_bound.nil?
|
data/lib/ruby-cbc/version.rb
CHANGED