@@ -553,6 +553,7 @@ GraphComplexity StarComplexityGen::complexity(linkRep g) const
553
553
554
554
unsigned starUpperBound (linkRep x, unsigned nodes)
555
555
{
556
+ if (x.empty ()) return 3 ; // intersection of 3 stars is empty.
556
557
// Firstly remove those nodes that are full stars
557
558
vector<unsigned > fullStars;
558
559
for (unsigned i=0 ; i<nodes; ++i)
@@ -590,18 +591,33 @@ unsigned starUpperBound(linkRep x, unsigned nodes)
590
591
// compute the number of operations xᵢ∪(xₖ∩xₗ…)
591
592
auto maxDegree=max_element (nodeDegree.begin (), nodeDegree.end (), SecondLess ());
592
593
594
+ vector<unsigned > prevNbrs;
593
595
while (maxDegree->second >0 )
594
596
{
595
- stars+=1 +maxDegree->second ;
596
- maxDegree->second =0 ; // accounted for all links to this node
597
+ vector<unsigned > neighbours;
597
598
for (unsigned j=0 ; j<maxNodes; ++j)
598
599
if (x (maxDegree->first , j) && nodeDegree[j])
599
- --nodeDegree[j];
600
+ {
601
+ --nodeDegree[j];
602
+ neighbours.push_back (j);
603
+ }
604
+ if (neighbours==prevNbrs)
605
+ ++stars;
606
+ else
607
+ stars+=1 +maxDegree->second ;
608
+ prevNbrs=std::move (neighbours);
609
+ maxDegree->second =0 ; // accounted for all links to this node
600
610
maxDegree=max_element (nodeDegree.begin (), nodeDegree.end (), SecondLess ());
601
611
}
602
612
603
613
return stars;
604
614
}
605
615
606
616
unsigned StarComplexityGen::starUpperBound (const linkRep& x) const
607
- {return min (::starUpperBound (x, elemStars.size ()), ::starUpperBound (~x,elemStars.size ()));}
617
+ {
618
+ unsigned ub=::starUpperBound (x, elemStars.size ());
619
+ unsigned complementUb=::starUpperBound (~x, elemStars.size ());
620
+ if (ub==0 ) return complementUb;
621
+ if (complementUb==0 ) return ub;
622
+ return min (::starUpperBound (x, elemStars.size ()), ::starUpperBound (~x,elemStars.size ()));
623
+ }
0 commit comments