aboutsummaryrefslogtreecommitdiff
Interactive graph visualizer and laboratory suite

Interactive graph visualizer and laboratory suite

1. Tasks

1.1. Random DAG generation and shimbel path metrics1

  1. Generate a randomly connected acyclic graph according to a given distribution (distribution parameters set as constants) with the required number of vertices. The distribution is best taken from the Wadzinski handbook.
  2. Implement the Shimbell method on the resulting graph (the user enters number of edges).
  3. Determine the possibility of building a route from one specified point to another one (the vertex is entered by the user) and find the number of such routes.

1.2. Shortest paths and algorithm performance comparison2

  1. For the given graphs (randomly generated in the previous task) it is necessary to generate a weight matrix (positive or with negative weights – the user chooses) and find the shortest path for two points selected by the user. The user enters the numbers of the starting and ending vertices. As a result, not only the distance is displayed, but also the path itself in the form of a sequence of vertices. For Dijkstra’s and Bellman‑Ford’s algorithms, it is necessary output the distance vector, for Floyd-Warshall – the matrix distances. Implemented algorithms:
    • classic Dijkstra algorithm
    • the Floyd-Warshall algorithm
    • Finding the maximum path (for user-defined vertices)
  2. Compare the speeds of these algorithms (by number of iterations).

1.3. Maximum flow and minimum-cost network flows3

  1. Form a connected acyclic graph randomly in according to the specified distribution. Based on it, build throughput and cost matrices.
  2. For the resulting graph, find the maximum flow using the algorithm Ford-Fulkerson (or any of those listed in the lecture).
  3. Calculate the minimum cost flow (as the flow value take a value equal to ⅔max, where max is the maximum flow). Use previously implemented Dijkstra and/or Bellman-Ford algorithms.

1.4. Spanning trees, matrix-tree theorem, and Prüfer codes4

  1. For the given graphs (randomly generated in the first task), using Kirchhoff’s matrix theorem, find the number of spanning trees in the original graph.
  2. Construct a minimum‑weight spanning tree for the generated weighted graph using the Prim and Boruvka algorithms. Compare The given algorithms (by the number of iterations).
  3. Encode the resulting skeleton using the Prüfer code and decode it. his. It is essential to maintain the weights during encoding.

1.5. Eulerian, Hamiltonian, and traveling salesman problems5

  1. For the given graphs (randomly generated in the first task), check whether the graph is Eulerian and Hamiltonian.
  2. Check whether the graph is Eulerian. If not, modify the graph (show what was changed). Construct an Eulerian cycle.
  3. Check whether the graph is Hamiltonian. If not, modify the graph (show what was changed). Solve the problem. The traveling salesman problem on a Hamiltonian graph (we output all Hamiltonian cycles with a total weight either to the screen if there are few of them, or to a file). There are separate bonuses for implemented heuristics (by default, a complete search).

2. Documentation

The exported report can be found at this link.

3. Showcase

3.1. Distribution of the random number generator

distribution-my.png

3.2. Creation of graph with 8 vertices

graph1.png

ADJECENCY_MATRIX:
   [00][01][02][03][04][05][06][07]
[0]  0   0   0   0   0   1   0   0
[1]  0   0   1   1   0   0   1   1
[2]  0   0   0   0   1   0   0   0
[3]  0   0   0   0   0   1   0   0
[4]  0   0   0   0   0   1   0   1
[5]  0   0   0   0   0   0   1   1
[6]  0   0   0   0   0   0   0   1
[7]  0   0   0   0   0   0   0   0

WEIGHT/COST_MATRIX:
   [00][01][02][03][04][05][06][07]
[0]  0   0   0   0   0   7   0   0
[1]  0   0   4   2   0   0   8   2
[2]  0   0   0   0   5   0   0   0
[3]  0   0   0   0   0   4   0   0
[4]  0   0   0   0   0   7   0   2
[5]  0   0   0   0   0   0   2   5
[6]  0   0   0   0   0   0   0   1
[7]  0   0   0   0   0   0   0   0

CAPACITY_MATRIX:
   [00][01][02][03][04][05][06][07]
[0]  0   0   0   0   0   3   0   0
[1]  0   0   4   1   0   0   1   6
[2]  0   0   0   0   7   0   0   0
[3]  0   0   0   0   0   6   0   0
[4]  0   0   0   0   0   9   0   8
[5]  0   0   0   0   0   0   6   5
[6]  0   0   0   0   0   0   0   1
[7]  0   0   0   0   0   0   0   0

3.3. Shimbell method

SHIMBELL METHOD EDGE COUNT: 2
MIN PATH MATRIX:
   [000][001][002][003][004][005][006][007]
[0] inf  inf  inf  inf  inf  inf  inf   10
[1] inf  inf  inf  inf  inf   16    8   11
[2] inf  inf  inf  inf  inf  inf   14   17
[3] inf  inf  inf  inf  inf  inf  inf    7
[4] inf  inf  inf  inf  inf  inf  inf   10
[5] inf  inf  inf  inf  inf  inf  inf  inf
[6] inf  inf  inf  inf  inf  inf  inf  inf
[7] inf  inf  inf  inf  inf  inf  inf  inf

