From e19f45935440ffe79ad133070c7a42273c441dfa Mon Sep 17 00:00:00 2001 From: SimonRohou Date: Tue, 16 Jun 2020 13:25:55 +0200 Subject: [PATCH] [ctc] CtcDeriv: restoring performances of V2 (polygons) --- CMakeLists.txt | 2 +- .../arithmetic/tubex_polygon_arithmetic.cpp | 1 + .../dynamics/slice/tubex_Slice_polygon.cpp | 49 ++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2487bea0..ddfc52cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,7 @@ COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure $(ARGS) DEPENDS tubex COMMENT "Running the tests") - #add_subdirectory(tests) + add_subdirectory(tests) endif() option(TEST_EXAMPLES "Testing examples" OFF) diff --git a/src/core/arithmetic/tubex_polygon_arithmetic.cpp b/src/core/arithmetic/tubex_polygon_arithmetic.cpp index e4ac007e..2abc2169 100644 --- a/src/core/arithmetic/tubex_polygon_arithmetic.cpp +++ b/src/core/arithmetic/tubex_polygon_arithmetic.cpp @@ -33,6 +33,7 @@ namespace tubex vector v_result_thick_pts = Point::to_Points(x.vertices()); for(auto& pt : v_result_thick_pts) pt = Point(pt.box() + v); + // ^ The operation may transform a degenerate point-box into a large box return ConvexPolygon(v_result_thick_pts); } diff --git a/src/core/dynamics/slice/tubex_Slice_polygon.cpp b/src/core/dynamics/slice/tubex_Slice_polygon.cpp index 09db9c49..bc41abd1 100644 --- a/src/core/dynamics/slice/tubex_Slice_polygon.cpp +++ b/src/core/dynamics/slice/tubex_Slice_polygon.cpp @@ -103,8 +103,8 @@ namespace tubex else { - vector v_pts; - v_pts.push_back(Point(t.lb(), input_gate().lb())); + vector v_pts; + v_pts.push_back(Vector({t.lb(), input_gate().lb()})); // Lower bounds @@ -126,23 +126,35 @@ namespace tubex y_inter_lb = yolb(t_inter_lb, *this, v) | yilb(t_inter_lb, *this, v); if(y_inter_lb.ub() >= codomain().lb()) - v_pts.push_back(Point(t_inter_lb, y_inter_lb)); + { + if(t_inter_lb.is_degenerated()) + v_pts.push_back(Vector({t_inter_lb.ub(), y_inter_lb.lb()})); + + else + { + // The following transforms the line intersection result into + // two floating 2d vectors. This creates an additional point, + // but maintains reliability. + v_pts.push_back(Vector({t_inter_lb.lb(), y_inter_lb.lb()})); + v_pts.push_back(Vector({t_inter_lb.ub(), y_inter_lb.lb()})); + } + } else { Interval t_a = yilb_inv(codomain().lb(), *this, v); - v_pts.push_back(Point(t_a.lb(), codomain().lb())); + v_pts.push_back(Vector({t_a.lb(), codomain().lb()})); Interval t_b = yolb_inv(codomain().lb(), *this, v); - v_pts.push_back(Point(t_b.ub(), codomain().lb())); + v_pts.push_back(Vector({t_b.ub(), codomain().lb()})); } } } - v_pts.push_back(Point(t.ub(), output_gate().lb())); + v_pts.push_back(Vector({t.ub(), output_gate().lb()})); // Upper bounds - v_pts.push_back(Point(t.ub(), output_gate().ub())); + v_pts.push_back(Vector({t.ub(), output_gate().ub()})); if(!v.codomain().is_degenerated()) { @@ -162,20 +174,33 @@ namespace tubex y_inter_ub = youb(t_inter_ub, *this, v) | yiub(t_inter_ub, *this, v); if(y_inter_ub.lb() <= codomain().ub()) - v_pts.push_back(Point(t_inter_ub, y_inter_ub)); + { + if(t_inter_ub.is_degenerated()) + v_pts.push_back(Vector({t_inter_ub.ub(), y_inter_ub.ub()})); + + else + { + // The following transforms the line intersection result into + // two floating 2d vectors. This creates an additional point, + // but maintains reliability. + v_pts.push_back(Vector({t_inter_ub.ub(), y_inter_ub.ub()})); + v_pts.push_back(Vector({t_inter_ub.lb(), y_inter_ub.ub()})); + } + } else { Interval t_b = youb_inv(codomain().ub(), *this, v); - v_pts.push_back(Point(t_b.ub(), codomain().ub())); + v_pts.push_back(Vector({t_b.ub(), codomain().ub()})); Interval t_a = yiub_inv(codomain().ub(), *this, v); - v_pts.push_back(Point(t_a.lb(), codomain().ub())); + v_pts.push_back(Vector({t_a.lb(), codomain().ub()})); } } } - v_pts.push_back(Point(t.lb(), input_gate().ub())); - return ConvexPolygon(v_pts); + v_pts.push_back(Vector({t.lb(), input_gate().ub()})); + v_pts = Point::remove_identical_pts(v_pts); + return ConvexPolygon(v_pts, true); } } } \ No newline at end of file