@@ -145,6 +145,128 @@ function linprog(c, A, sense, b, l, u, solver)
145
145
)
146
146
end
147
147
148
+ # -------------------------------------------------------------------------------------------
149
+ """
150
+ buildlp(c, A, sense, b, l, u, solver)
151
+
152
+ Function used to build a model using JuMP.
153
+
154
+ # INPUTS
155
+
156
+ - `c`: The objective vector, always in the sense of minimization
157
+ - `A`: Constraint matrix
158
+ - `sense`: Vector of constraint sense characters '<', '=', and '>'
159
+ - `b`: Right-hand side vector
160
+ - `l`: Vector of lower bounds on the variables
161
+ - `u`: Vector of upper bounds on the variables
162
+ - `solver`: A `::SolverConfig` object that contains a valid `handle`to the solver
163
+
164
+ # OUTPUTS
165
+
166
+ - `model`: An `::LPproblem` object that has been built using the JuMP.
167
+ - `x`: Primal solution vector
168
+
169
+ # EXAMPLES
170
+
171
+ ```julia
172
+ julia> model, x = buildlp(c, A, sense, b, l, u, solver)
173
+ ```
174
+
175
+ """
176
+
177
+ function buildlp (c, A, sense, b, l, u, solver)
178
+ N = length (c)
179
+ model = Model (solver)
180
+ x = @variable (model, l[i] <= x[i= 1 : N] <= u[i])
181
+ @objective (model, Min, c' * x)
182
+ eq_rows, ge_rows, le_rows = sense .== ' =' , sense .== ' >' , sense .== ' <'
183
+ @constraint (model, A[eq_rows, :] * x .== b[eq_rows])
184
+ @constraint (model, A[ge_rows, :] * x .>= b[ge_rows])
185
+ @constraint (model, A[le_rows, :] * x .<= b[le_rows])
186
+ return model, x, c
187
+ end
188
+
189
+ # -------------------------------------------------------------------------------------------
190
+ """
191
+ solvelp(model, x)
192
+
193
+ Function used to solve a LPproblem using JuMP.
194
+
195
+ # INPUTS
196
+
197
+ - `model`: An `::LPproblem` object that has been built using the JuMP.
198
+ - `x`: Primal solution vector
199
+
200
+ # OUTPUTS
201
+
202
+ - `status`: Termination status
203
+ - `objval`: Optimal objective value
204
+ - `sol`: Primal solution vector
205
+
206
+ # EXAMPLES
207
+
208
+ ```julia
209
+ julia> status, objval, sol = solvelp(model, x)
210
+ ```
211
+
212
+ """
213
+
214
+ function solvelp (model, x)
215
+ optimize! (model)
216
+ return (
217
+ status = termination_status (model),
218
+ objval = objective_value (model),
219
+ sol = value .(x)
220
+ )
221
+ end
222
+
223
+ # -------------------------------------------------------------------------------------------
224
+ """
225
+ linprog(c, A, sense, b, l, u, solver)
226
+
227
+ Function used to build and solve a LPproblem using JuMP.
228
+
229
+ # INPUTS
230
+
231
+ - `c`: The objective vector, always in the sense of minimization
232
+ - `A`: Constraint matrix
233
+ - `sense`: Vector of constraint sense characters '<', '=', and '>'
234
+ - `b`: Right-hand side vector
235
+ - `l`: Vector of lower bounds on the variables
236
+ - `u`: Vector of upper bounds on the variables
237
+ - `solver`: A `::SolverConfig` object that contains a valid `handle`to the solver
238
+
239
+ # OUTPUTS
240
+
241
+ - `status`: Termination status
242
+ - `objval`: Optimal objective value
243
+ - `sol`: Primal solution vector
244
+
245
+ # EXAMPLES
246
+
247
+ ```julia
248
+ julia> status, objval, sol = linprog(c, A, sense, b, l, u, solver)
249
+ ```
250
+
251
+ """
252
+
253
+ function linprog (c, A, sense, b, l, u, solver)
254
+ N = length (c)
255
+ model = Model (solver)
256
+ @variable (model, l[i] <= x[i= 1 : N] <= u[i])
257
+ @objective (model, Min, c' * x)
258
+ eq_rows, ge_rows, le_rows = sense .== ' =' , sense .== ' >' , sense .== ' <'
259
+ @constraint (model, A[eq_rows, :] * x .== b[eq_rows])
260
+ @constraint (model, A[ge_rows, :] * x .>= b[ge_rows])
261
+ @constraint (model, A[le_rows, :] * x .<= b[le_rows])
262
+ optimize! (model)
263
+ return (
264
+ status = termination_status (model),
265
+ objval = objective_value (model),
266
+ sol = value .(x)
267
+ )
268
+ end
269
+
148
270
# -------------------------------------------------------------------------------------------
149
271
"""
150
272
buildCobraLP(model, solver)
0 commit comments