Beispiel #1
0
        /// <summary>
        /// compute cost during generating a new Crg
        /// </summary>
        /// <param name="newAdjCorrCphsSD"></param>
        /// <param name="activecph"></param>
        /// <param name="passivecph"></param>
        /// <param name="unitedcph"></param>
        /// <param name="intFinalTypeIndex"></param>
        /// <param name="padblTD"></param>
        /// <returns></returns>
        public CRegion GenerateCrgAndUpdateQ(CRegion crg, CRegion lscrg, CRegion sscrg, SortedSet <CRegion> Q,
                                             List <SortedDictionary <CRegion, CRegion> > ExistingCrgSDLt, SortedDictionary <CCorrCphs, CCorrCphs> newAdjCorrCphsSD,
                                             CPatch activecph, CPatch passivecph, CPatch unitedcph, CCorrCphs unitingCorrCphs,
                                             double[,] padblTD, int intEstSteps)
        {
            int intactiveTypeIndex  = crg.GetCphTypeIndex(activecph);
            int intpassiveTypeIndex = crg.GetCphTypeIndex(passivecph);

            var newcrg = crg.GenerateCrgChildAndComputeCost(lscrg, newAdjCorrCphsSD,
                                                            activecph, passivecph, unitedcph, unitingCorrCphs, padblTD);

            //var intGIDLt = new List<int>();
            //var intTypeLt = new List<int>();
            //if (newcrg.intSumCphGID == 32961 && newcrg.intSumTypeIndex == 91)
            //{

            //    foreach (var cph in newcrg.GetCphCol())
            //    {
            //        intGIDLt.Add(cph.GID);
            //    }


            //    foreach (var inttype in newcrg.GetCphTypeIndexCol())
            //    {
            //        intTypeLt.Add(inttype);
            //    }

            //    foreach (var item in Q)
            //    {
            //        if (item.intSumCphGID == 65794 && item.intSumTypeIndex == 172)
            //        {
            //            int ss = 5;
            //        }
            //    }
            //}
            //if (CRegion._intStaticGID == 2008)
            //{
            //    int kes = 8;
            //}

            CRegion outcrg;

            if (ExistingCrgSDLt[newcrg.GetCphCount()].TryGetValue(newcrg, out outcrg))
            {
                int intResult = newcrg.dblCostExact.CompareTo(outcrg.dblCostExact);
                //int intResult = CCmpMethods.CmpDbl_CoordVerySmall(newcrg.dblCostExact, outcrg.dblCostExact);


                if (intResult == -1)
                {
                    //from the idea of A* algorithm, we know that outcrg must be in Q
                    //var Q = new SortedSet<CRegion>(CRegion.pCmpCrg_Cost_CphGIDTypeIndex);
                    //there is no decrease key function for SortedSet, so we have to remove it and later add it again
                    if (Q.Remove(outcrg) == true)
                    {
                        //we don't use newcrg dicrectly because some regions may use ourcrg as their child
                        outcrg.cenumColor       = newcrg.cenumColor;
                        outcrg.dblCostExactType = newcrg.dblCostExactType;
                        outcrg.dblCostExactComp = newcrg.dblCostExactComp;
                        outcrg.dblCostExactArea = newcrg.dblCostExactArea;
                        outcrg.dblCostExact     = newcrg.dblCostExact;
                        outcrg.d = newcrg.dblCostExact + outcrg.dblCostEst;

                        outcrg.AggCphs = newcrg.AggCphs;
                        outcrg.parent  = newcrg.parent;
                        newcrg         = outcrg;

                        //var cphcount = newcrg.GetCphCount();
                        //var dblCostExactType = newcrg.dblCostExactType;
                        //var dblCostEstType = newcrg.dblCostEstType;
                        //var dblCostExactComp = newcrg.dblCostExactComp * newcrg.dblArea;
                        //var dblCostEstComp = newcrg.dblCostEstComp * newcrg.dblArea;

                        //if ((newcrg.GetCphCount() == 3 || newcrg.GetCphCount() == 4)
                        //    && newcrg.dblCostEstType == 0 && newcrg.dblCostEstComp == 0)
                        //{
                        //    int sst = 9;
                        //}

                        //var dblCostExactArea = newcrg.dblCostExactArea;
                        //var dblCostExact = newcrg.dblCostExact;
                        //var d = newcrg.dblCostExact + newcrg.dblCostEst;
                        //Console.WriteLine("  GID: " + newcrg.GID + "    CphCount: " + cphcount +
                        //    "    EstType: " + dblCostEstType + "    EstComp: " + dblCostEstComp +
                        //    "    EstSum: " + newcrg.dblCostEst);


                        Q.Add(newcrg);
                    }
                    else
                    {
                        if (intEstSteps == 0)
                        {
                            throw new ArgumentException("outcrg should be removed! you might be overestimating!");
                        }
                        else
                        {
                            // if intEstSteps != 0, we are overestimating,
                            // outcrg may have been removed from queue Q as the node with least cost
                        }
                    }
                }
                else
                {
                    //we don't need to do operation Q.Add(newcrg);
                }
            }
            else
            {
                ComputeEstCost(lscrg, sscrg, newcrg, padblTD, intEstSteps);


                //var cphcount = newcrg.GetCphCount();
                //var dblCostExactType = newcrg.dblCostExactType;
                //var dblCostEstType = newcrg.dblCostEstType;
                //var dblCostExactComp = newcrg.dblCostExactComp * newcrg.dblArea;
                //var dblCostEstComp = newcrg.dblCostEstComp * newcrg.dblArea;

                //if ((newcrg.GetCphCount() == 3 || newcrg.GetCphCount() == 4)
                //    && newcrg.dblCostEstType == 0 && newcrg.dblCostEstComp == 0)
                //{
                //    int sst = 9;
                //}

                //var dblCostExactArea = newcrg.dblCostExactArea;
                //var dblCostExact = newcrg.dblCostExact;
                //var d = newcrg.dblCostExact + newcrg.dblCostEst;
                //Console.WriteLine("  GID: " + newcrg.GID + "    CphCount: " + cphcount +
                //    "    EstType: " + dblCostEstType + "    EstComp: " + dblCostEstComp +
                //    "    EstSum: " + newcrg.dblCostEst);


                Q.Add(newcrg);
                ExistingCrgSDLt[newcrg.GetCphCount()].Add(newcrg, newcrg);
                CRegion._intNodeCount++;
            }
            CRegion._intEdgeCount++;



            //the returned newcrg is just for counting, and thus not important
            return(newcrg);
        }