gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
dijkstra.C
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 // g++ dijkstra.C -o dijkstra
18 
19 #include <iostream>
20 using namespace std;
21 
22 #include <math.h>
23 
24 #include "dijkstra.H"
25 
26 int main(int argc, char *argv[]){
27 
28  int N=10;
29  // A B C D E F G H I J
30  int roadLength[10][10]={{0, 2, 1, 0, 0, 0, 0, 0, 0, 0}, // A
31  {2, 0, 0, 5, 3, 0, 0, 0, 0, 0}, // B
32  {1, 0, 0, 4, 0, 0, 0, 0, 0, 0}, // C
33  {0, 5, 4, 0, 0, 7, 8, 0, 0, 0}, // D
34  {0, 3, 0, 0, 0, 6, 0, 0, 0, 0}, // E
35  {0, 0, 0, 7, 6, 0, 0, 10, 0, 0}, // F
36  {0, 0, 0, 8, 0, 0, 0, 9, 0, 0}, // G
37  {0, 0, 0, 0, 0, 10, 9, 0, 11, 13}, // H
38  {0, 0, 0, 0, 0, 0, 0, 11, 0, 12}, // I
39  {0, 0, 0, 0, 0, 0, 0, 13, 12, 0} // J
40  };
41 
42  int visited[10]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
43 
44  int pathLengths[N][N];
45  int lastLoc[N][N];
46 
47  for (int i=0;i<N; i++)
48  for (int j=0;j<N; j++){
49  pathLengths[i][j]=99;
50  lastLoc[i][j]=11;
51  if (roadLength[i][j]==0)
52  roadLength[i][j]=99;
53  cout<<roadLength[i][j]<<endl;
54  }
55 
56  Dijkstra dijkstra(N);
57  dijkstra.setVisited((int *)visited);
58  for (int i=0; i<N; i++)
59  for (int j=0; j<N;j++)
60  dijkstra.setPathLengths(pathLengths[i][j], i , j);
61  for (int i=0; i<N; i++)
62  for (int j=0; j<N;j++)
63  dijkstra.setRoadLengths(roadLength[i][j], i, j);
64  for (int i=0; i<N; i++)
65  for (int j=0; j<N;j++)
66  dijkstra.setLastLoc(lastLoc[i][j], i , j);
67 
68  dijkstra.findShortestPath();
69 
70  return 0;
71 }
int N
void findShortestPath()
Definition: dijkstra.H:168
void setLastLoc(int pl, int i, int j)
Definition: dijkstra.H:164
void setRoadLengths(int pl, int i, int j)
Definition: dijkstra.H:161
STL namespace.
void setPathLengths(int pl, int i, int j)
Definition: dijkstra.H:158
int main(int argc, char *argv[])
Definition: dijkstra.C:26
void setVisited(int *vis)
Definition: dijkstra.H:154
gtkIOStream: /tmp/gtkiostream/include/mffm/possible.future.additions/Dijkstra/dijkstra.C Source File
GTK+ IOStream  Beta