-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.h
More file actions
116 lines (90 loc) · 3.96 KB
/
graph.h
File metadata and controls
116 lines (90 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
graph.h
Visible structs and functions for graph construction and manipulation.
Skeleton written by Grady Fitzpatrick for COMP20007 Assignment 1 2021 and
modified for Assignment 2 2021
*/
#include "pq.h"
/* Definition of a graph. */
struct graph;
enum problemPart;
struct solution;
/* A particular solution to a graph problem. */
#ifndef SOLUTION_STRUCT
#define SOLUTION_STRUCT
struct solution {
int connectedSubnets;
int largestSubnet;
int *largestSubnetSIDs;
int postOutageDiameter;
int postOutageDiameterCount;
int *postOutageDiameterSIDs;
int criticalServerCount;
int *criticalServerSIDs;
};
#endif
/* Which part the program should find a solution for. */
#ifndef PART_ENUM
#define PART_ENUM
enum problemPart {
TASK_2=0,
TASK_3=1,
TASK_4=2,
TASK_7=3
};
#endif
/* Creates an undirected graph with the given numVertices and no edges and
returns a pointer to it. NumEdges is the number of expected edges. */
struct graph *newGraph(int numVertices);
/* Adds an edge to the given graph. */
void addEdge(struct graph *g, int start, int end);
/* Finds:
- Number of connected subnetworks (before outage) (Task 2)
- Number of servers in largest subnetwork (before outage) (Task 3)
- SIDs of servers in largest subnetwork (before outage) (Task 3)
- Diameter of largest subnetworks (after outage) (Task 4)
- Number of servers in path with largest diameter - should be one more than
Diameter if a path exists (after outage) (Task 4)
- SIDs in largest subnetwork (after outage) (Task 4)
- Number of critical servers (before outage) (Task 7)
- SIDs of critical servers (before outage) (Task 7)
*/
struct solution *graphSolve(struct graph *g, enum problemPart part,
int numServers, int numOutages, int *outages);
/* Frees all memory used by graph. */
void freeGraph(struct graph *g);
/* Sets all values to initial values so free can work for all tasks without
change. */
void initaliseSolution(struct solution *solution);
/* Frees all data used by solution. */
void freeSolution(struct solution *solution);
/* finds the number of connected subnetworks by doing DFS traversal of graph */
void getConnectedSubnets(struct graph *g, int v, int visited[], int nvisited);
/* finds the number of servers is the largest subnetwork */
int getLargestSubnet(struct graph *g, int v, int visited[], int n);
/* helper function for task 3. finds the servers in the largest subnetwork */
void getservers(struct graph *g, int tempserver, int visited[]);
/* comparison function for inbuilt qsort */
int cmpfunc (const void * a, const void * b);
/* checks whether "vertex" has been affected by the outage */
int isOut(int vertex, int outageSIDs[], int numoutages);
/* implementation of dijkstra's algorithm to find the shortest path */
void dijkstras(struct graph *g, int start, int dist[], int prev[],
int n, int outageSIDs[], int numoutages);
/* helper function for dijkstra's. updates cost for adjacent nodes */
void updatecosts(struct graph *g, struct pq *priq, int u, int dist[],
int prev[], int outageSIDs[], int numoutages);
/* helper function for task 4. finds the local maximum shortest path length */
void getLocalMax(int dist[], int prev[], int *max, int *end, int n);
/* helper function for task 4. finds the global maximum shortest path length */
void getMax(int *start, int *end, int *maxpath, int tempmax, int prev[],
int finalprev[], int numServers, int tempend, int i);
/* helper function for task 4. finds the servers in the longest shortest path */
void populateServers(int servers[], int finalprev[], int startserver,
int endserver, int n);
/* does DFS traversal on the graph to find the push orders and highest reachable ancestors for all nodes */
void getOrderAndHRA(struct graph *g, int iscritical[], int u, int visited[], int order[], int hra[], int parent[], int numservers, int *count, int *crticalcount) ;
/* finds the minimum of the two integers provided */
int min(int a, int b);
/* finds the adjacent node of server "v" */
int isAdjacent(struct graph *g, int i, int v);