ruby-cbc 0.3.9 → 0.3.10

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: b400b079a0878a8b069de6806d0a39307ec7cbaa
4
- data.tar.gz: c12f4fb20c21d4f0a2f56ee300f14ab7af90a693
3
+ metadata.gz: fb4564011e69a1bd69b32e0717f34ade1b74ba08
4
+ data.tar.gz: 27e6c72d7a52f68782a4419565f654c6008ad8dd
5
5
  SHA512:
6
- metadata.gz: 7d60c2ca3659d4de0f4c2fc5619b372755b6d403fef0daa62f04117b4fab5a9c3808e9b1f1369e59445ffae46bc08ee31f393984e3714a887c31f2cea5758174
7
- data.tar.gz: d57f7aad33405975ca485b8a3cdb7ab5da8646ef49a1966b8dc0a6bb6ec5ab66a26236f3293ac0b30e3be23136bde96c2ea66fc0d4623d40e264660368334f9c
6
+ metadata.gz: b831fe254cfbcbb95360b09c779a2b952a9d1c64fc6b37ac23268eb2975fbbbe7c81e8d25f35c81e81a795a70d135b5f8e32d63956c472e4d86628dd57317798
7
+ data.tar.gz: ce4e9693f8448a70c2ad498bb6a0cac2af42a492ad328668830a8be1c58e54dce3d4305feb41e56b97de46e54925efd914be3b2cfdf7430a94b083aeb94269bd
@@ -23,7 +23,6 @@ module Cbc
23
23
  loop do
24
24
  range_idxs = first_failing(conflict_set_size, crs, continuous: continuous, max_iterations: max_iter)
25
25
  break if range_idxs.nil?
26
- puts "RANGE #{range_idxs}"
27
26
  crs = crs.restrict_to_n_constraints(range_idxs.max + 1)
28
27
  crs.move_constraint_to_start(range_idxs)
29
28
  clusters.insert(0, range_idxs.size)
@@ -34,7 +33,6 @@ module Cbc
34
33
  crs2 = crs.restrict_to_n_constraints(conflict_set_size)
35
34
  problem = Problem.from_compressed_row_storage(crs2, continuous: continuous)
36
35
  if infeasible?(problem)
37
- puts "CONFLICT"
38
36
  clusters.delete_at(-1)
39
37
  break if clusters.size == conflict_set_size
40
38
 
@@ -54,8 +52,7 @@ module Cbc
54
52
  end
55
53
 
56
54
  conflict_set_size = crs.nb_constraints - clusters[-1]
57
- puts "CLUSTERS #{clusters.inspect}"
58
- puts "VARS #{crs.col_idx.uniq.size}"
55
+ # puts "CLUSTERS #{clusters.inspect}"
59
56
  end
60
57
  crs.model.constraints[0, conflict_set_size]
61
58
  end
@@ -77,18 +74,18 @@ module Cbc
77
74
  max_iterations -= 1
78
75
  end
79
76
  half_constraint_idx = (max_idx + min_idx) / 2
80
- puts "Refining: [#{min_idx}:#{max_idx}] -> #{half_constraint_idx}"
77
+ # puts "Refining: [#{min_idx}:#{max_idx}] -> #{half_constraint_idx}"
81
78
  crs2 = crs.restrict_to_n_constraints(half_constraint_idx + 1)
82
79
  problem = Problem.from_compressed_row_storage(crs2, continuous: continuous)
83
80
  if infeasible?(problem)
84
81
  max_idx = half_constraint_idx
85
- puts " INFEAS"
82
+ # puts " INFEAS"
86
83
  else
87
84
  min_idx = half_constraint_idx + 1
88
- puts " FEAS"
85
+ # puts " FEAS"
89
86
  end
90
87
  if max_idx == min_idx
91
- puts "found: max = #{max_idx} min = #{min_idx} nb = #{crs.nb_constraints}"
88
+ # puts "found: max = #{max_idx} min = #{min_idx} nb = #{crs.nb_constraints}"
92
89
  return nil if max_idx > crs.nb_constraints
93
90
  return min_idx..max_idx
94
91
  end
@@ -86,13 +86,13 @@ module Cbc
86
86
 
87
87
  idx = 0
88
88
  while idx < @crs.nb_constraints do
89
- c = model.constraints[idx]
89
+ c = @crs.model.constraints[idx]
90
90
  set_constraint_bounds(c, idx)
91
91
  idx += 1
92
92
  end
93
93
  idx = 0
94
94
  while idx < ccs.nb_vars do
95
- v = model.vars[idx]
95
+ v = @crs.model.vars[idx]
96
96
  if continuous
97
97
  Cbc_wrapper.Cbc_setContinuous(@cbc_model, idx)
98
98
  else
@@ -44,11 +44,50 @@ module Util
44
44
  def restrict_to_n_constraints(nb_constraints)
45
45
  length_of_values = @row_ptr[nb_constraints]
46
46
  CompressedRowStorage.new.tap do |crs|
47
- crs.model = @model
47
+ crs.model = @model.clone
48
48
  crs.variable_index = @variable_index
49
49
  crs.row_ptr = @row_ptr[0, nb_constraints + 1]
50
50
  crs.col_idx = @col_idx[0, length_of_values]
51
51
  crs.values = @values[0, length_of_values]
52
+ crs.delete_missing_vars
53
+ end
54
+ end
55
+
56
+ def present_var_indices
57
+ is_present = Array.new(@variable_index.count, false)
58
+ @col_idx.each do |col_idx|
59
+ is_present[col_idx] = true
60
+ end
61
+ is_present
62
+ end
63
+
64
+ def delete_missing_vars
65
+ at_least_one_missing = false
66
+ here = present_var_indices
67
+ new_idx = Array.new(@variable_index.count, -1)
68
+ idx = 0
69
+ current_index = 0
70
+ while idx < new_idx.size do
71
+ if here[idx]
72
+ new_idx[idx] = current_index
73
+ current_index += 1
74
+ else
75
+ at_least_one_missing = true
76
+ end
77
+ idx += 1
78
+ end
79
+
80
+ return unless at_least_one_missing
81
+
82
+ new_variable_index = {}
83
+ @variable_index.each do |v, i|
84
+ new_variable_index[v] = new_idx[i] if new_idx[i] != -1
85
+ end
86
+ @variable_index = new_variable_index
87
+ @col_idx.map! { |idx| new_idx[idx] }
88
+ @model.vars = Array.new(@variable_index.size)
89
+ @variable_index.each do |var, idx|
90
+ @model.vars[idx] = var
52
91
  end
53
92
  end
54
93
 
@@ -1,3 +1,3 @@
1
1
  module Cbc
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.10"
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.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Verger