本文整理汇总了C++中Dijkstra类的典型用法代码示例。如果您正苦于以下问题:C++ Dijkstra类的具体用法?C++ Dijkstra怎么用?C++ Dijkstra使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dijkstra类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reader
void Application::run()
{
ra->init();
EventManager::getInstance()->subscribe(this);
MapFileReader reader("res/map.txt");
graph = reader.getGraph();
graph->updateNeighborhood();
GraphDrawer drawer(graph, ra);
Cell::Coord p1, p2;
p1.x = 0;
p1.y = 0;
p2.x = graph->getWidth()-1;
p2.y = graph->getHeight()-1;
Dijkstra *astar = new Dijkstra(graph, p1, p2);
drawer.createEdges();
drawer.createNodes();
astar->start();
while (running)
{
EventManager::getInstance()->captureEvent();
Application::lockRessources();
ra->display();
Application::unlockRessources();
}
}
示例2: SetUp
virtual void SetUp() {
RotasTest::SetUp();
using namespace teitz_bart;
Dijkstra dijkstra = Dijkstra();
TeitzBart teitz_bart = TeitzBart();
cout << "Total de cidades: " << cidades.size() << endl;
for (size_t i = 0; i < cidades.size(); i++)
{
Cidade c = cidades.at(i);
c.set_rotas(dijkstra.dijkstra_menor_caminho(rotas_context, c));
cidades_dijkstra.push_back(c);
}
teitz_bart.define_medianas(cidades_dijkstra, qtd_sedes);
cout << "Cidades sedes: " << endl;
unsigned int qtd_medianas = 0;
for (size_t i = 0; i < cidades_dijkstra.size(); i++)
{
Cidade& c = cidades_dijkstra[i];
if (c.is_mediana())
{
cout << "\t* " << c.get_nome() << endl;
qtd_medianas++;
}
}
gillet_johnson = algoritmos::GilletJohnson();
a = 5;
for (unsigned int i = 0; i < cidades_dijkstra.size(); i++) {
if (cidades_dijkstra[i].is_mediana()) {
pontos_atendimento.push_back(&(cidades_dijkstra[i]));
}
}
// Capacidades dos 3 caminhões
double capacidades[] = { 6200, 8300, 11000 };
for (size_t i = 0; i < pontos_atendimento.size(); i++) {
pontos_atendimento[i]->set_capacidade(capacidades[i % 3]);
}
gillet_johnson.encontra_medianas(cidades_dijkstra);
}
示例3: main
int main()
{
Dijkstra algorithm;
if (!algorithm.Init(3, 67, 100, 100))
{
std::cout << "...Initialization failed." << std::endl;
return 0;
}
return 0;
}
示例4: main
int main()
{
Dijkstra ds;
ds.ReadGraph("input.txt");
std::cout << "Shortest path between 0 and 6 : ";
ds.FindPath(0,6);
return 0;
}
示例5: init_random
/**
* Initialize the random initialisation
* @param anz [description]
*/
void ShortPath::init_random(int anz){
num_of_vertices = anz;
elements.clear();
for (int i = 0; i < num_of_vertices; i++){
Dijkstra d;
d.set_name(concat_string_and_int("J&P",i));
d.set_mark(false);
d.set_predecessor(-1);
d.set_position(i);
elements.push_back(d);
}
init_random_distances();
}
示例6: limitNumberOfNodesInPath
/**
* Encontra dois caminhos disjuntos usando Dijkstra
* A partir deles calcula o limit para o número de hops
*/
int WorstBalancedPathEdge::limitNumberOfNodesInPath(Graph g, int source,int target)
{
Graph s = g;//grafo auxiliar
Dijkstra d;
d.execute(s,source,target);
vector<int> p1;
p1 = d.shortestPath(target);
if ((int)p1.size() <= 1)
{
return 0;
}
/**
* Remove arestas do grafo
*/
int sum = (int)p1.size();
vector<int> adjcents;
Node node;
int u = 0;
for ( u = 0; u < (int)p1.size()-1; u++)
{
s.removeNode(p1[u],p1[u+1]);
s.removeNode(p1[u+1],p1[u]);
}
p1.clear();
d.execute(s,source,target);
p1 = d.shortestPath(target);
if ((int)p1.size() <= 1 )
{
return 0;
}
sum = sum + (int) p1.size();
p1.clear();
return sum;
}
示例7: main
void main(int argc, char* argv[])
{
Dijkstra* sPath = new Dijkstra();
Vertex* head = new Vertex(0,"v1");
//BUG: the comparison on the Vertex* will fail during insert/remove
BinaryHeap<Vertex*>* pQ = new BinaryHeap<Vertex*>();
pQ->Insert(head);
Vertex* current = pQ->RemoveMin();
sPath->ShortestPath(current, pQ);
getchar();
}
示例8: main
int main(){
char c;
clock_t start, end;
Dijkstra G;
int** matrix = G.read();
start = clock();
G.calculateDistance(matrix);
end = clock();
G.output();
cout << "\nExecution Time: " << (double)(end - start)/CLOCKS_PER_SEC << " seconds" << endl;
cout << "Enter a character to exit: ";
cin >> c;
return 0;
}
示例9: main
int main(int argc, char const *argv[])
{
READ;
WRITE;
read();
Dijkstra dijkstra;
dijkstra.init();
for(int i = 0 ; i < 300 ; i ++)
{
for(int j = 0 ; j < 300 ; j++)
{
if(g[i][j]!=-1)
{
// printf("* %c %c %d\n",i,j,g[i][j]);
dijkstra.AddEdge(i, j, g[i][j]);
}
}
}
dijkstra.dijkstra('Z');
return 0;
}
示例10: main
int main()
{
//Get data
Search dfs;
dfs.populateMatrix("distanceMatrix.txt");
dfs.displayKey();
Dijkstra d;
d.populateMatrix("distanceMatrix.txt");
// Get input
cout << "Enter the start intersection number: ";
int begin;
cin >> begin;
cout << "Enter the end intersection number: ";
int end;
cin >> end;
//Perform DFS algorithm
dfs.DFS(begin, end);
cout << "-------------------------" << endl;
cout << "DFS" << endl;
dfs.displayList();
//Perform Dijkstra's algorithm
d.dijkstra(begin, end);
cout << "-------------------------" << endl;
cout << "DIJKSTRA" << endl;
d.displayList();
cout << "Press Enter to Exit" << endl;
cin.ignore(10, '\n');
cin.get();
return 0;
}
示例11: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
string file = "adjacencyMatrix.txt";
Graph G;
G.LoadGraph(file,1);
cout<<"*********************************************************\n";
cout<<"\t\tVisit Graph\n";
cout<<"*********************************************************\n";
G.BreadthFirstSearch();
G.DepthFirstSearch();
string file2 = "weightedAdjacencyMatrix.txt";
G.LoadGraph(file2,2);
cout<<"*********************************************************\n";
cout<<"\t\tMinimum spanning tree\n";
cout<<"*********************************************************\n";
Kruskal k;
k.MSTKruskal(G.vertexNumber,G.weightedAdjacencyMatrix);
Prim p;
int startVertex = 0;
p.MSTPrim(G.vertexNumber,G.weightedAdjacencyMatrix,startVertex);
string file3 = "weightedDirectedGraph.txt";
G.LoadGraph(file3,3);
cout<<"*********************************************************\n";
cout<<"\t\tSingle-source shortest path \n";
cout<<"*********************************************************\n";
Dijkstra d;
d.SSSPDijkstra(G.vertexNumber,G.weightedDirectedAdjacencyMatrix,startVertex);
return 0;
}
示例12: CCLOG
bool TiledMapLayer::init()
{
if (Layer::init()) {
auto map = TMXTiledMap::create("tiledmap/TestMap.tmx");
map->setAnchorPoint(Vec2(0.0f, 0.0f));
map->setPosition(0, 0);
this->addChild(map);
auto mapLayer = map->getLayer("layer1");
Size maxSize = mapLayer->getLayerSize();
CCLOG("maplayer maxwidth %f maxheight %f" , maxSize.width,maxSize.height);
mapGraph = new GridMap((int)maxSize.width,(int)maxSize.height);
for (int row = 0; row < maxSize.width; row++) {
for (int col = 0; col < maxSize.height; col++) {
int gid = mapLayer->getTileGIDAt(Vec2(row,col));
printf(" %d",gid);
if (gid == 10) {
mapGraph->setGridVertexType(row, col, vertex_vertex);
}
}
printf("\n");
}
Dijkstra dij;
dij.Execute(*mapGraph, 10, 39 * ID_PARA + 13);
Vertex * vertex = mapGraph->getVertex(39, 13);
// AStar dij;
// dij.Execute(*mapGraph, 10, 39 * ID_PARA + 13);
// Vertex * vertex = mapGraph->getVertex(39, 13);
printf("path tree length %lld \n", dij.pathTree.size());
// for (auto it = dij.pathTree.find(vertex) , end = dij.pathTree.end(); it->second != 0&& it != end ; it= dij.pathTree.find(it->second)) {
// mapLayer->setTileGID(31, Vec2(vertex->getX(), vertex->getY()));
// vertex = it->second;
// }
auto end = dij.pathTree.end();
while (vertex != nullptr) {
mapLayer->setTileGID(31, Vec2(vertex->getX(), vertex->getY()));
auto it = dij.pathTree.find(vertex);
if (it != end && it->second != nullptr) {
vertex = it->second;
}else{
vertex = nullptr;
}
}
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(TiledMapLayer::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(TiledMapLayer::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(TiledMapLayer::onTouchEnded, this);
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}
return false;
}
示例13: on_BTNdijkstra_clicked
void MainWindow::on_BTNdijkstra_clicked()
{
layout->removeWidget(label);
dijkstra.resolver(ui->DBsrc->currentIndex());
dijkstra.print();
layout->addWidget(label);
}
示例14: main
int main() {
int kase = 0, N, S, E, M, K, X, Y, Z;
while(scanf("%d%d%d%d", &N, &S, &E, &M) == 4) {
solver.init(N);
S--; E--; // 编号从0~N-1
for(int i = 0; i < M; i++) {
scanf("%d%d%d", &X, &Y, &Z); X--; Y--;
solver.AddEdge(X, Y, Z);
solver.AddEdge(Y, X, Z);
}
solver.GetShortestPaths(S, d1, paths1); // S到所有点的距离和路径
solver.GetShortestPaths(E, d2, paths2); // T到所有点的距离和路径
int ans = d1[E]; // 初始解解为直达距离
vector<int> path = paths1[E]; // 初始解的station序列
int midpoint = -1; // 不坐商业线
scanf("%d", &K);
for(int i = 0; i < K; i++) {
scanf("%d%d%d", &X, &Y, &Z); X--; Y--;
for(int j = 0; j < 2; j++) { // j=0代表商业线坐X->Y,j=1代表Y->X
if(d1[X] + d2[Y] + Z < ans) {
ans = d1[X] + d2[Y] + Z;
path = paths1[X];
for(int j = paths2[Y].size()-1; j >= 0; j--) // 从Y到T的距离要反过来
path.push_back(paths2[Y][j]);
midpoint = X;
}
swap(X, Y);
}
}
if(kase != 0) printf("\n");
kase++;
for(int i = 0; i < path.size()-1; i++) printf("%d ", path[i]+1);
printf("%d\n", E+1);
if(midpoint == -1) printf("Ticket Not Used\n"); else printf("%d\n", midpoint+1);
printf("%d\n", ans);
}
return 0;
}
示例15: main
int main()
{
int n, m;
while(scanf("%d%d", &n, &m) == 2)
{
solver.init(n);
for(int i = 0; i < m; ++i)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c); --a; --b;
solver.AddEdge(a, b, c);
solver.AddEdge(b, a, c);
}
solver.dijkstra(1); // 家(1)到所有点的距离。因为道路都是双向的,所以把家看作起点也行
memset(d, -1, sizeof(d));
printf("%d\n", dp(0)); // 办公室(0)到家的符合条件的路径条数
}
return 0;
}