@@ -299,6 +299,7 @@ void StarComplexityGen::fillStarMap(unsigned maxStars)
299
299
if (elemStars.empty ()) return ;
300
300
// insert the single star graph
301
301
starMap.emplace (elemStars[0 ],1 );
302
+ counts.emplace (elemStars[0 ],1 );
302
303
303
304
// unsigned numStars=maxStars;
304
305
for (unsigned numStars=2 ; numStars<=maxStars; ++numStars)
@@ -319,7 +320,11 @@ void StarComplexityGen::fillStarMap(unsigned maxStars)
319
320
return ;
320
321
}
321
322
for (auto k: j)
322
- starMap.emplace (k, numStars);
323
+ {
324
+ auto res=starMap.emplace (k, numStars);
325
+ if (res.first ->second ==numStars) // only count least star operations
326
+ counts[k]++;
327
+ }
323
328
}
324
329
};
325
330
@@ -350,17 +355,17 @@ void StarComplexityGen::fillStarMap(unsigned maxStars)
350
355
handler.host_task ([&]() {
351
356
resultBufferConsumed=0 ;
352
357
populateStarMap ();
353
- if (!lastLoop)
354
- {
355
- block->alreadySeenBacked .clear ();
356
- for (auto & k: starMap) block->alreadySeenBacked .push_back (k.first );
357
- // push update already seen vector to device
358
- alreadySeenSwapped=syclQ ().single_task
359
- (compute,
360
- [=,block=&*block]{
361
- block->alreadySeen .swap (block->alreadySeenBacked );
362
- });
363
- }
358
+ // if (!lastLoop)
359
+ // {
360
+ // block->alreadySeenBacked.clear();
361
+ // for (auto& k: starMap) block->alreadySeenBacked.push_back(k.first);
362
+ // // push update already seen vector to device
363
+ // alreadySeenSwapped=syclQ().single_task
364
+ // (compute,
365
+ // [=,block=&*block]{
366
+ // block->alreadySeen.swap(block->alreadySeenBacked);
367
+ // });
368
+ // }
364
369
populating=false ;
365
370
});
366
371
});
@@ -459,23 +464,45 @@ void StarComplexityGen::canonicaliseStarMap()
459
464
if (c!=i->first )
460
465
{
461
466
auto & starC=starMap[c];
462
- starC=starC>0 ? min (starC, i->second ): i->second ;
467
+ if (starC==0 || i->second <starC)
468
+ {
469
+ starC=i->second ;
470
+ counts[c]=counts[i->first ];
471
+ }
472
+ else if (i->second ==starC)
473
+ counts[c]+=counts[i->first ];
474
+ assert (counts[c]);
463
475
toErase.push_back (i->first );
464
476
}
465
477
}
466
- for (auto i: toErase) starMap.erase (i);
478
+ for (auto i: toErase)
479
+ {
480
+ starMap.erase (i);
481
+ counts.erase (i);
482
+ }
483
+ }
484
+
485
+ linkRep StarComplexityGen::complement (linkRep x) const
486
+ {
487
+ return toLinkRep (toNautyRep (~x, elemStars.size ()).canonicalise ());
467
488
}
468
489
469
490
unsigned StarComplexityGen::symmStar (linkRep x) const
470
491
{
471
492
auto star=starMap.find (x);
472
493
if (star==starMap.end ()) return 0 ;
473
- linkRep complement=toLinkRep (toNautyRep (~x, elemStars.size ()).canonicalise ());
474
- auto starComp=starMap.find (complement);
494
+ auto starComp=starMap.find (complement (x));
475
495
if (starComp==starMap.end ()) return star->second ;
476
496
return min (star->second , starComp->second );
477
497
}
478
498
499
+ double lnFactorial (unsigned n)
500
+ {
501
+ double r=0 ;
502
+ for (unsigned i=2 ; i<n; ++i) r+=log (i);
503
+ return r;
504
+ }
505
+
479
506
GraphComplexity StarComplexityGen::complexity (linkRep g) const
480
507
{
481
508
const double ilog2=1 /log (2.0 );
@@ -485,10 +512,38 @@ GraphComplexity StarComplexityGen::complexity(linkRep g) const
485
512
ecolab_nauty (ng, ng, lnomega, false );
486
513
r.complexity =ecolab::baseComplexity (ng.nodes (), ng.links (), true ) - ilog2*lnomega;
487
514
auto star=symmStar (g);
488
- if (star==0 )
489
- r.starComplexity =nan (" " );
490
- else
491
- r.starComplexity =2 *ceil (ilog2*log (ng.nodes ()))+ceil (ilog2*log (star))+
492
- (2 *star-1 )*ceil (ilog2*(ng.nodes ()+2 )) - ilog2*lnomega;
515
+ switch (star)
516
+ {
517
+ case 0 :
518
+ r.starComplexity =nan (" " );
519
+ break ;
520
+ case 1 :
521
+ r.starComplexity =2 *ceil (ilog2*log (ng.nodes ()))+1 ;
522
+ break ;
523
+ default :
524
+ {
525
+ auto gIter =starMap.find (g);
526
+ unsigned count=0 ;
527
+ if (gIter !=starMap.end () && gIter ->second ==star)
528
+ {
529
+ auto countIter=counts.find (g);
530
+ assert (countIter!=counts.end ());
531
+ count=countIter->second ;
532
+ }
533
+ else
534
+ {
535
+ auto countIter=counts.find (complement (g));
536
+ assert (countIter!=counts.end ());
537
+ count=countIter->second ;
538
+ }
539
+ assert (count>0 );
540
+ r.starComplexity =2 *ceil (ilog2*log (ng.nodes ()))+ceil (ilog2*log (star))+(star-2 )-ilog2*log (count);
541
+ if (star<=ng.nodes ())
542
+ r.starComplexity +=ilog2*(lnFactorial (star));
543
+ else
544
+ r.starComplexity +=ilog2*(lnFactorial (ng.nodes ())+(star-ng.nodes ())*log (ng.nodes ()));
545
+ }
546
+ break ;
547
+ }
493
548
return r;
494
549
}
0 commit comments