From 5261c5bbef431d40cc45aa9cf2048f94ca527218 Mon Sep 17 00:00:00 2001 From: Dimitri Alston Date: Fri, 15 Sep 2023 16:38:09 -0400 Subject: [PATCH] Update McCormick.jl Added a new MC constructor that takes a convex relaxation, concave relaxation, and an interval as inputs and returns a struct with subgradients equal to 0. --- Project.toml | 2 +- src/McCormick.jl | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index ca9fffa..100fd4f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "McCormick" uuid = "53c679d3-6890-5091-8386-c291e8c8aaa1" authors = ["Matthew Wilhelm "] -version = "0.13.5" +version = "0.13.6" [deps] DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b" diff --git a/src/McCormick.jl b/src/McCormick.jl index 8f2c4a9..e2cea7c 100644 --- a/src/McCormick.jl +++ b/src/McCormick.jl @@ -333,7 +333,7 @@ end """ MC{N,T}(y::Interval{Float64}) -Constructs McCormick relaxation with convex relaxation equal to `y.lo` and +Constructs a McCormick relaxation with the convex relaxation equal to `y.lo` and concave relaxation equal to `y.hi`. """ function MC{N,T}(y::Interval{Float64}) where {N, T <: RelaxTag} @@ -344,7 +344,7 @@ end """ MC{N,T}(y::Float64) -Constructs McCormick relaxation with convex relaxation equal to `y` and +Constructs a McCormick relaxation with the convex relaxation equal to `y` and concave relaxation equal to `y`. """ MC{N,T}(y::Float64) where {N, T <: RelaxTag} = MC{N,T}(Interval{Float64}(y)) @@ -356,20 +356,31 @@ MC{N,T}(y::Q) where {N, T <: RelaxTag, Q <: NumberNotRelax} = MC{N,T}(Interval{F """ MC{N,T}(cv::Float64, cc::Float64) -Constructs McCormick relaxation with convex relaxation equal to `cv` and +Constructs a McCormick relaxation with the convex relaxation equal to `cv` and concave relaxation equal to `cc`. """ function MC{N,T}(cv::Float64, cc::Float64) where {N, T <: RelaxTag} MC{N,T}(cv, cc, Interval{Float64}(cv, cc), zero(SVector{N,Float64}), - zero(SVector{N,Float64}), true) + zero(SVector{N,Float64}), true) +end + +""" +MC{N,T}(cv::Float64, cc::Float64, Intv::Interval{Float64}) + +Constructs a McCormick relaxation with the convex relaxation equal to `cv`, +concave relaxation equal to `cc`, and interval bounds of `Intv`. +""" +function MC{N,T}(cv::Float64, cc::Float64, Intv::Interval{Float64}) where {N, T <: RelaxTag} + MC{N,T}(cv, cc, Intv, zero(SVector{N,Float64}), + zero(SVector{N,Float64}), true) end """ MC{N,T}(val::Float64, Intv::Interval{Float64}, i::Int64) -Constructs McCormick relaxation with convex relaxation equal to `val`, +Constructs a McCormick relaxation with the convex relaxation equal to `val`, concave relaxation equal to `val`, interval bounds of `Intv`, and a unit subgradient -with nonzero's ith dimension of length N. +with a nonzero ith dimension of length N. """ function MC{N,T}(val::Float64, Intv::Interval{Float64}, i::Int64) where {N, T <: RelaxTag} MC{N,T}(val, val, Intv, seed_gradient(i, Val{N}()), seed_gradient(i, Val{N}()), false)