@@ -281,19 +281,6 @@ bool NW::hasClockNodes() const noexcept {
281
281
return false ;
282
282
}
283
283
284
- // ==== DEBUG
285
-
286
- void NW::dot_comment (ostream& os, uint16_t dotMode, CStr msg) noexcept {
287
- if (!dotMode) return ;
288
- if (dotMode == 1 ) {
289
- os << s_dotComment;
290
- } else {
291
- assert (dotMode == 2 );
292
- os << s_metisComment;
293
- }
294
- if (msg) os << msg;
295
- }
296
-
297
284
bool NW::verifyOneRoot () const noexcept {
298
285
if (empty ()) return true ;
299
286
assert (!rids_.empty ());
@@ -310,277 +297,6 @@ bool NW::verifyOneRoot() const noexcept {
310
297
return true ;
311
298
}
312
299
313
- void NW::Node::print (ostream& os) const noexcept {
314
- using std::endl;
315
- os << " id:" << id_;
316
- if (XY::valid ())
317
- os << " (" << x_ << ' ' << y_ << ' )' ;
318
- else
319
- os << " ( )" ;
320
-
321
- os << " key=" << key_ << " deg=" << degree ();
322
- if (isTreeRoot ()) {
323
- if (isFlagRoot ())
324
- os << " R+" ;
325
- else
326
- os << " R-" ;
327
- } else if (isFlagRoot ()) {
328
- os << " r-" ;
329
- }
330
- if (sink_flag_) os << " S" ;
331
- os_printf (os, " par=%u lbl=%u" , par_, lbl_);
332
- if (not name_.empty ())
333
- os << " nm= " << name_;
334
- os << endl;
335
- }
336
-
337
- static void replace_bus_for_dot (char * buf) noexcept {
338
- assert (buf);
339
- // replace [] by __
340
- for (char * p = buf; *p; p++) {
341
- if (*p == ' [' or *p == ' ]' )
342
- *p = ' _' ;
343
- }
344
- }
345
-
346
- void NW::Node::nprint_dot (ostream& os) const noexcept {
347
- char name_buf[2048 ] = {};
348
- getName (name_buf);
349
- replace_bus_for_dot (name_buf);
350
-
351
- char attrib[512 ] = {};
352
-
353
- if (!inp_flag_ and !clk_flag_) {
354
- if (isRed ())
355
- ::strcpy (attrib, " [ shape=record, color=red, style=rounded ];" );
356
- else
357
- ::strcpy (attrib, " [ shape=record, style=rounded ];" );
358
- }
359
- else {
360
- if (inp_flag_) {
361
- CStr cs = isRed () ? " red" : " gray" ;
362
- ::sprintf (attrib, " [ shape=box, color=%s, style=filled ];" , cs);
363
- }
364
- else if (clk_flag_) {
365
- CStr cs = isRed () ? " red" : " orange" ;
366
- ::sprintf (attrib, " [ shape=record, color=%s, style=filled ];" , cs);
367
- }
368
- }
369
-
370
- os_printf (os, " %s %s // deg= %u;\n " ,
371
- name_buf, attrib, degree ());
372
- }
373
-
374
- void NW::Edge::eprint_dot (ostream& os, char arrow, const NW& g) const noexcept {
375
- assert (arrow == ' >' or arrow == ' -' );
376
- char buf[2048 ] = {};
377
- g.nodeRef (n1_).getName (buf);
378
- replace_bus_for_dot (buf);
379
- os_printf (os, " %s -%c " , buf, arrow);
380
-
381
- buf[0 ] = 0 ;
382
- g.nodeRef (n2_).getName (buf);
383
- replace_bus_for_dot (buf);
384
- os << buf;
385
-
386
- char attrib[512 ] = {};
387
- ::sprintf (attrib, " [%s %s" ,
388
- inCell_ ? " style=dashed" : " " ,
389
- color_ ? " color=" : " "
390
- );
391
- if (color_)
392
- ::strcat (attrib, i2color(color_));
393
- ::strcat (attrib, " ]" );
394
-
395
- os_printf (os, " %s;\n " , attrib);
396
- }
397
-
398
- uint NW::print (ostream& os, CStr msg) const noexcept {
399
- using std::endl;
400
- if (msg) os << msg << endl;
401
-
402
- if (empty ()) {
403
- os << " empty" << endl;
404
- return 0 ;
405
- }
406
-
407
- uint r0 = first_rid ();
408
- os << " nn=" << size () << " ne=" << numE () << " nr=" << rids_.size () << " root0:" << r0 << endl;
409
-
410
- for (cNI I (*this ); I.valid (); ++I) {
411
- const Node& nd = *I;
412
- nd.print (os);
413
- }
414
-
415
- os << " nids_:" << endl;
416
- for (uint i = 0 ; i < nids_.size (); i++) os << i << " : " << nid_at (i) << endl;
417
-
418
- return size ();
419
- }
420
- uint NW::dump (CStr msg) const noexcept { return print (lout (), msg); }
421
-
422
- uint NW::printNodes (ostream& os, CStr msg, uint16_t forDot) const noexcept {
423
- using std::endl;
424
- if (msg) {
425
- os_printf (os, " %s %s\n " , s_dotComment, msg);
426
- }
427
-
428
- if (empty ()) {
429
- os_printf (os, " %s empty\n " , s_dotComment);
430
- return 0 ;
431
- }
432
-
433
- for (cNI I (*this ); I.valid (); ++I) {
434
- const Node& nd = *I;
435
- if (forDot == 1 )
436
- os << s_dotComment << ' ' ;
437
- nd.print (os);
438
- }
439
-
440
- return size ();
441
- }
442
- uint NW::dumpNodes (CStr msg) const noexcept { return printNodes (lout (), msg, 0 ); }
443
-
444
- uint NW::printEdges (ostream& os, CStr msg) const noexcept {
445
- using std::endl;
446
- if (msg) os << msg << endl;
447
-
448
- uint esz = numE ();
449
- os_printf (os, " nw:%s esz= %u\n " , nw_name_.c_str (), esz);
450
- if (esz) {
451
- for (cEI I (*this ); I.valid (); ++I) {
452
- I->print (os);
453
- os << endl;
454
- }
455
- }
456
- return esz;
457
- }
458
- uint NW::dumpEdges (CStr msg) const noexcept { return printEdges (lout (), msg); }
459
-
460
- uint NW::printSum (ostream& os, uint16_t forDot) const noexcept {
461
- dot_comment (os, forDot);
462
- if (empty ()) {
463
- os_printf (os, " nw:%s (empty NW)\n )" , nw_name_.c_str ());
464
- return 0 ;
465
- }
466
- os_printf (os, " nw:%s\n " , nw_name_.c_str ());
467
-
468
- upair mmD = getMinMaxDeg ();
469
- upair mmL = getMinMaxLbl ();
470
- upair rcnt = countRoots ();
471
- uint numClkNodes = countClockNodes ();
472
-
473
- dot_comment (os, forDot);
474
- os_printf (os, " nn= %u ne= %u nr= %zu r0= %u #clkn= %u" ,
475
- numN (), numE (), rids_.size (), first_rid (), numClkNodes);
476
-
477
- os_printf (os, " mm-deg: (%u,%u)" , mmD.first , mmD.second );
478
- os_printf (os, " mm-lbl: (%u,%u)\n " , mmL.first , mmL.second );
479
-
480
- dot_comment (os, forDot);
481
- os_printf (os, " nr=(%u,%u)\n " , rcnt.first , rcnt.second );
482
-
483
- return size ();
484
- }
485
-
486
- uint NW::printMetis (ostream& os, bool nodeTable) const noexcept {
487
- using std::endl;
488
- if (!printSum (os, 2 )) return 0 ;
489
- if (nodeTable) {
490
- printNodes (os, nullptr , 2 );
491
- os_printf (os, " %s====\n " , s_metisComment);
492
- }
493
- os << numN () << ' ' << numE () << endl;
494
-
495
- vecu A;
496
- for (cNI I (*this ); I.valid (); ++I) {
497
- A.clear ();
498
- const Node& nd = *I;
499
- nd.getAdj (*this , A);
500
- os << nd.id_ ;
501
- for (uint a : A) os << ' ' << a;
502
- os << endl;
503
- }
504
- return size ();
505
- }
506
- uint NW::dumpMetis (bool nodeTable) const noexcept { return printMetis (lout (), nodeTable); }
507
-
508
- bool NW::writeMetis (CStr fn, bool nodeTable) const noexcept {
509
- assert (fn);
510
- if (!fn or !fn[0 ]) return false ;
511
- if (empty ()) return false ;
512
-
513
- bool ok = true ;
514
- uint status = 0 ;
515
-
516
- std::ofstream f (fn);
517
- if (f.is_open ()) {
518
- status = printMetis (f, nodeTable);
519
- if (trace_ >= 3 ) lprintf (" written %s status: %u\n\n " , fn, status);
520
- f.close ();
521
- } else {
522
- if (trace_ >= 2 ) lprintf (" \n [Error Metis] not f.is_open(), fn: %s\n\n " , fn);
523
- ok = false ;
524
- }
525
-
526
- return (ok and status > 0 );
527
- }
528
-
529
- uint NW::printDot (ostream& os, CStr nwNm, bool nodeTable, bool noDeg0) const noexcept {
530
- if (!printSum (os, 1 )) return 0 ;
531
- if (nodeTable) {
532
- printNodes (os, nullptr , 1 );
533
- os_printf (os, " %s====\n " , s_dotComment);
534
- }
535
-
536
- if (!nwNm or !nwNm[0 ]) {
537
- if (not nw_name_.empty ())
538
- nwNm = nw_name_.c_str ();
539
- }
540
- os_printf (os, " \n digraph %s {\n " , (nwNm and nwNm[0 ]) ? nwNm : " G" );
541
- os_printf (os, " label=\" %s\" ;\n " , (nwNm and nwNm[0 ]) ? nwNm : " G" );
542
-
543
- // os << " node [rankdir=LR];\n";
544
- os << " node [shape = record];\n " ;
545
-
546
- for (cNI I (*this ); I.valid (); ++I) {
547
- const Node& ii = *I;
548
- if (noDeg0 and ii.degree () == 0 )
549
- continue ;
550
- ii.nprint_dot (os);
551
- }
552
- os << std::endl;
553
-
554
- for (cEI I (*this ); I.valid (); ++I) {
555
- I->eprint_dot (os, ' >' , *this );
556
- }
557
-
558
- os_printf (os, " }\n " );
559
- return size ();
560
- }
561
- uint NW::dumpDot (CStr nwNm) const noexcept { return printDot (lout (), nwNm, false , false ); }
562
-
563
- bool NW::writeDot (CStr fn, CStr nwNm, bool nodeTable, bool noDeg0) const noexcept {
564
- assert (fn);
565
- if (!fn or !fn[0 ]) return false ;
566
- if (empty ()) return false ;
567
-
568
- bool ok = true ;
569
- uint status = 0 ;
570
-
571
- std::ofstream f (fn);
572
- if (f.is_open ()) {
573
- status = printDot (f, nwNm, nodeTable, noDeg0);
574
- if (trace_ >= 3 ) lprintf (" written %s status: %u\n\n " , fn, status);
575
- f.close ();
576
- } else {
577
- if (trace_ >= 2 ) lprintf (" \n [Error Dot-file] not f.is_open(), fn: %s\n\n " , fn);
578
- ok = false ;
579
- }
580
-
581
- return (ok and status > 0 );
582
- }
583
-
584
300
void NW::beComplete () noexcept {
585
301
assert (selfCheck ());
586
302
clearEdges ();
@@ -605,30 +321,12 @@ void NW::beComplete() noexcept {
605
321
}
606
322
}
607
323
608
- static const char * _colorNames[] = {
609
- " black" ,
610
- " red" ,
611
- " orange" ,
612
- " yellow" ,
613
- " green" ,
614
- " blue" ,
615
- " firebrick" ,
616
- " darkslategray" ,
617
- " purple" ,
618
- " aquamarine3" ,
619
- " chocolate4" ,
620
- " cadetblue4" ,
621
- " darkolivegreen4" ,
622
- " darkorchid4" ,
623
- " cyan" ,
624
- " goldenrod3" ,
625
- " black" ,
626
- " black" ,
627
- " black"
628
- };
629
-
630
- CStr NW::i2color (uint i) noexcept {
631
- return _colorNames[ i % (c_MAX_COLOR + 1 ) ];
324
+ void NW::beStar () noexcept {
325
+ assert (selfCheck ());
326
+ clearEdges ();
327
+
328
+ if (size () < 2 ) return ;
329
+
632
330
}
633
331
634
332
}
0 commit comments