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


C++ UndirectedGraph::weight方法代码示例

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


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

示例1: getGreedyHeuristicResult

void GreedyHeuristic::getGreedyHeuristicResult(UndirectedGraph* aTree, int cardinality, string ls_type) {

  UndirectedGraph* greedyTree = new UndirectedGraph();
  bool started = false;
  for (list<Edge*>::iterator anEdge = ((*graph).edges).begin(); anEdge != ((*graph).edges).end(); anEdge++) {
    greedyTree->clear();
    greedyTree->addVertex((*anEdge)->fromVertex());
    greedyTree->addVertex((*anEdge)->toVertex());
    greedyTree->addEdge(*anEdge);
    generateNeighborhoodFor(*anEdge);
    for (int k = 1; k < cardinality; k++) {
      Edge* kctn = getMinNeighbor();
      Vertex* nn = determineNeighborNode(kctn,greedyTree);
      greedyTree->addVertex(nn);
      greedyTree->addEdge(kctn);
      adaptNeighborhoodFor(kctn,nn,greedyTree);
    }
    if (!(ls_type == "no")) {
      
      /* application of local search */
      if (ls_type == "leafs") {
	LocalSearch lsm(graph,greedyTree);
	lsm.run(ls_type);
      }
      else {
	if (ls_type == "cycles_leafs") {
	  //cout << *greedyTree << endl;
	  LocalSearchB lsm;
	  lsm.run(graph,greedyTree);
	}
      }
      /* end local search */
      /*
      if (!isConnectedTree(greedyTree)) {
	cout << "non-connected tree" << endl;
      }
      */

    }
    greedyTree->setWeight(weightOfSolution(greedyTree));
    if (started == false) {
      started = true;
      aTree->copy(greedyTree);
    }
    else {
      if ((greedyTree->weight()) < (aTree->weight())) {
	aTree->copy(greedyTree);
      }
    }
  }
  delete(greedyTree);
}
开发者ID:contaconta,项目名称:neurons,代码行数:52,代码来源:GreedyHeuristic.cpp

示例2: main

int main( int argc, char **argv ) {

    if ( argc < 2 ) {
        print_help();
        exit(1);
    }
    else {
        read_parameters(argc,argv);
    }

    // initialize random number generator

    rnd = new Random((unsigned) time(&t));

    // initialize and read instance from file

    graph = new UndirectedGraph(i_file);
    GreedyHeuristic gho(graph);

    for (int i = cardb; i <= carde; i++) {
        cardinality = i;
        if ((cardinality == cardb) || (cardinality == carde) || ((cardinality % cardmod) == 0)) {
            Timer timer;

            UndirectedGraph* greedyTree = new UndirectedGraph();
            if (type == "edge_based") {
                gho.getGreedyHeuristicResult(greedyTree,cardinality,ls);
            }
            else {
                if (type == "vertex_based") {
                    gho.getVertexBasedGreedyHeuristicResult(greedyTree,cardinality,ls);
                }
            }

            printf("%d\t%f\t%f\n",cardinality,greedyTree->weight(),timer.elapsed_time(Timer::VIRTUAL));

            delete(greedyTree);
        }
    }
    delete(graph);
    delete rnd;
}
开发者ID:contaconta,项目名称:neurons,代码行数:42,代码来源:kcp.cpp

示例3: main

int main( int argc, char **argv ) {

    if ( argc < 2 ) {
        cout << "something wrong" << endl;
        exit(1);
    }
    else {
        read_parameters(argc,argv);
    }
    Timer initialization_timer;

    rnd = new Random((unsigned) time(&t));

    graph = new UndirectedGraph(i_file);

    init_pheromone_trail();

    register int i = 0;
    register int j = 0;
    register int k = 0;
    register int b = 0;

    cout << endl;
    for (int card_counter = cardb; card_counter <= carde; card_counter++) {
        cardinality = card_counter;
        if ((cardinality == cardb) || (cardinality == carde) || ((cardinality % cardmod) == 0)) {
            printf("begin cardinality %d\n",cardinality);

            if (tfile_is_given) {
                if (times.count(cardinality) == 1) {
                    time_limit = times[cardinality];
                }
            }
            vector<double> results;
            vector<double> times_best_found;
            double biar = 0.0;

            int n_of_ants = (int)(((double)((*graph).edges).size()) / ((double)cardinality));
            if (n_of_ants < 15) {
                n_of_ants = 15;
            }
            if (n_of_ants > 50) {
                n_of_ants = 50;
            }

            if (ants.size() > 0) {
                for (list<KCT_Ant*>::iterator anAnt = ants.begin(); anAnt != ants.end(); anAnt++) {
                    delete(*anAnt);
                }
            }
            ants.clear();

            for (i = 0; i < n_of_ants; i++) {
                KCT_Ant* ant = new KCT_Ant();
                ant->initialize(graph,rnd,pheromone,daemon_action);
                ants.push_back(ant);
            }

            for (int trial_counter = 1; trial_counter <= n_of_trials; trial_counter++) {
                printf("begin try %d\n",trial_counter);

                UndirectedGraph* best = NULL;
                UndirectedGraph* newSol = NULL;
                UndirectedGraph* restartBest = NULL;

                double ib_weight = 0.0;
                double rb_weight = 0.0;
                double gb_weight = 0.0;

                Timer timer;

                if ((!(card_counter == cardb)) || (!(trial_counter == 1))) {
                    reset_pheromone_trail();
                    for (list<KCT_Ant*>::iterator ant = ants.begin(); ant != ants.end(); ant++) {
                        (*ant)->restart_reset();
                    }
                }

                int iter = 1;
                double cf = 0.0;
                bool restart = false;
                bool program_stop = false;
                bool bs_update = false;

                while (program_stop == false) {

                    for (list<KCT_Ant*>::iterator ant = ants.begin(); ant != ants.end(); ant++) {
                        for (k = 0; k < cardinality; k++) {
                            (*ant)->step(0.8);
                        }
                        (*ant)->evaluate();
                    }

                    if (!(newSol == NULL)) {
                        delete(newSol);
                    }
                    if (elite_action == "no") {
                        newSol = getBestDaemonSolutionInIteration();
                    }
                    else {
//.........这里部分代码省略.........
开发者ID:contaconta,项目名称:neurons,代码行数:101,代码来源:aco_kct.cpp


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