Ejemplo n.º 1
0
void greedy_mis::initial_partition(const unsigned int seed, graph_access & G) {
    random_functions::setSeed(seed);
    NodePermutationMap permutation;
    generate_permutation(G, permutation);

    bucket_array *buckets = new bucket_array(G.number_of_nodes());
    G.set_partition_count(2);

    // Initialize the priority queue
    forall_nodes (G, n) {
        NodeID node = permutation[n];
        EdgeWeight node_degree = G.getNodeDegree(node);
        buckets->increment(node, node_degree);
        G.setPartitionIndex(node, 0);
    } endfor
Ejemplo n.º 2
0
void local_optimizer::run_maxent_optimization_internal( const Config & config, graph_access & G ) {
        if(G.number_of_edges() == 0) return;

        std::vector< coord_t > new_coord(G.number_of_nodes());
        CoordType alpha = config.maxent_alpha;
        int iterations  = config.maxent_inner_iterations;
        CoordType q     = config.q;

        std::vector<CoordType> distances(G.number_of_edges(),0); 
        configure_distances( config, G, distances);

        for( int i = 0; i < config.maxent_outer_iterations; i++) {

                CoordType norm_coords = 0;
                CoordType norm_diff = 0;
                do {
                        forall_nodes_parallel(G, node) {
                                CoordType rho_i = 0; // assume graph is connected?
                                if(G.getNodeDegree(node) == 0) continue;
                                forall_out_edges(G, e, node) {
                                        CoordType distance = distances[e];
                                        rho_i += 1/(distance*distance);
                                } endfor
                                rho_i = 1/rho_i;

                                CoordType S_x = 0;
                                CoordType S_y = 0;

                                CoordType n_S_x = 0;
                                CoordType n_S_y = 0;
                                forall_out_edges(G, e, node) {
                                        NodeID target      = G.getEdgeTarget(e);
                                        CoordType diffX       = G.getX(node) - G.getX(target);
                                        CoordType diffY       = G.getY(node) - G.getY(target);
                                        CoordType dist_square = diffX*diffX+diffY*diffY;
                                        CoordType distance    = distances[e];
                                        CoordType dist        = sqrt(dist_square);

                                        CoordType scaled_distance = distance/dist;
                                        CoordType squared_distance = distance*distance;

                                        S_x += (G.getX(target) + scaled_distance*diffX)/(squared_distance);
                                        S_y += (G.getY(target) + scaled_distance*diffY)/(squared_distance);

                                        CoordType dist_q = pow(dist, q+2);
                                        n_S_x -= diffX/dist_q;
                                        n_S_y -= diffY/dist_q;
                                } endfor

                                S_x *= rho_i;
                                S_y *= rho_i;

                                forall_nodes(G, target) {
                                        if( node == target ) continue;

                                        CoordType diffX       = G.getX(node) - G.getX(target);
                                        CoordType diffY       = G.getY(node) - G.getY(target);
                                        CoordType dist_square = diffX*diffX+diffY*diffY;
                                        CoordType dist        = sqrt(dist_square);

                                        CoordType dist_q = pow(dist, q+2);
                                        n_S_x += diffX/dist_q;
                                        n_S_y += diffY/dist_q;
                                } endfor
                                CoordType mult_factor = alpha*rho_i;

                                n_S_x *= mult_factor;
                                n_S_y *= mult_factor;

                                new_coord[node].x = S_x + sgn(q)*n_S_x;
                                new_coord[node].y = S_y + sgn(q)*n_S_y;
                        } endfor