From 79bbaa8c9746412e78cc04fcb9ddb96e4bf1bdba Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 1 May 2020 10:00:55 +0200 Subject: [PATCH 1/6] ignore zero generators for 1D zonotope constraints_list --- src/Interfaces/AbstractZonotope.jl | 13 +++++++++---- test/unit_Zonotope.jl | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index 0ec4eaccf6..362f67c2f0 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -498,12 +498,17 @@ function constraints_list(Z::AbstractZonotope{N}; check_full_rank::Bool=true # special handling of 1D case if n == 1 if p > 1 - error("1D-zonotope constraints currently only support a single " * - "generator") + Z_1g = remove_zero_generators(Z) + if ngens(Z_1g) > 1 + error("1D-zonotope constraints currently only support a " * + "single generator") + end + else + Z_1g = Z end - c = center(Z)[1] - g = G[:, 1][1] + c = center(Z_1g)[1] + g = genmat(Z_1g)[:, 1][1] constraints = [LinearConstraint([N(1)], c + g), LinearConstraint([N(-1)], g - c)] return constraints diff --git a/test/unit_Zonotope.jl b/test/unit_Zonotope.jl index 5626fc0795..98ea16afad 100644 --- a/test/unit_Zonotope.jl +++ b/test/unit_Zonotope.jl @@ -189,6 +189,10 @@ for N in [Float64, Rational{Int}, Float32] B = BallInf(zeros(N, 3), N(1)) # equivalent to Z constraints = constraints_list(Z) @test constraints isa Vector{<:HalfSpace{N}} && length(constraints) == 6 + + # 1D projection removes zero generators automatically + B = BallInf(N[0, 0], N(1)) + project(B, [1]) end for N in [Float64] From eb615df87017c3112265e30a6e7bdc201802dd50 Mon Sep 17 00:00:00 2001 From: Christian Schilling Date: Fri, 1 May 2020 14:55:50 +0200 Subject: [PATCH 2/6] Update src/Interfaces/AbstractZonotope.jl Co-authored-by: Marcelo Forets --- src/Interfaces/AbstractZonotope.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index 362f67c2f0..b9dc669e13 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -508,7 +508,7 @@ function constraints_list(Z::AbstractZonotope{N}; check_full_rank::Bool=true end c = center(Z_1g)[1] - g = genmat(Z_1g)[:, 1][1] + g = genmat(Z_1g)[1, 1] constraints = [LinearConstraint([N(1)], c + g), LinearConstraint([N(-1)], g - c)] return constraints From 0b13b6c97a15fe6b8d9fb785371e71ddc3eb47f6 Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 1 May 2020 15:05:01 +0200 Subject: [PATCH 3/6] generalize n=1 case in constraints_list of zonotopes --- src/Interfaces/AbstractZonotope.jl | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index b9dc669e13..06c437c012 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -497,18 +497,8 @@ function constraints_list(Z::AbstractZonotope{N}; check_full_rank::Bool=true # special handling of 1D case if n == 1 - if p > 1 - Z_1g = remove_zero_generators(Z) - if ngens(Z_1g) > 1 - error("1D-zonotope constraints currently only support a " * - "single generator") - end - else - Z_1g = Z - end - - c = center(Z_1g)[1] - g = genmat(Z_1g)[1, 1] + c = center(Z, 1) + g = sum(abs.(G[1, :])) constraints = [LinearConstraint([N(1)], c + g), LinearConstraint([N(-1)], g - c)] return constraints From a2780bd2928af2f689ce12a49b0bac4c8b2aa530 Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 1 May 2020 15:18:27 +0200 Subject: [PATCH 4/6] fix center --- src/Interfaces/AbstractZonotope.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index 06c437c012..f21707e857 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -497,7 +497,7 @@ function constraints_list(Z::AbstractZonotope{N}; check_full_rank::Bool=true # special handling of 1D case if n == 1 - c = center(Z, 1) + c = center(Z)[1] g = sum(abs.(G[1, :])) constraints = [LinearConstraint([N(1)], c + g), LinearConstraint([N(-1)], g - c)] From c64ff9cff5e111e1a47e6c34e2a12c499c9fde39 Mon Sep 17 00:00:00 2001 From: Christian Schilling Date: Fri, 1 May 2020 15:19:15 +0200 Subject: [PATCH 5/6] Update src/Interfaces/AbstractZonotope.jl Co-authored-by: Marcelo Forets --- src/Interfaces/AbstractZonotope.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index f21707e857..ccff2f8941 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -498,7 +498,7 @@ function constraints_list(Z::AbstractZonotope{N}; check_full_rank::Bool=true # special handling of 1D case if n == 1 c = center(Z)[1] - g = sum(abs.(G[1, :])) + g = sum(abs.(view(G, 1, :))) constraints = [LinearConstraint([N(1)], c + g), LinearConstraint([N(-1)], g - c)] return constraints From 20130d6896618fb5dca685213d2441a739dcb7ab Mon Sep 17 00:00:00 2001 From: Christian Schilling Date: Fri, 1 May 2020 16:04:51 +0200 Subject: [PATCH 6/6] Update test/unit_Zonotope.jl --- test/unit_Zonotope.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit_Zonotope.jl b/test/unit_Zonotope.jl index 98ea16afad..07939291a7 100644 --- a/test/unit_Zonotope.jl +++ b/test/unit_Zonotope.jl @@ -190,7 +190,7 @@ for N in [Float64, Rational{Int}, Float32] constraints = constraints_list(Z) @test constraints isa Vector{<:HalfSpace{N}} && length(constraints) == 6 - # 1D projection removes zero generators automatically + # 1D projection works correctly even with zero generators B = BallInf(N[0, 0], N(1)) project(B, [1]) end