コード例 #1
0
void interval_set_mixed_ctor_4_bicremental_types()
{         
    typedef interval_set<T> IntervalSetT;
    typedef typename IntervalSetT::interval_type IntervalT;

    T v1 = make<T>(1);
    T v2 = make<T>(2);
    T v3 = make<T>(3);
    T v4 = make<T>(4);
    T v5 = make<T>(5);

    IntervalT I1_3D = IntervalT::right_open(v1,v3);
    IntervalT I2_4D = IntervalT::right_open(v2,v4);
    IntervalT I4_5D = IntervalT::right_open(v4,v5);

    split_interval_set<T> split_set;
    split_set.add(I1_3D).add(I2_4D).add(I4_5D);
    BOOST_CHECK_EQUAL( split_set.iterative_size(), 4 );
    separate_interval_set<T> sep_set(split_set);
    BOOST_CHECK_EQUAL( sep_set.iterative_size(), 4 );
    interval_set<T> join_set(split_set);
    BOOST_CHECK_EQUAL( join_set.iterative_size(), 1 );

    separate_interval_set<T> sep_set2;
    sep_set2.add(I1_3D).add(I2_4D).add(I4_5D);
    BOOST_CHECK_EQUAL( sep_set2.iterative_size(), 2 );
    split_interval_set<T> split_set2(sep_set2);
    BOOST_CHECK_EQUAL( split_set2.iterative_size(), 2 );
    interval_set<T> join_set2(sep_set2);
    BOOST_CHECK_EQUAL( join_set2.iterative_size(), 1 );
}
コード例 #2
0
void interval_set_mixed_ctor_4_ordered_types()
{         
    typedef interval_set<T> IntervalSetT;
    typedef typename IntervalSetT::interval_type IntervalT;

    T v0 = boost::icl::identity_element<T>::value();
    
    split_interval_set<T>    split_set(v0);
    separate_interval_set<T> sep_set(split_set);
    interval_set<T>          join_set(sep_set);

    BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(sep_set).lower() );
    BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(join_set).lower() );
}
コード例 #3
0
ファイル: use_cpp.cpp プロジェクト: xingrui/algorithm
double get_min_distance(struct point* points, int point_count, int light_range)
{
    JoinSet join_set(point_count);
    int i, j;
    LOG("%d %d\n", point_count, light_range);

    for (i = 0; i < point_count; ++i) {
        for (j = 0; j < i; ++j) {
            int distance = judge_distance(points + i, points + j);
            //LOG("i=%d j=%d distance=%d calc_distance = %lf\n", i, j, distance,
            //    calc_distance(points + i, points + j));

            if (distance <= light_range) {
                join_set.join(i, j);
            }
        }
    }

    int root_count = 0;
    int roots[point_count];
    int leaf_count[point_count];
    memset(leaf_count, 0, point_count * sizeof(int));

    for (i = 0; i < point_count; ++i) {
        int i_root = join_set.find_root(i);

        if (i_root == i) {
            roots[root_count] = i;
            ++root_count;
            ++leaf_count[i];
        } else {
            ++leaf_count[i_root];
        }
    }

    int max_leaf_count = 0;

    for (i = 0; i < root_count; ++i) {
        LOG("%d leaf_count:%d\n", roots[i], leaf_count[roots[i]]);

        if (leaf_count[roots[i]] > max_leaf_count) {
            max_leaf_count = leaf_count[roots[i]];
        }
    }

    int root_index;
    double min_distance = INF;

    for (root_index = 0; root_index < root_count; ++root_index) {
        if (leaf_count[roots[root_index]] != max_leaf_count) {
            continue;
        }

        int dest_point_index[point_count];
        int dest_point_count = 0;

        for (i = 0; i < point_count; ++i) {
            if (join_set.find_root(i) == roots[root_index]) {
                dest_point_index[dest_point_count] = i;
                ++dest_point_count;
            }
        }

        double distance = get_sub_min_distance(
                points,
                dest_point_count,
                dest_point_index,
                point_count,
                light_range);

        if (min_distance > distance) {
            min_distance = distance;
        }
    }

    printf("%d %.2f\n", max_leaf_count, min_distance);
    return min_distance;
}