29 std::uniform_real_distribution<double> coord_dist;
30 std::uniform_real_distribution<double> size_dist;
34 coord_dist(0.0, 100000.0),
35 size_dist(0.001, 0.1) {}
40 std::vector<std::pair<geometry::Rectangle, geometry::Rectangle>>
42 std::vector<std::pair<geometry::Rectangle, geometry::Rectangle>>
components;
45 std::cout <<
"Generating " << count <<
" components..." << std::endl;
47 for (
size_t i = 0; i < count; ++i) {
48 double x = coord_dist(rng);
49 double y = coord_dist(rng);
50 double width = size_dist(rng);
51 double height = size_dist(rng);
56 if (i % 10000000 == 0 && i > 0) {
57 std::cout <<
" Generated " << i <<
" components..." << std::endl;
68 std::cout <<
"\n=== IP Block Hierarchy Demo ===" << std::endl;
91 std::cout <<
"Created hierarchical IP block structure" << std::endl;
95 std::cout <<
"Total blocks: " << stats.
total_blocks << std::endl;
96 std::cout <<
"Max depth: " << stats.max_depth << std::endl;
103 std::cout <<
"\n=== Performance Benchmark ===" << std::endl;
105 std::vector<size_t> test_sizes = {
114 for (
size_t size : test_sizes) {
115 std::cout <<
"\nTesting with " << size <<
" components:" << std::endl;
126 auto start = std::chrono::high_resolution_clock::now();
128 auto end = std::chrono::high_resolution_clock::now();
130 auto insertion_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
131 std::cout <<
" Insertion time: " << insertion_time.count() <<
" ms" << std::endl;
134 start = std::chrono::high_resolution_clock::now();
136 auto results = index->parallel_query_range(query_rect);
137 end = std::chrono::high_resolution_clock::now();
139 auto query_time = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
140 std::cout <<
" Query time: " << query_time.count() <<
" μs" << std::endl;
141 std::cout <<
" Results found: " << results.size() << std::endl;
144 start = std::chrono::high_resolution_clock::now();
145 auto intersections = index->parallel_find_intersections();
146 end = std::chrono::high_resolution_clock::now();
148 auto intersection_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
149 std::cout <<
" Intersection detection time: " << intersection_time.count() <<
" ms" << std::endl;
150 std::cout <<
" Potential intersections: " << intersections.size() << std::endl;
153 auto stats = index->get_statistics();
154 std::cout <<
" Memory usage: " << std::fixed << std::setprecision(2)
155 << stats.memory_usage_mb <<
" MB" << std::endl;
156 std::cout <<
" Total blocks: " << stats.total_blocks << std::endl;
157 std::cout <<
" Avg objects per block: " << stats.avg_objects_per_block << std::endl;
159 }
catch (
const std::exception& e) {
160 std::cout <<
" Error: " << e.what() << std::endl;
161 std::cout <<
" (Likely insufficient memory for this scale)" << std::endl;
171 std::cout <<
"\n=== Large Scale Design Rule Checking ===" << std::endl;
173 const size_t component_count = 10000000;
177 world_bounds, component_count);
182 std::cout <<
"Inserting " << component_count <<
" components..." << std::endl;
183 auto start = std::chrono::high_resolution_clock::now();
185 auto end = std::chrono::high_resolution_clock::now();
187 auto insertion_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
188 std::cout <<
"Insertion completed in " << insertion_time.count() <<
" ms" << std::endl;
191 std::cout <<
"\nPerforming design rule checking..." << std::endl;
192 const double min_spacing = 0.01;
194 start = std::chrono::high_resolution_clock::now();
195 auto potential_violations = index->parallel_find_intersections();
196 end = std::chrono::high_resolution_clock::now();
198 auto drc_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
199 std::cout <<
"DRC completed in " << drc_time.count() <<
" ms" << std::endl;
202 size_t real_violations = 0;
203 for (
const auto& [rect1, rect2] : potential_violations) {
204 double distance = rect1.distance_to(rect2);
205 if (distance < min_spacing) {
210 std::cout <<
"Potential violations: " << potential_violations.size() << std::endl;
211 std::cout <<
"Actual violations: " << real_violations << std::endl;
212 std::cout <<
"Violation rate: " << std::fixed << std::setprecision(4)
213 << (double)real_violations / component_count * 100 <<
"%" << std::endl;
220 std::cout <<
"\n=== Memory Pool Efficiency Demo ===" << std::endl;
222 const size_t allocation_count = 1000000;
225 std::cout <<
"Testing standard allocation..." << std::endl;
226 auto start = std::chrono::high_resolution_clock::now();
228 std::vector<geometry::Rectangle*> ptrs;
229 for (
size_t i = 0; i < allocation_count; ++i) {
232 for (
auto* ptr : ptrs) {
236 auto end = std::chrono::high_resolution_clock::now();
237 auto std_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
238 std::cout <<
"Standard allocation time: " << std_time.count() <<
" ms" << std::endl;
241 std::cout <<
"Testing memory pool allocation..." << std::endl;
242 start = std::chrono::high_resolution_clock::now();
245 std::vector<geometry::Rectangle*> pool_ptrs;
247 for (
size_t i = 0; i < allocation_count; ++i) {
248 pool_ptrs.push_back(pool.
allocate());
250 for (
auto* ptr : pool_ptrs) {
254 end = std::chrono::high_resolution_clock::now();
255 auto pool_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
256 std::cout <<
"Memory pool allocation time: " << pool_time.count() <<
" ms" << std::endl;
258 double speedup = (double)std_time.count() / pool_time.count();
259 std::cout <<
"Memory pool speedup: " << std::fixed << std::setprecision(2)
260 << speedup <<
"x" << std::endl;
267 std::cout <<
"\n=== Z-Order Curve Spatial Hashing Demo ===" << std::endl;
272 std::vector<geometry::Point> points = {
282 std::cout <<
"Point -> Z-order code mapping:" << std::endl;
283 for (
const auto& point : points) {
287 std::cout <<
" (" << point.x <<
", " << point.y <<
") -> "
288 << std::hex << z_code << std::dec
289 <<
" -> (" << decoded.first <<
", " << decoded.second <<
")" << std::endl;
293 std::cout <<
"\nSpatial locality demonstration:" << std::endl;
294 std::vector<std::pair<geometry::Point, uint64_t>> point_codes;
296 for (
const auto& point : points) {
298 point_codes.emplace_back(point, z_code);
302 std::sort(point_codes.begin(), point_codes.end(),
303 [](
const auto& a,
const auto& b) { return a.second < b.second; });
305 std::cout <<
"Points sorted by Z-order:" << std::endl;
306 for (
const auto& [point, z_code] : point_codes) {
307 std::cout <<
" (" << point.x <<
", " << point.y <<
") ["
308 << std::hex << z_code << std::dec <<
"]" << std::endl;
316 std::cout <<
"\n=== Spatial Index Algorithm Comparison ===" << std::endl;
318 const size_t component_count = 1000000;
325 std::cout <<
"\nTesting QuadTree..." << std::endl;
329 auto start = std::chrono::high_resolution_clock::now();
330 for (
const auto& [component, bbox] :
components) {
331 quadtree.
insert(component);
333 auto end = std::chrono::high_resolution_clock::now();
334 auto qt_insert_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
337 std::cout <<
"Testing R-tree..." << std::endl;
340 start = std::chrono::high_resolution_clock::now();
341 for (
const auto& [component, bbox] :
components) {
342 rtree.
insert(component, bbox);
344 end = std::chrono::high_resolution_clock::now();
345 auto rt_insert_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
350 start = std::chrono::high_resolution_clock::now();
351 auto qt_results = quadtree.
query_range(query_rect);
352 end = std::chrono::high_resolution_clock::now();
353 auto qt_query_time = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
355 start = std::chrono::high_resolution_clock::now();
357 end = std::chrono::high_resolution_clock::now();
358 auto rt_query_time = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
361 std::cout <<
"\nResults:" << std::endl;
362 std::cout <<
" QuadTree insertion: " << qt_insert_time.count() <<
" ms" << std::endl;
363 std::cout <<
" R-tree insertion: " << rt_insert_time.count() <<
" ms" << std::endl;
364 std::cout <<
" QuadTree query: " << qt_query_time.count() <<
" μs ("
365 << qt_results.size() <<
" results)" << std::endl;
366 std::cout <<
" R-tree query: " << rt_query_time.count() <<
" μs ("
367 << rt_results.size() <<
" results)" << std::endl;
371 std::cout <<
"\nMemory and structure:" << std::endl;
372 std::cout <<
" QuadTree nodes: " << qt_stats.
total_nodes << std::endl;
373 std::cout <<
" QuadTree depth: " << qt_stats.max_depth_reached << std::endl;
374 std::cout <<
" QuadTree efficiency: " << std::fixed << std::setprecision(2)
375 << qt_stats.tree_efficiency << std::endl;
380 std::cout <<
"=== Ultra-Large Scale EDA Layout Optimization Demo ===" << std::endl;
381 std::cout <<
"This demo showcases handling billions of components efficiently" << std::endl;
393 std::cout <<
"\nStarting performance benchmarks..." << std::endl;
394 std::cout <<
"Note: Large scale tests may take several minutes and require significant memory" << std::endl;
399 }
catch (
const std::exception& e) {
400 std::cerr <<
"Error: " << e.what() << std::endl;
404 std::cout <<
"\nDemo completed successfully!" << std::endl;
Advanced spatial indexing for ultra-large scale EDA layouts.
Simulate creating a massive EDA layout with billions of components.
void design_rule_checking()
Demonstrate design rule checking at scale.
void performance_benchmark()
Test performance with different scales.
void zorder_demo()
Demonstrate Z-order curve spatial hashing.
void memory_pool_demo()
Demonstrate memory pool efficiency.
void algorithm_comparison()
Compare different spatial indexing algorithms.
void demonstrate_ip_blocks()
Demonstrate hierarchical IP block creation.
std::vector< std::pair< geometry::Rectangle, geometry::Rectangle > > generate_components(size_t count)
Generate random components for testing.
2D point with high-precision coordinates and utility methods
Axis-aligned rectangle for bounding boxes and simple EDA components.
Hierarchical spatial index for ultra-large datasets.
void create_ip_block(const std::string &name, const geometry::Rectangle &boundary, const std::string &parent_name="root")
Statistics get_statistics() const
Memory pool for efficient object allocation.
Quadtree spatial index for efficient range and intersection queries.
bool insert(const T &object)
Insert object into quadtree.
std::vector< T > query_range(const geometry::Rectangle &range) const
Query objects in rectangular range.
Statistics get_statistics() const
Calculate tree statistics.
High-performance R-tree implementation.
void insert(const T &object, const geometry::Rectangle &bbox)
std::vector< T > query_range(const geometry::Rectangle &range) const
static std::unique_ptr< HierarchicalSpatialIndex< T > > create_optimized_index(const geometry::Rectangle &world_bounds, size_t expected_object_count, IndexType preferred_type=IndexType::HYBRID)
static std::pair< uint32_t, uint32_t > decode(uint64_t z)
static uint64_t encode_point(const geometry::Point &point, const geometry::Rectangle &bounds)
Main namespace for ZLayout library.
ZLayout - Advanced Electronic Design Automation Layout Library.