/
index.html
56 lines (48 loc) · 11.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Optimization · Polyhedra</title><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link href="../assets/documenter.css" rel="stylesheet" type="text/css"/></head><body><nav class="toc"><h1>Polyhedra</h1><select id="version-selector" onChange="window.location.href=this.value" style="visibility: hidden"></select><form class="search" id="search-form" action="../search/"><input id="search-query" name="q" type="text" placeholder="Search docs"/></form><ul><li><a class="toctext" href="../">Index</a></li><li><a class="toctext" href="../installation/">Installation</a></li><li><a class="toctext" href="../representation/">Representation</a></li><li><a class="toctext" href="../polyhedron/">Polyhedron</a></li><li><a class="toctext" href="../plot/">Plot</a></li><li><a class="toctext" href="../redundancy/">Containment/Redundancy</a></li><li><a class="toctext" href="../projection/">Projection/Elimination</a></li><li class="current"><a class="toctext" href>Optimization</a><ul class="internal"><li><a class="toctext" href="#Using-a-polyhedron-for-in-an-optimization-model-1">Using a polyhedron for in an optimization model</a></li><li><a class="toctext" href="#Creating-a-polyhedron-from-the-feasible-set-of-a-JuMP-model-1">Creating a polyhedron from the feasible set of a JuMP model</a></li></ul></li><li><a class="toctext" href="../utilities/">Utilities</a></li></ul></nav><article id="docs"><header><nav><ul><li><a href>Optimization</a></li></ul><a class="edit-page" href="https://github.com/JuliaPolyhedra/Polyhedra.jl/blob/master/docs/src/optimization.md"><span class="fa"></span> Edit on GitHub</a></nav><hr/><div id="topbar"><span>Optimization</span><a class="fa fa-bars" href="#"></a></div></header><h1><a class="nav-anchor" id="Optimization-1" href="#Optimization-1">Optimization</a></h1><p>A polyhedron can represents the feasible set of an optimization program. The program is infeasible when the polyhedron is empty.</p><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.isempty" href="#Base.isempty"><code>Base.isempty</code></a> — <span class="docstring-category">Function</span>.</div><div><div><pre><code class="language-none">isempty(p::Rep, solver::JuMP.OptimizerFactory=Polyhedra.linear_objective_solver(p))</code></pre><p>Check whether the polyhedron <code>p</code> is empty by using the solver <code>solver</code>.</p></div></div></section><p>If the V-representation of the polyhedron has been computed, it can be used to solve the linear program.</p><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Polyhedra.VRepOptimizer" href="#Polyhedra.VRepOptimizer"><code>Polyhedra.VRepOptimizer</code></a> — <span class="docstring-category">Type</span>.</div><div><div><pre><code class="language-none">VRepOptimizer{T} <: AbstractPolyhedraOptimizer{T}</code></pre><p>Linear Programming solver using the V-representation of the feasible set to find the optimal solution.</p></div></div></section><p>Otherwise, any programming solver implementing the <a href="https://github.com/JuliaOpt/MathOptInterface.jl">MathOptInterface</a> interface can be used. See <a href="http://www.juliaopt.org/JuMP.jl/dev/installation/#Getting-Solvers-1">here</a> for a list of available solvers.</p><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Polyhedra.default_solver" href="#Polyhedra.default_solver"><code>Polyhedra.default_solver</code></a> — <span class="docstring-category">Function</span>.</div><div><div><pre><code class="language-none">default_solver(p::Rep)</code></pre><p>Returns a default linear programming solver for the polyhedron <code>p</code> (e.g. CDD has an internal solver which is used by default).</p></div></div></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Polyhedra.linear_objective_solver" href="#Polyhedra.linear_objective_solver"><code>Polyhedra.linear_objective_solver</code></a> — <span class="docstring-category">Function</span>.</div><div><div><pre><code class="language-none">linear_objective_solver(p::Rep, solver::Union{Nothing, JuMP.OptimizerFactory}=default_solver(p))</code></pre><p>Return the solver to use for optimizing a linear objective over the polyhedron <code>p</code>, i.e.</p><pre><code class="language-julia">model = Model(solver)
x = @variable(model, [1:fulldim(p)])
@constraint(model, x in p)
@objective(model, c ⋅ x)</code></pre><p>for some vector <code>c</code>.</p><p>By default, if the V-representation of <code>p</code> has been computed, it returns <code>VRepOptimizer()</code>, otherwise, it returns <code>solver</code>.</p><p>If the problem has constraints different to <code>x in p</code>, use <code>default_solver(p)</code> instead as the fact that the V-representation of <code>p</code> has been computed does not help.</p></div></div></section><h2><a class="nav-anchor" id="Using-a-polyhedron-for-in-an-optimization-model-1" href="#Using-a-polyhedron-for-in-an-optimization-model-1">Using a polyhedron for in an optimization model</a></h2><p>A polyhedron or representation can be used in the constraint of a JuMP model. For instance, consider the 1-simplex:</p><pre><code class="language-julia-repl">julia> using Polyhedra
julia> simplex = HalfSpace([-1, 0], 0) ∩ HalfSpace([0, -1], 0) ∩ HyperPlane([1, 1], 1)
H-representation Polyhedra.Intersection{Int64,Array{Int64,1},Int64}:
1-element iterator of HyperPlane{Int64,Array{Int64,1}}:
HyperPlane([1, 1], 1),
2-element iterator of HalfSpace{Int64,Array{Int64,1}}:
HalfSpace([-1, 0], 0)
HalfSpace([0, -1], 0)</code></pre><p>and the following JuMP model with two variables</p><pre><code class="language-julia-repl">julia> using JuMP
julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
julia> @variable(model, λ[1:2])
2-element Array{VariableRef,1}:
λ[1]
λ[2]</code></pre><p>The variables can be constrained to belong to the simplex as follows:</p><pre><code class="language-julia-repl">julia> @constraint(model, λ in simplex)
[λ[1], λ[2]] ∈ Polyhedra.PolyhedraOptSet{Int64,Polyhedra.Intersection{Int64,Array{Int64,1},Int64}}(HyperPlane([1, 1], 1) ∩ HalfSpace([-1, 0], 0) ∩ HalfSpace([0, -1], 0))</code></pre><p>but a vector of affine or quadratic expressions can also be constrained to belong to the simplex:</p><pre><code class="language-julia-repl">julia> A = [1 1
1 -1]
2×2 Array{Int64,2}:
1 1
1 -1
julia> @constraint(model, A * λ in simplex)
[λ[1] + λ[2], λ[1] - λ[2]] ∈ Polyhedra.PolyhedraOptSet{Int64,Polyhedra.Intersection{Int64,Array{Int64,1},Int64}}(HyperPlane([1, 1], 1) ∩ HalfSpace([-1, 0], 0) ∩ HalfSpace([0, -1], 0))</code></pre><p>We can verify that the model contains both constraints:</p><pre><code class="language-julia">julia> model
A JuMP Model
Feasibility problem with:
Variables: 2
`Array{JuMP.VariableRef,1}`-in-`Polyhedra.PolyhedraOptSet{Int64,Polyhedra.Intersection{Int64,Array{Int64,1},Int64}}`: 1 constraint
`Array{JuMP.GenericAffExpr{Float64,JuMP.VariableRef},1}`-in-`Polyhedra.PolyhedraOptSet{Int64,Polyhedra.Intersection{Int64,Array{Int64,1},Int64}}`: 1 constraint
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: λ</code></pre><p>When the model is solved, the constraint is automatically transformed into appropriate constraints if the optimizer does not support consraints with the set <code>Polyhedra.PolyhedraOptSet</code>.</p><pre><code class="language-julia">julia> import GLPK
julia> optimize!(model, with_optimizer(GLPK.Optimizer))
julia> termination_status(model)
OPTIMAL::TerminationStatusCode = 1
julia> value.(λ)
2-element Array{Float64,1}:
0.5
0.5</code></pre><p>For instance, GLPK, does not support <code>Polyhedra.PolyhedraOptSet</code> constraints but supports <code>MOI.EqualTo{Float64}</code> and <code>MOI.LessThan{Float64}</code>. The polyhedral constraints are therefore bridged into several <code>MOI.EqualTo{Float64}</code> and <code>MOI.LessThan{Float64}</code> constraints using the following <a href="http://www.juliaopt.org/MathOptInterface.jl/stable/apimanual/#Constraint-bridges-1">constraint bridge</a>:</p><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Polyhedra.PolyhedraToLPBridge" href="#Polyhedra.PolyhedraToLPBridge"><code>Polyhedra.PolyhedraToLPBridge</code></a> — <span class="docstring-category">Type</span>.</div><div><div><pre><code class="language-none">PolyhedraToLPBridge{T}</code></pre><p>The <code>PolyhedraToLPBridge</code> converts a constraint <code>VF</code>-in-<code>PolyhedraOptSet</code> into the constraints <code>F</code>-in-<code>EqualTo</code> for the hyperplanes and <code>F</code>-to-<code>LessThan</code> for halfspaces.</p></div></div></section><p>See <a href="https://github.com/JuliaPolyhedra/Polyhedra.jl/blob/master/examples/Polyhedral%20Function.ipynb">Polyhedral Function</a> for an example notebook.</p><h2><a class="nav-anchor" id="Creating-a-polyhedron-from-the-feasible-set-of-a-JuMP-model-1" href="#Creating-a-polyhedron-from-the-feasible-set-of-a-JuMP-model-1">Creating a polyhedron from the feasible set of a JuMP model</a></h2><p>A typical application of polyhedral computation is the computation of the set of extreme points and rays of the feasible set of an optimization problem. This comes from the fact that given a minimization of a concave function (or maximization of a convex function) on a convex feasible set (e.g. Linear Programming), we are either in the following three situations:</p><ul><li>The feasible set is empty, i.e. the problem is infeasible.</li><li>An extreme ray is optimal, i.e. the problem is unbounded (or it may also be bounded if the objective is constant along the ray).</li><li>An extreme point is optimal.</li></ul><p>A JuMP model is treated by <code>polyhedron</code> just like any H-representation. For example, the hypercube of dimension <code>n</code> can be created as follows</p><pre><code class="language-julia">m = Model()
@variable(m, 0 ≤ x[1:n] ≤ 1)
poly = polyhedron(m, CDDLib.Library(:exact))</code></pre><footer><hr/><a class="previous" href="../projection/"><span class="direction">Previous</span><span class="title">Projection/Elimination</span></a><a class="next" href="../utilities/"><span class="direction">Next</span><span class="title">Utilities</span></a></footer></article></body></html>