-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Translate empty column rule and reduction to apply! syntax #18
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,71 @@ | ||
@doc raw""" | ||
RemoveEmptyColumn <: AbstractRule | ||
|
||
Eliminate a single column if it is empty, i.e. all coefficients are zero. | ||
|
||
## Presolve | ||
|
||
If column $j$ is empty, variable $x_{j}$ is fixed to $x_{j}^{*}$ as follows | ||
|
||
| $c_{j}$ | $l_{j}$ | $u_{j}$ | $x^{*}_{j}$ | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all assuming minimization, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. I'll mention it in the docs. |
||
|--------:|---------------:|---------------:|------------:| | ||
| $<0$ | - | $∈ \mathbb{R}$ | $u_{j}$ | | ||
| $<0$ | - | $+∞$ | $+∞^{†}$ | | ||
| $0$ | $∈ \mathbb{R}$ | - | $l_{j}$ | | ||
| $0$ | $-∞$ | $∈ \mathbb{R}$ | $u_{j}$ | | ||
| $0$ | $-∞$ | $+∞$ | $0$ | | ||
| $>0$ | $∈ \mathbb{R}$ | - | $l_{j}$ | | ||
| $>0$ | $-∞$ | - | $-∞^{†}$ | | ||
``^{†}`` problem is dual infeasible | ||
|
||
## Dual infeasibility (unboundedness) checks | ||
|
||
For a prescribed tolerance $ϵ ≥ 0$, the problem is dual infeasible if | ||
column $j$ is empty and either | ||
1. Variable $j$ has no lower bound, and its objective coefficient is positive, | ||
i.e., $l^{c}_{j} = -∞$ and $c_{j} > ϵ$. | ||
2. column $j$ is empty, has no upper bound, and its objective coefficient is negative, | ||
i.e., $l^{c}_{j} = +∞$ and $c_{j} < -ϵ$. | ||
|
||
The corresponding unbounded rays (dual infeasibility certificates) are | ||
1. $x = -e_{j}$, | ||
2. $x = e_{j}$, | ||
|
||
where $e_{j}$ is the $j$-th vector of the canonical basis. | ||
|
||
## Postsolve | ||
|
||
TODO | ||
|
||
## Misc | ||
|
||
* This is a dual reduction, and it can handle integer variables. | ||
* This reduction is non-destructive. | ||
* This reduction does not create any fill-in. | ||
""" | ||
struct RemoveEmptyColumn <: AbstractRule | ||
j::Int | ||
end | ||
|
||
@doc raw""" | ||
EmptyColumn{T} <: AbstractReduction{T} | ||
|
||
Column $j$ is empty (all coefficients are zero). | ||
""" | ||
struct EmptyColumn{T} <: AbstractReduction{T} | ||
j::Int # variable index | ||
x::T # Variable value | ||
s::T # Reduced cost | ||
end | ||
|
||
function remove_empty_column!(ps::PresolveData{T}, j::Int) where {T} | ||
function apply!( | ||
ps::PresolveData{T}, | ||
r::RemoveEmptyColumn, | ||
config::PresolveOptions{T}, | ||
) where {T} | ||
j = r.j | ||
ϵ = config.DualTolerance | ||
|
||
ps.pb0.is_continuous || error("Empty column routine currently only supported for LPs.") | ||
|
||
# Sanity check | ||
|
@@ -105,3 +166,26 @@ function postsolve!(sol::Solution{T}, op::EmptyColumn{T}) where {T} | |
sol.s_upper[op.j] = neg_part(op.s) | ||
return nothing | ||
end | ||
|
||
""" | ||
RemoveEmptyColumns <: AbstractRule | ||
|
||
Remove all empty columns in the problem. | ||
|
||
See [`RemoveEmptyColumn`](@ref). | ||
""" | ||
struct RemoveEmptyColumns <: AbstractRule end | ||
|
||
function apply!( | ||
ps::PresolveData{T}, | ||
::RemoveEmptyColumns, | ||
config::PresolveOptions{T} | ||
) where {T} | ||
for j in 1:ps.pb0.nvar | ||
if ps.colflag[j] && (ps.nzcol[j] == 0) | ||
apply!(ps, RemoveEmptyColumn(j), config) | ||
ps.status == NOT_INFERRED || return nothing | ||
end | ||
end | ||
return nothing | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,7 +421,7 @@ function presolve!(ps::PresolveData{T}) where {T} | |
# I. Remove all fixed variables, empty rows and columns | ||
@_return_if_inferred apply!(ps, RemoveFixedVariables(), config) | ||
@_return_if_inferred apply!(ps, RemoveEmptyRows(), config) | ||
@_return_if_inferred remove_empty_columns!(ps) | ||
@_return_if_inferred apply!(ps, RemoveEmptyColumns(), config) | ||
|
||
# Identify row singletons | ||
ps.row_singletons = [i for (i, nz) in enumerate(ps.nzrow) if ps.rowflag[i] && nz == 1] | ||
|
@@ -435,7 +435,7 @@ function presolve!(ps::PresolveData{T}) where {T} | |
@debug "Presolve pass $npasses" ps.nrow ps.ncol | ||
round_integer_bounds!(ps) | ||
@_return_if_inferred bounds_consistency_checks!(ps) | ||
@_return_if_inferred remove_empty_columns!(ps) | ||
@_return_if_inferred apply!(ps, RemoveEmptyColumns(), config) | ||
|
||
|
||
# Remove all fixed variables | ||
|
@@ -458,7 +458,7 @@ function presolve!(ps::PresolveData{T}) where {T} | |
@_return_if_inferred remove_dominated_columns!(ps) | ||
end | ||
|
||
@_return_if_inferred remove_empty_columns!(ps) | ||
@_return_if_inferred apply!(ps, RemoveEmptyColumns(), config) # Why this here?? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea why this was here in the first place |
||
|
||
@debug("Presolved problem info", | ||
ps.pb0.ncon, ps.nrow, | ||
|
@@ -593,23 +593,6 @@ function bounds_consistency_checks!(ps::PresolveData{T}) where {T} | |
return nothing | ||
end | ||
|
||
""" | ||
remove_empty_columns!(ps::PresolveData) | ||
|
||
Remove all empty columns. | ||
|
||
Called once at the beginning of the presolve procedure. | ||
If an empty column is created later, it is removed on the spot. | ||
""" | ||
function remove_empty_columns!(ps::PresolveData{T}) where {T} | ||
for j in 1:ps.pb0.nvar | ||
remove_empty_column!(ps, j) | ||
ps.status == NOT_INFERRED || break | ||
end | ||
return nothing | ||
end | ||
|
||
|
||
""" | ||
round_integer_bounds!(ps::PresolveData) | ||
|
||
|
@@ -681,7 +664,7 @@ function remove_dominated_columns!(ps::PresolveData{T}) where {T} | |
iszero(aij) && continue # empty column | ||
|
||
# Strengthen dual bounds | ||
#= | ||
#= | ||
|
||
=# | ||
cj = ps.obj[j] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: