-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.cpp
113 lines (90 loc) · 3.48 KB
/
Demo.cpp
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
#include "Graph.hpp"
#include "Algorithms.hpp"
using ariel::Algorithms;
//[email protected] 322695883
#include <iostream>
#include <stdexcept>
#include <vector>
using namespace std;
int main()
{
// First graphs with algoritems before operators
ariel::Graph g1;
vector<vector<int>> m1= {
{0, 3, 5},
{3, 0, 1},
{5, 1 ,0}};
g1.loadGraph(m1);
cout <<"before operator" << endl;
cout <<g1 <<endl;
cout << "connected? "<<Algorithms::isConnected(g1) << endl; // Yes he is connected
cout << "shortest path "<<Algorithms::shortestPath(g1, 0, 2) << endl; //shortest path is 4 (0->1->2)
cout << "isBipartite? "<<Algorithms::isBipartite(g1) << endl << endl; //And not Bipartite
//now we reduce every edge weight by 1
--g1;
cout <<"after operator (--graph)" << endl;
//and lest see the difference
cout <<g1 <<endl;
cout << "connected? "<<Algorithms::isConnected(g1) << endl; // still connected even after lose edge
cout <<"shortest path "<< Algorithms::shortestPath(g1, 0, 2) << endl; //shortest path is now 4 but different routh (0->2)
cout << "isBipartite? "<<Algorithms::isBipartite(g1) << endl<< endl; //Now we can divide the graph into 2 groups
ariel::Graph g2;
vector<vector<int>> m2 = {
{0, 1, 0, 4},
{1, 0, 1, 0},
{0, 1, 0, 1},
{4, 0, 1, 0}
};
g1.loadGraph(m2);
cout << "Before operator" << endl;
cout << g1 << endl;
cout << "shortest path "<< Algorithms::shortestPath(g1, 0, 3) << endl<< endl; // best path now will be go by detour and do 1+1+1=3<4 (the directly routh)
// Now let's add another graph with all weights of 10
ariel::Graph g3;
vector<vector<int>> m3 = {
{0, 10, 0, 10},
{10, 0, 10, 0},
{0, 10, 0, 10},
{10, 0, 10, 0}
};
g2.loadGraph(m3);
// Now add the graphs
g1 += g2;
cout << "After operator (add to this graph another graph with same edges but with weight 10)" << endl;
// Let's see the difference
cout << g1 << endl;
cout << "shortest path "<< Algorithms::shortestPath(g1, 0, 3) << endl<< endl; // after every edge got 10 weight more its better go directly (11+11+11>14)
ariel::Graph g4;
vector<vector<int>> m4 = {
{0, -2, -4, 0},
{-2, 0, -3, 0},
{-4, -3, 0, 0},
{0, 0, 0, 0 }
};
g4.loadGraph(m4);
cout <<"before operator" << endl;
cout <<g4 <<endl;
cout << "negative cycle? "<< Algorithms::negativeCycle(g4) << endl<< endl; //has negative cycle
//now multiply the edges by -5
ariel::Graph g5=g4*-5;
cout <<"after operators (first do graph*-5 than -graph)" << endl;
cout <<g5 <<endl;
cout << "negative cycle? "<<Algorithms::negativeCycle(g5)<< endl<< endl; // now doesn't has negative cycles
//now we do - operator to our graph
g5= -g5;
cout <<g5 <<endl;
cout << "negative cycle? "<<Algorithms::negativeCycle(g5)<< endl<< endl; // now has again
ariel::Graph g6;
vector<vector<int>> m6= {
{0, -1},
{-1, 0,},};
g6.loadGraph(m6);
cout <<"before operator" << endl;
cout <<g6 <<endl;
cout <<"connected? "<< Algorithms::isConnected(g6) << endl<< endl; // Yes he is connected
//now we add 1 to our graph edges
++g6;
cout <<"after operator (++graph)" << endl;
cout <<g6 <<endl;
cout <<"connected? "<< Algorithms::isConnected(g6) << endl<< endl; // Yes he is NOT connected
}