/// <summary> /// 一阶邻接边长均值(子图) /// </summary> /// <param name="tinNode"></param> /// <param name="globalEdge"></param> /// <returns></returns> private double Local1Mean(ITinNode tinNode, List <ITinEdge> globalEdge) { ITinEdgeArray incdentEdges = tinNode.GetIncidentEdges(); double a = 0; int incdentEdgeCount = incdentEdges.Count; int dataIncdentEdgeCount = incdentEdgeCount; for (int i = 0; i < incdentEdgeCount; i++) { if (IsInEdges(incdentEdges.get_Element(i), globalEdge)) { a = a + incdentEdges.get_Element(i).Length; } else { dataIncdentEdgeCount--; } } if (dataIncdentEdgeCount <= 0) { return(0); } return(a / (double)dataIncdentEdgeCount); }
/// <summary> /// 得到局部聚类的EdgeList /// </summary> /// <param name="subGraph"></param> /// <returns></returns> private List <ITinEdge> GetLocalEdgeList(ASCDTSubGraph subGraph) { List <ITinEdge> localEdge = new List <ITinEdge>(); double mean1StDev = Mean1StDev(subGraph); for (int i = 0; i < subGraph.GetNodeList().Count; i++) { ITinNode localNode = subGraph.GetNodeList()[i]; double local2Mean = Local2Mean(localNode, subGraph); double localConstraint = local2Mean + mean1StDev; ITinEdgeArray incidentEdges = localNode.GetIncidentEdges(); for (int j = 0; j < incidentEdges.Count; j++) { ITinEdge currenEdge = incidentEdges.get_Element(j); if (IsInEdges(currenEdge, subGraph.GetEdgeList()) && currenEdge.Length < localConstraint) { localEdge.Add(currenEdge); } } } //去掉多加的neighbor边 localEdge = CompleteEdges(localEdge); return(localEdge); }
/// <summary> /// 获得全局聚类的EdgeList /// </summary> /// <returns></returns> private List <ITinEdge> GetGlobalEdgeList() { List <ITinEdge> globalEdge = new List <ITinEdge>(); ITinAdvanced tinAdvanced = m_DT as ITinAdvanced; double globalMean = GlobalMean(m_DT); double globalStDev = GlobalStDev(m_DT, globalMean); int nodeCount = tinAdvanced.NodeCount; for (int i = 1; i <= nodeCount; i++) { ITinNode tinNode = tinAdvanced.GetNode(i); double local1Mean = Local1Mean(tinNode); double globalConstraint = globalMean * (1 + globalStDev / local1Mean); ITinEdgeArray incdentEdges = tinNode.GetIncidentEdges(); int incdentEdgeCount = incdentEdges.Count; for (int j = 0; j < incdentEdgeCount; j++) { ITinEdge currentEdge = incdentEdges.get_Element(j); if (currentEdge.Length < globalConstraint && currentEdge.IsInsideDataArea) { globalEdge.Add(currentEdge); } } } //去掉多加的neighbor边 globalEdge = CompleteEdges(globalEdge); return(globalEdge); }
/// <summary> /// 得到二阶邻接边 /// </summary> /// <param name="currentNode"></param> /// <param name="subGraph"></param> /// <returns></returns> private List <ITinEdge> Get2IncidentEdges(ITinNode currentNode, ASCDTSubGraph subGraph) { List <ITinEdge> incidentEdges = new List <ITinEdge>(); List <ITinEdge> subGraphEdge = subGraph.GetEdgeList(); List <ITinNode> subGraphNode = subGraph.GetNodeList(); //加入一阶邻接边 ITinEdgeArray incEdges = currentNode.GetIncidentEdges(); for (int j = 0; j < incEdges.Count; j++) { if (IsInEdges(incEdges.get_Element(j), subGraphEdge)) { incidentEdges.Add(incEdges.get_Element(j)); } } //查找相邻点,加入二阶邻接边 ITinNodeArray adjNodes = currentNode.GetAdjacentNodes(); for (int j = 0; j < adjNodes.Count; j++) { if (!IsInNodes(adjNodes.get_Element(j), subGraphNode)) { continue; } ITinEdgeArray inc2Edges = adjNodes.get_Element(j).GetIncidentEdges(); for (int k = 0; k < inc2Edges.Count; k++) { ITinEdge edge = inc2Edges.get_Element(k); if (IsInEdges(edge, incidentEdges)) { continue; } if (IsInEdges(edge, subGraphEdge)) { incidentEdges.Add(edge); } } } return(incidentEdges); }
private ASCDTSubGraph ExpandSubGraph(ITinNode currentNode, List <ITinEdge> globalEdge, ASCDTSubGraph newSubGraph) { m_nodeFlag[currentNode.Index - 1] = 1; newSubGraph.AddNode(currentNode); ITinEdgeArray incidentEdges = currentNode.GetIncidentEdges(); for (int i = 0; i < incidentEdges.Count; i++) { ITinEdge currentEdge = incidentEdges.get_Element(i); if (IsInEdges(currentEdge, globalEdge)) { newSubGraph.AddEdge(currentEdge); ITinNode nextNode = currentEdge.ToNode; if (m_nodeFlag[nextNode.Index - 1] == 0) { ExpandSubGraph(nextNode, globalEdge, newSubGraph); } } } return(newSubGraph); }