Skip to content

Commit b0bbe5c

Browse files
authored
Update README.md (#57)
1 parent 75c2948 commit b0bbe5c

File tree

1 file changed

+90
-43
lines changed

1 file changed

+90
-43
lines changed

README.md

Lines changed: 90 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,129 @@
1-
# PiecewiseLinearOpt
1+
# PiecewiseLinearOpt.jl
22

33
[![Build Status](https://github.com/jump-dev/PiecewiseLinearOpt.jl/workflows/CI/badge.svg)](https://github.com/jump-dev/PiecewiseLinearOpt.jl/actions?query=workflow%3ACI)
44
[![codecov](https://codecov.io/gh/jump-dev/PiecewiseLinearOpt.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jump-dev/PiecewiseLinearOpt.jl)
55

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
88
functions.
99

1010
This package is an accompaniment to a paper entitled
1111
[_Nonconvex piecewise linear functions: Advanced formulations and simple modeling tools_](https://arxiv.org/abs/1708.00050),
1212
by Joey Huchette and Juan Pablo Vielma.
1313

14-
This package offers helper functions for the
15-
[JuMP algebraic modeling language](https://github.com/jump-dev/JuMP.jl).
14+
## Getting help
1615

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).
1917

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`:
2127

2228
```julia
23-
using JuMP, PiecewiseLinearOpt
24-
m = Model()
25-
@variable(m, x)
29+
import Pkg
30+
Pkg.add("PiecewiseLinearOpt")
2631
```
2732

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:
3244

3345
```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
3667
```
3768

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:
4070

4171
```julia
4272
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
4680

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)
4998
```
5099

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
54101

55102
Supported univariate formulations:
56103

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`)
65112

66113
Supported bivariate formulations for entire constraint:
67114

68-
* Convex combination (``:CC``)
69-
* Multiple choice (``:MC``)
70-
* Dissaggregated Logarithmic (``:DisaggLogarithmic``)
115+
* Convex combination (`:CC`)
116+
* Multiple choice (`:MC`)
117+
* Dissaggregated Logarithmic (`:DisaggLogarithmic`)
71118

72119
Also, you can use any univariate formulation for bivariate functions as well.
73120
They will be used to impose two axis-aligned SOS2 constraints, along with the
74121
"6-stencil" formulation for the triangle selection portion of the constraint.
75122
See the associated paper for more details. In particular, the following are also
76123
acceptable bivariate formulation choices:
77124

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

Comments
 (0)