Skip to content

WIP: break everything, new docs #173

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

Closed
wants to merge 99 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
869d850
begin rewrite of docs, big changes to SolverInterface
mlubin Jun 14, 2017
7cce014
more work
mlubin Jun 14, 2017
c7234e7
beginning of sets
mlubin Jun 14, 2017
8f0662b
argument naming
mlubin Jun 14, 2017
514810c
more coherent interface
mlubin Jun 14, 2017
32c68f0
tidy notation
mlubin Jun 14, 2017
855cd86
variable bounds and variable constraints
mlubin Jun 14, 2017
dbf2b42
Added draft documentation with documenter
tazz0416 Jun 14, 2017
9e72b7f
Added draft documentation with documenter
tazz0416 Jun 14, 2017
cbf0d04
variable and constraint references
mlubin Jun 14, 2017
5bfd73f
Minor fix for latex support
tazz0416 Jun 14, 2017
1e5a9b2
isactive -> isvalid
mlubin Jun 14, 2017
9c005e4
typo
mlubin Jun 14, 2017
6063807
todo is done
mlubin Jun 14, 2017
d607a86
Resolve conflicts with SolverInterFace.md
tazz0416 Jun 14, 2017
dd6eebe
Merge branch 'break_everything' into break_everything
Jun 14, 2017
3ab0181
replace sense symbol with enum
mlubin Jun 14, 2017
5e3b472
Merge pull request #175 from jac0320/break_everything
mlubin Jun 14, 2017
ff15c3d
dimension of interval
mlubin Jun 14, 2017
8c08031
discussion of duals
mlubin Jun 14, 2017
4f33981
constructor for VariablePrimal
mlubin Jun 15, 2017
efad7db
document result status
mlubin Jun 15, 2017
2f3320b
Constructors for VariableLower/UpperBoundDual
joehuchette Jun 15, 2017
fab357e
[ci skip] tidy
mlubin Jun 15, 2017
37424f1
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
mlubin Jun 15, 2017
0e69f4a
[ci skip] fix reference in docs, add todo
mlubin Jun 15, 2017
b77bfd7
[ci skip] constraint attributes
mlubin Jun 15, 2017
b814ac7
Add SOS constraints
joehuchette Jun 15, 2017
ba299f2
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
joehuchette Jun 15, 2017
3b32653
Fallback methods for attribute getters/setters
joehuchette Jun 15, 2017
8454821
Move SOS to sets
joehuchette Jun 15, 2017
a79e635
Add the option for deleting multiple variables and constraints
joaquimg Jun 15, 2017
2de174f
[ci skip] counts and supported sets
mlubin Jun 15, 2017
af22102
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
mlubin Jun 15, 2017
9ce67c1
Add writeproblem, getbasis
joehuchette Jun 15, 2017
b997edd
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
joehuchette Jun 15, 2017
56b873a
Merge pull request #176 from joaquimg/break_everything
mlubin Jun 15, 2017
bc20db9
Add LinearConstraintCount
joehuchette Jun 15, 2017
c987600
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
joehuchette Jun 15, 2017
c772b0d
[ci skip] generalize variable references
mlubin Jun 15, 2017
6661fb8
Remove LinearConstraintCount; change basis getters
joehuchette Jun 15, 2017
c835a03
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
joehuchette Jun 15, 2017
c44a0ff
Tweak docs for basis attributes
joehuchette Jun 15, 2017
8c6da94
Modify constraints
odow Jun 15, 2017
e0d4042
Merge pull request #177 from odow/break_everything
mlubin Jun 15, 2017
90fb1e0
Begin objectives
odow Jun 15, 2017
d4a9e82
modify and get objective
odow Jun 15, 2017
86f9377
Multi-objective attributes
odow Jun 15, 2017
a0e44d3
Same basis return statuses for both variables and constraints
joehuchette Jun 15, 2017
4a62e4b
Revert objective attributes
odow Jun 15, 2017
e127590
Merge pull request #178 from odow/break_everything
mlubin Jun 15, 2017
a6dfeff
include file and fix typo
odow Jun 15, 2017
f17e27c
Merge pull request #179 from odow/break_everything
mlubin Jun 15, 2017
9cdad13
fix constructor for ObjectiveValue
mlubin Jun 15, 2017
838db37
making latest docs build from break_everything branch
ccoffrin Jun 15, 2017
8868c85
collapse high-level interface docs into one file
mlubin Jun 15, 2017
e9075b4
restructure docs into separate files
mlubin Jun 15, 2017
8022f6f
Merge pull request #180 from ccoffrin/break_everything
mlubin Jun 15, 2017
102906c
comment out interface tests, to be rewritten
mlubin Jun 15, 2017
cd91815
Models (#181)
odow Jun 15, 2017
402839f
split variable references, specialized affine-in-set constraint
mlubin Jun 15, 2017
1d6ef9e
document objectives
mlubin Jun 15, 2017
8402970
Modify sets
odow Jun 15, 2017
0e67cb3
Merge pull request #184 from odow/break_everything
mlubin Jun 16, 2017
2427d59
Proposed NLP Interface (#183)
ccoffrin Jun 16, 2017
446c8db
temporarily disable tests
mlubin Jun 16, 2017
6677152
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
mlubin Jun 16, 2017
f85eba9
remove AbstractNonlinearModel
mlubin Jun 16, 2017
0cbe981
Fix typos and color syntaxing (#185)
blegat Jun 16, 2017
6393409
fix addvariable
mlubin Jun 16, 2017
9513474
update intro
mlubin Jun 16, 2017
d8cc314
rename attributes for constraint support
mlubin Jun 16, 2017
4909aef
spellcheck
mlubin Jun 16, 2017
b7e35bf
warn on high-level docs
mlubin Jun 16, 2017
cd71439
define SOC
mlubin Jun 16, 2017
48c5736
lighten load on travis
mlubin Jun 16, 2017
ac06eba
clarify variable references, not indices
mlubin Jun 16, 2017
87e61f2
move attributes out of status code list
mlubin Jun 16, 2017
0e1a103
column generation (#189)
odow Jun 16, 2017
3308af5
preliminary migration of nlp tests (#187)
ccoffrin Jun 16, 2017
b509ca6
restructure docs
mlubin Jun 16, 2017
b4dfb06
Merge branch 'break_everything' of https://github.com/JuliaOpt/MathPr…
mlubin Jun 16, 2017
57c1480
missing file
mlubin Jun 16, 2017
2f685d0
getters for constraint and objective data
mlubin Jun 16, 2017
f795d13
WIP: Migrated First Conic Model (#191)
ccoffrin Jun 16, 2017
dfa8cd8
WIP: redo tests (#182)
odow Jun 16, 2017
0c92ff4
another pass on attributes
mlubin Jun 19, 2017
7643636
More tests (#192)
joaquimg Jun 19, 2017
c6f3838
Add the PSD cone (#194)
blegat Jun 24, 2017
5a7e00f
added exp and pow sets, tidied definitions
chriscoey Jun 26, 2017
92e3da9
address comments
chriscoey Jun 27, 2017
a58ab57
tidy PSD definitions
chriscoey Jun 27, 2017
73d3303
empty manual
mlubin Jun 27, 2017
9980f87
missing file
mlubin Jun 27, 2017
564d645
potential math definition of set problem
chriscoey Jun 27, 2017
b9b8e54
another pass on sets
mlubin Jun 28, 2017
699698f
tidy
mlubin Jun 28, 2017
81ce4cd
remove variable bound attributes and add basic discussion of duals
mlubin Jun 29, 2017
d9a1074
1-d variablewise constraints
mlubin Jun 29, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ makedocs(
format = :html,
sitename = "MathProgBase",
pages = [
"index.md",
"Introduction" => "index.md",
"Linear Programming" => "linearprog.md",
"Mixed-Integer Programming" => "mixedintprog.md",
"Quadratic Programming" => "quadprog.md",
"Solver Interface" => "solverinterface.md",
"Choosing Solver" => "choosingsolver.md"
]
)

Expand Down
10 changes: 10 additions & 0 deletions docs/src/choosingsolver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Choosing Solvers

Solvers and solver-specific parameters are specified by [`AbstractMathProgSolver`](@ref) objects, which are provided by particular solver packages. For example, the `Clp` package exports a `ClpSolver` object, which can be passed to [`linprog`](@ref) as follows::

```julia
using Clp
linprog([-1,0],[2 1],'<',1.5, ClpSolver())
```

Options are passed as keyword arguments, for example, `ClpSolver(LogLevel=1)`. See the [Clp](https://github.com/mlubin/Clp.jl), [Cbc](https://github.com/mlubin/Cbc.jl), [GLPKMathProgInterface](https://github.com/JuliaOpt/GLPKMathProgInterface.jl), and [Gurobi](https://github.com/JuliaOpt/Gurobi.jl) packages for more information.
8 changes: 7 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# MathProgBase documentation
# MathProgBase

Solver-independent functions and low-level interfaces for Mathematical Programming

[MathProgBase.jl](https://github.com/JuliaOpt/MathProgBase.jl) provides high-level one-shot functions for linear and mixed-integer programming, as well as a solver-independent low-level interface for implementing advanced techniques that require efficiently solving a sequence of linear programming problems.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it a bit restricted to talk about linear programming here ?


To use MathProgBase, an external solver must be installed. See [Choosing Solvers](@ref).
11 changes: 11 additions & 0 deletions docs/src/linearprog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Linear Programming

```@meta
CurrentModule = MathProgBase
```

```@docs
linprog
buildlp
solvelp
```
5 changes: 5 additions & 0 deletions docs/src/mixedintprog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Mixed-integer Programming

```@docs
mixintprog
```
9 changes: 9 additions & 0 deletions docs/src/quadprog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Quadratic Programming

```@meta
CurrentModule = MathProgBase
```

```@docs
quadprog
```
107 changes: 107 additions & 0 deletions docs/src/solverinterface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Solver Interface

```@meta
CurrentModule = MathProgBase
```

```@docs
AbstractMathProgModel
AbstractMathProgSolver
```

## Basic Methods

```@docs
optimize!
freemodel!
```

## Variables

```@docs
VariableReference
candelete(::AbstractMathProgModel,::VariableReference)
isvalid(::AbstractMathProgModel,::VariableReference)
delete!(::AbstractMathProgModel,::VariableReference)
addvariables!
addvariable!
```

## Constraints

How to add constraints.
```@docs
ConstraintReference
candelete(::AbstractMathProgModel,::ConstraintReference)
isvalid(::AbstractMathProgModel,::ConstraintReference)
delete!(::AbstractMathProgModel,::ConstraintReference)
addconstraint!
```

## Sets



List of sets.
```@docs
NonNegative
NonPositive
Zero
Interval
Integers
Binaries
```
## Attributes

These are used to get and set properties of the model.

```@docs
AbstractAttribute
cangetattribute
getattribute
cansetattribute
setattribute!
```

### Scalar Attributes

```@docs
ObjectiveValue
ObjectiveBound
RelativeGap
SolveTime
Sense
SimplexIterations
BarrierIterations
NodeCount
RawSolver
ResultCount
```

### Variable Attributes

These attributes are associated with variables. Calls to `getattribute` and `setattribute!` should include a single `VariableReference` or a vector of `VariableReference` objects.

```@docs
VariableStart
VariableLowerBoundDualStart
VariableUpperBoundDualStart
VariableLowerBound
VariableUpperBound
VariablePrimal
VariableLowerBoundDual
VariableUpperBoundDual
```


## Termination Status

The `TerminationStatus` attribute is meant to explain the reason why the solver stopped executing. The value of the attribute is of type `TerminationStatusCode`.

```@docs
TerminationStatusCode
```

## Duals

We take the convention that duals on variable lower bounds should be nonnegative, duals on variable upper bounds should be nonpositive, and duals on closed convex cones should belong to the dual cone.
7 changes: 0 additions & 7 deletions src/HighLevelInterface/HighLevelInterface.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
module HighLevelInterface

using ..SolverInterface
using ..MathProgBase

function warn_no_inf(T)
if !(isinf(typemin(T)) && isinf(typemax(T)))
Base.warn_once("Element type $T does not have an infinite value. Note that this may artifically introduce ranged (two-sided) constraints. To avoid this, consider casting the problem data to Float64.")
Expand All @@ -12,5 +7,3 @@ end
include("linprog.jl")
include("mixintprog.jl")
include("quadprog.jl")

end
177 changes: 177 additions & 0 deletions src/HighLevelInterface/linprog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,50 @@ function no_lp_solver()
""")
end

"""
buildlp(c::InputVector, A::AbstractMatrix, sense::InputVector, b::InputVector, lb::InputVector, ub::InputVector, solver::AbstractMathProgSolver)

Builds the linear programming problem as defined in [`linprog`](@ref) and accepts the following arguments:

* ``c`` is the objective vector, always in the sense of minimization

* ``A`` is the constraint matrix

* ``sense`` is a vector of constraint sense characters ``'<'``, ``'='``, and ``'>'``

* ``b`` is the right-hand side vector

* ``l`` is the vector of lower bounds on the variables

* ``u`` is the vector of upper bounds on the variables, and

* ``solver`` specifies the desired solver, see [Choosing Solvers](@ref).

A scalar is accepted for the ``b``, ``sense``, ``l``, and ``u`` arguments, in which case its value is replicated. The values ``-Inf`` and ``Inf`` are interpreted to mean that there is no corresponding lower or upper bound.

This variant of [`buildlp`](@ref) allows to specify two-sided linear constraints (also known as range constraints) similar to [`linprog`](@ref), and accepts the following arguments:

buildlp(c::InputVector, A::AbstractMatrix, rowlb::InputVector, rowub::InputVector, lb::InputVector, ub::InputVector, solver::AbstractMathProgSolver)

* ``c`` is the objective vector, always in the sense of minimization

* ``A`` is the constraint matrix

* ``rowlb`` is the vector of row lower bounds

* ``rowub`` is the vector of row upper bounds

* ``lb`` is the vector of lower bounds on the variables

* ``ub`` is the vector of upper bounds on the variables, and

* ``solver`` specifies the desired solver, see [Choosing Solvers](@ref).

A scalar is accepted for the ``l``, ``u``, ``lb``, and ``ub`` arguments, in which case its value is replicated. The values ``-Inf`` and ``Inf`` are interpreted to mean that there is no corresponding lower or upper bound. Equality constraints are specified by setting the row lower and upper bounds to the same value.

The [`buildlp`](@ref) function returns an [`AbstractLinearQuadraticModel`](@ref) that can be input to [`solvelp`](@ref) in order to obtain a solution.
"""

function buildlp(c::InputVector, A::AbstractMatrix, rowlb::InputVector, rowub::InputVector, lb::InputVector, ub::InputVector, solver::AbstractMathProgSolver)
m = LinearQuadraticModel(solver)
nrow,ncol = size(A)
Expand Down Expand Up @@ -73,6 +117,23 @@ function buildlp(c::InputVector, A::AbstractMatrix, rowlb::InputVector, rowub::I
return m
end

"""
Solves the linear programming problem as defined in [`linprog`](@ref) and accepts the following argument:

* `m` is an [`AbstractLinearQuadraticModel`](@ref) (e.g., as returned by [`buildlp`](@ref)).

The [`solvelp`](@ref) function returns an instance of the type::

```julia
type LinprogSolution
status
objval
sol
attrs
end
```

"""
function solvelp(m)
optimize!(m)
stat = status(m)
Expand Down Expand Up @@ -101,7 +162,123 @@ function solvelp(m)
return LinprogSolution(stat, nothing, [], Dict())
end
end
"""

linprog(c::InputVector, A::AbstractMatrix, rowlb::InputVector, rowub::InputVector, lb::InputVector, ub::InputVector, solver::AbstractMathProgSolver)

This function allows one to specify two-sided linear constraints (also known as range constraints) to solve the linear programming problem:

```math
\\begin{align*}
\\text{min}_{x} \\quad & c^{T} x \\\\
\\text{s.t.} \\quad & rowlb \\leq A^{T} x \\leq rowub \\\\
\\quad & l \\leq x \\leq u \\\\

\\end{align*}
```

where:

* ``c`` is the objective vector, always in the sense of minimization

* ``A`` is the constraint matrix

* ``rowlb`` is the vector of row lower bounds

* ``rowub`` is the vector of row upper bounds

* ``lb`` is the vector of lower bounds on the variables

* ``ub`` is the vector of upper bounds on the variables, and

* ``solver`` specifies the desired solver, see [Choosing Solvers](@ref).

A scalar is accepted for the ``l``, ``u``, ``rowlb``, and ``rowub`` arguments, in which case its value is replicated. The values ``-Inf`` and ``Inf`` are interpreted to mean that there is no corresponding lower or upper bound. Equality constraints are specified by setting the row lower and upper bounds to the same value.

A variant usage of this function is to consider the linear programming problem in the following form,

linprog(c::InputVector, A::AbstractMatrix, sense::InputVector, b::InputVector, lb::InputVector, ub::InputVector, solver::AbstractMathProgSolver)

```math
\\begin{align*}
\\text{min}_{x} \\quad & c^{T}x \\\\
\\text{s.t.} \\quad & A_{i}^{T} \\, \\text{sense}_{i} \\, b_{i} \\quad \\forall i \\\\
\\quad & l \\leq x \\leq u
\\end{align*}
```

where:

* ``c``: is the objective vector, always in the sense of minimization

* ``A``: is the constraint matrix, with rows a_i (viewed as column-oriented vectors)

* sense: is a vector of constraint sense characters ``<``, ``=``, and ``>``

* ``b``: is the right-hand side vector

* ``l``: is the vector of lower bounds on the variables

* ``u`` is the vector of upper bounds on the variables, and solver specifies the desired solver, see [Choosing Solvers](@ref).


A shortened version is defined as::

linprog(c, A, lb, ub, solver) = linprog(c, A, lb, ub, 0, Inf, solver)

!!! note
The function [`linprog`](@ref) calls two independent functions for building and solving the linear programming problem, namely [`buildlp`](@ref) and [`solvelp`](@ref).

The [`linprog`](@ref) function returns an instance of the type::

```julia
type LinprogSolution
status
objval
sol
attrs
end
```

where `status` is a termination status symbol, one of `:Optimal`, `:Infeasible`, `:Unbounded`, `:UserLimit` (iteration limit or timeout), `:Error` (and maybe others).

If `status` is `:Optimal`, the other members have the following values:

* `objval` -- optimal objective value
* `sol` -- primal solution vector
* `attrs` -- a dictionary that may contain other relevant attributes such as:

- `redcost` -- dual multipliers for active variable bounds (zero if inactive)
- `lambda` -- dual multipliers for active linear constraints (equalities are always active)

If `status` is `:Infeasible`, the `attrs` member will contain an `infeasibilityray` if available; similarly for `:Unbounded` problems, `attrs` will contain an `unboundedray` if available.

- `colbasis` -- optimal simplex basis statuses for the variables (columns) if available. Possible values are `:NonbasicAtLower`, `:NonbasicAtUpper`, `:Basic`, and `:Superbasic` (not yet implemented by any solvers)
- `rowbasis` -- optimal simplex basis statuses for the constraints (rows) if available (not yet implemented by any solvers)

For example, we can solve the two-dimensional problem (see ``test/linprog.jl``):

```math
\\begin{align*}
\\text{min}_{x,y} \\quad & -x \\\\
\\text{s.t.} \\quad & 2x + y \\leq 1.5 \\\\
\\quad & x \\geq 0, y \\geq 0
\\end{align*}
```

```julia
using MathProgBase, Clp

sol = linprog([-1,0],[2 1],'<',1.5, ClpSolver())
if sol.status == :Optimal
println("Optimal objective value is \$(sol.objval)")
println("Optimal solution vector is: [\$(sol.sol[1]), \$(sol.sol[2])]")
else
println("Error: solution status \$(sol.status)")
end
```

"""
function linprog(c::InputVector, A::AbstractMatrix, rowlb::InputVector, rowub::InputVector, lb::InputVector, ub::InputVector, solver::AbstractMathProgSolver)
m = buildlp(c, A, rowlb, rowub, lb, ub, solver)
return solvelp(m)
Expand Down
Loading