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
|
struct find_neigbour {
const std::pair<int,int> label;
find_neigbour(const std::pair<int,int> label) : label(label) {}
bool operator()(const Edge& j) const {
return j.label == label;
}
};
void createGraph()
{
cout << "I was called, graph size: " << graph.size() << endl;
// Creating Each node
// By looking at each entry of the 2d arrat
//--------------------------------------------------------------//
for (int col = 0; col < getCol(); col++) {
for (int row = 0; row < getRow(); row++) {
if (!isspace(getChar(row,col)))
{
Edge edge;
edge.Element = getChar(row,col);
edge.label = make_pair(row,col);
//cout << edge.Element << " at: " << edge.label.first << edge.label.second << endl;
graph.push_back(edge);
//cout << edge.Element << endl;
//cout << graph.size() << endl;
}
}
}
cout << "I end with graph size: " << graph.size() << endl;
cout << endl;
//finding NeigbourNodes
//Looking at each node neigbour.
//-------------------------------------------------------//
for(auto it : graph)
{
double beforeCount = 0;
double nextCount = 0;
double upCount = 0;
double downCount = 0;
if (it.label.first > 0 && it.label.first < getRow())
{
//cout << "doing something" << endl;
auto before = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(it.label.first-1,it.label.second)));
auto next = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(it.label.first+1,it.label.second)));
if(before != graph.end() && !isspace(graph[before-graph.begin()].Element))
{
Arcs arc;
arc.me = ⁢
arc.neighbour = &graph[before - graph.begin()];
cout <<"before is: "<< arc.neighbour->Element << endl;
cout << "at: " << "(" << arc.neighbour->label.first << "," <<arc.neighbour->label.second<< ")" << endl;
cout << "now: " << "(" << arc.me->label.first << "," << arc.me->label.second << ")" << endl;
beforeCount++;
it.neighbours.push_back(arc);
}
if(next != graph.end()&& !isspace(graph[next-graph.begin()].Element))
{
Arcs arc;
arc.me = ⁢
arc.neighbour = &graph[next - graph.begin()];
cout <<"next is: "<< arc.neighbour->Element << endl;
cout << "at: " << "(" << arc.neighbour->label.first << "," <<arc.neighbour->label.second<< ")" << endl;
cout << "now: " << "(" << arc.me->label.first << "," << arc.me->label.second << ")" << endl;
nextCount++;
it.neighbours.push_back(arc);
cout << "-next arc - added" << endl;
cout <<"size: "<< it.neighbours.size() << endl;
}
}
if (it.label.second >= 0 && it.label.second <= getCol() )
{
auto down = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(it.label.first,it.label.second-1)));
auto up = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(it.label.first,it.label.second+1)));
if(up != graph.end()&& !isspace(graph[up-graph.begin()].Element))
{
Arcs arc;
arc.me = ⁢
arc.neighbour = &graph[up - graph.begin()];
cout <<"up is: "<< arc.neighbour->Element << endl;
cout << "at: " << "(" << arc.neighbour->label.first << "," <<arc.neighbour->label.second<< ")" << endl;
cout << "now: " << "(" << arc.me->label.first << "," << arc.me->label.second << ")" << endl;
upCount++;
it.neighbours.push_back(arc);
//cout << "up - arc - added" << endl;
}
if(down != graph.end() && !isspace(graph[down-graph.begin()].Element))
{
Arcs arc;
arc.me = ⁢
arc.neighbour = &graph[down - graph.begin()];
cout <<"down is: "<< arc.neighbour->Element << endl;
cout << "at: " << "(" << arc.neighbour->label.first << "," <<arc.neighbour->label.second<< ")" << endl;
cout << "now: " << "(" << arc.me->label.first << "," << arc.me->label.second << ")" << endl;
downCount++;
it.neighbours.push_back(arc);
//cout << " down - arc - added" << endl;
}
}
//down = 0;
//up = 0;
//before = 0;
//next = 0;
cout << "beforeCount: " << beforeCount << endl;
cout << "nextCount: " << nextCount << endl;
cout << "downCount: " << downCount << endl;
cout << "upCount: " << upCount << endl;
cout << "Size of neig: "<<it.neighbours.size() << endl;
cout << endl;
if(it.neighbours.size() == 0 )
{
cout << "______________________________________________Hey something is wrong here ___________________________________ " << endl;
cout <<"("<<it.label.first << "," << it.label.second << ")" << endl;
}
}
cout << "I know who is next to me " << endl;
cout << graph.begin()->Element << graph.begin()->neighbours.size() << graph.begin()->label.first << graph.begin()->label.second << endl;
}
|