|
1 |
| -# PiecewiseLinearOpt |
| 1 | +# PiecewiseLinearOpt.jl |
2 | 2 |
|
3 | 3 | [](https://github.com/jump-dev/PiecewiseLinearOpt.jl/actions?query=workflow%3ACI)
|
4 | 4 | [](https://codecov.io/gh/jump-dev/PiecewiseLinearOpt.jl)
|
5 | 5 |
|
6 |
| -A package for modeling optimization problems containing piecewise linear |
7 |
| -functions. Current support is for (the graphs of) continuous univariate |
| 6 | +[PiecewiseLinearOpt.jl](https://github.com/jump-dev/PiecewiseLinearOpt.jl) is a |
| 7 | +JuMP extension for modeling optimization problems containing piecewise linear |
8 | 8 | functions.
|
9 | 9 |
|
10 | 10 | This package is an accompaniment to a paper entitled
|
11 | 11 | [_Nonconvex piecewise linear functions: Advanced formulations and simple modeling tools_](https://arxiv.org/abs/1708.00050),
|
12 | 12 | by Joey Huchette and Juan Pablo Vielma.
|
13 | 13 |
|
14 |
| -This package offers helper functions for the |
15 |
| -[JuMP algebraic modeling language](https://github.com/jump-dev/JuMP.jl). |
| 14 | +## Getting help |
16 | 15 |
|
17 |
| -Consider a piecewise linear function. The function is described in terms of the |
18 |
| -breakpoints between pieces, and the function value at those breakpoints. |
| 16 | +If you need help, please ask a question on the [JuMP community forum](https://jump.dev/forum). |
19 | 17 |
|
20 |
| -Consider a JuMP model |
| 18 | +If you have a reproducible example of a bug, please open a [GitHub issue](https://github.com/jump-dev/PiecewiseLinearOpt.jl/issues/new). |
| 19 | + |
| 20 | +## License |
| 21 | + |
| 22 | +`PiecewiseLinearOpt.jl` is licensed under the [MIT license](https://github.com/jump-dev/PiecewiseLinearOpt.jl/blob/master/LICENSE.md). |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +Install PiecewiseLinearOpt using `Pkg.add`: |
21 | 27 |
|
22 | 28 | ```julia
|
23 |
| -using JuMP, PiecewiseLinearOpt |
24 |
| -m = Model() |
25 |
| -@variable(m, x) |
| 29 | +import Pkg |
| 30 | +Pkg.add("PiecewiseLinearOpt") |
26 | 31 | ```
|
27 | 32 |
|
28 |
| -To model the graph of a piecewise linear function ``f(x)``, take ``d`` as some |
29 |
| -set of breakpoints along the real line, and ``fd = [f(x) for x in d]`` as the |
30 |
| -corresponding function values. You can model this function in JuMP using the |
31 |
| -following function: |
| 33 | +## Use with JuMP |
| 34 | + |
| 35 | +Current support is limited to modeling the graph of a continuous piecewise |
| 36 | +linear function, either univariate or bivariate, with the goal of adding support |
| 37 | +for the epigraphs of lower semicontinuous piecewise linear functions. |
| 38 | + |
| 39 | +### Univariate |
| 40 | + |
| 41 | +Consider a piecewise linear function `f`. The function is described a domain `d`, |
| 42 | +which is a set of breakpoints between pieces, and the function value `fd` at |
| 43 | +those breakpoints: |
32 | 44 |
|
33 | 45 | ```julia
|
34 |
| -z = piecewiselinear(m, x, d, fd) |
35 |
| -@objective(m, Min, z) # minimize f(x) |
| 46 | +julia> f(x) = sin(x) |
| 47 | +f (generic function with 1 method) |
| 48 | + |
| 49 | +julia> d = 0:0.5:2pi |
| 50 | +0.0:0.5:6.0 |
| 51 | + |
| 52 | +julia> fd = f.(d) |
| 53 | +13-element Vector{Float64}: |
| 54 | + 0.0 |
| 55 | + 0.479425538604203 |
| 56 | + 0.8414709848078965 |
| 57 | + 0.9974949866040544 |
| 58 | + 0.9092974268256817 |
| 59 | + 0.5984721441039564 |
| 60 | + 0.1411200080598672 |
| 61 | + -0.35078322768961984 |
| 62 | + -0.7568024953079282 |
| 63 | + -0.977530117665097 |
| 64 | + -0.9589242746631385 |
| 65 | + -0.7055403255703919 |
| 66 | + -0.27941549819892586 |
36 | 67 | ```
|
37 | 68 |
|
38 |
| -For another example, think of a piecewise linear approximation for the function |
39 |
| -$f(x,y) = exp(x+y)$: |
| 69 | +To represent this function in a JuMP model, do: |
40 | 70 |
|
41 | 71 | ```julia
|
42 | 72 | using JuMP, PiecewiseLinearOpt
|
43 |
| -m = Model() |
44 |
| -@variable(m, x) |
45 |
| -@variable(m, y) |
| 73 | +model = Model() |
| 74 | +@variable(model, x) |
| 75 | +z = PiecewiseLinearOpt.piecewiselinear(model, x, d, fd; method = :CC) |
| 76 | +@objective(model, Min, z) # minimize f(x) |
| 77 | +``` |
| 78 | + |
| 79 | +### Bivariate |
46 | 80 |
|
47 |
| -z = piecewiselinear(m, x, y, 0:0.1:1, 0:0.1:1, (u,v) -> exp(u+v)) |
48 |
| -@objective(m, Min, z) |
| 81 | +Consider piecewise linear approximation for the function $f(x, y) = exp(x + y)$: |
| 82 | + |
| 83 | +```julia |
| 84 | +using JuMP, PiecewiseLinearOpt |
| 85 | +model = Model() |
| 86 | +@variable(model, x) |
| 87 | +@variable(model, y) |
| 88 | +z = PiecewiseLinearOpt.piecewiselinear( |
| 89 | + model, |
| 90 | + x, |
| 91 | + y, |
| 92 | + 0:0.1:1, |
| 93 | + 0:0.1:1, |
| 94 | + (u, v) -> exp(u + v); |
| 95 | + method = :DisaggLogarithmic, |
| 96 | +) |
| 97 | +@objective(model, Min, z) |
49 | 98 | ```
|
50 | 99 |
|
51 |
| -Current support is limited to modeling the graph of a continuous piecewise |
52 |
| -linear function, either univariate or bivariate, with the goal of adding support |
53 |
| -for the epigraphs of lower semicontinuous piecewise linear functions. |
| 100 | +## Methods |
54 | 101 |
|
55 | 102 | Supported univariate formulations:
|
56 | 103 |
|
57 |
| -* Convex combination (``:CC``) |
58 |
| -* Multiple choice (``:MC``) |
59 |
| -* Native SOS2 branching (``:SOS2``) |
60 |
| -* Incremental (``:Incremental``) |
61 |
| -* Logarithmic (``:Logarithmic``; default) |
62 |
| -* Disaggregated Logarithmic (``:DisaggLogarithmic``) |
63 |
| -* Binary zig-zag (``:ZigZag``) |
64 |
| -* General integer zig-zag (``:ZigZagInteger``) |
| 104 | +* Convex combination (`:CC`) |
| 105 | +* Multiple choice (`:MC`) |
| 106 | +* Native SOS2 branching (`:SOS2`) |
| 107 | +* Incremental (`:Incremental`) |
| 108 | +* Logarithmic (`:Logarithmic`; default) |
| 109 | +* Disaggregated Logarithmic (`:DisaggLogarithmic`) |
| 110 | +* Binary zig-zag (`:ZigZag`) |
| 111 | +* General integer zig-zag (`:ZigZagInteger`) |
65 | 112 |
|
66 | 113 | Supported bivariate formulations for entire constraint:
|
67 | 114 |
|
68 |
| -* Convex combination (``:CC``) |
69 |
| -* Multiple choice (``:MC``) |
70 |
| -* Dissaggregated Logarithmic (``:DisaggLogarithmic``) |
| 115 | +* Convex combination (`:CC`) |
| 116 | +* Multiple choice (`:MC`) |
| 117 | +* Dissaggregated Logarithmic (`:DisaggLogarithmic`) |
71 | 118 |
|
72 | 119 | Also, you can use any univariate formulation for bivariate functions as well.
|
73 | 120 | They will be used to impose two axis-aligned SOS2 constraints, along with the
|
74 | 121 | "6-stencil" formulation for the triangle selection portion of the constraint.
|
75 | 122 | See the associated paper for more details. In particular, the following are also
|
76 | 123 | acceptable bivariate formulation choices:
|
77 | 124 |
|
78 |
| -* Native SOS2 branching (``:SOS2``) |
79 |
| -* Incremental (``:Incremental``) |
80 |
| -* Logarithmic (``:Logarithmic``) |
81 |
| -* Binary zig-zag (``:ZigZag``) |
82 |
| -* General integer zig-zag (``:ZigZagInteger``) |
| 125 | +* Native SOS2 branching (`:SOS2`) |
| 126 | +* Incremental (`:Incremental`) |
| 127 | +* Logarithmic (`:Logarithmic`) |
| 128 | +* Binary zig-zag (`:ZigZag`) |
| 129 | +* General integer zig-zag (`:ZigZagInteger`) |
0 commit comments