PSORLab / EAGO.jl

A development environment for robust and global optimization
MIT License
140 stars 16 forks source link

Issue with McCormick relaxation #40

Closed ca0h closed 4 years ago

ca0h commented 4 years ago

May find an issue with McCormick relaxation on exponentiation. Plots look weird (both NS and Diff mode). MWE is attached in the following:

EAGO@0.3.1

using EAGO.McCormick, DataFrames, IntervalArithmetic

# initializes function to explicitly solve for x
f(x,y) = (x-2)^2 + (x-y)^3+ (x-y)^4

# create a data frame to store output data
df = DataFrame(x = Float64[], y = Float64[], z = Float64[], cv1 = Float64[], cv2 = Float64[],
               cc1 = Float64[], cc2 = Float64[], l1 = Float64[], l2 = Float64[],
               u1 = Float64[], u2 = Float64[])

n = 30
X = EAGO.Interval(-1,1)
Y = EAGO.Interval(-1,1)
xrange = range(X.lo,stop=X.hi,length=n)
yrange = range(Y.lo,stop=Y.hi,length=n)

for (i,x) in enumerate(xrange)
    for (j,y) in enumerate(yrange)
        z = f(x,y)
        x_mc = MC{1,NS}(x,X,1)
        y_mc = MC{1,NS}(y,Y,2)
        x_dmc = MC{1,Diff}(x,X,1)
        y_dmc = MC{1,Diff}(y,Y,2)
        f_mc = f(x_mc,y_mc)
        f_dmc = f(x_dmc,y_dmc)
        save_tuple = (x, y, z, f_dmc.cv, f_mc.cv, f_dmc.cc, f_mc.cc,
                      lo(f_dmc.Intv), lo(f_mc.Intv), hi(f_dmc.Intv), hi(f_mc.Intv))
        push!(df, save_tuple)
    end
end

using Plots, CSV
pyplot()

Plots.plot(df.x, df.y, df.z, st = [:surface], title = "Smooth McCormick Relaxation")
Plots.plot!(df.x, df.y, df.cv1, st = [:surface])
Plots.plot!(df.x, df.y, df.cc1, st = [:surface])

# Plots.plot(df.x, df.y, df.z, st = [:surface], title = "Nonsmooth McCormick Relaxation")
# Plots.plot!(df.x, df.y, df.cv2, st = [:surface])
# Plots.plot!(df.x, df.y, df.cc2, st = [:surface])
# Plots.plot!(camera = (150,20))

# CSV.write("plot_data.csv", df)
mewilhel commented 4 years ago

This was coming from an improper conversion in x - 2. Basically the conversion of 2 (Int) to 2.0 (Float64) missed adjusting the interval field appropriately. Commit https://github.com/PSORLab/EAGO.jl/commit/ad9ad3535c9d4ba4d297e07a8048a336b5fcffda to the master fixes this. I'm going to resolve a couple more bugs then tag a 3.2 release.