public CRegion GenerateCrgChildAndComputeCost(CRegion lscrg, SortedDictionary <CCorrCphs, CCorrCphs> newAdjCorrCphsSD, CPatch activecph, CPatch passivecph, CPatch unitedcph, CCorrCphs unitingCorrCphs, double[,] padblTD) { var intactiveTypeIndex = this.GetCphTypeIndex(activecph); var intpassiveTypeIndex = this.GetCphTypeIndex(passivecph); var newCphTypeIndexSD = new SortedDictionary <CPatch, int>(this.CphTypeIndexSD_Area_CphGID, CPatch.pCmpCPatch_Area_CphGID); newCphTypeIndexSD.Remove(activecph); newCphTypeIndexSD.Remove(passivecph); newCphTypeIndexSD.Add(unitedcph, intactiveTypeIndex); //****if I update the codes below, then I should consider updating the codes in function GenerateCrgAndUpdateQ //for transfering information to outcrg //e.g., outcrg.newCph = newcrg.newCph; CRegion newcrg = new CRegion(this.ID); newcrg.dblArea = this.dblArea; newcrg.cenumColor = CEnumColor.gray; newcrg.parent = this; newcrg.AggCphs = new CValTri <CPatch, CPatch, CPatch>(activecph, passivecph, unitedcph); newcrg.AdjCorrCphsSD = newAdjCorrCphsSD; newcrg.CphTypeIndexSD_Area_CphGID = newCphTypeIndexSD; newcrg.intSumCphGID = this.intSumCphGID - activecph.GID - passivecph.GID + unitedcph.GID; newcrg.intSumTypeIndex = this.intSumTypeIndex - intpassiveTypeIndex; //newcrg.intEdgeCount = this.intEdgeCount - intDecreaseEdgeCount; newcrg.intInteriorEdgeCount = this.intInteriorEdgeCount - unitingCorrCphs.intSharedCEdgeCount; newcrg.intExteriorEdgeCount = this.intExteriorEdgeCount; newcrg.dblInteriorSegLength = this.dblInteriorSegLength - unitingCorrCphs.dblSharedSegLength; newcrg.dblExteriorSegLength = this.dblExteriorSegLength; if (CConstants.blnComputeMinComp == true) { ComputeMinCompIncremental(newcrg, this, activecph, passivecph, unitedcph); } else if (CConstants.blnComputeAvgComp == true) { newcrg.dblSumComp = this.dblSumComp - activecph.dblComp - passivecph.dblComp + unitedcph.dblComp; newcrg.dblAvgComp = newcrg.dblSumComp / newcrg.GetCphCount(); } double dblTypeCost = passivecph.dblArea * padblTD[intactiveTypeIndex, intpassiveTypeIndex]; ComputeExactCost(lscrg, newcrg, dblTypeCost); return(newcrg); }
public void ComputeExactCost(CRegion lscrg, CRegion NewCrg, double dblTypeCost) { var ParentCrg = NewCrg.parent; NewCrg.dblCostExactType = ParentCrg.dblCostExactType + dblTypeCost; var intTimeNum = lscrg.GetCphCount(); if (CConstants.strShapeConstraint == "MaximizeMinArea") { //NewCrg.dblCostExactArea = ParentCrg.dblCostExactArea + passivecph.dblArea //* ComputeCostArea(NewCrg.CphTypeIndexSD.Keys, NewCrg.dblArea); //NewCrg.dblCostExact = NewCrg.dblCostExactType + NewCrg.dblCostExactArea; } else if (CConstants.strShapeConstraint == "MaximizeAvgComp_EdgeNumber" || CConstants.strShapeConstraint == "MaximizeAvgComp_Combine") { //divide by intTimeNum - 2, because at each step the value for AvgComp can be 1 and //there are intotal intTimeNum - 2 steps; //only when intTimeNum - 1 > 0, we are in this function and run the following codes if (intTimeNum - NewCrg.GetCphCount() > 1) //we have exact cost from t=3 { NewCrg.dblCostExactComp = ParentCrg.dblCostExactComp + (1 - ParentCrg.dblAvgComp) / (intTimeNum - 2); } else { NewCrg.dblCostExactComp = 0; } NewCrg.dblCostExact = (1 - CAreaAgg_Base.dblLamda) * NewCrg.dblCostExactType + CAreaAgg_Base.dblLamda * NewCrg.dblArea * NewCrg.dblCostExactComp; } else if (CConstants.strShapeConstraint == "MaximizeMinComp_EdgeNumber" || CConstants.strShapeConstraint == "MaximizeMinComp_Combine") { //divide by intTimeNum - 2, because at each step the value for AvgComp can be 1 and //there are intotal intTimeNum - 2 steps; //only when intTimeNum - 1 > 0, we are in this function and run the following codes if (intTimeNum - NewCrg.GetCphCount() > 1) //we have exact cost from t=3 { NewCrg.dblCostExactComp = ParentCrg.dblCostExactComp + (1 - ParentCrg.dblMinComp) / (intTimeNum - 2); } else { NewCrg.dblCostExactComp = 0; } NewCrg.dblCostExact = (1 - CAreaAgg_Base.dblLamda) * NewCrg.dblCostExactType + CAreaAgg_Base.dblLamda * NewCrg.dblArea * NewCrg.dblCostExactComp; } else if (CConstants.strShapeConstraint == "MinimizeInteriorBoundaries") { //divide by intTimeNum - 2, because at each step the value for InteriorSegLength can be 1 and //there are intotal intTimeNum - 2 steps; //only when intTimeNum - 1 > 0, we are in this function and run the following codes if (intTimeNum - NewCrg.GetCphCount() > 1) //we have exact cost from t=3 { // lscrg.dblInteriorSegLength * NewCrg.GetCphCount() / (intTimeNum - 1) //is the expected interior length at time t-1 NewCrg.dblCostExactComp = ParentCrg.dblCostExactComp + ParentCrg.dblInteriorSegLength / (lscrg.dblInteriorSegLength * NewCrg.GetCphCount() / (intTimeNum - 1)) / (intTimeNum - 2); } else { NewCrg.dblCostExactComp = 0; } NewCrg.dblCostExact = (1 - CAreaAgg_Base.dblLamda) * NewCrg.dblCostExactType + CAreaAgg_Base.dblLamda * NewCrg.dblArea * NewCrg.dblCostExactComp; } else if (CConstants.strShapeConstraint == "NonShape") { NewCrg.dblCostExact = NewCrg.dblCostExactType; } }
public CRegion GenerateCrgChildAndComputeExactCost(CRegion lscrg, SortedDictionary <CCorrCphs, CCorrCphs> newAdjCorrCphsSD, CPatch activecph, CPatch passivecph, CPatch unitedcph, CCorrCphs unitingCorrCphs, double[,] padblTD) { var intactiveTypeIndex = this.GetCphTypeIndex(activecph); var intpassiveTypeIndex = this.GetCphTypeIndex(passivecph); var corecpg = this.GetCoreCpg(activecph); var newCphCpgSD = new SortedDictionary <CPatch, CPolygon>(this.CphCpgSD_Area_CphGID, CPatch.pCmpCPatch_Area_CphGID); if (newCphCpgSD.Remove(activecph) == false || newCphCpgSD.Remove(passivecph) == false) { throw new ArgumentOutOfRangeException("This should be impossible!"); } newCphCpgSD.Add(unitedcph, corecpg); //var passivecpg = this.GetCoreCpg(passivecph); //if (lscrg.GetCphCount() - this.GetCphCount() == 4) //{ // if ((corecpg.ID == 5058 && passivecpg.ID == 5060) || (corecpg.ID == 5060 && passivecpg.ID == 5058)) // { // Console.WriteLine(passivecpg.ID + " " + passivecpg.intTypeIndex + " " + passivecph.dblArea); // Console.WriteLine(corecpg.ID + " " + corecpg.intTypeIndex + " " + activecph.dblArea); // Console.WriteLine(); // } //} //if (lscrg.GetCphCount() - this.GetCphCount() == 5) //{ // if ((corecpg.ID == 5060 && passivecpg.ID == 5061)) // { // Console.WriteLine(passivecpg.ID + " " + passivecpg.intTypeIndex + " " + passivecph.dblArea); // Console.WriteLine(corecpg.ID + " " + corecpg.intTypeIndex + " " + activecph.dblArea); // Console.WriteLine(); // } //} //var intLSCphCount = lscrg.GetCphCount(); //var intThisCphCount = this.GetCphCount(); //if (CRegion._intStaticGID == 1698) //{ // foreach (var cpg in this.CphCpgSD_Area_CphGID.Values) // { // Console.WriteLine(cpg.ID); // } // int ss = 5; //} //****if I update the codes below, then I should consider updating the codes in function GenerateCrgAndUpdateQ //for transfering information to outcrg //e.g., outcrg.newCph = newcrg.newCph; var newcrg = new CRegion(this.ID) { dblArea = this.dblArea, cenumColor = CEnumColor.gray, parent = this, AggCphs = new CValTri <CPatch, CPatch, CPatch>(activecph, passivecph, unitedcph), AdjCorrCphsSD = newAdjCorrCphsSD, CphCpgSD_Area_CphGID = newCphCpgSD, intSumCphGID = this.intSumCphGID - activecph.GID - passivecph.GID + unitedcph.GID, intSumTypeIndex = this.intSumTypeIndex - intpassiveTypeIndex, intInteriorEdgeCount = this.intInteriorEdgeCount - unitingCorrCphs.intSharedCEdgeCount, intExteriorEdgeCount = this.intExteriorEdgeCount, dblInteriorSegLength = this.dblInteriorSegLength - unitingCorrCphs.dblSharedSegLength, dblExteriorSegLength = this.dblExteriorSegLength //intEdgeCount = this.intEdgeCount - intDecreaseEdgeCount }; //if (newcrg.GID == 1698) //{ // Console.WriteLine("face id of region 1698:"); // foreach (var cpg in newcrg.CphCpgSD_Area_CphGID.Values) // { // Console.WriteLine(cpg.ID); // } // int ss = 5; //} if (CConstants.blnComputeMinComp == true) { ComputeMinCompIncremental(newcrg, this, activecph, passivecph, unitedcph); } else if (CConstants.blnComputeAvgComp == true) { newcrg.dblSumComp = this.dblSumComp - activecph.dblComp - passivecph.dblComp + unitedcph.dblComp; newcrg.dblAvgComp = newcrg.dblSumComp / newcrg.GetCphCount(); } double dblTypeCost = passivecph.dblArea * padblTD[intactiveTypeIndex, intpassiveTypeIndex]; ComputeExactCost(lscrg, newcrg, dblTypeCost); return(newcrg); }