From 9b59c50efce9aaa2ad74802ed75e3e1bffb0e647 Mon Sep 17 00:00:00 2001 From: HoangAnhP Date: Thu, 16 Jun 2022 18:14:47 +0200 Subject: [PATCH] Seabreeze : new version of function build_branch(). No more recursivity --- Seabreeze/src/Seabreeze.cpp | 97 +++++++++++++++++++++++++++-- Seabreeze/src/Seabreeze/Seabreeze.h | 3 +- 2 files changed, 93 insertions(+), 7 deletions(-) diff --git a/Seabreeze/src/Seabreeze.cpp b/Seabreeze/src/Seabreeze.cpp index 77d12083..7c85e91d 100644 --- a/Seabreeze/src/Seabreeze.cpp +++ b/Seabreeze/src/Seabreeze.cpp @@ -138,11 +138,14 @@ namespace Seabreeze { //---------------------------------------------------------------------------------------- cerr << "Target contact : " << ccont << endl; //---------------------------------------------------------------------------------------- - ccont = build_branch(ccont); +// ccont = build_branch(ccont); + Contact* ctr = nullptr; + build_branch(ctr, ccont); //---------------------------------------------------------------------------------------- - cerr << "Found a node : " << ccont << endl; + cerr << "Found a node : " << ctr << endl; //---------------------------------------------------------------------------------------- - if ( not ccont ) { +// if ( not ccont ) { + if ( not ctr ) { cerr << "This branch leads to a NULL contact ?" << endl; cerr << "Tree build failed" << endl; return; @@ -150,14 +153,16 @@ namespace Seabreeze { Node* node = new Node(s, ccont); int count = 1; - for ( Component* comp : ccont->getSlaveComponents() ) { +// for ( Component* comp : ccont->getSlaveComponents() ) { + for ( Component* comp : ctr->getSlaveComponents() ) { count += (dynamic_cast(comp)) ? 1 : 0; } if ( count == 1 ){ _tree->add_node(node); } else if ( count > 2 ) { - for ( Component* comp : ccont->getSlaveComponents() ) { +// for ( Component* comp : ccont->getSlaveComponents() ) { + for ( Component* comp : ctr->getSlaveComponents() ) { Segment* segmt = dynamic_cast(comp); if ( not segmt ) continue; build_from_Node(node, segmt); @@ -165,6 +170,46 @@ namespace Seabreeze { } } + void Elmore::build_branch ( Contact* ctr, Contact* ct ) { + int count = 0; + checker.insert(ct); +//----------------------------------------------------------------------------------- + cerr << "Build branch from contact : " << ct << endl; +//----------------------------------------------------------------------------------- + for ( Component* cp : ct->getSlaveComponents() ) { + count += (dynamic_cast(cp)) ? 1 : 0; + } + + if ( count == 0 ) { + cerr << "Something is not right here : Contact " << ct << " is isolated ?" << endl; + } + else if ( count == 2 ) { + Segment* sm = nullptr; + for ( Component* cp : ct->getSlaveComponents() ) { + sm = dynamic_cast(cp); + if ( not sm ) continue; + } + + Contact* cct = dynamic_cast(sm->getOppositeAnchor(ct)); +//------------------------------------------------------------------------------------ + cerr << "To contact : " << cct << endl; +//------------------------------------------------------------------------------------ + if ( not cct || find(checker.begin(), checker.end(), cct) != checker.end() ) { + cerr << "This branch leads to no where ?" << endl; + } + else { + build_branch(ctr, cct); + } + } + else { + ctr = ct; +//------------------------------------------------------------------- + cerr << "Return contact : " << ctr << endl; +//------------------------------------------------------------------- + } + } + +/* Contact* Elmore::build_branch ( Contact* ct ) { int count = 0; checker.insert(ct); @@ -174,7 +219,7 @@ namespace Seabreeze { for ( Component* cp : ct->getSlaveComponents() ) { count += (dynamic_cast(cp)) ? 1 : 0; } - + Contact* cont = nullptr; if ( count == 0 ) { cerr << "Something is not right here : Contact " << ct << " is isolated ?" << endl; @@ -205,10 +250,50 @@ namespace Seabreeze { } //------------------------------------------------------------------- cerr << "After the else : " << cont << endl; + cerr << "Is this line printed twice ?" << endl; //------------------------------------------------------------------- return cont; } +*/ + Contact* Elmore::build_branch ( Contact* ct ) { + Contact* tmp = ct; + + int count; + do { + checker.insert(tmp); + count = 0; + for ( Component* cp : tmp->getSlaveComponents() ) { + count += (dynamic_cast(cp)) ? 1 : 0; + } + if ( count == 0 ) { + cerr << "Something is not right here : Contact " << tmp << " is isolated ?" << endl; + break; + } + else if ( count != 2 ) { + break; + } + else { + Segment* sm = nullptr; + for ( Component* cp : tmp->getSlaveComponents() ) { + sm = dynamic_cast(cp); + if ( not sm ) continue; + } + + Contact* cct = dynamic_cast(sm->getOppositeAnchor(ct)); + if ( not cct || checker.count(cct) != 0 ) { + cerr << "This branch leads to no where ?" << endl; + tmp = nullptr; + break; + } + else + tmp = cct; + } + } while ( count == 2 ); + + return tmp; + } + void Elmore::clearTree () { _tree->clear(); diff --git a/Seabreeze/src/Seabreeze/Seabreeze.h b/Seabreeze/src/Seabreeze/Seabreeze.h index 6ea717d0..c80eee30 100644 --- a/Seabreeze/src/Seabreeze/Seabreeze.h +++ b/Seabreeze/src/Seabreeze/Seabreeze.h @@ -38,7 +38,8 @@ namespace Seabreeze { void buildTree ( RoutingPad* rp ); void build_from_node ( Node* source ); void build_from_Node ( Node* source, Segment* seg ); - Contact* build_branch ( Contact* ct ); + Contact* build_branch ( Contact* contact ); + void build_branch ( Contact* ctr, Contact* contact ); void clearTree (); Tree* getTree (); inline const set& get_conts () const;