Let's remove an edge:
int main(void)
{
Graph g;
Gnode *n1 = g.addNode("Quinn");
Gnode *n2 = g.addNode("Qaitlin");
Gnode *n3 = g.addNode("Pauli");
g.addEdge(n2,n1,4.0);
g.addEdge(n1,n3,5.0);
g.addEdge(n3,n2,1.0);
g.addNode("Jim");
g.addNode("Clive");
g.addEdge(g.findNode("Qaitlin"),g.findNode("Jim"),6.0);
g.addEdge(g.findNode("Pauli"),g.findNode("Clive"),3.0);
g.addEdge(g.findNode("Pauli"),g.findNode("Jim"),4.5);
g.addEdge(g.findNode("Pauli"),g.findNode("Quinn"),3.5);
g.addEdge(g.findNode("Pauli"),g.findNode("Pauli"),14.5);
cout << g;
Gedge *T1 = g.findEdge(g.findNode("Qaitlin"),g.findNode("Jim"));
if(T1!=NULL){
g.removeEdge(T1);
cout << "removed edge Qaitlin to Jim" << g;
}
else{
cout << "Couldn't find edge" << endl;
}
return 0;
}
This generates the following output: first, the original graph:
Graph:
Nodes:
Clive Jim Pauli Qaitlin Quinn
Edges: Pauli-----(14.5)---> Pauli //first edge
Pauli-----(3.5)---> Quinn //second edge
Pauli-----(4.5)---> Jim //third edge
Pauli-----(3)---> Clive //fourth edge
Qaitlin-----(6)---> Jim //fifth edge
Pauli-----(1)---> Qaitlin //sixth edge
Quinn-----(5)---> Pauli //seventh edge
Qaitlin-----(4)---> Quinn //eigth edge
End Graph
Now remove the edge from Qaitlin to Jim:
In Graph removeEdge agent:
edge is 6 //the edge we want has value 6
//now step through graph level edge bag
visiting edge 14.5 //first edgeMan() evaluation
visiting edge 3.5 //second edgeMan() evaluation
visiting edge 4.5 //third edgeMan() evaluation
visiting edge 3 //fourth edgeMan() evaluation
visiting edge 6 //fifth edgeMan() evaluation
//this is a edge match
//call node level remove methods
In Gnode remove agent //remove the to node
In Gnode remove agent //remove the from node
//call edge manipulator remove method
In edgeMan.remove() //remove the edge from the bag
visiting edge 1 //sixth edgeMan() evaluation
visiting edge 5 //seventh edgeMan() evaluation
visiting edge 4 //eight edgeMan() evaluation
removed edge Qaitlin to JimGraph:
//output altered graph
Nodes:
Clive Jim Pauli Qaitlin Quinn
Edges: Pauli-----(14.5)---> Pauli
Pauli-----(3.5)---> Quinn
Pauli-----(4.5)---> Jim
Pauli-----(3)---> Clive
Pauli-----(1)---> Qaitlin
Quinn-----(5)---> Pauli
Qaitlin-----(4)---> Quinn
End Graph