3.4. Route count

FROM: 0
TO: 7
ROUTE COUNT FROM 0 TO 7: 2

FROM: 2
TO: 7
ROUTE COUNT FROM 2 TO 7: 3

FROM: 5
TO: 0
NO ROUTES FROM 5 TO 0

3.5. Dijkstra's algorithm

graph2.png

MIN
FROM: 2
TO: 7
DISTANCEVECTOR: (inf inf inf 0 inf 5 12 14 7)
PATH: 2 -> 4 -> 7

FROM: 0
TO: 7
DISTANCE VECTOR: (0 0 inf inf inf inf 7 9 10)
PATH: 0 -> 5 -> 6 -> 7

FROM: 2
TO: 0
DISTANCE VECTOR: (inf inf inf 0 inf 5 12 14 7)
NO PATH FROM 2 TO 0

3.6. The Floyd-Warshall algorithm

graph3-1.png

graph3-2.png

MAX
FROM: 2
TO: 7
DISTANCE MATRIX:
     [0] [1] [2] [3] [4] [5] [6] [7]
[0]   0-inf-inf-inf-inf   7   9  12
[1]-inf   0   4   2   9  16  18  21
[2]-inf-inf   0-inf   5  12  14  17
[3]-inf-inf-inf   0-inf   4   6   9
[4]-inf-inf-inf-inf   0   7   9  12
[5]-inf-inf-inf-inf-inf   0   2   5
[6]-inf-inf-inf-inf-inf-inf   0   1
[7]-inf-inf-inf-inf-inf-inf-inf   0
PATH: 2 -> 4 -> 5 -> 7

3.7. The Ford–Fulkerson algorithm

graph4.png

FROM: 2
TO: 7
MAX_FLOW: 7

FROM: 4
TO: 7
MAX_FLOW: 14

3.8. Calculation of the minimum cost flow

graph5.png

FROM: 4
TO: 7
REQUIRED_FLOW: [14*2/3] = 9
FLOW_MATRIX:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    0    0    0    0
[1]   0    0    0    0    0    0    0    0
[2]   0    0    0    0    0    0    0    0
[3]   0    0    0    0    0    0    0    0
[4]   0    0    0    0    0    1    0    8
[5]   0    0    0    0    0    0    1    0
[6]   0    0    0    0    0    0    0    1
[7]   0    0    0    0    0    0    0    0
MIN_COST: 26

3.9. Determining the number of possible spanning trees

KIRCHHOFF_MATRIX:
   [000][001][002][003][004][005][006][007]
[0]   1    0    0    0    0   -1    0    0
[1]   0    4   -1   -1    0    0   -1   -1
[2]   0   -1    2    0   -1    0    0    0
[3]   0   -1    0    2    0   -1    0    0
[4]   0    0   -1    0    3   -1    0   -1
[5]  -1    0    0   -1   -1    5   -1   -1
[6]   0   -1    0    0    0   -1    3   -1
[7]   0   -1    0    0   -1   -1   -1    4
SPANNING TREE COUNT 181

3.10. Prim, Borovka, and Prufer codes

graph6.png

PRIM
MINIMUM_SPANNING_TREE_WEIGHTS:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    0    7    0    0
[1]   0    0    4    2    0    0    0    2
[2]   0    4    0    0    0    0    0    0
[3]   0    2    0    0    0    0    0    0
[4]   0    0    0    0    0    0    0    2
[5]   7    0    0    0    0    0    2    0
[6]   0    0    0    0    0    2    0    1
[7]   0    2    0    0    2    0    1    0
TOTAL_WEIGHT: 20
ITERATION_COUNT: 448
MINIMAL_SPANNING_TREE:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    0    7    0    0
[1]   0    0    4    2    0    0    0    2
[2]   0    4    0    0    0    0    0    0
[3]   0    2    0    0    0    0    0    0
[4]   0    0    0    0    0    0    0    2
[5]   7    0    0    0    0    0    2    0
[6]   0    0    0    0    0    2    0    1
[7]   0    2    0    0    2    0    1    0
PRUFER_CODE:   5 1 1 7 7 6 7
SAVED_WEIGHTS: 7 4 2 2 2 2 1
DECODED_MINIMAL_SPANNING_TREE:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    0    7    0    0
[1]   0    0    4    2    0    0    0    2
[2]   0    4    0    0    0    0    0    0
[3]   0    2    0    0    0    0    0    0
[4]   0    0    0    0    0    0    0    2
[5]   7    0    0    0    0    0    2    0
[6]   0    0    0    0    0    2    0    1
[7]   0    2    0    0    2    0    1    0
Success, matrices the same!
BORUVKA
MINIMUM_SPANNING_TREE_WEIGHTS:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    0    7    0    0
[1]   0    0    4    2    0    0    0    2
[2]   0    4    0    0    0    0    0    0
[3]   0    2    0    0    0    0    0    0
[4]   0    0    0    0    0    0    0    2
[5]   7    0    0    0    0    0    2    0
[6]   0    0    0    0    0    2    0    1
[7]   0    2    0    0    2    0    1    0
TOTAL_WEIGHT: 20
ITERATION_COUNT: 44
MINIMAL_SPANNING_TREE:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    0    7    0    0
[1]   0    0    4    2    0    0    0    2
[2]   0    4    0    0    0    0    0    0
[3]   0    2    0    0    0    0    0    0
[4]   0    0    0    0    0    0    0    2
[5]   7    0    0    0    0    0    2    0
[6]   0    0    0    0    0    2    0    1
[7]   0    2    0    0    2    0    1    0
PRUFER_CODE:   5 1 1 7 7 6 7
SAVED_WEIGHTS: 7 4 2 2 2 2 1
DECODED_MINIMAL_SPANNING_TREE:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    0    7    0    0
[1]   0    0    4    2    0    0    0    2
[2]   0    4    0    0    0    0    0    0
[3]   0    2    0    0    0    0    0    0
[4]   0    0    0    0    0    0    0    2
[5]   7    0    0    0    0    0    2    0
[6]   0    0    0    0    0    2    0    1
[7]   0    2    0    0    2    0    1    0
Success, matrices the same!

