mipper 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mipper/cbc/model.rb +11 -9
- data/lib/mipper/constraint.rb +1 -0
- data/lib/mipper/glpk/model.rb +8 -7
- data/lib/mipper/gurobi/model.rb +14 -6
- data/lib/mipper/lp_solve/model.rb +8 -6
- data/lib/mipper/model.rb +1 -1
- data/lib/mipper/variable.rb +2 -3
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d16f46d5a09d8ff89563f7fbb92a54f257dbb901
|
4
|
+
data.tar.gz: 67f1a0b959ec203c4f27911030d7b41e6db2265a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 168c66e33986ff8822d988992991ea83dabd649ada9a7d7382e7106f041c148e17c711abcd669949729f3684890fc378071149b9c47b7b178b4ccc19fe267bb0
|
7
|
+
data.tar.gz: ec215186c4ca682f8c7cf1391c8c074fe4e6ce805635b69b1bc393e1d66455d09c9b319485040064689044c53ba483b1402bed1f9357e85cc8452d37d48c8d46
|
data/lib/mipper/cbc/model.rb
CHANGED
@@ -80,7 +80,8 @@ module MIPPeR
|
|
80
80
|
# Store all the variables in the model
|
81
81
|
# Most of the work will be done when we add the constraints
|
82
82
|
vars.each do |var|
|
83
|
-
var.
|
83
|
+
var.model = self
|
84
|
+
var.index = @variables.count
|
84
85
|
@variables << var
|
85
86
|
end
|
86
87
|
end
|
@@ -117,7 +118,8 @@ module MIPPeR
|
|
117
118
|
# Store the index which will be used for each constraint
|
118
119
|
def store_constraint_indexes(constrs)
|
119
120
|
constrs.each do |constr|
|
120
|
-
constr.
|
121
|
+
constr.model = self
|
122
|
+
constr.index = @constr_count
|
121
123
|
@constr_count += 1
|
122
124
|
end
|
123
125
|
end
|
@@ -137,7 +139,7 @@ module MIPPeR
|
|
137
139
|
|
138
140
|
var.constraints.each do |constr|
|
139
141
|
col_start += 1
|
140
|
-
index << constr.
|
142
|
+
index << constr.index
|
141
143
|
value << constr.expression.terms[var]
|
142
144
|
end
|
143
145
|
end
|
@@ -156,7 +158,8 @@ module MIPPeR
|
|
156
158
|
|
157
159
|
# We store variables now since they didn't exist earlier
|
158
160
|
vars.each_with_index do |var, i|
|
159
|
-
var.
|
161
|
+
var.index = i
|
162
|
+
var.model = self
|
160
163
|
store_variable var
|
161
164
|
end
|
162
165
|
end
|
@@ -178,7 +181,7 @@ module MIPPeR
|
|
178
181
|
dblptr = Cbc.Cbc_getColSolution @ptr
|
179
182
|
values = dblptr.read_array_of_double(@variables.length)
|
180
183
|
variable_values = Hash[@variables.map do |var|
|
181
|
-
[var.
|
184
|
+
[var.index, values[var.index]]
|
182
185
|
end]
|
183
186
|
else
|
184
187
|
objective_value = nil
|
@@ -201,12 +204,11 @@ module MIPPeR
|
|
201
204
|
# Save the constraint to the model and update the constraint pointers
|
202
205
|
def store_constraint(constr)
|
203
206
|
# Update the constraint to track the index in the model
|
204
|
-
|
205
|
-
constr.instance_variable_set :@model, self
|
207
|
+
constr.model = self
|
206
208
|
|
207
209
|
# Set constraint properties
|
208
|
-
Cbc.Cbc_setRowName(@ptr, index, constr.name) unless constr.name.nil?
|
209
|
-
store_constraint_bounds index, constr.sense, constr.rhs
|
210
|
+
Cbc.Cbc_setRowName(@ptr, constr.index, constr.name) unless constr.name.nil?
|
211
|
+
store_constraint_bounds constr.index, constr.sense, constr.rhs
|
210
212
|
end
|
211
213
|
|
212
214
|
# Store the bounds for a given constraint
|
data/lib/mipper/constraint.rb
CHANGED
data/lib/mipper/glpk/model.rb
CHANGED
@@ -92,8 +92,8 @@ module MIPPeR
|
|
92
92
|
constrs.each do |constr|
|
93
93
|
store_constraint constr
|
94
94
|
constr.expression.terms.each do |var, coeff|
|
95
|
-
@ia << constr.
|
96
|
-
@ja << var.
|
95
|
+
@ia << constr.index
|
96
|
+
@ja << var.index
|
97
97
|
@ar << coeff
|
98
98
|
end
|
99
99
|
end
|
@@ -125,7 +125,7 @@ module MIPPeR
|
|
125
125
|
objective_value = GLPK.glp_mip_obj_val @ptr
|
126
126
|
variable_values = Hash[@variables.map do |var|
|
127
127
|
value = GLPK.glp_mip_col_val(@ptr, var.index)
|
128
|
-
[var.
|
128
|
+
[var.index, value]
|
129
129
|
end]
|
130
130
|
else
|
131
131
|
objective_value = nil
|
@@ -139,8 +139,9 @@ module MIPPeR
|
|
139
139
|
def store_constraint(constr)
|
140
140
|
# Update the constraint to track the index in the model
|
141
141
|
index = @constr_count + 1
|
142
|
-
constr.
|
143
|
-
constr.
|
142
|
+
constr.model = self
|
143
|
+
constr.index = index
|
144
|
+
constr.freeze
|
144
145
|
@constr_count += 1
|
145
146
|
|
146
147
|
# Set constraint properties
|
@@ -166,8 +167,8 @@ module MIPPeR
|
|
166
167
|
def store_variable(var)
|
167
168
|
# Update the variable to track the index in the model
|
168
169
|
index = @var_count + 1
|
169
|
-
var.
|
170
|
-
var.
|
170
|
+
var.model = self
|
171
|
+
var.index = index
|
171
172
|
@var_count += 1
|
172
173
|
|
173
174
|
@variables << var
|
data/lib/mipper/gurobi/model.rb
CHANGED
@@ -151,14 +151,19 @@ module MIPPeR
|
|
151
151
|
sense_buffer, rhs_buffer, names_buffer
|
152
152
|
fail if ret != 0
|
153
153
|
|
154
|
-
|
154
|
+
constrs.each do |constr|
|
155
|
+
constr.model = self
|
156
|
+
constr.index = @constraints.length
|
157
|
+
constr.freeze
|
158
|
+
@constraints << constr
|
159
|
+
end
|
155
160
|
end
|
156
161
|
|
157
162
|
# Add a new constraint to the model
|
158
163
|
def add_constraint(constr)
|
159
164
|
terms = constr.expression.terms
|
160
165
|
indexes_buffer = build_pointer_array(terms.each_key.map do |var|
|
161
|
-
var.
|
166
|
+
var.index
|
162
167
|
end, :int)
|
163
168
|
values_buffer = build_pointer_array terms.values, :double
|
164
169
|
|
@@ -168,6 +173,9 @@ module MIPPeR
|
|
168
173
|
constr.rhs, constr.name
|
169
174
|
fail if ret != 0
|
170
175
|
|
176
|
+
constr.model = self
|
177
|
+
constr.index = @constraints.length
|
178
|
+
constr.freeze
|
171
179
|
@constraints << constr
|
172
180
|
end
|
173
181
|
|
@@ -186,7 +194,7 @@ module MIPPeR
|
|
186
194
|
constrs.each.map do |constr|
|
187
195
|
cbeg << cind.length
|
188
196
|
constr.expression.terms.each do |var, coeff|
|
189
|
-
cind << var.
|
197
|
+
cind << var.index
|
190
198
|
cval << coeff
|
191
199
|
end
|
192
200
|
end
|
@@ -205,7 +213,7 @@ module MIPPeR
|
|
205
213
|
Gurobi.GRBgetdblattrarray @ptr, Gurobi::GRB_DBL_ATTR_X,
|
206
214
|
var.index, 1, dblptr
|
207
215
|
value = dblptr.read_array_of_double(1)[0]
|
208
|
-
[var.
|
216
|
+
[var.index, value]
|
209
217
|
end]
|
210
218
|
else
|
211
219
|
objective_value = nil
|
@@ -218,8 +226,8 @@ module MIPPeR
|
|
218
226
|
# Save the variable to the model and update the variable pointers
|
219
227
|
def store_variable(var)
|
220
228
|
# Update the variable to track the index in the model
|
221
|
-
var.
|
222
|
-
var.
|
229
|
+
var.model = self
|
230
|
+
var.index = @var_count
|
223
231
|
@var_count += 1
|
224
232
|
|
225
233
|
@variables << var
|
@@ -73,7 +73,7 @@ module MIPPeR
|
|
73
73
|
colno = []
|
74
74
|
constr.expression.terms.each do |var, coeff|
|
75
75
|
row << coeff * 1.0
|
76
|
-
colno << var.
|
76
|
+
colno << var.index
|
77
77
|
end
|
78
78
|
|
79
79
|
row_buffer = build_pointer_array row, :double
|
@@ -102,7 +102,7 @@ module MIPPeR
|
|
102
102
|
rows = LPSolve.get_Nrows(@ptr)
|
103
103
|
variable_values = Hash[@variables.map do |var|
|
104
104
|
value = LPSolve.get_var_primalresult @ptr, rows + var.index
|
105
|
-
[var.
|
105
|
+
[var.index, value]
|
106
106
|
end]
|
107
107
|
else
|
108
108
|
objective_value = nil
|
@@ -116,8 +116,9 @@ module MIPPeR
|
|
116
116
|
def store_constraint(constr)
|
117
117
|
# Update the constraint to track the index in the model
|
118
118
|
index = LPSolve.get_Nrows(@ptr)
|
119
|
-
constr.
|
120
|
-
constr.
|
119
|
+
constr.model = self
|
120
|
+
constr.index = index
|
121
|
+
constr.freeze
|
121
122
|
@constr_count += 1
|
122
123
|
|
123
124
|
# Set constraint properties
|
@@ -144,8 +145,9 @@ module MIPPeR
|
|
144
145
|
def store_variable(var)
|
145
146
|
# Update the variable to track the index in the model
|
146
147
|
index = @var_count + 1
|
147
|
-
var.
|
148
|
-
var.
|
148
|
+
var.model = self
|
149
|
+
var.index = index
|
150
|
+
var.freeze
|
149
151
|
@var_count += 1
|
150
152
|
|
151
153
|
ret = LPSolve.add_columnex @ptr, 0, nil, nil
|
data/lib/mipper/model.rb
CHANGED
data/lib/mipper/variable.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module MIPPeR
|
2
2
|
class Variable
|
3
|
-
attr_accessor :constraints
|
4
|
-
attr_reader :lower_bound, :upper_bound, :coefficient, :type, :name
|
5
|
-
:index
|
3
|
+
attr_accessor :constraints, :model, :index
|
4
|
+
attr_reader :lower_bound, :upper_bound, :coefficient, :type, :name
|
6
5
|
|
7
6
|
def initialize(lb, ub, coeff, type, name = nil)
|
8
7
|
@lower_bound = lb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Mior
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -56,7 +56,7 @@ files:
|
|
56
56
|
- lib/mipper/variable.rb
|
57
57
|
homepage: https://github.com/michaelmior/mipper
|
58
58
|
licenses:
|
59
|
-
-
|
59
|
+
- GPL-3.0
|
60
60
|
metadata: {}
|
61
61
|
post_install_message:
|
62
62
|
rdoc_options: []
|
@@ -74,9 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.5.1
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: A Ruby interface to various MIP solvers
|
81
81
|
test_files: []
|
82
|
-
has_rdoc:
|