aboutsummaryrefslogtreecommitdiff
path: root/README.org
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-07 03:20:46 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-07 04:21:37 +0000
commit556fea05affe6fe8866557d42b6c1ef6559d7880 (patch)
treef8de5473f16e65fcbe10f280b4cf54ee7e32b5b7 /README.org
downloadlab-01-05-556fea05affe6fe8866557d42b6c1ef6559d7880.tar.gz
publishHEADmaster
Diffstat (limited to 'README.org')
-rw-r--r--README.org422
1 files changed, 422 insertions, 0 deletions
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..59ddc53
--- /dev/null
+++ b/README.org
@@ -0,0 +1,422 @@
1#+title: Interactive graph visualizer and laboratory suite
2
3* Tasks
4** Random DAG generation and shimbel path metrics[fn:1]
51. Generate a randomly connected acyclic graph according to a given
6 distribution (distribution parameters set as constants) with the
7 required number of vertices. The distribution is best taken from
8 the Wadzinski handbook.
92. Implement the Shimbell method on the resulting graph (the user
10 enters number of edges).
113. Determine the possibility of building a route from one specified
12 point to another one (the vertex is entered by the user) and find
13 the number of such routes.
14
15** Shortest paths and algorithm performance comparison[fn:2]
161. For the given graphs (randomly generated in the previous task) it
17 is necessary to generate a weight matrix (positive or with negative
18 weights -- the user chooses) and find the shortest path for two
19 points selected by the user. The user enters the numbers of the
20 starting and ending vertices. As a result, not only the distance
21 is displayed, but also the path itself in the form of a sequence of
22 vertices. For Dijkstra’s and Bellman‑Ford’s algorithms, it is
23 necessary output the distance vector, for Floyd-Warshall -- the
24 matrix distances. Implemented algorithms:
25 - *classic Dijkstra algorithm*
26 - *the Floyd-Warshall algorithm*
27 - *Finding the maximum path* (for user-defined vertices)
282. Compare the speeds of these algorithms (by number of iterations).
29
30** Maximum flow and minimum-cost network flows[fn:3]
311. Form a connected acyclic graph randomly in according to the
32 specified distribution. Based on it, build throughput and cost
33 matrices.
342. For the resulting graph, find the maximum flow using the algorithm
35 Ford-Fulkerson (or any of those listed in the lecture).
363. Calculate the minimum cost flow (as the flow value take a value
37 equal to ⅔max, where max is the maximum flow). Use previously
38 implemented Dijkstra and/or Bellman-Ford algorithms.
39
40** Spanning trees, matrix-tree theorem, and Prüfer codes[fn:4]
411. For the given graphs (randomly generated in the first task), using
42 Kirchhoff’s matrix theorem, find the number of spanning trees in
43 the original graph.
442. Construct a minimum‑weight spanning tree for the generated weighted
45 graph using the *Prim* and *Boruvka* algorithms. Compare The given
46 algorithms (by the number of iterations).
473. Encode the resulting skeleton using the Prüfer code and decode it.
48 his. It is essential to maintain the weights during encoding.
49
50** Eulerian, Hamiltonian, and traveling salesman problems[fn:5]
511. For the given graphs (randomly generated in the first task), check
52 whether the graph is Eulerian and Hamiltonian.
532. Check whether the graph is Eulerian. If not, modify the graph
54 (show what was changed). Construct an Eulerian cycle.
553. Check whether the graph is Hamiltonian. If not, modify the graph
56 (show what was changed). Solve the problem. The traveling
57 salesman problem on a Hamiltonian graph (we output all Hamiltonian
58 cycles with a total weight either to the screen if there are few of
59 them, or to a file). There are separate bonuses for implemented
60 heuristics (by default, a complete search).
61
62* Documentation
63The exported report can be found at [[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/report.pdf][this link]].
64
65* Showcase
66** Distribution of the random number generator
67#+attr_html: :width 500em
68[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/distribution-my.png]]
69
70** Creation of graph with 8 vertices
71#+attr_html: :width 800em
72[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph1.png]]
73#+begin_example
74ADJECENCY_MATRIX:
75 [00][01][02][03][04][05][06][07]
76[0] 0 0 0 0 0 1 0 0
77[1] 0 0 1 1 0 0 1 1
78[2] 0 0 0 0 1 0 0 0
79[3] 0 0 0 0 0 1 0 0
80[4] 0 0 0 0 0 1 0 1
81[5] 0 0 0 0 0 0 1 1
82[6] 0 0 0 0 0 0 0 1
83[7] 0 0 0 0 0 0 0 0
84
85WEIGHT/COST_MATRIX:
86 [00][01][02][03][04][05][06][07]
87[0] 0 0 0 0 0 7 0 0
88[1] 0 0 4 2 0 0 8 2
89[2] 0 0 0 0 5 0 0 0
90[3] 0 0 0 0 0 4 0 0
91[4] 0 0 0 0 0 7 0 2
92[5] 0 0 0 0 0 0 2 5
93[6] 0 0 0 0 0 0 0 1
94[7] 0 0 0 0 0 0 0 0
95
96CAPACITY_MATRIX:
97 [00][01][02][03][04][05][06][07]
98[0] 0 0 0 0 0 3 0 0
99[1] 0 0 4 1 0 0 1 6
100[2] 0 0 0 0 7 0 0 0
101[3] 0 0 0 0 0 6 0 0
102[4] 0 0 0 0 0 9 0 8
103[5] 0 0 0 0 0 0 6 5
104[6] 0 0 0 0 0 0 0 1
105[7] 0 0 0 0 0 0 0 0
106#+end_example
107
108** Shimbell method
109#+begin_example
110SHIMBELL METHOD EDGE COUNT: 2
111MIN PATH MATRIX:
112 [000][001][002][003][004][005][006][007]
113[0] inf inf inf inf inf inf inf 10
114[1] inf inf inf inf inf 16 8 11
115[2] inf inf inf inf inf inf 14 17
116[3] inf inf inf inf inf inf inf 7
117[4] inf inf inf inf inf inf inf 10
118[5] inf inf inf inf inf inf inf inf
119[6] inf inf inf inf inf inf inf inf
120[7] inf inf inf inf inf inf inf inf
121#+end_example
122
123** Route count
124#+begin_example
125FROM: 0
126TO: 7
127ROUTE COUNT FROM 0 TO 7: 2
128
129FROM: 2
130TO: 7
131ROUTE COUNT FROM 2 TO 7: 3
132
133FROM: 5
134TO: 0
135NO ROUTES FROM 5 TO 0
136#+end_example
137
138** Dijkstra's algorithm
139#+attr_html: :width 500em
140[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph2.png]]
141#+begin_example
142MIN
143FROM: 2
144TO: 7
145DISTANCEVECTOR: (inf inf inf 0 inf 5 12 14 7)
146PATH: 2 -> 4 -> 7
147
148FROM: 0
149TO: 7
150DISTANCE VECTOR: (0 0 inf inf inf inf 7 9 10)
151PATH: 0 -> 5 -> 6 -> 7
152
153FROM: 2
154TO: 0
155DISTANCE VECTOR: (inf inf inf 0 inf 5 12 14 7)
156NO PATH FROM 2 TO 0
157
158#+end_example
159
160** The Floyd-Warshall algorithm
161#+attr_html: :width 500em
162[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph3-1.png]]
163#+attr_html: :width 800em
164[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph3-2.png]]
165#+begin_example
166MAX
167FROM: 2
168TO: 7
169DISTANCE MATRIX:
170 [0] [1] [2] [3] [4] [5] [6] [7]
171[0] 0-inf-inf-inf-inf 7 9 12
172[1]-inf 0 4 2 9 16 18 21
173[2]-inf-inf 0-inf 5 12 14 17
174[3]-inf-inf-inf 0-inf 4 6 9
175[4]-inf-inf-inf-inf 0 7 9 12
176[5]-inf-inf-inf-inf-inf 0 2 5
177[6]-inf-inf-inf-inf-inf-inf 0 1
178[7]-inf-inf-inf-inf-inf-inf-inf 0
179PATH: 2 -> 4 -> 5 -> 7
180#+end_example
181
182** The Ford–Fulkerson algorithm
183#+attr_html: :width 500em
184[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph4.png]]
185#+begin_example
186FROM: 2
187TO: 7
188MAX_FLOW: 7
189
190FROM: 4
191TO: 7
192MAX_FLOW: 14
193#+end_example
194
195** Calculation of the minimum cost flow
196#+attr_html: :width 500em
197[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph5.png]]
198#+begin_example
199FROM: 4
200TO: 7
201REQUIRED_FLOW: [14*2/3] = 9
202FLOW_MATRIX:
203 [000][001][002][003][004][005][006][007]
204[0] 0 0 0 0 0 0 0 0
205[1] 0 0 0 0 0 0 0 0
206[2] 0 0 0 0 0 0 0 0
207[3] 0 0 0 0 0 0 0 0
208[4] 0 0 0 0 0 1 0 8
209[5] 0 0 0 0 0 0 1 0
210[6] 0 0 0 0 0 0 0 1
211[7] 0 0 0 0 0 0 0 0
212MIN_COST: 26
213#+end_example
214
215** Determining the number of possible spanning trees
216#+begin_example
217KIRCHHOFF_MATRIX:
218 [000][001][002][003][004][005][006][007]
219[0] 1 0 0 0 0 -1 0 0
220[1] 0 4 -1 -1 0 0 -1 -1
221[2] 0 -1 2 0 -1 0 0 0
222[3] 0 -1 0 2 0 -1 0 0
223[4] 0 0 -1 0 3 -1 0 -1
224[5] -1 0 0 -1 -1 5 -1 -1
225[6] 0 -1 0 0 0 -1 3 -1
226[7] 0 -1 0 0 -1 -1 -1 4
227SPANNING TREE COUNT 181
228#+end_example
229
230** Prim, Borovka, and Prufer codes
231#+attr_html: :width 500em
232[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph6.png]]
233#+begin_example
234PRIM
235MINIMUM_SPANNING_TREE_WEIGHTS:
236 [000][001][002][003][004][005][006][007]
237[0] 0 0 0 0 0 7 0 0
238[1] 0 0 4 2 0 0 0 2
239[2] 0 4 0 0 0 0 0 0
240[3] 0 2 0 0 0 0 0 0
241[4] 0 0 0 0 0 0 0 2
242[5] 7 0 0 0 0 0 2 0
243[6] 0 0 0 0 0 2 0 1
244[7] 0 2 0 0 2 0 1 0
245TOTAL_WEIGHT: 20
246ITERATION_COUNT: 448
247MINIMAL_SPANNING_TREE:
248 [000][001][002][003][004][005][006][007]
249[0] 0 0 0 0 0 7 0 0
250[1] 0 0 4 2 0 0 0 2
251[2] 0 4 0 0 0 0 0 0
252[3] 0 2 0 0 0 0 0 0
253[4] 0 0 0 0 0 0 0 2
254[5] 7 0 0 0 0 0 2 0
255[6] 0 0 0 0 0 2 0 1
256[7] 0 2 0 0 2 0 1 0
257PRUFER_CODE: 5 1 1 7 7 6 7
258SAVED_WEIGHTS: 7 4 2 2 2 2 1
259DECODED_MINIMAL_SPANNING_TREE:
260 [000][001][002][003][004][005][006][007]
261[0] 0 0 0 0 0 7 0 0
262[1] 0 0 4 2 0 0 0 2
263[2] 0 4 0 0 0 0 0 0
264[3] 0 2 0 0 0 0 0 0
265[4] 0 0 0 0 0 0 0 2
266[5] 7 0 0 0 0 0 2 0
267[6] 0 0 0 0 0 2 0 1
268[7] 0 2 0 0 2 0 1 0
269Success, matrices the same!
270#+end_example
271
272#+begin_example
273BORUVKA
274MINIMUM_SPANNING_TREE_WEIGHTS:
275 [000][001][002][003][004][005][006][007]
276[0] 0 0 0 0 0 7 0 0
277[1] 0 0 4 2 0 0 0 2
278[2] 0 4 0 0 0 0 0 0
279[3] 0 2 0 0 0 0 0 0
280[4] 0 0 0 0 0 0 0 2
281[5] 7 0 0 0 0 0 2 0
282[6] 0 0 0 0 0 2 0 1
283[7] 0 2 0 0 2 0 1 0
284TOTAL_WEIGHT: 20
285ITERATION_COUNT: 44
286MINIMAL_SPANNING_TREE:
287 [000][001][002][003][004][005][006][007]
288[0] 0 0 0 0 0 7 0 0
289[1] 0 0 4 2 0 0 0 2
290[2] 0 4 0 0 0 0 0 0
291[3] 0 2 0 0 0 0 0 0
292[4] 0 0 0 0 0 0 0 2
293[5] 7 0 0 0 0 0 2 0
294[6] 0 0 0 0 0 2 0 1
295[7] 0 2 0 0 2 0 1 0
296PRUFER_CODE: 5 1 1 7 7 6 7
297SAVED_WEIGHTS: 7 4 2 2 2 2 1
298DECODED_MINIMAL_SPANNING_TREE:
299 [000][001][002][003][004][005][006][007]
300[0] 0 0 0 0 0 7 0 0
301[1] 0 0 4 2 0 0 0 2
302[2] 0 4 0 0 0 0 0 0
303[3] 0 2 0 0 0 0 0 0
304[4] 0 0 0 0 0 0 0 2
305[5] 7 0 0 0 0 0 2 0
306[6] 0 0 0 0 0 2 0 1
307[7] 0 2 0 0 2 0 1 0
308Success, matrices the same!
309#+end_example
310
311** Euler
312#+attr_html: :width 500em
313[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph7.png]]
314#+begin_example
315Added edge: 0 -> 4 (9/6)
316Removed edge: 5 -> 6
317ADJECENCY_MATRIX:
318 [000][001][002][003][004][005][006][007]
319[0] 0 0 0 0 1 1 0 0
320[1] 0 0 1 1 0 0 1 1
321[2] 0 0 0 0 1 0 0 0
322[3] 0 0 0 0 0 1 0 0
323[4] 0 0 0 0 0 1 0 1
324[5] 0 0 0 0 0 0 0 1
325[6] 0 0 0 0 0 0 0 1
326[7] 0 0 0 0 0 0 0 0
327EULER_CYCLE: 0 -> 5 -> 7 -> 6 -> 1 -> 7 -> 4 -> 5 -> 3 -> 1 -> 2 -> 4 -> 0
328#+end_example
329
330** Hamilton
331#+attr_html: :width 500em
332[[https://git.michalec.dev/uni/term-04/graph-theory/lab-01-05/graph8.png]]
333#+begin_example
334Added edge: 0 -> 2 (3/1)
335CYCLES_TOTAL: 16
336All cycles are saved here: hamiltonian-cycles.txt
337Cycle with minimum weight (30): 0 -> 2 -> 4 -> 7 -> 6 -> 1 -> 3 -> 5 -> 0
338#+end_example
339
340* Unlicense
341#+include: UNLICENSE verse
342
343* Footnotes
344[fn:1] Original text:
345#+HTML: <i>
346#+begin_quote
3471. Сформировать случайным образом связный ациклический граф в
348 соответствии с заданным распределением (параметры распределения
349 задаются как константы) с необходимым количеством вершин.
350 Распределение лучше всего брать из справочника Вадзинского.
3512. Реализовать метод Шимбелла на полученном графе (пользователь вводит
352 количество ребер).
3533. Определить возможность построения маршрута от одной заданной точки
354 до другой (вершины вводит пользователь) и указывать количество
355 таковых маршрутов.
356#+end_quote
357#+HTML: </i>
358
359[fn:2] Original text:
360#+HTML: <i>
361#+begin_quote
3621. Для заданных графов (случайно сгенерированных в предыдущей работе)
363 необходимо сгенерировать весовую матрицу (положительную или с
364 отрицательными весами -- выбирает пользователь) и найти кратчайший
365 путь для двух выбранных пользователем точек. Пользователь вводит
366 номера вершин начальной и конечной. В результате выводится не
367 только расстояние, но и сам путь в виде последовательности
368 вершин. Для алгоритмов Дейкстры и Беллмана-Форда необходимо
369 выводить вектор расстояний, для Флойда-Уоршалла -- матрицу
370 расстояний. Реализуемые алгоритмы:
371 - *классический алгоритм Дейкстры*
372 - *алгоритм Флойда-Уоршалла*
373 - *Нахождение максимального пути* (для заданных пользователем вершин)
3742. Сравнить скорости работы данных алгоритмов (по количеству
375 итераций).
376#+end_quote
377#+HTML: </i>
378
379[fn:3] Original text:
380#+HTML: <i>
381#+begin_quote
3821. Сформировать связный ациклический граф случайным образом в
383 соответствии с заданным распределением. На его основе построить
384 матрицы пропускных способностей и стоимости.
3852. Для полученного графа найти максимальный поток по алгоритму
386 Форда-Фалкерсона (или любого из перечисленных в лекции).
3873. Вычислить поток минимальной стоимости (в качестве величины потока
388 брать значение, равное ⅔max, где max -- максимальный поток).
389 Использовать ранее реализованные алгоритмы Дейкстры и/или
390 Беллмана-Форда.
391#+end_quote
392#+HTML: </i>
393
394[fn:4] Original text:
395#+HTML: <i>
396#+begin_quote
3971. Для заданных графов (случайно сгенерированных в первой работе),
398 используя матричную теорему Кирхгофа, найти число остовных деревьев
399 в исходном графе.
4002. Построить минимальный по весу остов для сгенерированного
401 взвешенного графа, используя алгоритмы: *Прима* и *Борувки*. Сравнить
402 данные алгоритмы (по количеству итераций).
4033. Полученный остов закодировать с помощью кода Прюфера и декодировать
404 его. Cохранять веса при кодировании обязательно.
405#+end_quote
406#+HTML: </i>
407
408[fn:5] Original text:
409#+HTML: <i>
410#+begin_quote
4111. Для заданных графов (случайно сгенерированных в первой работе)
412 проверить, является ли граф эйлеровым и гамильтоновым.
4132. Проверить, является ли граф эйлеровым. Если нет, то модифицировать
414 граф (показывать, что изменено). Построить эйлеров цикл.
4153. Проверить, является ли граф гамильтоновым. Если нет, то
416 модифицировать граф (показывать, что изменено). Решить задачу
417 коммивояжера на гамильтоновом графе (все гамильтоновы циклы с
418 суммарным весом выводим либо на экран, если их мало, либо в файл).
419 За реализованные эвристики отдельные бонусы (по умолчанию -- полный
420 перебор).
421#+end_quote
422#+HTML: </i>