本文整理汇总了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);
}
示例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;
}
示例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 {
//.........这里部分代码省略.........