Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Speeding Up Arrangement Insertion

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Speeding Up Arrangement Insertion


Chronological Thread 
  • From: Guillaume Damiand <>
  • To:
  • Subject: Re: [cgal-discuss] Speeding Up Arrangement Insertion
  • Date: Fri, 5 Nov 2021 13:46:21 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-data: A9a23:qYwBRaxKyg5T22Vbijh6t+dPxyrEfRIJ4+MujC/XYbTApG8l0DdUmmEYWW2DMqncMGP0ft1zOYTg8x9SuZfVnIJhOVdlrnsFo1Bi+ZOUX4zBRqvTF3rPdZObFBoPA/3z27AsFehsJpPnjkrrYueJQUVUj/nSH+OlULOcYEideCc9IMsfoUI78wIGqtUw6TSJK1vlVeLa+6UzCnf9s9JHGj58B5a4lf9alK+aVAX0EbAJTasjUFf2zxH5BX+ETE27ByOQroJ8RoZWSwtfpYxV8F81/z91Yj+kur36aVcRR6LKYU6TjHtIHqyzhR4b4CIouko5HKNHNQEN0mnPxoAhjowR6vRcSi9xVkHIsOsAUh1cGjx7MOtK8brGKH6zmciS1UzdNXDq2e4oAlte0YgwoL8nWzoRqJT0LxhXN0vb37rrqF6hccFnic0nacXqJ4gCoWpI1iDcFf9gQJbZQqyM68Uw4duartQWSK2YOt5APGIpNACaNkUJYApJVoZlyb/u222gJhRGjnmQg4Y3x0na6jBr9qy0aI+MPoSeLSlOtk2ZvXjd+njhXlcHMt2BjD6U9XT1wOHV9R4Xkbk6TNWQnsOGSnXKroDSNPEXabd/ifK4kVSlXs5HdwoJ/Csw6Kwj80ryCNfnN/F9iBZooTZEM+e80cVjgO1O9kYQywKYHGkfCDVHcsdgutVeqfkCyAqSh92wbdBwmOT9dJ9en4t4aRu2ODIUNikJYzUfCwUfizUmiOnfkTqXJute/GWJYhEZ1N0+L/1mbMTzulnLsfM26g==
  • Ironport-hdrordr: A9a23:IfeYF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ULMVFIdRGdg4T0NFzDIvb1BuqljVu2ijdk3fXGM6XhAprTKnjDl6/scqp8605H0goz1tVf545MCrwOOv7zR0nxtN3GDhMgNwy1w+HnCNNg2o8EV2KPGLeVMKLUsVCW+uIiO/SAaYEatTrnNfQp+vHjgWUklVIefqSlx4YbZX+6E/h+JkWWe3vsgtMPEWcQuQo+SfTniFKfUT5SY3ayW7gz5iw+CI24F4vMW5qigLmA3CihGJ1Ze3tLClSNEXfydoWEQO0AZz6UIs97iTwIT7ahS5U52RG0qAD606ZnLvbT+iAAqZ3j28J65+nKmR4v9Dx0FNiS03yWT2FvhW4IXD833KVnoUNn0FuD0K54g+ZZFdNJ/f9JXB06ZtbhyfdnAYXyRh7ZZYXOD023R82vRzA3VNM4hdEUJF1sHs2ryRHF0S3tCLAck/mHBYc/77nHjEX3PNt362rD0Pwhk0U+WZkIcna3g7Z2sQnVHY/A1UuD0L27cLwVmy/L+mDExmWHuARUURV7TL7eDk0ZfVbckdnp+hbCU6O2EuZgdRBQzNaLbKpMcNzgy1tcA+zyPczXJGO3lWD3DhmBwvaAbZHhZn4GjxnaXUMLmgRW8XedPhUlHQ+gpXjfBXpgDwHBeUTppMZjqXe/R1IxwkmmZkhg3ry5skoamP2YT/oO279CtC4kqjxyEH653sjXEJyLoRB6OqtGN4BuqGxb3H7U4lQudqerKLpv0wZ2m+Ffu0L01g4xAYNaio4ktiFypOKdAaaZylJaMTiex4u2NKeFcwEaHTikarXMwVTCyIrQ56EO9rE8ulLl5UenDBh6m0g=

Hi Bruno;

