-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.h
70 lines (52 loc) · 2.32 KB
/
Graph.h
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
#pragma once
#include <string>
#include "DynamicArray.h"
using Vertex = int;
using AdjList = DynamicArray<DynamicArray<Vertex>>;
//mandatory undirected graph
class Graph
{
///stores the edge-connection adjacency list.
AdjList adj_list_;
public:
Graph() = default;
Graph(AdjList other_adj_list);
Graph(int vertex_count);
int VertexCount() const;
int VertexDeg(Vertex vertex) const;
bool PushVertex(int count = 1);
bool PopVertex();
int EdgeCount() const;
Vertex* FindEdge(Vertex vertex1, Vertex vertex2);
bool HasEdge(Vertex vertex1, Vertex vertex2) const;
bool AddEdge(Vertex vertex1, Vertex vertex2);
bool RemoveEdge(Vertex vertex1, Vertex vertex2);
bool ClearEdges(Vertex vertex);
bool ClearEdges();
void ClearGraph();
void PrintGraph(int width = 3) const;
bool IsConnected(const DynamicArray<Vertex>& vertex_exclustion_list = DynamicArray<Vertex>{}) const;
bool IsKVertexConnected(int k) const;
bool IsSimpleGraph() const;
bool HasChord(const DynamicArray<Vertex>& cycle) const;
bool IsValidDirectionalCycle(const DynamicArray<Vertex>& cycle) const;
bool DoAllLargestCyclesHaveAChord() const;
bool DoAllLargestCyclesHaveAChordV2(); //WARNING: this method destroys a given graph. Use it on copies only to be safe
bool CheckThomassenConj() const;
bool CheckThomassenConjV2() const;
bool CheckThomassenConjV3() const;
bool CheckThomassenConjV4() const;
bool CheckThomassenConjV5() const;
bool CheckThomassenConjV6() const;
private:
static void DFS(const Graph& graph, DynamicArray<DynamicArray<Vertex>>& largest_cycles, DynamicArray<bool>& visited, DynamicArray<Vertex>& current_cycle, Vertex v);
static void DFSV2(Vertex par, Vertex curr, DynamicArray<int>& colors, DynamicArray<Vertex>& parents, int& cycle_num, const Graph& graph, DynamicArray<DynamicArray<Vertex>>& cycles);
public:
explicit operator std::string() const;
static const Graph K_4;
static DynamicArray<DynamicArray<Vertex>> AllPermutations(const int& num_choices);
static DynamicArray<DynamicArray<Vertex>> AllPermutations(const int& num_choices, const int& max_length);
static DynamicArray<DynamicArray<Vertex>> AllCombinations(const int& num_choices);
static DynamicArray<DynamicArray<Vertex>> AllCombinations(const int& num_choices, const int& max_length);
static std::string VertexListToString(const DynamicArray<Vertex>& vertex_list);
};