//加入连边 public bool AddEdge(IfCoreNode curNode, IfCoreNode tarNode, IfCoreEdge newEdge) { try { //连边的头指针指向起节点 newEdge.Start = curNode; //连边的尾指针指向目标节点 newEdge.End = tarNode; } catch (Exception e) {//如果连边和起始/目标节点类型不匹配则会报错 MessageBox.Show(e.Message, "警告", MessageBoxButtons.OK); return(false); } //将新连边加入起始节点的outbound if (curNode.AddEdge(newEdge) == false) { return(false); } //将新连边加入目标节点的Inbound if (tarNode.RegisterInbound(newEdge) == false) { return(false); } //全部完成后将连边加入网络连边列表 EdgeList.Add(newEdge); return(true); }
//移除连边 public bool RemoveEdge(IfCoreNode curNode, IfCoreNode tarNode) { IfCoreEdge curEdge = null; //从起始节点的出边中遍历 foreach (IfCoreEdge edge in curNode.OutBound) { //查找终止节点编号和目标节点编号一致的连边 if (edge.End.Number == tarNode.Number) { //找到则返回,本图数据库不支持两点间多连边 curEdge = edge; break; } } if (curEdge == null) {//没找到直接返回 return(false); } //起始节点Outbound中移除连边 curNode.RemoveEdge(curEdge); //从终止节点InBound中注销连边 tarNode.UnRegisterInbound(curEdge); //全部完成后,从总连边列表中移除该边 EdgeList.Remove(curEdge); return(true); }
//删除节点 public bool RemoveNode(IfCoreNode curNode) { //清除节点所有连边 ClearUnusedEdge(curNode.ClearEdge()); //从节点列表中移除节点 NodeList.Remove(curNode); return(true); }
//加入节点 public bool AddNode(IfCoreNode newNode) { //节点加入节点列表 NodeList.Add(newNode); return(true); }