Instead of inserting each segment successively, insert them "simultaneously" using the following insert free function:
https://doc.cgal.org/latest/Arrangement_on_surface_2/group__PkgArrangementOnSurface2Insert.html#ga744ea4ef5e40e521af139e106b6480f8

The complexity of the global method is almost in O(nlogn), while it is O(n^2) for the other solution.

cf. also https://doc.cgal.org/latest/Arrangement_on_surface_2/index.html#title68

Best
Guillaume



Le 05/11/2021 à 13:37, Bruno Silva a écrit :
Hi Andreas,
Now, I've put this code on gist.github.com: https://gist.github.com/BrunoRammon/c2850f4aef513571ba27e69773c5d3eb
arrangementInsertion.cpp GitHub Gist: instantly share code, notes, and snippets. gist.github.com
Best,
Bruno

De: em nome de Andreas Fabri
Enviado: sexta-feira, 5 de novembro de 2021 06:51
Para: Bruno Silva ( via cgal-discuss Mailing List)
Assunto: Re: [cgal-discuss] Speeding Up Arrangement Insertion
 

Hello,


Ideally, you put code on gist.github.com

 

Best,

Andreas


On 11/5/2021 12:39 PM, Bruno Silva ( via cgal-discuss Mailing List) wrote:

Just sending the code once again with some small changes:

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Arr_naive_point_location.h>
#include <CGAL/Arr_non_caching_segment_basic_traits_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>


typedef CGAL::Exact_predicates_exact_constructions_kernel                       K1;
typedef CGAL::Arr_segment_traits_2<K1>                                          Traits_2;
typedef CGAL::Arrangement_2<Traits_2>                                           Arrangement_2;
typedef CGAL::Delaunay_triangulation_2<K1>                                      Delaunay2;
typedef CGAL::Constrained_Delaunay_triangulation_2<K1, CGAL::Default, Itag>     CDT2;
typedef Traits_2::Point_2                                                       Point_2;
typedef Traits_2::X_monotone_curve_2                                            Segment_2;
typedef CGAL::Arr_naive_point_location<Arrangement_2>                           WalkPL_2;

int main()
{
    ExternalDataSet datas("data1.txt","data2.txt");
   
    Arrangement_2 arr;
    WalkPL_2 walkPL(arr);

    // first step of insertions
    std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();

    std::vector<Segment_2> segmentSet1 = datas.externalData(0);
    CGAL::insert_non_intersecting_curves(arr, segmentSet1.begin(), segmentSet1.end());
    segmentSet1.clear();

    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
    if (verbose) std::cout << "Time spent - First Insertion: " << std::setprecision(6) << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()/1.0e+6 << std::fixed << " sec." << std::endl;  
   
    //Second step of insertions
    begin = std::chrono::steady_clock::now();

    std::vector<Segment_2> segmentSet2 = datas.externalData(1);
    // #pragma omp parallel for if(_parallelOptimization)
    for(auto seg = segmentSet2.begin(); seg < segmentSet2.end(); ++seg)
    {
        CGAL::insert(arr, *seg, walkPL);
    }
    segmentSet2.clear();

    end = std::chrono::steady_clock::now();
    if (verbose) std::cout << "Time spent - Second Insertion: " << std::setprecision(6) << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()/1.0e+6 << std::fixed << " sec." << std::endl;  
   
    CDT2 cdt;
    // Constrained Delaunay package to triangulate the arrangement
    begin = std::chrono::steady_clock::now();
    for (auto it = arr.edges_begin(); it != arr.edges_end(); ++it) {
        cdt.insert(it->source()->point(), it->target()->point());
    }
    end = std::chrono::steady_clock::now();
    if (verbose) std::cout << "Time spent - Creation of the Constrained Delaunay Triangulation: " << std::setprecision(6) << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()/1.0e+6 << std::fixed << " sec." << std::endl;  
}


-------

Att, 

Bruno Rammon Silva Souza


De: Bruno Silva
Enviado: sexta-feira, 5 de novembro de 2021 06:20
Para: <>
Assunto: Speeding Up Arrangement Insertion
 
Hi everyone,

I'm having a problem with efficiency when computing arrangements by CGAL. Thus, I would like to know whether there's any way to improve the efficiency of this.

