ruby-cbc 0.3.1 → 0.3.2

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: c4c35ac50e1d6033308676657596808d43ee1562
4
- data.tar.gz: 93ae6e4aa7b33bd8f17585d6a6ac20d671054e2e
3
+ metadata.gz: 123d2f19ca6c970f616b7fc8809132bb40a25e90
4
+ data.tar.gz: a757a87c2e76369d441fe123ec73d399b62e8177
5
5
  SHA512:
6
- metadata.gz: 68893fc94cab781da6b5728f9e26752161394c252b9b558162c0fa2926bf4458ec47a7585c6c61e51d0e8dc849f26f8590fa86f63904d25dde1cd206f6f1d7a0
7
- data.tar.gz: afa5911247b564e559025151f816351e9f9b3871de8922fdb4db50faa8e01f3abc522e960ae58bf6300eb829c2ebbd47ef62a39c7d0e5dabb81af9748ee992e0
6
+ metadata.gz: a77e3149e6f303cecf36e20a8cd75aa5c09a34aacaa56a2dc47af448c8b11df48069ce2c30e65d0e6970819c254a757a94dae906254d89fee283ff0030ed62a8
7
+ data.tar.gz: 5ee5d181c9554e2c6e66719cda6e9c6bec32ea4c3f8884d222d798e93ecb2920c8ac246c7226b1ddb1ad00d880424d0e52a0e10056bf5fa10cae26cb0ccb0cec
@@ -11,44 +11,50 @@ module Cbc
11
11
  continuous = is_continuous_conflict?
12
12
  conflict_set = []
13
13
  all_constraints = @model.constraints.to_a
14
+ nb_constraints = all_constraints.count
14
15
  loop do
15
16
  m = Model.new
16
17
  m.vars = @model.vars
17
18
  m.enforce(conflict_set)
18
19
  return conflict_set if infeasible?(m, continuous: continuous)
19
20
 
20
- constraint = first_failing(conflict_set, all_constraints, continuous: continuous)
21
- return conflict_set if !constraint
21
+ constraint_idx = first_failing(conflict_set, all_constraints, nb_constraints, continuous: continuous)
22
+ return conflict_set if !constraint_idx
22
23
 
23
- conflict_set << constraint
24
+ nb_constraints = constraint_idx
25
+ conflict_set << all_constraints[constraint_idx]
24
26
  end
25
27
  end
26
28
 
27
29
  def is_continuous_conflict?
28
- infeasible?(@model, continuous: true)
30
+ # Same model without objective
31
+ model = Model.new
32
+ model.vars = @model.vars
33
+ model.constraints = @model.constraints
34
+ infeasible?(model, continuous: true)
29
35
  end
30
36
 
31
37
  private
32
38
  # finds the first constraint from constraints that makes the problem infeasible
33
- def first_failing(conflict_set, constraints, continuous: false)
39
+ def first_failing(conflict_set, constraints, nb_constraints, continuous: false)
34
40
  min_nb_constraints = 1
35
- max_nb_constraints = constraints.count + 1
41
+ max_nb_constraints = nb_constraints + 1
36
42
 
37
43
  loop do
38
44
  m = Model.new
39
45
  m.vars = @model.vars
40
46
  m.enforce(conflict_set)
41
47
 
42
- nb_constraints = (max_nb_constraints + min_nb_constraints) / 2
43
- m.enforce(constraints.take(nb_constraints))
48
+ half_constraints = (max_nb_constraints + min_nb_constraints) / 2
49
+ m.enforce(constraints.take(half_constraints))
44
50
  if infeasible?(m, continuous: continuous)
45
- max_nb_constraints = nb_constraints
51
+ max_nb_constraints = half_constraints
46
52
  else
47
- min_nb_constraints = nb_constraints
53
+ min_nb_constraints = half_constraints
48
54
  end
49
55
  if max_nb_constraints - min_nb_constraints <= 1
50
56
  return nil if max_nb_constraints > constraints.count
51
- return constraints[max_nb_constraints - 1]
57
+ return max_nb_constraints - 1
52
58
  end
53
59
  end
54
60
  # Shouldn't come here if the whole problem is infeasible
@@ -1,3 +1,3 @@
1
1
  module Cbc
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Verger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler