-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (36 loc) · 1.18 KB
/
main.cpp
File metadata and controls
46 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <vector>
#include "networkit/graph/Graph.hpp"
#include "TSPLib/TSPGraphReader.h"
#include "TSPLib/Checker.h"
#include "TSPLib/TSPGraphMaker.h"
#include "TSPLib/ApproximationTSPAlgorithm.h"
//"../samples/realGraph/att48.edges"
using namespace NetworKit;
int main(int argc, char** argv) {
TSPGraphReader gr = TSPGraphReader();
Graph g = gr.getGraph(argv[1]);
std::cout << "Nodes: " << g.numberOfNodes() << std::endl;
std::cout << "Edges: "<< g.numberOfEdges() << std::endl;
// check for completed graph
Checker ck;
if(!ck.isComplete(g))
{
std::cout<< "Input graph is not complete.";
return 0;
}
// check for non-negative weights
if(!ck.isNonNegativeWeights(g))
{
std::cout<< "Input graph has not non-negative weights.";
return 0;
}
std::vector<node> H = ApproximationTSPAlgorithm().run(g);
TSPGraphMaker tspGraph = TSPGraphMaker();
Graph tsp = tspGraph.findTSPGraph(g,H);
std::cout << "Tour: " ;
for (auto i = H.begin(); i != H.end(); ++i)
std::cout << *i << ' ';
std::cout << std::endl << "Tour cost: " << tspGraph.getTSPCost()<< std::endl;
return 0;
}