-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.hpp
158 lines (147 loc) · 5.49 KB
/
graph.hpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef GRAPH_H
#define GRAPH_H
#include <vector>
#include <iostream>
//[email protected] 322695883
// create ariel name space
namespace ariel {
class Graph {
private:
// the graph will be neighbor matrix
std::vector<std::vector<int>> neighborMatrix;
public:
//constructor and distractor
Graph();
~Graph();
/**
* First make sure that the matrix is square and than put her to the graph
* @param matrix the given matrix
*/
void loadGraph(const std::vector<std::vector<int>>& matrix);
/**
* print the graph as matrix of neighbors
*/
void printGraph() const;
/**
*
* @return the Neighbor matrix
*/
const std::vector<std::vector<int>>& getNeigborMatrix() const;
//*******************EX2**********************
/**
* Helper method that checks if 2 matrix's are the same size
* @param matrix1 first matrix to compare
* @param matrix2 second matrix to compare
* @return if same size return true else return false
*/
bool sizeCheck(const std::vector<std::vector<int>>& matrix1, const std::vector<std::vector<int>>& matrix2) const;
/**
* This method adds two graphs together
* @param graph2 the graph to be added
* @return The resulting graph (graph3) after addition
*/
Graph operator+(const Graph& graph2) const;
/**
* This method add to original graph, graph2
* @param graph2 the graph to be added
*/
void operator+=(const Graph& graph2);
/**
* This method will do unary plus to the graph
*/
Graph operator+() const;
/**
* This method subtract two graphs
* @param graph2 the graph to be subtracted
* @return The resulting graph (graph3) after subtraction
*/
Graph operator-(const Graph& graph2) const;
/**
* This method subtract the original graph with graph2
* @param graph2 the graph that subtract original graph
*/
void operator-=(const Graph& graph2);
/**
* This method will do unary minus to the graph
*/
Graph operator-() const;
/**
* This method compares 2 graphs and check if they in same size and have the same weighs on their edges
* @param graph2 the second graph we compare
* @return true if they are equals and false if not
*/
bool operator==(const Graph& graph2) const;
/**
* This method compares 2 graphs and check if they in same size and have the same weighs on their edges
* @param graph2 the second graph we compare
* @return true if they are NOT equals and false if they are equals
*/
bool operator!=(const Graph& graph2) const;
/**
* Helper method that check if every edge in the graph is also in graph2
* @param graph1 first matrix to compare
* @param graph2 second matrix to compare
* @return true if g1 contains g2
*/
bool contains(const Graph& graph1, const Graph& graph2) const;
/**
* Helper method that sum number of the graph edges
* @param graph the given graph
* @return number of edges
*/
size_t getNumEdges(const Graph& graph) const;
/**
* This method check if graph is greater than graph2
* @param graph2 second graph
* @return true if the graph is greater than graph2
*/
bool operator>(const Graph& graph2) const;
/**
* This method check if graph is greater or equal than graph2
* @param graph2 second graph
* @return true if the graph is greater or equal than graph2
*/
bool operator>=(const Graph& graph2) const;
/**
* This method check if graph2 is greater than original graph
* @param graph2 second graph
* @return true if the graph2 is greater than original graph
*/
bool operator<(const Graph& graph2) const;
/**
* This method check if graph2 is greater or equal than original graph
* @param graph2 second graph
* @return true if the graph2 is greater or equal than original graph
*/
bool operator<=(const Graph& graph2) const;
/**
* This method will add 1 to all graph edges (only if the edge exist)
*/
void operator++();
/**
* This method will subtract 1 to all graph edges (only if the edge exist)
*/
void operator--();
/**
* This method will multiply all edges by given scalar
* @param scalar the given scalar
* @return multipleied graph by the scalar
*/
Graph operator*(int scalar) const;
/**
*This method will multiply 2 matrix's
* @param graph2 given graph to multiply with
* @return result graph of multiplication matrix
*/
Graph operator*(const Graph& graph2) const;
/**
* This method will print the graph as neighbor matrix
* if there isn't an edge it will show 0 else shows the weigth of the edge
* @param os The output stream
* @param graph The graph to be printed
*/
friend std::ostream& operator<<(std::ostream& os, const Graph& graph);
};
std::ostream& operator<<(std::ostream& os, const Graph& graph);
}
#endif // GRAPH_H