Пример #1
0
box box_factory::map_box(box ratio, box b)
{
    map<string, capd::interval> b_map = b.get_map();
    map<string, capd::interval> res_map;
    for(auto it = b_map.cbegin(); it != b_map.cend(); it++)
    {
        res_map.insert(make_pair(it->first, it->second.leftBound() + ratio.get_map()[it->first] * capd::intervals::width(it->second)));
    }
    return box(res_map);
}
Пример #2
0
box box_factory::get_keys_diff(box lhs, box rhs)
{
    map<string, capd::interval> res;
    map<string, capd::interval> lhs_map = lhs.get_map();
    map<string, capd::interval> rhs_map = rhs.get_map();
    for(auto it = lhs_map.cbegin(); it != lhs_map.cend(); it++)
    {
        if(rhs_map.find(it->first) == rhs_map.cend())
        {
            res.insert(make_pair(it->first, it->second));
        }
    }
    return box(res);
}
Пример #3
0
// partitioning a box
vector<box> box_factory::partition(box b, double e)
{
    // setting up a precision map
    map<string, capd::interval> e_map;
    map<string, capd::interval> edges = b.get_map();
    for(auto it = edges.cbegin(); it != edges.cend(); it++)
    {
        e_map.insert(make_pair(it->first, capd::interval(e)));
    }
    // main algorithm
    vector<box> q = {b};
    vector<box> res;
    while(!q.empty())
    {
        box tmp_b = q.front();
        q.erase(q.cbegin());
        vector<box> tmp_v = bisect(tmp_b, e_map);
        if(tmp_v.empty())
        {
            res.push_back(tmp_b);
        }
        else
        {
            q.insert(q.cend(), tmp_v.cbegin(), tmp_v.cend());
        }
    }
    return res;
}
Пример #4
0
box box_factory::sqrt(box b)
{
    map<string, capd::interval> b_map = b.get_map();
    map<string, capd::interval> res;
    for(auto it = b_map.cbegin(); it != b_map.cend(); it++)
    {
        res.insert(make_pair(it->first, capd::intervals::sqrt(it->second)));
    }
    return box(res);
}
Пример #5
0
/**
 * Dividing the box in all n dimensions producing 2^n boxes of the same size
 */
std::vector<box> box_factory::bisect(box b)
{
    std::map<std::string, capd::interval> e;
    std::map<std::string, capd::interval> m = b.get_map();
    for(auto it = m.cbegin(); it != m.cend(); it++)
    {
        e.insert(make_pair(it->first, capd::interval(0)));
    }

    return box_factory::bisect(b,e);
}
Пример #6
0
box box_factory::merge(box lhs, box rhs)
{
    std::map<std::string, capd::interval> m = lhs.get_map();
    for(auto it = m.cbegin(); it != m.cend(); it++)
    {
        if(rhs.get_map().find(it->first) == rhs.get_map().cend())
        {
            std::stringstream s;
            s << "Variables of the compared boxes are not the same";
            throw std::invalid_argument(s.str());
        }
    }
    int neq_counter = 0;
    std::string neq_dim;

    for(auto it = m.cbegin(); it != m.cend(); it++)
    {
        //std::cout << it->first << " " << it->second << std::endl;
        if(it->second != rhs.get_map()[it->first])
        {
            neq_counter++;
            neq_dim = it->first;
        }

        if(neq_counter > 1)
        {
            return box();
        }
    }

    if(m[neq_dim].rightBound() == rhs.get_map()[neq_dim].leftBound())
    {
        m[neq_dim] = capd::interval(m[neq_dim].leftBound(), rhs.get_map()[neq_dim].rightBound());
        return box(m);
    }
    else
    {
        if(m[neq_dim].leftBound() == rhs.get_map()[neq_dim].rightBound())
        {
            m[neq_dim] = capd::interval(rhs.get_map()[neq_dim].leftBound(), m[neq_dim].rightBound());
            return box(m);
        }
        else
        {
            return box();
        }
    }
}
Пример #7
0
/**
 * Dividing the box in all n dimensions producing 2^n boxes of the same size
 * according to the precision vector e
 */
std::vector<box> box_factory::bisect(box b, std::map<std::string, capd::interval> e)
{
    std::map<std::string, std::vector<capd::interval>> tmp_m;
    std::map<std::string, capd::interval> m = b.get_map();
    for(auto it = m.cbegin(); it != m.cend(); it++)
    {
        if(capd::intervals::width(it->second) > e[it->first].leftBound())
        {
            std::vector<capd::interval> tmp_v;
            tmp_v.push_back(capd::interval((it->second).leftBound(), (it->second).mid().rightBound()));
            tmp_v.push_back(capd::interval((it->second).mid().leftBound(), (it->second).rightBound()));
            tmp_m.insert(make_pair(it->first, tmp_v));
        }
    }
    return box_factory::cartesian_product(tmp_m);
}
Пример #8
0
/**
 * Dividing the box in all n dimensions producing 2^n boxes of the same size
 */
std::vector<box> box_factory::bisect(box b, vector<string> vars, double prec)
{
    std::map<std::string, capd::interval> e;
    std::map<std::string, capd::interval> m = b.get_map();
    for(auto it = m.cbegin(); it != m.cend(); it++)
    {
        if(find(vars.begin(), vars.end(), it->first) != vars.end())
        {
            e.insert(make_pair(it->first, capd::interval(prec)));
        }
        else
        {
            e.insert(make_pair(it->first, capd::intervals::width(it->second)));
        }

    }

    return box_factory::bisect(b,e);
}
Пример #9
0
/**
 * Dividing the box in all n dimensions producing 2^n boxes of the same size
 * according to the precision vector e
 */
vector<box> box_factory::bisect(box b, map<string, pdrh::node*> e)
{
    std::map<std::string, std::vector<capd::interval>> tmp_m;
    std::map<std::string, capd::interval> m = b.get_map();
    //cout << "BISECTING ";
    for(auto it = m.cbegin(); it != m.cend(); it++)
    {
        //cout << it->first << ":" << it->second;
        if(capd::intervals::width(it->second) > pdrh::node_to_interval(e[it->first]).leftBound())
        {
            //cout << " yes" << endl;
            std::vector<capd::interval> tmp_v;
            tmp_v.push_back(capd::interval((it->second).leftBound(), (it->second).mid().rightBound()));
            tmp_v.push_back(capd::interval((it->second).mid().leftBound(), (it->second).rightBound()));
            tmp_m.insert(make_pair(it->first, tmp_v));
        }
        else
        {
            //cout << " no" << endl;
        }
    }
    return box_factory::cartesian_product(tmp_m);
}