Solving a piecewise linear system

#22

Are you sure? If I solve an instance using PiecewiseLinearOpt with the following code:

using JuMP
using Random
using LinearAlgebra
using PiecewiseLinearOpt

Random.seed!(2)
n = 5
# problem data
a = rand()
b = rand()
κ = rand()
c₀ = rand()
c = randn(n)
f = randn(n)

# using Gurobi
# model = Model(solver=GurobiSolver())
using Cbc
model = Model(solver=CbcSolver())
@variable model s₀
@variable model s[1 : n]
s⁺ = piecewiselinear.(Ref(model), s, Ref([-100, 0, 100]), x -> max(0, x)) # 10 is arbitrary
δ = Matrix{Variable}(undef, n, n)
for i = 1 : n
δ[:, i] = piecewiselinear.(Ref(model), s - s[i], Ref([-100, 0, 100]), x -> max(0, x)) # 10 is arbitrary
end
@constraint model a * s₀ == c₀ + κ * s⁺ ⋅ f
for i = 1 : n
@constraint model a * s₀ + b * s[i] == c[i] + δ[:, i] ⋅ f
end
solve(model)


and then run the following tests:

using Test
@test getvalue.(s⁺) ≈ max.(getvalue.(s), 0) atol=1e-6
for i = 1 : n
@test getvalue.(δ[:, i]) ≈ max.(getvalue.(s) .- getvalue(s[i]), 0) atol=1e-6
end
@test a * getvalue(s₀) ≈ c₀ + κ * max.(getvalue.(s), 0) ⋅ f atol=1e-6
for i = 1 : n
@test a * getvalue(s₀) + b * getvalue(s[i]) ≈ c[i] + max.(getvalue.(s) .- getvalue(s[i]), 0) ⋅ f atol=1e-6
end

I = sortperm(c)
@test issorted(c[I])
@test issorted(getvalue.(s)[I])