ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rrr::NewBdd::Man Class Reference

#include <rrrBddManager.h>

Public Member Functions

lit Bvar2Lit (bvar a) const
 
lit Bvar2Lit (bvar a, bool c) const
 
bvar Lit2Bvar (lit x) const
 
var VarOfBvar (bvar a) const
 
lit ThenOfBvar (bvar a) const
 
lit ElseOfBvar (bvar a) const
 
ref RefOfBvar (bvar a) const
 
lit Const0 () const
 
lit Const1 () const
 
bool IsConst0 (lit x) const
 
bool IsConst1 (lit x) const
 
lit IthVar (var v) const
 
lit LitRegular (lit x) const
 
lit LitIrregular (lit x) const
 
lit LitNot (lit x) const
 
lit LitNotCond (lit x, bool c) const
 
bool LitIsCompl (lit x) const
 
bool LitIsEq (lit x, lit y) const
 
var Var (lit x) const
 
var Level (lit x) const
 
lit Then (lit x) const
 
lit Else (lit x) const
 
ref Ref (lit x) const
 
double OneCount (lit x) const
 
void IncRef (lit x)
 
void DecRef (lit x)
 
bool Resize ()
 
void ResizeUnique (var v)
 
bool Gbc ()
 
 Man (int nVars_, Param p)
 
 ~Man ()
 
void Reorder ()
 
lit And (lit x, lit y)
 
lit Or (lit x, lit y)
 
void SetRef (std::vector< lit > const &vLits)
 
void RemoveRefIfUnused ()
 
void TurnOnReo (int nReo_=0, std::vector< lit > const *vLits=NULL)
 
void TurnOffReo ()
 
var GetNumVars () const
 
void GetOrdering (std::vector< int > &Var2Level_)
 
bvar CountNodes ()
 
bvar CountNodes (std::vector< lit > const &vLits)
 
void PrintStats ()
 
unsigned long long GetNumTotalCreatedNodes ()
 

Detailed Description

Definition at line 178 of file rrrBddManager.h.

Constructor & Destructor Documentation

◆ Man()

rrr::NewBdd::Man::Man ( int nVars_,
Param p )
inline

Definition at line 646 of file rrrBddManager.h.

646 {
647 nCreatedTotal = 0;
648 nVerbose = p.nVerbose;
649 // parameter sanity check
650 if(p.nObjsMaxLog < p.nObjsAllocLog)
651 fatal_error("nObjsMax must not be smaller than nObjsAlloc");
652 if(nVars_ >= (int)VarMax())
653 fatal_error("Memout (nVars) in init");
654 nVars = nVars_;
655 lit nObjsMaxLit = (lit)1 << p.nObjsMaxLog;
656 if(!nObjsMaxLit)
657 fatal_error("Memout (nObjsMax) in init");
658 if(nObjsMaxLit > (lit)BvarMax())
659 nObjsMax = BvarMax();
660 else
661 nObjsMax = (bvar)nObjsMaxLit;
662 lit nObjsAllocLit = (lit)1 << p.nObjsAllocLog;
663 if(!nObjsAllocLit)
664 fatal_error("Memout (nObjsAlloc) in init");
665 if(nObjsAllocLit > (lit)BvarMax())
666 nObjsAlloc = BvarMax();
667 else
668 nObjsAlloc = (bvar)nObjsAllocLit;
669 if(nObjsAlloc <= (bvar)nVars)
670 fatal_error("nObjsAlloc must be larger than nVars");
671 uniq nUniqueSize = (uniq)1 << p.nUniqueSizeLog;
672 if(!nUniqueSize)
673 fatal_error("Memout (nUniqueSize) in init");
674 // allocation
675 if(nVerbose)
676 std::cout << "Allocating " << nObjsAlloc << " nodes and " << nVars << " x " << nUniqueSize << " unique table entries" << std::endl;
677 vVars.resize(nObjsAlloc);
678 vObjs.resize((lit)nObjsAlloc * 2);
679 vNexts.resize(nObjsAlloc);
680 vMarks.resize(nObjsAlloc);
681 vvUnique.resize(nVars);
682 vUniqueMasks.resize(nVars);
683 vUniqueCounts.resize(nVars);
684 vUniqueTholds.resize(nVars);
685 for(var v = 0; v < nVars; v++) {
686 vvUnique[v].resize(nUniqueSize);
687 vUniqueMasks[v] = nUniqueSize - 1;
688 if((lit)(nUniqueSize * p.UniqueDensity) > (lit)BvarMax())
689 vUniqueTholds[v] = BvarMax();
690 else
691 vUniqueTholds[v] = (bvar)(nUniqueSize * p.UniqueDensity);
692 }
693 if(p.fCountOnes) {
694 if(nVars > 1023)
695 fatal_error("nVars must be less than 1024 to count ones");
696 vOneCounts.resize(nObjsAlloc);
697 }
698 // set up cache
699 cache = new Cache(p.nCacheSizeLog, p.nCacheMaxLog, p.nCacheVerbose);
700 // create nodes for variables
701 nObjs = 1;
702 vVars[0] = VarMax();
703 for(var v = 0; v < nVars; v++)
704 UniqueCreateInt(v, 1, 0);
705 // set up variable order
706 Var2Level.resize(nVars);
707 Level2Var.resize(nVars);
708 for(var v = 0; v < nVars; v++) {
709 if(p.pVar2Level)
710 Var2Level[v] = (*p.pVar2Level)[v];
711 else
712 Var2Level[v] = v;
713 Level2Var[Var2Level[v]] = v;
714 }
715 // set other parameters
716 RemovedHead = 0;
717 nGbc = p.nGbc;
718 nReo = p.nReo;
719 MaxGrowth = p.MaxGrowth;
720 fReoVerbose = p.fReoVerbose;
721 if(nGbc || nReo != BvarMax())
722 vRefs.resize(nObjsAlloc);
723 }
Cube * p
Definition exorList.c:222
unsigned short var
unsigned uniq
unsigned lit

