Skip to content

Commit

Permalink
Introduce presolve rules and tentative documentation template
Browse files Browse the repository at this point in the history
  • Loading branch information
mtanneau committed Dec 12, 2020
1 parent fbf7428 commit 8a3d440
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ makedocs(;
),
pages=[
"Home" => "index.md",
"User guide" => [
"Rules" => "manual/rules.md",
]
],
)

Expand Down
4 changes: 0 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ CurrentModule = MathOptPresolve

```@index
```

```@autodocs
Modules = [MathOptPresolve]
```
9 changes: 9 additions & 0 deletions docs/src/manual/rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```@meta
CurrentModule = MathOptPresolve
```

# Primal reductions

```@docs
FixedVariableRule
```
54 changes: 49 additions & 5 deletions src/lp/fixed_variable.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
"""
FixedVariableRule
Eliminate all fixed variables.
A variable ``x_{j}`` is fixed if its current lower and upper bounds are equal.
## Presolve
A row
```math
l_{i} \\leq a_{i, j}x_{j} + \\sum_{k \\neq j} a_{i, k} x_{k} \\leq u_{i}
```
is transformed into
```math
l_{i} - a_{i, j} \\bar{x}_{j} \\leq \\sum_{k \\neq j} a_{i, k} x_{k} \\leq u_{i} - a_{i, j} \\bar{x}_{j}
```
## Postsolve
For dual variables, first compute
```math
z_{j} = c_{j} - \\sum_{i} a_{i, j} (y_{i}^{l} - y_{i}^{u}),
```
then recover ``z_{j}^{l} = z_{j}^{+}`` and ``z_{j}^{u} = z_{j}^{-}``.
## Misc
* This is a primal reduction.
* If ``x_{j}`` is integer and fixed to a fractional value, then the problem in infeasible.
"""
struct FixedVariableRule <: AbstractPresolveRule end

struct FixedVariable{T} <: PresolveTransformation{T}
j::Int # variable index
x::T # primal value
c::T # current objective coeff
col::Col{T} # current column
end

function remove_fixed_variable!(ps::PresolveData, j::Int)
function apply!(::FixedVariableRule, ps::PresolveData)

for (j, flag) in enumerate(ps.colflag)
remove_fixed_variable!(ps, j)
end

return nothing
end

function remove_fixed_variable!(ps::PresolveData{T}, j::Int; ϵ::T=eps(T)) where {T}
ps.colflag[j] || return nothing # Column was already removed

# Check bounds
lb, ub = ps.lcol[j], ps.ucol[j]

# TODO: use tolerance
if lb == ub
if abs(ub - lb) <= ϵ
@debug "Fix variable $j to $lb"

col = ps.pb0.acols[j]
Expand Down Expand Up @@ -65,4 +109,4 @@ function postsolve!(sol::Solution{T}, op::FixedVariable{T}) where{T}
sol.s_lower[op.j] = pos_part(s)
sol.s_upper[op.j] = neg_part(s)
return nothing
end
end
2 changes: 2 additions & 0 deletions src/presolve.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
abstract type AbstractPresolveRule end

"""
PresolveTransformation{T}
Expand Down

0 comments on commit 8a3d440

Please sign in to comment.