### how to implement the Dijkstra algorithm?

this is my homework, it really strikes me.
I uploaded the pdf and the txt in the
 https://hotfile.com/dl/190161205/25500c0/Dijkstra.tar.gz.html

hope you can help me, and give me some tips.

although I know the basic Dijkstra algorithm from the graphic, but I can't convert it to code.

I don't know how to compare the length if one node is selected, the optional

I have two txt files, the net_data.txt and the trip_data.txt
net_data.txt:
first line is the nodes, next line is the edges
and next each line : first 2 numbers are the node, and the next 4 numbers are 4 parameters to calculate the from node 1 to 2 's time.
trip_data.txt:
first line is the nodes, next line is the pairs
and next each line: first 2 numbers are the node, followed by the drives are in this edge

if you want to calculate the time form 2 nodes, you need 5 parameters, the 4 is in the net_data.txt, and the last is the drives amount in the the trip_data.txt

here's my bad code, I really don't know how to design the class, functions and data members, I'm so suck!!
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546`` ``````.h #include #include #include using namespace std; class Node // I m not sure whether this is necessary { public: private: Node* first; Node* previous; }; class Edge // I don't know how to design it { // how many variablbs public: Edge(char arg_origin, char arg_dest); void setOrigin(char value) : origin(value) {} void setDest(char value) : dest(value) {} void setParameter(double f, double b, double c, int p) : f(f), b(b), c(c), p(p) {} private: char origin; char dest; double f; double b; double c; int p; }; class Network // this stucks me, too difficult for me { public: void read(string file1, string file2); private: int nodes; int pairs; vector agents; vector network; };``````

 ``123456789101112131415161718192021222324252627282930313233343536`` `````` .cpp #include "Dijk.h" #include void Network::read(string file1, string file2) { Edge edge_temp; ifstream inFile; inFile.open(file1.c_str()); inFile >> nodes; inFile >> pairs; for(int i = 0; i < pairs; ++i) { char first, second; inFile >> first; edge_temp.setOrigin(first); inFile >> second; edge_temp.setDest(second); double f, b, c; int p; inFile >> f; inFile >> b; inFile >> c; inFile >> p; edge_temp.setParameter(f, b, c, p); network.push_back(edge_temp); } }``````
Last edited on
Topic archived. No new replies allowed.