当前位置: 首页>>代码示例>>C++>>正文


C++ graph::n方法代码示例

本文整理汇总了C++中graph::n方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::n方法的具体用法?C++ graph::n怎么用?C++ graph::n使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graph的用法示例。


在下文中一共展示了graph::n方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: solve_instance

unsigned int quality_exp::solve_instance(graph<int> &g1, graph<int> &g2) {
    graph<int>* large_graph, * small_graph;

    if (g1.n() <= g2.n()) {
        small_graph = &g1;
        large_graph = &g2;
    }
    else {
        small_graph = &g2;
        large_graph = &g1;
    }

    graph<pair<int, int>>* start_point = solve_greedy(*small_graph, *large_graph);
    solution_graph_ptr = solve_tabu(*small_graph,       // graph<int>& g1,
                                    *large_graph,       // graph<int>& g2,
                                    *start_point,       // graph<pair<int, int>>& start_point,
                                    1,                  // int neighbourhood_type,
                                    60,                  // unsigned int tabu_list_size,
                                    2000,                  // int iteration_limit,
                                    0.01,                // float neighbourhood_proportion,
                                    true,               // bool strict_comparisons,
                                    800,                  // int no_gain_iteration_limit,
                                    0.5,                // float edges_vs_time,
                                    0.1,                  // float time_delta,
                                    0.3);                 // float aspiration_threshold

    delete start_point;

    return solution_graph_ptr->m();
}
开发者ID:ivanpondal,项目名称:aed3-tp3,代码行数:30,代码来源:experimentation.cpp

示例2: improve_solution_2

bool improve_solution_2(
    graph<pair<int, int>>* solution,
    graph<int>& g1,
    graph<int>& g2,
    unordered_map<int, int>& g2_to_g1_mapping,
    unordered_set<int>& mapped_nodes,
    unordered_set<int>& unmapped_nodes,
    vector<int>& unmapped_nodes_vector,
    float neighbourhood_proportion,
    bool strict_comparisons,
    unsigned int tabu_list_size,
    priority_queue<movement, vector<movement>,
        movement_compare>& tabu_queue,
    movement_compare& mc,
    vector<movement>& tabu_list,
    bool allow_worse,
    const float time_delta,
    int& max_edge_diff,
    const float aspiration_threshold
) {
    enum action_type {none, swap, exchange};

    vector<pair<int, int>> solution_vertices = solution->get_vertices();
    vector<int> g2_vertices = g2.get_vertices();

    bool use_tabu = tabu_list_size > 0;
    bool is_tabu_mapping = false;
    vector<pair<int, int>> tabu_free_mappings;
    vector<bool> tabu_free_mapping_type;

    bool any_improvement = false;
    int best_edge_diff = 0;
    action_type best_action = none;
    pair<int, int> best_node_1;
    pair<int, int> best_node_2;
    vector<int> best_new_edges_1;
    vector<int> best_new_edges_2;

    for (unsigned int i = 0; i < g2.n(); i++) {
        bool i_mapped = mapped_nodes.find(g2_vertices[i]) != mapped_nodes.end();
        for (unsigned int j = 0; j < i; j++) {
            if (rand() < neighbourhood_proportion * RAND_MAX) {
                bool j_mapped = mapped_nodes.find(g2_vertices[j]) != mapped_nodes.end();

                action_type action;
                int node_1;  // to add if exchange
                int node_2;  // to remove if exchange
                int node_1_mapped;
                int node_2_mapped;
                int lost_edges;
                vector<int> new_edges_1;
                vector<int> new_edges_2;
                int edge_diff = -1;  // to avoid trying to make invalid moves

                if (i_mapped && j_mapped) {
                    // cout << "  try SWAP  " << g2_vertices[i] << " <-> " << g2_vertices[j] << endl;
                    action = swap;

                    node_1 = g2_vertices[i];
                    node_2 = g2_vertices[j];
                    node_1_mapped = g2_to_g1_mapping[node_1];
                    node_2_mapped = g2_to_g1_mapping[node_2];

                    lost_edges =
                        solution->degree({node_1_mapped, node_1}) +
                        solution->degree({node_2_mapped, node_2});
                    if (solution->adjacent({node_1_mapped, node_1}, {node_2_mapped, node_2})) {
                        lost_edges -= 2;
                    }

                    vector<int> node_1_neigh = g2.neighbours(node_1);
                    for (unsigned int k = 0; k < node_1_neigh.size(); k++) {
                        if (node_1_neigh[k] != node_2 &&
                            unmapped_nodes.find(node_1_neigh[k]) ==
                                unmapped_nodes.end() &&
                            g1.adjacent(node_2_mapped,
                                g2_to_g1_mapping[node_1_neigh[k]])
                        )
                        {
                            new_edges_1.push_back(node_1_neigh[k]);
                        }
                    }

                    vector<int> node_2_neigh = g2.neighbours(node_2);
                    for (unsigned int k = 0; k < node_2_neigh.size(); k++) {
                        if (node_2_neigh[k] != node_1 &&
                            unmapped_nodes.find(node_2_neigh[k]) ==
                                unmapped_nodes.end() &&
                            g1.adjacent(node_1_mapped,
                                g2_to_g1_mapping[node_2_neigh[k]])
                        )
                        {
                            new_edges_2.push_back(node_2_neigh[k]);
                        }
                    }
                    // cout << "      lost edges:  " << lost_edges  << endl;
                    // cout << "      new edges 1: " << new_edges_1 << endl;
                    // cout << "      new edges 2: " << new_edges_2 << endl;

                    edge_diff = new_edges_1.size() + new_edges_2.size() - lost_edges;
//.........这里部分代码省略.........
开发者ID:ivanpondal,项目名称:aed3-tp3,代码行数:101,代码来源:local_search.cpp


注:本文中的graph::n方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。