std::vector<boost::shared_ptr<ribi::trim::Face>> ribi::trim::CellsCreator::FindKnownFacesBetween( const boost::shared_ptr<const Face> a, const boost::shared_ptr<const Face> b ) { assert(a->GetOrientation() == FaceOrientation::horizontal); assert(b->GetOrientation() == FaceOrientation::horizontal); assert(a->GetPoints().size() == 3); assert(b->GetPoints().size() == 3); //Collect the points the candidates must be a subset of std::vector<boost::shared_ptr<Point>> points { a->GetPoints() }; for (const auto& p: b->GetPoints()) { points.push_back(p); } std::sort(points.begin(),points.end(),Helper().OrderByX()); assert(std::unique(points.begin(),points.end()) == points.end()); assert(std::count(points.begin(),points.end(),nullptr) == 0); //Collect the candidates std::vector<boost::weak_ptr<Face>> weak_candidates; for (const auto& p: a->GetPoints()) { for (const auto& q: p->GetConnected()) { weak_candidates.push_back(q); } } for (const auto& p: b->GetPoints()) { for (const auto& q: p->GetConnected()) { weak_candidates.push_back(q); } } std::vector<boost::shared_ptr<Face>> candidates; for (const auto& p: weak_candidates) { const auto q = p.lock(); if (q) candidates.push_back(q); } //std::vector<boost::shared_ptr<Face>> candidates; //for (const auto& p: candidates) { const auto q = p.lock(); if (q) candidates.push_back(q); } std::sort(candidates.begin(),candidates.end(),Helper().OrderByIndex()); candidates.erase(std::unique(candidates.begin(),candidates.end()),candidates.end()); assert(std::count(candidates.begin(),candidates.end(),nullptr) == 0); //Collect the faces between std::vector<boost::shared_ptr<Face>> faces; for (const auto& c: candidates) { if (IsSubset(c->GetPoints(),points)) { faces.push_back(c); } } assert(std::is_sorted(faces.begin(),faces.end(),Helper().OrderByIndex())); assert(std::unique(faces.begin(),faces.end()) == faces.end()); assert(std::count(faces.begin(),faces.end(),nullptr) == 0); //Remove the faces a and b assert(std::count(faces.begin(),faces.end(),a) == 1); assert(std::count(faces.begin(),faces.end(),b) == 1); std::remove(faces.begin(),faces.end(),a); faces.pop_back(); std::remove(faces.begin(),faces.end(),b); faces.pop_back(); return faces; }
//************************* FUNCTION MarkSubsets ******************************* void MarkSubsets(PrimeImplChart &chart, BoolExpr &minterms, BoolExpr &prime_implicants) { /* * Receives: the inputted minterms for the expression to minimze * Task: Get the minimized expression of minterms * Returns: the essential primes as a BoolExpr */ int num_primes = prime_implicants.size(); int num_minterms = minterms.size(); // Compare each prime implicant to each minterm to see if it's a subset for (int i = 0; i < num_primes; ++i) { for (int j = 0; j < num_minterms; ++j) { if (IsSubset(minterms[j], prime_implicants[i])) { chart[i][j] = 1; } } } }