-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.h
80 lines (59 loc) · 2.53 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
70
71
72
73
74
75
76
77
78
79
80
#ifndef SEMESTER_PROJECT_GRAPH_H
#define SEMESTER_PROJECT_GRAPH_H
#include <bits/stdc++.h>
#include <utility>
using namespace std;
// Node class representing individual nodes in the graph
class Node
{
public:
string id;
int nodeWeight;
bool addedToCluster;
vector<pair<string, long long int>> neighbors;
explicit Node(string _id, int _nodeWeight = 0, bool _addedToCluster = false) : id(std::move(_id)), nodeWeight(_nodeWeight), addedToCluster(_addedToCluster) {}
};
// Graph class representing the entire graph structure
class Graph
{
public:
unordered_map<string, Node> nodes;
// Function to add a node to the graph
void addNode(const string &nodeId);
// Function to add an edge between two nodes in the graph
void addEdge(const string &sourceId, const string &targetId, double weight);
// Function to initialize a sample graph
void initializeSampleGraph(const string &);
// Function for finding degree of a node
unsigned long long int findDegree(const string &nodeId);
// Function to find common neighbors between two nodes
vector<string> findCommonNeighbors(const string &sourceId, const string &targetId);
// Function to find common neighbors of each node
void findCommonNeighborOfEach();
// Function to get max degree of the graph
pair<string, unsigned long long int> getMaxDegree();
// Function that will take the density to make the clusters;
bool AllAreAdded();
bool isPresent(unordered_map<string, Node> currCluster, Node currNode);
double calculateDensity(unordered_map<string, Node> currCluster);
double calculateDensity(unordered_map<string, Node> currCluster, Node nextNode);
double NumOfEdgesBtNodeAndCluster(unordered_map<string, Node> currCluster, Node nextNode);
double calculate_cp(unordered_map<string, Node> currCluster, Node nextNode);
void MakeClusters(double t_density, double t_cp);
void makeCluster(Node &startingNode, double t_density, double t_cp, unordered_map<string, Node> &currCluster);
// Function to get max weight of the graph
pair<string, long long> getMaxWeight();
// Function to find node weight
void findNodeWeightOfEach();
// density
double findDensity(int numberOfEdges, int numberOfNodes);
void displayNodeWeights();
void makeCluster();
// Function to display the graph
void displayGraph();
void displayClusters();
vector<unordered_map<string, Node>> GetClusters();
private:
vector<unordered_map<string, Node>> clusters;
};
#endif // SEMESTER_PROJECT_GRAPH_H