Tasks for "Graphs and Their Uses" course at AGH UST.
The project was developed and tested in Python 3.8 in Windows system.
Each project is shortly described in the list below. Details about each class, method and functionality such as arguments or certain requirements are described in the appropriate file as docstrings.
To run solutions of tasks from project it's enough to run the Project_01.py file. The solutions use:
- Graph.py - represent simple graphs.
- reading graph data from file and printing it;
- drawing a graph.
- GraphManager.py - allow to perform some operations connected with simple graphs.
- constructing random graphs using Erdos-Renyi model and Gilbert model.
- representation_checks.py - check correctness of graph representation.
- checking whether passed graph data, that is adjacency matrix, incidence matrix or adjacency list, is correct.
- representation_conversions.py - convert graph representation from one to the other.
- checking graph representation and converting it to the other.
To run solutions of tasks from project it's enough to run the Project_02.py file. The solutions use:
- Some functionalities from previous project described above.
- GraphManager.py - allow to perform some operations connected with simple graphs.
- randomizing edges in graph.
- Sequence.py and Stack.py - custom implementation of sequences and stacks.
- reading data from files and lists;
- performing characteristic operations such as adding or removing elements.
- degree_sequences.py - allow to perform operations connected with degree sequence of a graph.
- checking whether sequence is a degree sequence using Havel-Hakimi algorithm;
- constructing a degree sequence from graph and vice versa.
- dfs.py - allow to perform DFS
- recursive DFS algorithm implementation
- regularity.py - allow to perform operations connected with regular graphs.
- checking whether a graph is regular;
- constructing a regular graph using degree sequence.
- connectivity.py - allow to perform operations connected with connected graphs.
- checking whether a graph is connected;
- extracting components of a graph (maximum component in particular).
- eulerianity.py - allow to perform operation connected with eulerian graphs.
- checking whether a graph is eulerian;
- constructing an eulerian graph;
- extracting eulerian cycle from graph.
- hamiltonicity.py - allow to perform operation connected with hamiltonian graphs.
- extracting hamiltonian cycle from graph;
- optimized extracting of hamiltonian cycle from graph using S. Martello approach.
To run solutions of tasks from project it's enough to run the Project_03.py file. The solutions use:
- Some functionalities from previous projects described above.
- WeightedGraph.py - represent weighted graphs.
- reading weighted graph data from file and printing it;
- drawing a weighted graph.
- WeightedGraphManager.py - allow to perform some operations connected with weighted graphs.
- constructing weighted graph from simple graph;
- constructing random connected weighted graphs using Prufer code, Erdos-Renyi model and Gilbert model.
- connectivity.py - allow to perform operations connected with connected graphs.
- constructing random connected trees using Prufer code
- constructing random connected graphs using Prufer code followed with Erdos-Renyi model and Gilbert model.
- shortest_weighted_paths.py - allow to find objects connected with shortest distance in weighted graphs.
- implementation of Dijkstra algorithm;
- finding distance matrix between any two vertices;
- finding center and minimax-center.
- minimum_spanning_trees.py - allow to find minimum spanning tree of weighted graph.
- implementation of Kruskal algorithm.
To run solutions of tasks from project it's enough to run the Project_04.py file. The solutions use:
- Some functionalities from previous projects described above.
- Digraph.py - represent digraphs.
- reading digraphs data from file and printing it;
- drawing a digraphs.
- DigraphManager.py - allow to perform some operations connected with digraphs.
- constructing random digraph using Gilbert model;
- constructing transpose digraph of passed digraph.
- WeightedDigraph.py - represent weighted digraphs.
- reading weighted digraphs data from file and printing it;
- drawing a digraphs.
- WeightedDigraphManager.py - allow to perform some operations connected with weighted digraphs.
- constructing weighted digraph from passed digraph;
- constructing random weighted digraph using Gilbert model.
- strong_connectivity.py - allow to perform some operations connected with strongly connected digraphs.
- implementation of Kosaraju algorithm;
- constructing strongly connected digraph using modified implementation of Tarjan algorithm.
- shortest_weighted_digraph_paths.py - allow to find objects connected with shortest distance in weighted digraphs.
- implementation of Bellman-Ford algorithm;
- finding distance matrix between any two vertices using Bellman-Ford algorithm;
- implementation of Johnson algorithm.
To run solutions of tasks from project it's enough to run the Project_05.py file. The solutions use:
- Some functionalities from previous projects described above.
- FlowNetwork.py - represent flow networks.
- reading weighted graph data from file and printing it;
- drawing a weighted graph.
- FlowNetworkManager.py - allow to perform some operations connected with flow networks.
- constructing random flow network using layers approach and Erdos-Renyi model;
- constructing residual network of passed flow network.
- maximum_flow.py - allow to find maximum flow of flow network.
- implementation of Ford-Fulkerson algorithm;
- finding augmenting path (as a part of Ford-Fulkerson algorithm) in flow flow network using BFS.
- representation_checks.py - check correctness of flow network representation.
- checking whether passed flow network data is correct (improved is_adjacency_matrix function)
To run solutions of tasks from project it's enough to run the Project_06.py file. Example solutions of TSP problem (using implemented algorithm) are placed in tsp_results directory. The solutions use:
- Some functionalities from previous projects described above.
- WeightedGraphManager.py - allow to perform some operations connected with weighted graphs.
- added constructing weighted graph from metric data;
- traveling_salesman_problem.py - allow to find TSP solution.
- getting length of cycle in weighted graph
- perform 2-opt algorithm on weighted graph
- perform simulated annealing algorithm on weighted graph
- implementation of Metropolis–Hastings algorithm using 2-opt and simulated annealing to find TSP solution
- saving found TSP solution as a diagram to a .png file