//add Element to the dummy Cluster public void AddElement2defaultCluster(Element t) { Cluster tempcluster = (Cluster)clusterList[0]; tempcluster.Add(t); elementList.Add(t); t.ElementID = elementList.IndexOf(t) + 1; }
public void Add(Element t) {//向cluster增加元素 t.setClusterID(ID); if (First == null) { First = t; } else { First.Before = t; t.After = First; First = t; } NumberLinks += num; num++; }
private double Move_Vari_ValueCalculator(Element t0, Cluster sA)//should confirm AddVal[t0,s0]&AddVal[t0,sA] updated!! { Cluster s0 = getClusterbyID(t0.ClusterID); if (s0.ID == sA.ID) { return 0; } double NewFullValA = (Sum_Value[sA.ID] + AddVal[t0.ElementID, sA.ID]) / (sA.NumberLinks + sA.num); double NewFullVal0 = (Sum_Value[s0.ID] - AddVal[t0.ElementID, s0.ID]) / (s0.NumberLinks - s0.num + 1); double new_Vari_s0 = 0; Element ele1, ele2; double temval; #region MoveVariValue Changed in S0 ele1 = s0.First; while (ele1 != null) { if (ele1 != t0) { ele2 = ele1.After; while (ele2 != null) { if (ele2 != t0) { temval = CalculateScore(ele1, ele2); new_Vari_s0 += (temval - NewFullVal0) * (temval - NewFullVal0); } ele2 = ele2.After; } } ele1 = ele1.After; } #endregion #region MoveVariValue Changed in SA double new_Vari_SA = 0; ele1 = sA.First; while (ele1 != null) { ele2 = ele1.After; while (ele2 != null) { temval = CalculateScore(ele1, ele2); new_Vari_SA += (temval - NewFullValA) * (temval - NewFullValA); ele2 = ele2.After; } temval = CalculateScore(ele1, t0); new_Vari_SA += (temval - NewFullValA) * (temval - NewFullValA); ele1 = ele1.After; } #endregion new_Vari_s0 = new_Vari_s0 / (s0.NumberLinks - s0.num + 1); new_Vari_SA = new_Vari_SA / (sA.NumberLinks + sA.num); return new_Vari_s0 + new_Vari_SA - Vari_Value[s0.ID] - Vari_Value[sA.ID]; }
private double MoveValueCalculator(Element t0, Cluster sA) { double valueSA = Calculator(sA); double _valueSA = valueSA + AddValueCalculator(t0, sA); int numlinkSA = sA.num * (sA.num - 1) / 2; int _numlinkSA = numlinkSA + sA.num; double DelFullA = _valueSA / _numlinkSA - valueSA / numlinkSA; Cluster s0 = getClusterbyID(t0.ClusterID); double valueS0 = Calculator(s0); double _valueS0 = valueS0 - AddValueCalculator(t0, s0); int numlinkS0 = s0.num * (s0.num - 1) / 2; int _numlinkS0 = numlinkS0 - s0.num + 1; double DelFullD = _valueS0 / _numlinkS0 - valueS0 / numlinkS0; return DelFullA + DelFullD; }
private double AddValueCalculator(Element t0, Cluster s0) { Element t = s0.First; double tempval = 0; while (t != null) { tempval += CalculateScore(t0, t); t = t.After; } return tempval; }
public double CalculateScore(Element t1, Element t2)//坐标距离计算 当前版本不需要计算,直接从Score中取值 { //double score = 0; //if (t1 == t2) //{ // return 0; //} //if (t1 == null || t2 == null) //{ // return double.MaxValue; //} //for (int i = 0; i < t1.AttributesX.Count; i++) //{ // double tempscore = Convert.ToDouble(t1.AttributesX[i]) - Convert.ToDouble(t2.AttributesX[i]); // if (tempscore < 0) // { // tempscore = 0 - tempscore; // } // score += tempscore*tempscore; //} //int X = t1.ElementID; //int Y = t2.ElementID; //score = Score[X, Y]; //if (score > 0) //{ //return score; //} //else //{ // return -score; //} return Score[t1.ElementID, t2.ElementID]; }