3.11. Euler

graph7.png

Added edge: 0 -> 4 (9/6)
Removed edge: 5 -> 6
ADJECENCY_MATRIX:
   [000][001][002][003][004][005][006][007]
[0]   0    0    0    0    1    1    0    0
[1]   0    0    1    1    0    0    1    1
[2]   0    0    0    0    1    0    0    0
[3]   0    0    0    0    0    1    0    0
[4]   0    0    0    0    0    1    0    1
[5]   0    0    0    0    0    0    0    1
[6]   0    0    0    0    0    0    0    1
[7]   0    0    0    0    0    0    0    0
EULER_CYCLE: 0 -> 5 -> 7 -> 6 -> 1 -> 7 -> 4 -> 5 -> 3 -> 1 -> 2 -> 4 -> 0

3.12. Hamilton

graph8.png

Added edge: 0 -> 2 (3/1)
CYCLES_TOTAL: 16
All cycles are saved here: hamiltonian-cycles.txt
Cycle with minimum weight (30): 0 -> 2 -> 4 -> 7 -> 6 -> 1 -> 3 -> 5 -> 0

4. Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to https://unlicense.org/

Footnotes:

1

Original text:

  1. Сформировать случайным образом связный ациклический граф в соответствии с заданным распределением (параметры распределения задаются как константы) с необходимым количеством вершин. Распределение лучше всего брать из справочника Вадзинского.
  2. Реализовать метод Шимбелла на полученном графе (пользователь вводит количество ребер).
  3. Определить возможность построения маршрута от одной заданной точки до другой (вершины вводит пользователь) и указывать количество таковых маршрутов.
2

Original text:

  1. Для заданных графов (случайно сгенерированных в предыдущей работе) необходимо сгенерировать весовую матрицу (положительную или с отрицательными весами – выбирает пользователь) и найти кратчайший путь для двух выбранных пользователем точек. Пользователь вводит номера вершин начальной и конечной. В результате выводится не только расстояние, но и сам путь в виде последовательности вершин. Для алгоритмов Дейкстры и Беллмана-Форда необходимо выводить вектор расстояний, для Флойда-Уоршалла – матрицу расстояний. Реализуемые алгоритмы:
    • классический алгоритм Дейкстры
    • алгоритм Флойда-Уоршалла
    • Нахождение максимального пути (для заданных пользователем вершин)
  2. Сравнить скорости работы данных алгоритмов (по количеству итераций).
3

Original text:

  1. Сформировать связный ациклический граф случайным образом в соответствии с заданным распределением. На его основе построить матрицы пропускных способностей и стоимости.
  2. Для полученного графа найти максимальный поток по алгоритму Форда-Фалкерсона (или любого из перечисленных в лекции).
  3. Вычислить поток минимальной стоимости (в качестве величины потока брать значение, равное ⅔max, где max – максимальный поток). Использовать ранее реализованные алгоритмы Дейкстры и/или Беллмана-Форда.
4

Original text:

  1. Для заданных графов (случайно сгенерированных в первой работе), используя матричную теорему Кирхгофа, найти число остовных деревьев в исходном графе.
  2. Построить минимальный по весу остов для сгенерированного взвешенного графа, используя алгоритмы: Прима и Борувки. Сравнить данные алгоритмы (по количеству итераций).
  3. Полученный остов закодировать с помощью кода Прюфера и декодировать его. Cохранять веса при кодировании обязательно.
5

Original text:

  1. Для заданных графов (случайно сгенерированных в первой работе) проверить, является ли граф эйлеровым и гамильтоновым.
  2. Проверить, является ли граф эйлеровым. Если нет, то модифицировать граф (показывать, что изменено). Построить эйлеров цикл.
  3. Проверить, является ли граф гамильтоновым. Если нет, то модифицировать граф (показывать, что изменено). Решить задачу коммивояжера на гамильтоновом графе (все гамильтоновы циклы с суммарным весом выводим либо на экран, если их мало, либо в файл). За реализованные эвристики отдельные бонусы (по умолчанию – полный перебор).

Created: 2026-11-07 Sat 07:19