Skip to content

Commit b5d5b37

Browse files
Collect like terms
Return 3 star intersection solution for empty graphs.
1 parent aa22378 commit b5d5b37

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

models/starComplexity.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ GraphComplexity StarComplexityGen::complexity(linkRep g) const
553553

554554
unsigned starUpperBound(linkRep x, unsigned nodes)
555555
{
556+
if (x.empty()) return 3; // intersection of 3 stars is empty.
556557
// Firstly remove those nodes that are full stars
557558
vector<unsigned> fullStars;
558559
for (unsigned i=0; i<nodes; ++i)
@@ -590,18 +591,33 @@ unsigned starUpperBound(linkRep x, unsigned nodes)
590591
// compute the number of operations xᵢ∪(xₖ∩xₗ…)
591592
auto maxDegree=max_element(nodeDegree.begin(), nodeDegree.end(), SecondLess());
592593

594+
vector<unsigned> prevNbrs;
593595
while (maxDegree->second>0)
594596
{
595-
stars+=1+maxDegree->second;
596-
maxDegree->second=0; // accounted for all links to this node
597+
vector<unsigned> neighbours;
597598
for (unsigned j=0; j<maxNodes; ++j)
598599
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
600610
maxDegree=max_element(nodeDegree.begin(), nodeDegree.end(), SecondLess());
601611
}
602612

603613
return stars;
604614
}
605615

606616
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

Comments
 (0)