In this task we were required to create a structure that will present a graph. We were given some interfaces that we have implemented. In this project we need to calculate algorithms on the graph that we created (center, shortest path between two nodes, TSP, ...). Eventually, we created a GUI that draws the graph.
The algorithm logic is based on the following:
- copying the graph and creating a list of NodeData.
- sending the source and dest nodes to the Shortest Path Distance Algorithm.
- if it won't return us -1, that means that there's a track between them.
- we will transpose the copied graph.
- now we will start from the dest node, add it to the list, and check for his neighbors which neighbor weight + edge weight = dest weight.
- the one node that will give us the equality is our next node, we will add it to the list, and now check on this node, the previous question.
- we will continue doing that until we will get to the source node.
- in the end, we will reverse the list.
- checking the weight of the dest node.
The algorithm logic is based on the following:
- going through all of the graph nodes.
- for each node we will perform the Dijkstra Algorithm.
- find the maximum weight relative to all other nodes.
- going to the next node and doing the same.
- find the minimum of the maximum weights.
- the one node that gave us the minimum is the center of the graph.
The algorithm logic is based on the following:
- creating an ArrayList that will present the sequence of the given nodes that we will need to perform shortest path.
- going through all of the nodes in the given list.
- creating an ArrayList that will present an optional sequence of the given nodes.
- adding the node to the optional ArrayList.
- sending the node to a help function (tspHelp) and it will return us the next node (from the given nodes) that we would like to move to.
- add the next node to the optional ArrayList.
- keep sending to tspHelp and finding the next node until we did it size of the given nodes list.
- going through the optional ArrayList, and calculating the shortest path dist in this list order.
- going to the next given node and doing the above.
- the minimum shortest path dist will be the final ArrayList.
- sending the final ArrayList to the Shortest Path algorithm and return this list.
Class name | description |
---|---|
Point2D | present a location of graph node. |
Node_Data | present a graph node. |
Edge_Data | Present a graph edge. |
DiGraph | Present a graph. |
GraphAlgo | Present a class to perform algorithms on a graph. |
- Install python 3 on your pc.
- Download (clone) the project.
- Run the main class and change the graph path to the path that you want.
Matan Yarin Shimon & Yarin Hindi