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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: def94f63dff658ab3ab9eeeccea2035d7d7e48b0
4
- data.tar.gz: 69d3ebaa3e51a0d84bbd36ec51de60284146850a
3
+ metadata.gz: c4c35ac50e1d6033308676657596808d43ee1562
4
+ data.tar.gz: 93ae6e4aa7b33bd8f17585d6a6ac20d671054e2e
5
5
  SHA512:
6
- metadata.gz: 9dc9707ea5aea3055b058a373e3490332f86d2ce2a7f3954bafd054dbce1f81d37dec5c72d7948cd20aa21e6353f6b76935af8aafe337c83a3d80dbfea699a14
7
- data.tar.gz: 13daf4f282e9c9863a9c23d00c296924b0e7c30c31951343a43b6538953fa64e1126c0726b985e1cb6775f84ef84156cac2fd83a5ce8a0a9d9c660a6d3cd43db
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.to_problem
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
@@ -25,11 +25,11 @@ module Cbc
25
25
  end
26
26
 
27
27
  def bin_var(name: nil)
28
- var(Ilp::Var::BINARY_KIND, nil, name)
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, nil, names)
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)
@@ -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
- case v.kind
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?
@@ -1,3 +1,3 @@
1
1
  module Cbc
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-cbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Verger