WIP: hierarchical net clusters - some testing

This commit is contained in:
Matthias Koefferlein 2018-12-02 23:05:58 +01:00
parent 22651b83c0
commit 7e36018356
3 changed files with 74 additions and 3 deletions

View File

@ -472,7 +472,7 @@ template class DB_PUBLIC local_clusters<db::PolygonRef>;
template <class T>
const typename connected_clusters<T>::connections_type &
connected_clusters<T>::connections_for_cluster (typename local_cluster<T>::id_type id)
connected_clusters<T>::connections_for_cluster (typename local_cluster<T>::id_type id) const
{
typename std::map<typename local_cluster<T>::id_type, connections_type>::const_iterator c = m_connections.find (id);
if (c == m_connections.end ()) {
@ -532,6 +532,9 @@ connected_clusters<T>::find_cluster_with_connection (const ClusterInstance &ci,
return 0;
}
// explicit instantiations
template class DB_PUBLIC connected_clusters<db::PolygonRef>;
// ------------------------------------------------------------------------------
// connected_clusters implementation

View File

@ -391,7 +391,7 @@ public:
/**
* @brief Gets the connections for a given cluster ID
*/
const connections_type &connections_for_cluster (typename local_cluster<T>::id_type id);
const connections_type &connections_for_cluster (typename local_cluster<T>::id_type id) const;
/**
* @brief Adds a connection between a local cluster and one from a child instance
@ -414,7 +414,6 @@ public:
private:
std::map<typename local_cluster<T>::id_type, connections_type> m_connections;
box_type m_full_bbox;
};
template <typename> class cell_clusters_box_converter;

View File

@ -323,3 +323,72 @@ TEST(20_LocalClustersBasic)
);
}
TEST(30_LocalConnectedClusters)
{
db::Layout layout;
db::cell_index_type ci1 = layout.add_cell ("C1");
db::cell_index_type ci2 = layout.add_cell ("C2");
db::cell_index_type ci3 = layout.add_cell ("C3");
db::Instance i1 = layout.cell (ci1).insert (db::CellInstArray (db::CellInst (ci2), db::Trans ()));
db::Instance i2 = layout.cell (ci2).insert (db::CellInstArray (db::CellInst (ci3), db::Trans ()));
db::connected_clusters<db::PolygonRef> cc;
db::ClusterInstance::inst_path_type p1;
p1.push_back (db::InstElement (i1));
db::ClusterInstance::inst_path_type p2;
p2.push_back (db::InstElement (i1));
p2.push_back (db::InstElement (i2));
db::ClusterInstance::inst_path_type p3;
p3.push_back (db::InstElement (i2));
db::connected_clusters<db::PolygonRef>::connections_type x;
db::connected_clusters<db::PolygonRef>::connections_type::const_iterator ix;
x = cc.connections_for_cluster (1);
EXPECT_EQ (x.size (), size_t (0));
x = cc.connections_for_cluster (2);
EXPECT_EQ (x.size (), size_t (0));
cc.add_connection (1, db::ClusterInstance (1, p1));
cc.add_connection (1, db::ClusterInstance (2, p2));
x = cc.connections_for_cluster (1);
EXPECT_EQ (x.size (), size_t (2));
x = cc.connections_for_cluster (2);
EXPECT_EQ (x.size (), size_t (0));
cc.add_connection (2, db::ClusterInstance (1, p2));
x = cc.connections_for_cluster (2);
EXPECT_EQ (x.size (), size_t (1));
cc.join_connected_clusters (1, 2);
x = cc.connections_for_cluster (1);
EXPECT_EQ (x.size (), size_t (3));
ix = x.begin ();
EXPECT_EQ (ix->id (), size_t (1));
EXPECT_EQ (ix->inst () == p1, true);
++ix;
EXPECT_EQ (ix->id (), size_t (2));
EXPECT_EQ (ix->inst () == p2, true);
++ix;
EXPECT_EQ (ix->id (), size_t (1));
EXPECT_EQ (ix->inst () == p2, true);
x = cc.connections_for_cluster (2);
EXPECT_EQ (x.size (), size_t (0));
cc.add_connection (2, db::ClusterInstance (3, p1));
EXPECT_EQ (cc.find_cluster_with_connection (db::ClusterInstance (3, p1), 0), 2);
EXPECT_EQ (cc.find_cluster_with_connection (db::ClusterInstance (2, p1), 0), 0);
EXPECT_EQ (cc.find_cluster_with_connection (db::ClusterInstance (2, p2), 0), 1);
cc.add_connection (17, db::ClusterInstance (2, p3));
// p3 == p2 minus 1 at the beginning
EXPECT_EQ (cc.find_cluster_with_connection (db::ClusterInstance (2, p2), 1 /*one stripped*/), 17);
}