◆ ~Man()

rrr::NewBdd::Man::~Man ( )
inline

Definition at line 724 of file rrrBddManager.h.

724 {
725 if(nVerbose) {
726 std::cout << "Free " << nObjsAlloc << " nodes (" << nObjs << " live nodes)" << std::endl;
727 std::cout << "Free {";
728 std::string delim;
729 for(var v = 0; v < nVars; v++) {
730 std::cout << delim << vvUnique[v].size();
731 delim = ", ";
732 }
733 std::cout << "} unique table entries" << std::endl;
734 if(!vRefs.empty())
735 std::cout << "Free " << vRefs.size() << " refs" << std::endl;
736 }
737 delete cache;
738 }

Member Function Documentation

◆ And()

lit rrr::NewBdd::Man::And ( lit x,
lit y )
inline

Definition at line 750 of file rrrBddManager.h.

750 {
751 if(nObjs > nReo) {
752 Reorder();
753 while(nReo < nObjs) {
754 nReo <<= 1;
755 if((lit)nReo > (lit)BvarMax())
756 nReo = BvarMax();
757 }
758 }
759 return And_rec(x, y);
760 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bvar2Lit() [1/2]

lit rrr::NewBdd::Man::Bvar2Lit ( bvar a) const
inline

Definition at line 207 of file rrrBddManager.h.

207{ return (lit)a << 1; }
Here is the caller graph for this function:

◆ Bvar2Lit() [2/2]

lit rrr::NewBdd::Man::Bvar2Lit ( bvar a,
bool c ) const
inline

Definition at line 208 of file rrrBddManager.h.

208{ return ((lit)a << 1) ^ (lit)c; }

◆ Const0()

lit rrr::NewBdd::Man::Const0 ( ) const
inline

Definition at line 214 of file rrrBddManager.h.

214{ return (lit)0; }
Here is the caller graph for this function:

◆ Const1()

lit rrr::NewBdd::Man::Const1 ( ) const
inline

Definition at line 215 of file rrrBddManager.h.

215{ return (lit)1; }
Here is the caller graph for this function:

◆ CountNodes() [1/2]

bvar rrr::NewBdd::Man::CountNodes ( )
inline

Definition at line 801 of file rrrBddManager.h.

801 {
802 bvar count = 1;
803 if(!vEdges.empty()) {
804 for(bvar a = 1; a < nObjs; a++)
805 if(EdgeOfBvar(a))
806 count++;
807 return count;
808 }
809 for(bvar a = 1; a <= (bvar)nVars; a++) {
810 count++;
811 SetMarkOfBvar(a);
812 }
813 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
814 if(RefOfBvar(a))
815 count += CountNodes_rec(Bvar2Lit(a));
816 for(bvar a = 1; a <= (bvar)nVars; a++)
817 ResetMarkOfBvar(a);
818 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
819 if(RefOfBvar(a))
820 ResetMark_rec(Bvar2Lit(a));
821 return count;
822 }
ref RefOfBvar(bvar a) const
lit Bvar2Lit(bvar a) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CountNodes() [2/2]

bvar rrr::NewBdd::Man::CountNodes ( std::vector< lit > const & vLits)
inline

Definition at line 823 of file rrrBddManager.h.

823 {
824 bvar count = 1;
825 for(size_t i = 0; i < vLits.size(); i++)
826 count += CountNodes_rec(vLits[i]);
827 for(size_t i = 0; i < vLits.size(); i++)
828 ResetMark_rec(vLits[i]);
829 return count;
830 }

◆ DecRef()

void rrr::NewBdd::Man::DecRef ( lit x)
inline

Definition at line 240 of file rrrBddManager.h.

240{ if(!vRefs.empty() && Ref(x) != RefMax()) vRefs[Lit2Bvar(x)]--; }
bvar Lit2Bvar(lit x) const
ref Ref(lit x) const
Here is the call graph for this function:

◆ Else()

lit rrr::NewBdd::Man::Else ( lit x) const
inline

Definition at line 228 of file rrrBddManager.h.

228{ return LitNotCond(vObjs[LitIrregular(x)], LitIsCompl(x)); }
lit LitNotCond(lit x, bool c) const
bool LitIsCompl(lit x) const
lit LitIrregular(lit x) const
Here is the call graph for this function:

◆ ElseOfBvar()

lit rrr::NewBdd::Man::ElseOfBvar ( bvar a) const
inline

Definition at line 212 of file rrrBddManager.h.

212{ return vObjs[Bvar2Lit(a, true)]; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gbc()

bool rrr::NewBdd::Man::Gbc ( )
inline

Definition at line 371 of file rrrBddManager.h.

371 {
372 if(nVerbose >= 2)
373 std::cout << "Garbage collect" << std::endl;
374 if(!vEdges.empty()) {
375 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
376 if(!EdgeOfBvar(a) && VarOfBvar(a) != VarMax())
377 RemoveBvar(a);
378 } else {
379 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
380 if(RefOfBvar(a))
381 SetMark_rec(Bvar2Lit(a));
382 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
383 if(!MarkOfBvar(a) && VarOfBvar(a) != VarMax())
384 RemoveBvar(a);
385 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
386 if(RefOfBvar(a))
387 ResetMark_rec(Bvar2Lit(a));
388 }
389 cache->Clear();
390 return RemovedHead;
391 }
var VarOfBvar(bvar a) const
Here is the call graph for this function:

◆ GetNumTotalCreatedNodes()

unsigned long long rrr::NewBdd::Man::GetNumTotalCreatedNodes ( )
inline

Definition at line 846 of file rrrBddManager.h.

846 {
847 return nCreatedTotal;
848 }

◆ GetNumVars()

var rrr::NewBdd::Man::GetNumVars ( ) const
inline

Definition at line 793 of file rrrBddManager.h.

793 {
794 return nVars;
795 }

◆ GetOrdering()

void rrr::NewBdd::Man::GetOrdering ( std::vector< int > & Var2Level_)
inline

Definition at line 796 of file rrrBddManager.h.

796 {
797 Var2Level_.resize(nVars);
798 for(var v = 0; v < nVars; v++)
799 Var2Level_[v] = Var2Level[v];
800 }

◆ IncRef()

void rrr::NewBdd::Man::IncRef ( lit x)
inline

Definition at line 239 of file rrrBddManager.h.

239{ if(!vRefs.empty() && Ref(x) != RefMax()) vRefs[Lit2Bvar(x)]++; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsConst0()

bool rrr::NewBdd::Man::IsConst0 ( lit x) const
inline

Definition at line 216 of file rrrBddManager.h.

216{ return x == Const0(); }
lit Const0() const
Here is the call graph for this function:

◆ IsConst1()

bool rrr::NewBdd::Man::IsConst1 ( lit x) const
inline

Definition at line 217 of file rrrBddManager.h.

217{ return x == Const1(); }
lit Const1() const
Here is the call graph for this function:

◆ IthVar()

lit rrr::NewBdd::Man::IthVar ( var v) const
inline

Definition at line 218 of file rrrBddManager.h.

218{ return Bvar2Lit((bvar)v + 1); }
Here is the call graph for this function:

◆ Level()

var rrr::NewBdd::Man::Level ( lit x) const
inline

Definition at line 226 of file rrrBddManager.h.

226{ return Var2Level[Var(x)]; }
int Var
Definition exorList.c:228

◆ Lit2Bvar()

bvar rrr::NewBdd::Man::Lit2Bvar ( lit x) const
inline

Definition at line 209 of file rrrBddManager.h.

209{ return (bvar)(x >> 1); }
Here is the caller graph for this function:

◆ LitIrregular()

lit rrr::NewBdd::Man::LitIrregular ( lit x) const
inline

Definition at line 220 of file rrrBddManager.h.

220{ return x | (lit)1; }
Here is the caller graph for this function:

◆ LitIsCompl()

bool rrr::NewBdd::Man::LitIsCompl ( lit x) const
inline

Definition at line 223 of file rrrBddManager.h.

223{ return x & (lit)1; }
Here is the caller graph for this function:

◆ LitIsEq()

bool rrr::NewBdd::Man::LitIsEq ( lit x,
lit y ) const
inline

Definition at line 224 of file rrrBddManager.h.

224{ return x == y; }

◆ LitNot()

lit rrr::NewBdd::Man::LitNot ( lit x) const
inline

Definition at line 221 of file rrrBddManager.h.

221{ return x ^ (lit)1; }
Here is the caller graph for this function:

◆ LitNotCond()

lit rrr::NewBdd::Man::LitNotCond ( lit x,
bool c ) const
inline

Definition at line 222 of file rrrBddManager.h.

222{ return x ^ (lit)c; }
Here is the caller graph for this function:

◆ LitRegular()

lit rrr::NewBdd::Man::LitRegular ( lit x) const
inline

Definition at line 219 of file rrrBddManager.h.

219{ return x & ~(lit)1; }
Here is the caller graph for this function:

◆ OneCount()

double rrr::NewBdd::Man::OneCount ( lit x) const
inline

Definition at line 230 of file rrrBddManager.h.

230 {
231 if(vOneCounts.empty())
232 fatal_error("fCountOnes was not set");
233 if(LitIsCompl(x))
234 return std::pow(2.0, nVars) - vOneCounts[Lit2Bvar(x)];
235 return vOneCounts[Lit2Bvar(x)];
236 }
Here is the call graph for this function:

◆ Or()

lit rrr::NewBdd::Man::Or ( lit x,
lit y )
inline

Definition at line 761 of file rrrBddManager.h.

761 {
762 return LitNot(And(LitNot(x), LitNot(y)));
763 }
lit LitNot(lit x) const
lit And(lit x, lit y)
Here is the call graph for this function:

◆ PrintStats()

void rrr::NewBdd::Man::PrintStats ( )
inline

Definition at line 831 of file rrrBddManager.h.

831 {
832 bvar nRemoved = 0;
833 bvar a = RemovedHead;
834 while(a)
835 a = vNexts[a], nRemoved++;
836 bvar nLive = 1;
837 for(var v = 0; v < nVars; v++)
838 nLive += vUniqueCounts[v];
839 std::cout << "ref: " << std::setw(10) << (vRefs.empty()? 0: CountNodes()) << ", "
840 << "used: " << std::setw(10) << nObjs << ", "
841 << "live: " << std::setw(10) << nLive << ", "
842 << "dead: " << std::setw(10) << nRemoved << ", "
843 << "alloc: " << std::setw(10) << nObjsAlloc
844 << std::endl;
845 }
Here is the call graph for this function:

◆ Ref()

ref rrr::NewBdd::Man::Ref ( lit x) const
inline

Definition at line 229 of file rrrBddManager.h.

229{ return vRefs[Lit2Bvar(x)]; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RefOfBvar()

ref rrr::NewBdd::Man::RefOfBvar ( bvar a) const
inline

Definition at line 213 of file rrrBddManager.h.

213{ return vRefs[a]; }
Here is the caller graph for this function:

◆ RemoveRefIfUnused()

void rrr::NewBdd::Man::RemoveRefIfUnused ( )
inline

Definition at line 772 of file rrrBddManager.h.

772 {
773 if(!nGbc && nReo == BvarMax())
774 vRefs.clear();
775 }

◆ Reorder()

void rrr::NewBdd::Man::Reorder ( )
inline

Definition at line 739 of file rrrBddManager.h.

739 {
740 if(nVerbose >= 2)
741 std::cout << "Reorder" << std::endl;
742 int nGbc_ = nGbc;
743 nGbc = 0;
744 CountEdges();
745 Sift();
746 vEdges.clear();
747 cache->Clear();
748 nGbc = nGbc_;
749 }
Here is the caller graph for this function:

◆ Resize()

bool rrr::NewBdd::Man::Resize ( )
inline

Definition at line 314 of file rrrBddManager.h.

314 {
315 if(nObjsAlloc == nObjsMax)
316 return false;
317 lit nObjsAllocLit = (lit)nObjsAlloc << 1;
318 if(nObjsAllocLit > (lit)BvarMax())
319 nObjsAlloc = BvarMax();
320 else
321 nObjsAlloc = (bvar)nObjsAllocLit;
322 if(nVerbose >= 2)
323 std::cout << "Reallocating " << nObjsAlloc << " nodes" << std::endl;
324 vVars.resize(nObjsAlloc);
325 vObjs.resize((lit)nObjsAlloc * 2);
326 vNexts.resize(nObjsAlloc);
327 vMarks.resize(nObjsAlloc);
328 if(!vRefs.empty())
329 vRefs.resize(nObjsAlloc);
330 if(!vEdges.empty())
331 vEdges.resize(nObjsAlloc);
332 if(!vOneCounts.empty())
333 vOneCounts.resize(nObjsAlloc);
334 return true;
335 }

◆ ResizeUnique()

void rrr::NewBdd::Man::ResizeUnique ( var v)
inline

Definition at line 336 of file rrrBddManager.h.

336 {
337 uniq nUniqueSize, nUniqueSizeOld;
338 nUniqueSize = nUniqueSizeOld = vvUnique[v].size();
339 nUniqueSize <<= 1;
340 if(!nUniqueSize) {
341 vUniqueTholds[v] = BvarMax();
342 return;
343 }
344 if(nVerbose >= 2)
345 std::cout << "Reallocating " << nUniqueSize << " unique table entries for Var " << v << std::endl;
346 vvUnique[v].resize(nUniqueSize);
347 vUniqueMasks[v] = nUniqueSize - 1;
348 for(uniq i = 0; i < nUniqueSizeOld; i++) {
349 std::vector<bvar>::iterator q, tail, tail1, tail2;
350 q = tail1 = vvUnique[v].begin() + i;
351 tail2 = q + nUniqueSizeOld;
352 while(*q) {
353 uniq hash = UniqHash(ThenOfBvar(*q), ElseOfBvar(*q)) & vUniqueMasks[v];
354 if(hash == i)
355 tail = tail1;
356 else
357 tail = tail2;
358 if(tail != q)
359 *tail = *q, *q = 0;
360 q = vNexts.begin() + *tail;
361 if(tail == tail1)
362 tail1 = q;
363 else
364 tail2 = q;
365 }
366 }
367 vUniqueTholds[v] <<= 1;
368 if((lit)vUniqueTholds[v] > (lit)BvarMax())
369 vUniqueTholds[v] = BvarMax();
370 }
lit ElseOfBvar(bvar a) const
lit ThenOfBvar(bvar a) const
Here is the call graph for this function:

◆ SetRef()

void rrr::NewBdd::Man::SetRef ( std::vector< lit > const & vLits)
inline

Definition at line 766 of file rrrBddManager.h.

766 {
767 vRefs.clear();
768 vRefs.resize(nObjsAlloc);
769 for(size_t i = 0; i < vLits.size(); i++)
770 IncRef(vLits[i]);
771 }
void IncRef(lit x)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Then()

lit rrr::NewBdd::Man::Then ( lit x) const
inline

Definition at line 227 of file rrrBddManager.h.

227{ return LitNotCond(vObjs[LitRegular(x)], LitIsCompl(x)); }
lit LitRegular(lit x) const
Here is the call graph for this function:

◆ ThenOfBvar()

lit rrr::NewBdd::Man::ThenOfBvar ( bvar a) const
inline

Definition at line 211 of file rrrBddManager.h.

211{ return vObjs[Bvar2Lit(a)]; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TurnOffReo()

void rrr::NewBdd::Man::TurnOffReo ( )
inline

Definition at line 790 of file rrrBddManager.h.

790 {
791 nReo = BvarMax();
792 }

◆ TurnOnReo()

void rrr::NewBdd::Man::TurnOnReo ( int nReo_ = 0,
std::vector< lit > const * vLits = NULL )
inline

Definition at line 776 of file rrrBddManager.h.

776 {
777 if(nReo_)
778 nReo = nReo_;
779 else
780 nReo = nObjs << 1;
781 if((lit)nReo > (lit)BvarMax())
782 nReo = BvarMax();
783 if(vRefs.empty()) {
784 if(vLits)
785 SetRef(*vLits);
786 else
787 vRefs.resize(nObjsAlloc);
788 }
789 }
void SetRef(std::vector< lit > const &vLits)
Here is the call graph for this function:

◆ Var()

var rrr::NewBdd::Man::Var ( lit x) const
inline

Definition at line 225 of file rrrBddManager.h.

225{ return vVars[Lit2Bvar(x)]; }
Here is the call graph for this function:

◆ VarOfBvar()

var rrr::NewBdd::Man::VarOfBvar ( bvar a) const
inline

Definition at line 210 of file rrrBddManager.h.

210{ return vVars[a]; }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: