src/libminisyncpp/minisync.cpp
/*
 * Removes un-used data points from the algorithm internal storage.
 */
Removes un-used data points from the algorithm internal storage.
Removes un - used data points from the algorithm internal storage .
void MiniSync::Algorithms::MiniSync::cleanup()
{
    for (auto iter_j = low_points.begin(); iter_j != low_points.end();)
    {
        if (low_constraint_pts.first != *iter_j && high_constraint_pts.first != *iter_j)
        {
            bool store = false;
            for (auto iter_i = low_points.begin(); iter_i != iter_j; ++iter_i)
            {
                for (auto iter_k = std::next(iter_j, 1); iter_k != low_points.end(); ++iter_k)
                {
                    if (low_slopes.at(std::make_pair(*iter_i, *iter_j))
                        > low_slopes.at(std::make_pair(*iter_j, *iter_k)))
                    {
                        store = true;
                        break;
                    }
                }
                if (store) break;
            }
            if (!store)
            {
                for (auto iter_slope = low_slopes.begin(); iter_slope != low_slopes.end();)
                {
                    if (iter_slope->first.first == *iter_j || iter_slope->first.second == *iter_j)
                        iter_slope = low_slopes.erase(iter_slope);
                    else ++iter_slope;
                }
                iter_j = low_points.erase(iter_j);
            }
            else
                ++iter_j;
        }
        else
            ++iter_j;
    }
    for (auto iter_j = high_points.begin(); iter_j != high_points.end();)
    {
        if (low_constraint_pts.second != *iter_j && high_constraint_pts.second != *iter_j)
        {
            bool store = false;
            for (auto iter_i = high_points.begin(); iter_i != iter_j; ++iter_i)
            {
                for (auto iter_k = std::next(iter_j, 1); iter_k != high_points.end(); ++iter_k)
                {
                    try
                    {
                        if (high_slopes.at(std::make_pair(*iter_i, *iter_j))
                            < high_slopes.at(std::make_pair(*iter_j, *iter_k)))
                        {
                            store = true;
                            break;
                        }
                    }
                    catch (std::out_of_range& e)
                    {
#ifdef LOGURU_ENABLE
                        DLOG_F(WARNING, "iter_i: (%Lf, %Lf)",
                               iter_i->get()->getX().count(),
                               iter_i->get()->getY().count());
                        DLOG_F(WARNING, "iter_j: (%Lf, %Lf)",
                               iter_j->get()->getX().count(),
                               iter_j->get()->getY().count());
                        DLOG_F(WARNING, "iter_k: (%Lf, %Lf)",
                               iter_k->get()->getX().count(),
                               iter_k->get()->getY().count());
#endif
                        throw;
                    }
                }
                if (store) break;
            }
            if (!store)
            {
                for (auto iter_slope = high_slopes.begin(); iter_slope != high_slopes.end();)
                {
                    if (iter_slope->first.first == *iter_j || iter_slope->first.second == *iter_j)
                        iter_slope = high_slopes.erase(iter_slope);
                    else ++iter_slope;
                }
                iter_j = high_points.erase(iter_j);
            }
            else
                ++iter_j;
        }
        else
            ++iter_j;
    }
    auto tmp_low_cons = std::move(this->low_constraints);
    auto tmp_high_cons = std::move(this->high_constraints);
    for (auto h_point: high_points)
    {
        for (auto l_point: low_points)
        {
            auto pair = std::make_pair(l_point, h_point);
            if (tmp_low_cons.count(pair) > 0)
                this->low_constraints.emplace(pair, tmp_low_cons.at(pair));
            else if (tmp_high_cons.count(pair) > 0)
                this->high_constraints.emplace(pair, tmp_high_cons.at(pair));
        }
    }
}
void MiniSync :: Algorithms :: MiniSync :: cleanup ( ) { for ( auto iter_j = low_points . begin ( ) ; iter_j != low_points . end ( ) ; ) { if ( low_constraint_pts . first != * iter_j && high_constraint_pts . first != * iter_j ) { bool store = false ; for ( auto iter_i = low_points . begin ( ) ; iter_i != iter_j ; ++ iter_i ) { for ( auto iter_k = std :: next ( iter_j , 1 ) ; iter_k != low_points . end ( ) ; ++ iter_k ) { if ( low_slopes . at ( std :: make_pair ( * iter_i , * iter_j ) ) > low_slopes . at ( std :: make_pair ( * iter_j , * iter_k ) ) ) { store = true ; break ; } } if ( store ) break ; } if ( ! store ) { for ( auto iter_slope = low_slopes . begin ( ) ; iter_slope != low_slopes . end ( ) ; ) { if ( iter_slope -> first . first == * iter_j || iter_slope -> first . second == * iter_j ) iter_slope = low_slopes . erase ( iter_slope ) ; else ++ iter_slope ; } iter_j = low_points . erase ( iter_j ) ; } else ++ iter_j ; } else ++ iter_j ; } for ( auto iter_j = high_points . begin ( ) ; iter_j != high_points . end ( ) ; ) { if ( low_constraint_pts . second != * iter_j && high_constraint_pts . second != * iter_j ) { bool store = false ; for ( auto iter_i = high_points . begin ( ) ; iter_i != iter_j ; ++ iter_i ) { for ( auto iter_k = std :: next ( iter_j , 1 ) ; iter_k != high_points . end ( ) ; ++ iter_k ) { try { if ( high_slopes . at ( std :: make_pair ( * iter_i , * iter_j ) ) < high_slopes . at ( std :: make_pair ( * iter_j , * iter_k ) ) ) { store = true ; break ; } } catch ( std :: out_of_range & e ) { #ifdef LOGURU_ENABLE DLOG_F ( WARNING , " " , iter_i -> get ( ) -> getX ( ) . count ( ) , iter_i -> get ( ) -> getY ( ) . count ( ) ) ; DLOG_F ( WARNING , " " , iter_j -> get ( ) -> getX ( ) . count ( ) , iter_j -> get ( ) -> getY ( ) . count ( ) ) ; DLOG_F ( WARNING , " " , iter_k -> get ( ) -> getX ( ) . count ( ) , iter_k -> get ( ) -> getY ( ) . count ( ) ) ; #endif throw ; } } if ( store ) break ; } if ( ! store ) { for ( auto iter_slope = high_slopes . begin ( ) ; iter_slope != high_slopes . end ( ) ; ) { if ( iter_slope -> first . first == * iter_j || iter_slope -> first . second == * iter_j ) iter_slope = high_slopes . erase ( iter_slope ) ; else ++ iter_slope ; } iter_j = high_points . erase ( iter_j ) ; } else ++ iter_j ; } else ++ iter_j ; } auto tmp_low_cons = std :: move ( this -> low_constraints ) ; auto tmp_high_cons = std :: move ( this -> high_constraints ) ; for ( auto h_point : high_points ) { for ( auto l_point : low_points ) { auto pair = std :: make_pair ( l_point , h_point ) ; if ( tmp_low_cons . count ( pair ) > 0 ) this -> low_constraints . emplace ( pair , tmp_low_cons . at ( pair ) ) ; else if ( tmp_high_cons . count ( pair ) > 0 ) this -> high_constraints . emplace ( pair , tmp_high_cons . at ( pair ) ) ; } } }
Removes un-used data points from the algorithm internal storage.
Removes un - used data points from the algorithm internal storage .
// cleanup // low point is not one of the current constraint low points // now we compare the slopes with each other point to see if we store it for future use or not // if current point is Aj, compare each M(Ai, Aj) with M(Aj, Ak) // store point Aj only iff there exists // M(Ai, Aj) > M(Aj, Ak) for 0 <= i < j < k <= total number of points. // delete all associated slopes then delete the point // done same thing for high points // high point is not one of the current constraint high points // now we compare the slopes with each other point to see if we store it for future use or not // if current point is Aj, compare each M(Ai, Aj) with M(Aj, Ak) // store point Aj only iff there exists // M(Ai, Aj) < M(Aj, Ak) for 0 <= i < j < k <= total number of points. This is the inverse condition as // the low points. // delete all associated slopes then delete the point