aboutsummaryrefslogtreecommitdiff
path: root/src/graph.h
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 /src/graph.h
downloadlab-01-05-master.tar.gz
publishHEADmaster
Diffstat (limited to 'src/graph.h')
-rw-r--r--src/graph.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/graph.h b/src/graph.h
new file mode 100644
index 0000000..f55e975
--- /dev/null
+++ b/src/graph.h
@@ -0,0 +1,71 @@
1#ifndef INCLUDED_GRAPH_H
2#define INCLUDED_GRAPH_H
3
4#include <stdlib.h>
5#include <stdbool.h>
6#include <gsl/gsl_matrix.h>
7#include <raylib.h>
8#include "distribution.h"
9
10enum graph_type {
11 GRAPH_TYPE_NONE,
12 GRAPH_TYPE_POSITIVE = 1 << 0,
13 GRAPH_TYPE_NEGATIVE = 1 << 1,
14 GRAPH_TYPE_POSITIVE_NEGATIVE = GRAPH_TYPE_POSITIVE | GRAPH_TYPE_NEGATIVE,
15};
16
17struct edge {
18 size_t from;
19 size_t to;
20};
21
22struct edges {
23 struct edge *items;
24 size_t count;
25 size_t capacity;
26};
27
28typedef struct graph {
29 enum graph_type type;
30 size_t vertex_count;
31 gsl_matrix *adjecency_matrix;
32 gsl_matrix *weight_matrix;
33 gsl_matrix *capacity_matrix;
34 size_t *highlighted_path;
35 struct edges highlighted_edges;
36} *GRAPH;
37
38void generate_graph (GRAPH, DISTRIBUTION,
39 size_t vertex_count, enum graph_type);
40void graph_unhighlight (GRAPH g);
41void graph_edge_set (GRAPH, size_t from, size_t to,
42 double weight, double capacity);
43void print_graph (GRAPH);
44void highlight_graph (GRAPH, const gsl_matrix *);
45
46// lab 1
47gsl_matrix *shimbell_method (GRAPH, size_t edge_count, bool max);
48size_t graph_count_routes (GRAPH, size_t from, size_t to);
49
50// lab 2
51size_t *dijkstra_positive (GRAPH, size_t from, size_t to, bool max);
52size_t *floyd_warshall (GRAPH, size_t from, size_t to, bool max);
53
54// lab 3
55double max_flow_ford_fulkerson (GRAPH, size_t from, size_t to);
56double min_cost_flow (GRAPH, size_t from, size_t to, double required_flow);
57
58// lab 4
59size_t count_spanning_trees (GRAPH);
60gsl_matrix *min_weight_spannig_tree_prim (GRAPH);
61gsl_matrix *min_weight_spannig_tree_boruvka (GRAPH);
62void prufer_code (gsl_matrix *);
63
64// lab 5
65bool is_graph_eulerian (GRAPH);
66bool is_graph_hamiltonian (GRAPH);
67void graph_ensure_eulerian (GRAPH);
68void graph_ensure_hamiltonian (GRAPH);
69void find_hamiltonian_cycles (GRAPH);
70
71#endif