The code is:
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Arr_naive_point_location.h>
#include <CGAL/Arr_non_caching_segment_basic_traits_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>


typedef CGAL::Exact_predicates_exact_constructions_kernel                       K1;
typedef CGAL::Arr_segment_traits_2<K1>                                          Traits_2;
typedef CGAL::Arrangement_2<Traits_2>                                           Arrangement_2;
typedef CGAL::Delaunay_triangulation_2<K1>                                      Delaunay2;
typedef CGAL::Constrained_Delaunay_triangulation_2<K1, CGAL::Default, Itag>     CDT2;
typedef Traits_2::Point_2                                                       Point_2;
typedef Traits_2::X_monotone_curve_2                                            Segment_2;
typedef CGAL::Arr_naive_point_location<Arrangement_2>                           WalkPL_2;

int main()
{
    ExternalDataSet datas("data1.txt","data2.txt");


    std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();

    std::vector<Segment_2> segmentSet1 = datas.externalData(0);
    CGAL::insert_non_intersecting_curves(arr, segmentSet1.begin(), segmentSet1.end());
    segmentSet1.clear();std::chrono::steady_clock::time_point
   
    end = std::chrono::steady_clock::now();
    if (verbose) std::cout << "Time spent - First Insertion: " << std::setprecision(6) <<          std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()/1.0e+6 << std::fixed << " sec." << std::endl;
   
    // Insertion of the second set of segments
    begin = std::chrono::steady_clock::now();

    std::vector<Segment_2> segmentSet2 = datas.externalData(1);
    // #pragma omp parallel for //Parllellization is not working!!
    for(auto seg = segments1.begin(); seg < segments1.end(); ++seg)
    {
        CGAL::insert(arr, *seg, walkPL);
    }
    segmentSet2.clear();
   
    end = std::chrono::steady_clock::now();
    if (verbose) std::cout << "Time spent - Second Insertion: " << std::setprecision(6) << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()/1.0e+6 << std::fixed << " sec." << std::endl;  
   
    // Section 2 - It is using the constrained Delaunay package to triangulate the arrangement vertices and constrained edges
    begin = std::chrono::steady_clock::now();


    for (auto it = arr.edges_begin(); it != arr.edges_end(); ++it) {
        CDT.insert(it->source()->point(), it->target()->point());
    }
    end = std::chrono::steady_clock::now();
    if (verbose) std::cout << "Time spent - Creation of the Constrained Delaunay Triangulation: " << std::setprecision(6) << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()/1.0e+6 << std::fixed << " sec." << std::endl;  
}


I have two distinct sets of segments (std::vector<Segment_2> segmentSet1 and std::vector<Segment_2> segmentSet2 ) that comes up from external data. The segments in segmentSet1 don't intersect with others segments in this set. This is also true for the segments in segmentSet2. However, the segments in segmentSet1 certainly intersects with the segments in segmentSet2.

I insert the first set of segments by the function CGAL::insert_non_intersecting_curves(arr, segmentSet1.begin(), segmentSet1.end()). The insertions of the second set of segments are performed by the function CGAL::insert(arr, *seg, walkPL). The efficiency first intersection is pretty good, but the second one is very inefficient. After these insertions, a Constrained Delaunay Triangulation is created.

I would like to know whether there is a way to improve the efficiency of this second insection. I've tried without success to perform a parallelization of the loop in the second insertion.

Is there any way to parallelize this for-loop for the second insertion? Or should I try another approach to improve the overall efficiency?

-------

Best, 

Bruno Souza


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss

-- 
Andreas Fabri, PhD
Chief Officer, GeometryFactory
Editor, The CGAL Project

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss



-- 
===================================================================
Guillaume DAMIAND

CNRS - LIRIS UMR 5205
Université Claude Bernard
Bâtiment Nautibus (710)
43 Boulevard du 11 Novembre 1918
69622 Villeurbanne Cedex (France)
-------------------------------------------------------------------
Tél: +33 (0)4.72.43.14.34                 Fax: +33 (0)4.72.43.15.36
Mail: 
Web: http://liris.cnrs.fr/guillaume.damiand/
===================================================================

Attachment: smime.p7s
Description: Signature cryptographique S/MIME




Archive powered by MHonArc 2.6.19+.

Top of Page