WIP: more tests, some debugging.

This commit is contained in:
Matthias Koefferlein 2018-12-04 23:21:19 +01:00
parent 37fad6da97
commit 10f7750a89
6 changed files with 92 additions and 9 deletions

View File

@ -383,6 +383,48 @@ private:
};
template <class T> class hier_clusters;
template <class T> class connected_clusters;
/**
* @brief An iterator delivering all clusters of a connected_clusters set
*/
template <class T>
class DB_PUBLIC connected_clusters_iterator
{
public:
typedef typename local_cluster<T>::id_type value_type;
connected_clusters_iterator (const connected_clusters<T> &c);
connected_clusters_iterator &operator++ ()
{
if (! m_lc_iter.at_end ()) {
++m_lc_iter;
} else if (m_x_iter != m_x_iter_end) {
++m_x_iter;
}
return *this;
}
bool at_end () const
{
return m_lc_iter.at_end () && m_x_iter == m_x_iter_end;
}
value_type operator* () const
{
if (m_lc_iter.at_end ()) {
return m_x_iter->first;
} else {
return m_lc_iter->id ();
}
}
private:
typename local_clusters<T>::const_iterator m_lc_iter;
typedef std::list<ClusterInstance> connections_type;
typename std::map<typename local_cluster<T>::id_type, connections_type>::const_iterator m_x_iter, m_x_iter_end;
};
/**
* @brief Local clusters with connections to clusters from child cells
@ -394,6 +436,7 @@ class DB_PUBLIC connected_clusters
public:
typedef std::list<ClusterInstance> connections_type;
typedef typename local_clusters<T>::box_type box_type;
typedef connected_clusters_iterator<T> all_iterator;
/**
* @brief Constructor
@ -429,11 +472,38 @@ public:
*/
void join_cluster_with (typename local_cluster<T>::id_type id, typename local_cluster<T>::id_type with_id);
/**
* @brief An iterator delivering all clusters (even the connectors)
*
* This iterator will deliver ID's rather than cluster objects.
*/
all_iterator begin_all () const
{
return connected_clusters_iterator<T> (*this);
}
private:
template<typename> friend class connected_clusters_iterator;
std::map<typename local_cluster<T>::id_type, connections_type> m_connections;
std::map<ClusterInstance, typename local_cluster<T>::id_type> m_rev_connections;
};
template <class T>
connected_clusters_iterator<T>::connected_clusters_iterator (const connected_clusters<T> &c)
: m_lc_iter (c.begin ())
{
size_t max_id = 0;
for (typename connected_clusters<T>::const_iterator i = c.begin (); i != c.end (); ++i) {
if (i->id () > max_id) {
max_id = i->id ();
}
}
m_x_iter = c.m_connections.lower_bound (max_id + 1);
m_x_iter_end = c.m_connections.end ();
}
template <typename> class cell_clusters_box_converter;
/**

View File

@ -421,7 +421,7 @@ static void normalize_layer (db::Layout &layout, unsigned int layer)
}
}
static void copy_cluster_shapes (db::Shapes &out, db::cell_index_type ci, const db::hier_clusters<db::PolygonRef> &hc, const db::local_cluster<db::PolygonRef> &cluster, const db::ICplxTrans &trans, const db::Connectivity &conn)
static void copy_cluster_shapes (db::Shapes &out, db::cell_index_type ci, const db::hier_clusters<db::PolygonRef> &hc, db::local_cluster<db::PolygonRef>::id_type cluster_id, const db::ICplxTrans &trans, const db::Connectivity &conn)
{
// use property #1 to code the cell name
@ -431,9 +431,12 @@ static void copy_cluster_shapes (db::Shapes &out, db::cell_index_type ci, const
pm.insert (std::make_pair (pn_id, tl::Variant (out.layout ()->cell_name (ci))));
db::properties_id_type cell_pid = pr.properties_id (pm);
const db::connected_clusters<db::PolygonRef> &clusters = hc.clusters_per_cell (ci);
const db::local_cluster<db::PolygonRef> &lc = clusters.cluster_by_id (cluster_id);
// copy the shapes from this cell
for (db::Connectivity::layer_iterator l = conn.begin_layers (); l != conn.end_layers (); ++l) {
for (db::local_cluster<db::PolygonRef>::shape_iterator s = cluster.begin (*l); ! s.at_end (); ++s) {
for (db::local_cluster<db::PolygonRef>::shape_iterator s = lc.begin (*l); ! s.at_end (); ++s) {
db::Polygon poly = s->obj ().transformed (trans * db::ICplxTrans (s->trans ()));
out.insert (db::PolygonWithProperties (poly, cell_pid));
}
@ -443,13 +446,13 @@ static void copy_cluster_shapes (db::Shapes &out, db::cell_index_type ci, const
// copy the shapes from the child cells too
typedef db::connected_clusters<db::PolygonRef>::connections_type connections_type;
const connections_type &connections = hc.clusters_per_cell (ci).connections_for_cluster (cluster.id ());
const connections_type &connections = clusters.connections_for_cluster (cluster_id);
for (connections_type::const_iterator i = connections.begin (); i != connections.end (); ++i) {
db::ICplxTrans t = trans * i->inst ().complex_trans ();
db::cell_index_type cci = i->inst ().inst_ptr.cell_index ();
copy_cluster_shapes (out, cci, hc, hc.clusters_per_cell (cci).cluster_by_id (i->id ()), t, conn);
copy_cluster_shapes (out, cci, hc, i->id (), t, conn);
}
}
@ -510,7 +513,7 @@ static void run_hc_test (tl::TestBase *_this, const std::string &file, const std
for (db::Layout::top_down_const_iterator td = ly.begin_top_down (); td != ly.end_top_down (); ++td) {
const db::connected_clusters<db::PolygonRef> &clusters = hc.clusters_per_cell (*td);
for (db::connected_clusters<db::PolygonRef>::const_iterator c = clusters.begin (); ! c.at_end (); ++c) {
for (db::connected_clusters<db::PolygonRef>::all_iterator c = clusters.begin_all (); ! c.at_end (); ++c) {
net_layers.push_back (std::make_pair (0, ly.insert_layer ()));
@ -543,22 +546,32 @@ static void run_hc_test (tl::TestBase *_this, const std::string &file, const std
db::compare_layouts (_this, ly, tl::testsrc () + "/testdata/algo/" + au_file);
}
TEST(40_HierClusters)
TEST(41_HierClusters)
{
run_hc_test (_this, "hc_test_l1.gds", "hc_test_au1.gds");
}
TEST(41_HierClusters)
TEST(42_HierClusters)
{
run_hc_test (_this, "hc_test_l2.gds", "hc_test_au2.gds");
}
TEST(42_HierClusters)
TEST(43_HierClusters)
{
run_hc_test (_this, "hc_test_l3.gds", "hc_test_au3.gds");
}
TEST(43_HierClusters)
TEST(44_HierClusters)
{
run_hc_test (_this, "hc_test_l4.gds", "hc_test_au4.gds");
}
TEST(45_HierClusters)
{
run_hc_test (_this, "hc_test_l5.gds", "hc_test_au5.gds");
}
TEST(46_HierClusters)
{
run_hc_test (_this, "hc_test_l6.gds", "hc_test_au6.gds");
}

BIN
testdata/algo/hc_test_au5.gds vendored Normal file

Binary file not shown.

BIN
testdata/algo/hc_test_au6.gds vendored Normal file

Binary file not shown.

BIN
testdata/algo/hc_test_l5.gds vendored Normal file

Binary file not shown.

BIN
testdata/algo/hc_test_l6.gds vendored Normal file

Binary file not shown.