Skip to content

Commit a226650

Browse files
More aggressive star bar ABC algorithm
1 parent 1c6e928 commit a226650

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

models/starComplexity.cc

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,12 @@ unsigned StarComplexityGen::starUpperBound(const linkRep& x) const
697697
return min(ub, complementUb);
698698
}
699699

700-
unsigned starUpperBoundABC(linkRep x, unsigned nodes)
700+
unsigned starUpperBoundABC(linkRep x, const ElemStars& elemStars)
701701
{
702702
if (x.empty()) return 3; // intersection of 3 stars is empty.
703703
// Firstly remove those nodes that are full stars
704704
vector<unsigned> fullStars;
705+
unsigned nodes=elemStars.size();
705706
for (unsigned i=0; i<nodes; ++i)
706707
{
707708
bool fullStar=true;
@@ -727,24 +728,36 @@ unsigned starUpperBoundABC(linkRep x, unsigned nodes)
727728
abc::Abc_Obj_t* graphRemainder=edges[0];
728729
for (size_t i=1; i<edges.size(); ++i)
729730
graphRemainder=&aig.addOr(*graphRemainder, *edges[i]);
731+
assert(aig.numGates()==2*edges.size()-1);
730732
aig.addOutputs(*graphRemainder);
733+
assert(aig.eval(elemStars)==x);
731734
aig.cleanup();
732-
for (unsigned i=0; i<3; ++i)
735+
assert(aig.eval(elemStars)==x);
736+
for (unsigned i=0; i<100; ++i)
733737
{
738+
auto prevNumGates=aig.numGates();
739+
for (unsigned i=0; i<3; ++i)
740+
{
741+
aig.balance();
742+
assert(aig.eval(elemStars)==x);
743+
aig.rewrite();
744+
assert(aig.eval(elemStars)==x);
745+
aig.refactor();
746+
assert(aig.eval(elemStars)==x);
747+
}
734748
aig.balance();
735-
aig.rewrite();
736-
aig.refactor();
749+
assert(aig.eval(elemStars)==x);
750+
aig.rewrite(true); // final zero-cost pass
751+
assert(aig.eval(elemStars)==x);
752+
if (aig.numGates()==prevNumGates) break; // terminate on no improvement
737753
}
738-
aig.balance();
739-
aig.rewrite(true); // final zero-cost pass
740754
return fullStars.size()+aig.numGates()+1;
741755
}
742756

743757
unsigned StarComplexityGen::starUpperBoundABC(const linkRep& x) const
744758
{
745-
unsigned n=elemStars.size();
746-
unsigned ub=::starUpperBoundABC(x, n);
747-
unsigned complementUb=::starUpperBoundABC((~x).maskOut(n), n);
759+
unsigned ub=::starUpperBoundABC(x, elemStars);
760+
unsigned complementUb=::starUpperBoundABC((~x).maskOut(elemStars.size()), elemStars);
748761
assert(ub>0 && complementUb>0);
749762
return min(ub, complementUb);
750763
}

models/starComplexity.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ class linkRepImpl
8989
}
9090
};
9191

92+
template <class I>
93+
std::ostream& operator<<(std::ostream& o, const linkRepImpl<I>& x)
94+
{
95+
auto d=x.dataAsVector();
96+
o<<"[";
97+
for (auto& i:d) o<<i<<",";
98+
o<<"]";
99+
return o;
100+
}
101+
92102
//#ifdef SYCL_LANGUAGE_VERSION
93103
//using linkRep=linkRepImpl<VecBitSet<unsigned,4>>;
94104
//#else

0 commit comments

Comments
 (0)