|
1 | 1 | abstract type PresolveOperation{T, S} end
|
2 | 2 |
|
3 |
| -mutable struct OutputPoint{T, S} |
| 3 | +""" |
| 4 | +Type used to define a solution point when using [`postsolve`](@ref). |
| 5 | +
|
| 6 | + sol = QMSolution(x, y, s_l, s_u) |
| 7 | +
|
| 8 | +where `s_l` and `s_u` should be of type `SparseVector`. |
| 9 | +""" |
| 10 | +mutable struct QMSolution{T, S} |
4 | 11 | x::S
|
5 | 12 | y::S
|
6 | 13 | s_l::SparseVector{T, Int}
|
@@ -347,49 +354,46 @@ end
|
347 | 354 | function postsolve!(
|
348 | 355 | qm::QuadraticModel{T, S},
|
349 | 356 | psqm::PresolvedQuadraticModel{T, S},
|
350 |
| - pt_out::OutputPoint{T, S}, |
351 |
| - x_in::S, |
352 |
| - y_in::S, |
| 357 | + sol::QMSolution{T, S}, |
| 358 | + sol_in::QMSolution{T, S}, |
353 | 359 | ) where {T, S}
|
| 360 | + x_in, y_in = sol_in.x, sol_in.y |
354 | 361 | n_operations = length(psqm.psd.operations)
|
355 |
| - nvar = length(pt_out.x) |
356 |
| - restore_x!(psqm.psd.kept_cols, x_in, pt_out.x, nvar) |
357 |
| - ncon = length(pt_out.y) |
358 |
| - restore_y!(psqm.psd.kept_rows, y_in, pt_out.y, ncon) |
| 362 | + nvar = length(sol.x) |
| 363 | + restore_x!(psqm.psd.kept_cols, x_in, sol.x, nvar) |
| 364 | + ncon = length(sol.y) |
| 365 | + restore_y!(psqm.psd.kept_rows, y_in, sol.y, ncon) |
359 | 366 | for i = n_operations:-1:1
|
360 | 367 | operation_i = psqm.psd.operations[i]
|
361 |
| - postsolve!(pt_out, operation_i) |
| 368 | + postsolve!(sol, operation_i) |
362 | 369 | end
|
363 | 370 | end
|
364 | 371 |
|
365 | 372 | """
|
366 |
| - pt = postsolve(qm::QuadraticModel{T, S}, psqm::PresolvedQuadraticModel{T, S}, |
367 |
| - x_in::S, y_in::S, |
368 |
| - s_l_in::SparseVector{T, Int}, |
369 |
| - s_u_in::SparseVector{T, Int}) where {T, S} |
| 373 | + sol = postsolve(qm::QuadraticModel{T, S}, psqm::PresolvedQuadraticModel{T, S}, |
| 374 | + sol_in::QMSolution{T, S}) where {T, S} |
370 | 375 |
|
371 |
| -Retrieve the solution `(x, y, s_l, s_u)` of the original QP `qm` given the solution of the presolved QP (`psqm`) |
372 |
| -`x_in, y_in, s_l_in, s_u_in`. |
| 376 | +Retrieve the solution `sol = (x, y, s_l, s_u)` of the original QP `qm` given the solution of the presolved QP (`psqm`) |
| 377 | +`sol_in` of type [`QMSolution`](@ref). |
373 | 378 | """
|
374 | 379 | function postsolve(
|
375 | 380 | qm::QuadraticModel{T, S},
|
376 | 381 | psqm::PresolvedQuadraticModel{T, S},
|
377 |
| - x_in::S, |
378 |
| - y_in::S, |
379 |
| - s_l::SparseVector{T, Int}, |
380 |
| - s_u::SparseVector{T, Int}, |
| 382 | + sol_in::QMSolution{T, S}, |
381 | 383 | ) where {T, S}
|
382 |
| - x_out = similar(qm.meta.x0) |
383 |
| - y_out = similar(qm.meta.y0) |
| 384 | + x = similar(qm.meta.x0) |
| 385 | + y = similar(qm.meta.y0) |
| 386 | + s_l = sol_in.s_l |
| 387 | + s_u = sol_in.s_u |
384 | 388 |
|
385 | 389 | ilow, iupp = s_l.nzind, s_u.nzind
|
386 | 390 | restore_ilow_iupp!(ilow, iupp, psqm.psd.kept_cols)
|
387 |
| - pt_out = OutputPoint( |
388 |
| - x_out, |
389 |
| - y_out, |
| 391 | + sol = QMSolution( |
| 392 | + x, |
| 393 | + y, |
390 | 394 | SparseVector(qm.meta.nvar, ilow, s_l.nzval),
|
391 | 395 | SparseVector(qm.meta.nvar, iupp, s_u.nzval),
|
392 | 396 | )
|
393 |
| - postsolve!(qm, psqm, pt_out, x_in, y_in) |
394 |
| - return pt_out |
| 397 | + postsolve!(qm, psqm, sol, sol_in) |
| 398 | + return sol |
395 | 399 | end
|
0 commit comments