// adds a node to the graph public void AddNode(GraphNode node) { Nodes.Add(node); if (node.NodeType == GraphNode.Type.Type2) { ModelsSet.Add(node); } if (node.NodeType == GraphNode.Type.Type1) { VariablesSet.Add(node); } }
// adds a node to the graph public void AddNode(string value, GraphNode.Type type) //for bipartite graph { var t = new GraphNode(value, type); Nodes.Add(t); if (type == GraphNode.Type.Type2) { ModelsSet.Add(t); } if (type == GraphNode.Type.Type1) { VariablesSet.Add(t); } }
public bool Remove(string value) { // first remove the node from the nodeset var nodeToRemove = (GraphNode)Nodes.FindByValue(value); if (nodeToRemove == null) { // node wasn't found return(false); } // otherwise, the node was found Nodes.Remove(nodeToRemove); //removing the node from the node of the graph if (nodeToRemove.NodeType == GraphNode.Type.Type2) //removing the same node from modeSet if its type is 'model' { ModelsSet.Remove(nodeToRemove); } if (nodeToRemove.NodeType == GraphNode.Type.Type1)//removing hte same node from varSet if its type is 'variable' { VariablesSet.Remove(nodeToRemove); } // enumerate through each node in the nodeSet, removing edges to this node foreach (GraphNode gnode in Nodes) {//not deleting properly the edges while deleting the node... index is not found properly 27-12-2016...check edge deletion works or not if (gnode.Neighbors.Remove(nodeToRemove)) { Edges.Remove(Edges.FindByNodes(gnode, nodeToRemove)); //YHB: nodeToRemove is 'toNode' in the edge whereas 'fromNode' is a node(here gnode) in whos neighbors contains nodeToRemove } if (nodeToRemove.Neighbors.Contains(gnode)) { Edges.Remove(Edges.FindByNodes(nodeToRemove, gnode)); //added on 27-12-2016 } } return(true); }