Esempio n. 1
0
    public static string AgregarRegion(string Region)
    {
        CObjeto Respuesta = new CObjeto();

        CUnit.Firmado(delegate(CDB Conn)
        {
            string Error = Conn.Mensaje;
            if (Conn.Conectado)
            {
                CObjeto Datos = new CObjeto();

                CRegion cRegion = new CRegion();
                cRegion.Region  = Region;
                cRegion.Baja    = false;
                Error           = ValidarRegion(cRegion);
                if (Error == "")
                {
                    cRegion.Agregar(Conn);
                }

                Respuesta.Add("Datos", Datos);
            }
            Respuesta.Add("Error", Error);
        });

        return(Respuesta.ToString());
    }
Esempio n. 2
0
        /// <summary>
        /// from time t to n-1
        /// </summary>
        /// <param name="crg"></param>
        /// <returns></returns>
        private IEnumerable <double> EstimateMinComp_EdgeNumber(CRegion crg, CRegion lscrg)
        {
            var intEdgeCountSS = new SortedSet <int>(new CIntCompare());

            foreach (var pCorrCphs in crg.AdjCorrCphsSD.Keys)
            {
                intEdgeCountSS.Add(pCorrCphs.intSharedCEdgeCount);
            }

            IEnumerator <int> intEdgeCountSSEt = intEdgeCountSS.GetEnumerator();
            int intEdgeCountAtmost             = crg.intExteriorEdgeCount + 2 * crg.intInteriorEdgeCount;
            int intEstCount = crg.GetCphCount();

            while (intEstCount > 1)
            {
                intEdgeCountSSEt.MoveNext();

                //if intEstCount == lscrg.GetCphCount(), we are estimating from the start map (t==1)
                //we define that the estimation value of the start map is 0, therefore we skip intEstCount == lscrg.GetCphCount()
                if (intEstCount < lscrg.GetCphCount())
                {
                    int intAverageEdgeCount = Convert.ToInt32(
                        Math.Floor(Convert.ToDouble(intEdgeCountAtmost) / Convert.ToDouble(intEstCount)));
                    yield return(CGeoFunc.CalCompRegularPolygon(intAverageEdgeCount));
                }

                intEdgeCountAtmost -= (2 * intEdgeCountSSEt.Current);
                intEstCount--;
            }
        }
        public IEnumerable <CRegion> AggregateSmallestAndUpdateQ(CRegion crg, CRegion lscrg, CRegion sscrg, SortedSet <CRegion> Q,
                                                                 List <SortedDictionary <CRegion, CRegion> > ExistingCrgSDLt, List <SortedDictionary <CPatch, CPatch> > ExistingCphSDLt,
                                                                 SortedDictionary <CCorrCphs, CCorrCphs> ExistingCorrCphsSD, double[,] padblTD, int intEstSteps)
        {
            var pAdjCorrCphsSD = crg.AdjCorrCphsSD;
            var mincph         = crg.GetSmallestCph();

            var pCphRecords = crg.GetNeighborCphRecords(mincph).ToList();

            if (pCphRecords.Count == 0)
            {
                CSaveFeature.SaveCpgEb(mincph.CpgSS, "PolygonsOfMincph");
                throw new ArgumentNullException("There is no neighbor of mincph!");
            }

            //for every pair of neighboring Cphs, we aggregate them and generate a new Crg
            foreach (var pCphRecord in pCphRecords)
            {
                foreach (var item in AggregateAndUpdateQ_Common(crg, lscrg, sscrg, Q, pAdjCorrCphsSD, pCphRecord.CorrCphs,
                                                                ExistingCrgSDLt, ExistingCphSDLt, ExistingCorrCphsSD, padblTD, intEstSteps))
                {
                    yield return(item);
                }
            }
        }
Esempio n. 4
0
    public static string DesactivarRegion(int IdRegion, int Baja)
    {
        CObjeto Respuesta = new CObjeto();

        CUnit.Firmado(delegate(CDB Conn)
        {
            string Error = Conn.Mensaje;
            if (Conn.Conectado)
            {
                bool desactivar = false;
                if (Baja == 0)
                {
                    desactivar = true;
                }
                else
                {
                    desactivar = false;
                }
                CObjeto Datos = new CObjeto();

                CRegion cRegion  = new CRegion();
                cRegion.IdRegion = IdRegion;
                cRegion.Baja     = desactivar;
                cRegion.Desactivar(Conn);

                Respuesta.Add("Datos", Datos);
            }
            Respuesta.Add("Error", Error);
        });

        return(Respuesta.ToString());
    }
Esempio n. 5
0
        private void init_combo()
        {
            CRegion region;

            try
            {
                comboBoxRegion.Items.Clear();

                region = new CRegion(connect);

                List <STRegion> list_r = region.GetListRegion();

                string text = null;

                foreach (STRegion item in list_r)
                {
                    comboBoxRegion.Items.Add(item.name);

                    if (item.name == "Минск")
                    {
                        text = "Минск";
                    }
                }

                if (text != null)
                {
                    comboBoxRegion.Text = text;
                }
                ;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
        }
Esempio n. 6
0
        public static int CmpCrg_CphGIDTypeIndex(CRegion crg1, CRegion crg2)
        {
            int intResult = crg1.GetCphCount().CompareTo(crg2.GetCphCount());

            if (intResult == 0)
            {
                intResult = crg1.intSumCphGID.CompareTo(crg2.intSumCphGID);
            }

            if (intResult == 0)
            {
                intResult = crg1.intSumTypeIndex.CompareTo(crg2.intSumTypeIndex);
            }

            if (intResult == 0)
            {
                //this will compare the GID of every CPatch in the two SortedDictionary
                intResult = CCmpMethods.CmpWithSameElements(crg1.GetCphCol(), crg2.GetCphCol(), cph => cph);
            }

            if (intResult == 0)
            {
                intResult = CCmpMethods.CmpWithSameElements(crg1.GetCphTypeIndexCol(), crg2.GetCphTypeIndexCol(),
                                                            intTypeIndex => intTypeIndex);
            }
            return(intResult);
        }
Esempio n. 7
0
        private double BalancedEstCompInteriorLength_Basic(CRegion crg, CRegion lscrg, int intEstSteps)
        {
            // if lscrg.GetCphCount() <= 2, the domain only have two polygons
            // A value will be divided by (lscrg.GetCphCount() - 2). To avoid being divided by 0, we directly return 0.
            if (lscrg.GetCphCount() <= 2 || crg.GetCphCount() <= 1)
            {
                return(0);
            }

            int intOverestimationCount = Math.Min(intEstSteps, crg.GetCphCount() - 2);

            var    EstimateLt = EstimateInteriorLength(crg, lscrg);
            double dblSum     = crg.dblInteriorSegLength / (crg.GetCphCount() - 1); //n-s= crg.GetCphCount()-1

            for (int i = 0; i < intOverestimationCount; i++)
            {
                dblSum += crg.dblInteriorSegLength / (crg.GetCphCount() - (i + 2));  //overestimation; n-s= crg.GetCphCount()-(i+2)
            }
            for (int i = 0; i < EstimateLt.Count - intOverestimationCount; i++)
            {
                dblSum += (EstimateLt[i] / (i + 1));  //normal estimation; n-s = i+1= crg.GetCphCount()-1
            }

            double dblEstComp = dblSum / (lscrg.dblInteriorSegLength / (lscrg.GetCphCount() - 1)) / (lscrg.GetCphCount() - 2);

            if (dblEstComp == 0)
            {
                throw new ArgumentException("impossible!");
            }

            return(dblEstComp);
        }
Esempio n. 8
0
        /// <summary>
        /// currently doesn't work
        /// </summary>
        /// <param name="crg"></param>
        /// <param name="intTimeNum"></param>
        /// <returns></returns>
        /// <remarks>we need to improve this estimation to make sure this is an upper bound.
        /// We don't need to compute one step further because the estimation based on edge number will "never" be 0</remarks>
        ///
        private double BalancedEstMinComp_Combine(CRegion crg, CRegion lscrg, CRegion sscrg)
        {
            if (crg.GetCphCount() == 1)
            {
                return(0);
            }

            var EstEdgeNumberEt = EstimateMinComp_EdgeNumber(crg, lscrg).GetEnumerator();
            //we need to improve this estimation to make sure this is an upper bound
            var EstEdgeLengthEt = EstimateMinComp_EdgeLength(crg, lscrg).GetEnumerator();

            double dblSumCompValue = 0;

            while (EstEdgeNumberEt.MoveNext() && EstEdgeLengthEt.MoveNext())
            {
                if (EstEdgeNumberEt.Current < EstEdgeLengthEt.Current)
                {
                    CRegion._lngEstCountEdgeNumber++;
                }
                else if (EstEdgeNumberEt.Current > EstEdgeLengthEt.Current)
                {
                    CRegion._lngEstCountEdgeLength++;
                }
                else
                {
                    CRegion._lngEstCountEqual++;
                }

                dblSumCompValue += (1 - Math.Min(EstEdgeNumberEt.Current, EstEdgeLengthEt.Current));
            }

            return(dblSumCompValue / (lscrg.GetCphCount() - 1));
        }
Esempio n. 9
0
        private void DlgRegions_Load(object sender, EventArgs e)
        {
            this.Text = caption;

            clRegion = new CRegion(connect);

            textBoxName.Focus();
        }
Esempio n. 10
0
        //public void InitialEstimatedCost(CRegion sscrg, double[,] padblTD, int intEstSteps)
        //{
        //    this.dblCostEstType = 0;
        //    foreach (var kvp in this.CphTypeIndexSD_Area_CphGID)
        //    {
        //        //there is only one element in targetCrg
        //        this.dblCostEstType += kvp.Key.dblArea * padblTD[kvp.Value, sscrg.GetSoloCphTypeIndex()];
        //    }
        //    this.dblCostEstType = intEstSteps * this.dblCostEstType;

        //    if (CConstants.strShapeConstraint == "MaximizeMinArea")
        //    {
        //        //this.dblCostEstArea = intEstSteps * EstimateSumMinArea(this);
        //        //this.dblCostEst += this.dblCostEstArea;
        //    }
        //    else if (CConstants.strShapeConstraint == "MaximizeAvgComp_EdgeNumber")
        //    {
        //        this.dblCostEstComp = intEstSteps * BalancedEstAvgComp_EdgeNumber(this, this, sscrg);
        //    }
        //    else if (CConstants.strShapeConstraint == "MaximizeMinComp_Combine")
        //    {
        //        this.dblCostEstComp = intEstSteps * BalancedEstMinComp_Combine(this, this, sscrg);
        //    }
        //    else if (CConstants.strShapeConstraint == "MaximizeMinComp_EdgeNumber")
        //    {
        //        this.dblCostEstComp = intEstSteps * BalancedEstMinComp_EdgeNumber(this, this, sscrg);
        //    }
        //    else if (CConstants.strShapeConstraint == "MinimizeInteriorBoundaries")
        //    {
        //        this.dblCostEstComp = intEstSteps * BalancedEstCompInteriorLength_Basic(this, this);
        //    }

        //    this.dblCostEst = (1 - CAreaAgg_Base.dblLamda) * this.dblCostEstType +
        //        CAreaAgg_Base.dblLamda * this.dblArea * this.dblCostEstComp;

        //    this.d = this.dblCostEst;
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="activecph"></param>
        /// <param name="passivecph"></param>
        /// <param name="unitedcph"></param>
        /// <param name="SSCph"></param>
        /// <param name="NewCrg"></param>
        /// <param name="padblTD"></param>
        /// <remarks>if we change the cost method, then we will also need to
        /// change the codes of InitialSubCostEstimated in CRegion.cs, the codes of updating existing outcrg </remarks>
        public void ComputeEstCost(CRegion lscrg, CRegion sscrg, CRegion NewCrg, double[,] padblTD, int intEstSteps)
        {
            NewCrg.dblCostEstType = BalancedEstType(NewCrg, sscrg.GetSoloCphTypeIndex(), padblTD, intEstSteps);

            if (CConstants.strShapeConstraint == "MaximizeMinArea")
            {
                //NewCrg.dblCostEstArea = intEstSteps*EstimateSumMinArea(NewCrg);  //will we do this twice????

                //NewCrg.dblCostEst = NewCrg.dblCostEstType + NewCrg.dblCostEstArea;
            }
            else if (CConstants.strShapeConstraint == "MaximizeAvgComp_EdgeNumber")
            {
                NewCrg.dblCostEstComp = BalancedEstAvgComp_EdgeNumber(NewCrg, lscrg, sscrg, intEstSteps);

                //to make dblCostEstComp comparable to dblCostEstType and to avoid digital problems, we time dblCostEstComp by area
                //we will adjust the value later
                NewCrg.dblCostEst = (1 - CAreaAgg_Base.dblLamda) * NewCrg.dblCostEstType +
                                    CAreaAgg_Base.dblLamda * NewCrg.dblArea * NewCrg.dblCostEstComp;
            }
            else if (CConstants.strShapeConstraint == "MaximizeAvgComp_Combine")
            {
            }
            else if (CConstants.strShapeConstraint == "MaximizeMinComp_Comine")
            {
                //NewCrg.dblCostEstComp = intEstSteps * BalancedEstMinComp_Combine(NewCrg, lscrg, sscrg);

                ////to make dblCostEstComp comparable to dblCostEstType and to avoid digital problems, we time dblCostEstComp by area
                ////we will adjust the value later
                //NewCrg.dblCostEst = (1 - CAreaAgg_Base.dblLamda) * NewCrg.dblCostEstType +
                //    CAreaAgg_Base.dblLamda * NewCrg.dblArea * NewCrg.dblCostEstComp;
            }
            else if (CConstants.strShapeConstraint == "MaximizeMinComp_EdgeNumber")
            {
                //NewCrg.dblCostEstComp = intEstSteps * BalancedEstMinComp_EdgeNumber(NewCrg, lscrg, sscrg);

                ////to make dblCostEstComp comparable to dblCostEstType and to avoid digital problems, we time dblCostEstComp by area
                ////we will adjust the value later
                //NewCrg.dblCostEst = (1 - CAreaAgg_Base.dblLamda) * NewCrg.dblCostEstType +
                //    CAreaAgg_Base.dblLamda * NewCrg.dblArea * NewCrg.dblCostEstComp;
            }
            else if (CConstants.strShapeConstraint == "MinimizeInteriorBoundaries")
            {
                NewCrg.dblCostEstComp = BalancedEstCompInteriorLength_Basic(NewCrg, lscrg, intEstSteps);

                //to make dblCostEstComp comparable to dblCostEstType and to avoid digital problems, we time dblCostEstComp by area
                //we will adjust the value later
                NewCrg.dblCostEst = (1 - CAreaAgg_Base.dblLamda) * NewCrg.dblCostEstType +
                                    CAreaAgg_Base.dblLamda * NewCrg.dblArea * NewCrg.dblCostEstComp;
            }
            else if (CConstants.strShapeConstraint == "NonShape")
            {
                NewCrg.dblCostEst = NewCrg.dblCostEstType;
            }

            //double dblWeight = 0.5;
            NewCrg.d = NewCrg.dblCostExact + NewCrg.dblCostEst;
        }
Esempio n. 11
0
        private double BalancedEstMinComp_EdgeLength(CRegion crg, CRegion lscrg, CRegion sscrg)
        {
            if (crg.GetCphCount() == 1)
            {
                return(0);
            }

            return(EstimatedComp_Common(EstimateMinComp_EdgeLength(crg, lscrg), crg, lscrg, sscrg));
        }
Esempio n. 12
0
    private static string ValidarRegion(CRegion Region)
    {
        string Mensaje = "";

        Mensaje += (Region.Region == "") ? "<li>Favor de completar el campo región.</li>" : Mensaje;

        Mensaje = (Mensaje != "") ? "<p>Favor de completar los siguientes campos:<ul>" + Mensaje + "</ul></p>" : Mensaje;

        return(Mensaje);
    }
Esempio n. 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="crg">crg.GetCphCount() > 1</param>
        /// <param name="lscrg">lscrg.GetCphCount() > 2</param>
        /// <param name="sscrg"></param>
        /// <returns></returns>
        private double BalancedEstMinComp_EdgeNumber(CRegion crg, CRegion lscrg, CRegion sscrg)
        {
            // if lscrg.GetCphCount() <= 2, the domain only have two polygons
            // A value will be divided by (lscrg.GetCphCount() - 2). To avoid being divided by 0, we directly return 0.
            if (lscrg.GetCphCount() <= 2)
            {
                return(0);
            }

            return(EstimatedComp_Common(EstimateMinComp_EdgeNumber(crg, lscrg), crg, lscrg, sscrg));
        }
Esempio n. 14
0
        public Regions(SqlConnection cn, ushort md)
        {
            InitializeComponent();

            connect = cn;
            mode    = md;

            clRegion = new CRegion(connect);

            this.WindowState = FormWindowState.Maximized;

            gpos = 0;
        }
Esempio n. 15
0
        private void AddVirtualItem(List <List <object> > pobjDataLtLt, CRegion LSCrg, string strAreaAggregation, int intCount)
        {
            List <object> objDataLt = new List <object>(14);

            objDataLt.Add(LSCrg.ID);
            objDataLt.Add(LSCrg.GetCphCount());
            objDataLt.Add(LSCrg.GetAdjCount());
            objDataLt.Add(strAreaAggregation);
            for (int i = 4; i < intCount; i++)
            {
                objDataLt.Add(-1);
            }
            pobjDataLtLt.Add(objDataLt);
        }
Esempio n. 16
0
        private void set_data()
        {
            CRegion region;

            try
            {
                textBoxName.Text = gstCity.name;

                region = new CRegion(connect, gstCity.idreg);

                comboBoxRegion.Text = region.stReg.name;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
        }
Esempio n. 17
0
        private IEnumerable <double> EstimateMinComp_EdgeLength(CRegion crg, CRegion lscrg)
        {
            throw new ArgumentException("We need to update the cost functions!");

            //double dblEstComp
            var EstimateEt  = EstimateInteriorLength(crg, lscrg).GetEnumerator();
            int intEstCount = crg.GetCphCount() - 1;

            while (EstimateEt.MoveNext())
            {
                double dblEdgeLength = crg.dblExteriorSegLength + 2 * EstimateEt.Current;
                yield return(EstimateCompEdgeLengthOneCrgInstance(intEstCount--, crg.dblArea, dblEdgeLength));
            }
        }
Esempio n. 18
0
 protected void Page_Load(object sender, EventArgs e)
 {
     CUnit.Firmado(delegate(CDB Conn)
     {
         if (Conn.Conectado)
         {
             IdRegion         = Convert.ToInt32(Request["IdRegion"]);
             CRegion cRegion  = new CRegion();
             cRegion.IdRegion = IdRegion;
             cRegion.Obtener(Conn);
             Region = cRegion.Region;
         }
     });
 }
Esempio n. 19
0
        private double EstimatedComp_Common(IEnumerable <double> EstimateEb, CRegion crg, CRegion lscrg, CRegion sscrg)
        {
            var EstimateEt = EstimateEb.GetEnumerator();

            //we include current step so that we can make the ration type/comp
            double dblSumCompValue = 0;  //for the current crg, whose dblMinComp is known

            while (EstimateEt.MoveNext())
            {
                dblSumCompValue += (1 - EstimateEt.Current);
            }

            return(dblSumCompValue / (lscrg.GetCphCount() - 2));
        }
Esempio n. 20
0
        public IEnumerable <CRegion> AggregateAllAndUpdateQ(CRegion crg, CRegion lscrg, CRegion sscrg, SortedSet <CRegion> Q,
                                                            List <SortedDictionary <CRegion, CRegion> > ExistingCrgSDLt, List <SortedDictionary <CPatch, CPatch> > ExistingCphSDLt,
                                                            SortedDictionary <CCorrCphs, CCorrCphs> ExistingCorrCphsSD, double[,] padblTD, int intEstSteps)
        {
            var pAdjCorrCphsSD = crg.AdjCorrCphsSD;

            //for every pair of neighboring Cphs, we aggregate them and generate a new Crg
            foreach (var unitingCorrCphs in pAdjCorrCphsSD.Keys)
            {
                foreach (var item in AggregateAndUpdateQ_Common(crg, lscrg, sscrg, Q, pAdjCorrCphsSD, unitingCorrCphs,
                                                                ExistingCrgSDLt, ExistingCphSDLt, ExistingCorrCphsSD, padblTD, intEstSteps))
                {
                    yield return(item);
                }
            }
        }
Esempio n. 21
0
        public IEnumerable <CRegion> AggregateSmallestAndUpdateQ(CRegion crg, CRegion lscrg, CRegion sscrg, SortedSet <CRegion> Q,
                                                                 List <SortedDictionary <CRegion, CRegion> > ExistingCrgSDLt, List <SortedDictionary <CPatch, CPatch> > ExistingCphSDLt,
                                                                 SortedDictionary <CCorrCphs, CCorrCphs> ExistingCorrCphsSD, double[,] padblTD, int intEstSteps)
        {
            var pAdjCorrCphsSD = crg.AdjCorrCphsSD;
            var mincph         = crg.GetSmallestCph();

            //for every pair of neighboring Cphs, we aggregate them and generate a new Crg
            foreach (var pCphRecord in crg.GetNeighborCphRecords(mincph))
            {
                foreach (var item in AggregateAndUpdateQ_Common(crg, lscrg, sscrg, Q, pAdjCorrCphsSD, pCphRecord.CorrCphs,
                                                                ExistingCrgSDLt, ExistingCphSDLt, ExistingCorrCphsSD, padblTD, intEstSteps))
                {
                    yield return(item);
                }
            }
        }
Esempio n. 22
0
        private void init_list()
        {
            dataGridViewCity.Rows.Clear();

            list = clCity.GetListCity();

            CRegion region;

            try
            {
                if (list.Count > 0)
                {
                    g_f = true;

                    dataGridViewCity.Rows.Add(list.Count);

                    for (int i = 0; i < list.Count; i++)
                    {
                        dataGridViewCity.Rows[i].Cells[0].Value = (i + 1).ToString();

                        dataGridViewCity.Rows[i].Cells[1].Value = list[i].name;

                        region = new CRegion(connect, list[i].idreg);

                        dataGridViewCity.Rows[i].Cells[2].Value = region.stFullReg.name;
                        dataGridViewCity.Rows[i].Cells[3].Value = region.stFullReg.shortnamecountry;

                        if (flawour.Equals(list[i]))
                        {
                            gpos = i;
                        }
                    }

                    dataGridViewCity.AllowUserToAddRows = false;
                }
                else
                {
                    dataGridViewCity.AllowUserToAddRows = false;
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); }
        }
Esempio n. 23
0
        private IEnumerable <CRegion> AggregateAndUpdateQ_Common(CRegion crg, CRegion lscrg, CRegion sscrg, SortedSet <CRegion> Q,
                                                                 SortedDictionary <CCorrCphs, CCorrCphs> pAdjCorrCphsSD, CCorrCphs unitingCorrCphs,
                                                                 List <SortedDictionary <CRegion, CRegion> > ExistingCrgSDLt, List <SortedDictionary <CPatch, CPatch> > ExistingCphSDLt,
                                                                 SortedDictionary <CCorrCphs, CCorrCphs> ExistingCorrCphsSD, double[,] padblTD, int intEstSteps)
        {
            var newcph           = crg.ComputeNewCph(unitingCorrCphs, ExistingCphSDLt);
            var newAdjCorrCphsSD = CRegion.ComputeNewAdjCorrCphsSDAndUpdateExistingCorrCphsSD(pAdjCorrCphsSD,
                                                                                              unitingCorrCphs, newcph, ExistingCorrCphsSD);


            var frcph          = unitingCorrCphs.FrCph;
            var tocph          = unitingCorrCphs.ToCph;
            int intfrTypeIndex = crg.GetCphTypeIndex(frcph);
            int inttoTypeIndex = crg.GetCphTypeIndex(tocph);


            //if the two cphs have the same type, then we only need to aggregate the smaller one into the larger one
            //(this will certainly have smaller cost in terms of area)
            //otherwise, we need to aggregate from two directions
            if (intfrTypeIndex == inttoTypeIndex)
            {
                if (frcph.dblArea >= tocph.dblArea)
                {
                    yield return(GenerateCrgAndUpdateQ(crg, lscrg, sscrg, Q, ExistingCrgSDLt, newAdjCorrCphsSD,
                                                       frcph, tocph, newcph, unitingCorrCphs, padblTD, intEstSteps));
                }
                else
                {
                    yield return(GenerateCrgAndUpdateQ(crg, lscrg, sscrg, Q, ExistingCrgSDLt, newAdjCorrCphsSD,
                                                       tocph, frcph, newcph, unitingCorrCphs, padblTD, intEstSteps));
                }
            }
            else
            {
                //The aggregate can happen from two directions
                yield return(GenerateCrgAndUpdateQ(crg, lscrg, sscrg, Q, ExistingCrgSDLt, newAdjCorrCphsSD,
                                                   frcph, tocph, newcph, unitingCorrCphs, padblTD, intEstSteps));

                yield return(GenerateCrgAndUpdateQ(crg, lscrg, sscrg, Q, ExistingCrgSDLt, newAdjCorrCphsSD,
                                                   tocph, frcph, newcph, unitingCorrCphs, padblTD, intEstSteps));
            }
        }
Esempio n. 24
0
        private STCity read_data()
        {
            STCity ret = new STCity();

            CRegion region;

            try
            {
                if (gstCity.id != 0)
                {
                    ret.id = gstCity.id;
                }
                else
                {
                    ret.id = clCity.GetFreeId();
                }

                if (textBoxName.Text.Length > 0)
                {
                    ret.name = textBoxName.Text.Trim();
                }
                else
                {
                    ret.name = null;
                }

                string str = comboBoxRegion.Text.Trim();
                if (str.Length > 0)
                {
                    region    = new CRegion(connect, str);
                    ret.idreg = region.stReg.id;
                }
                else
                {
                    ret.idreg = 0;
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }

            return(ret);
        }
Esempio n. 25
0
        private STRegion GetSelectionData()
        {
            STRegion ret = new STRegion();

            string n;

            try
            {
                foreach (DataGridViewRow item in dataGridViewRegion.SelectedRows)
                {
                    n = item.Cells[1].Value.ToString();

                    CRegion ct = new CRegion(connect, n);

                    ret = ct.stReg;
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); }

            return(ret);
        }
Esempio n. 26
0
        public static int CmpCrg_nmID(CRegion crg1, CRegion crg2)
        {
            int intResult = crg1.GetCphCount().CompareTo(crg2.GetCphCount());

            if (intResult == 0)
            {
                intResult = crg1.GetAdjCount().CompareTo(crg2.GetAdjCount());
            }

            if (intResult == 0)
            {
                intResult = crg1.ID.CompareTo(crg2.ID);
            }

            if (intResult == 0)
            {
                throw new ArgumentOutOfRangeException("this should not happen!");
            }

            return(intResult);
        }
Esempio n. 27
0
        /// <summary>
        /// Estimate Interior Lengths for the future steps, without current step
        /// </summary>
        /// <param name="crg"></param>
        /// <param name="lscrg"></param>
        /// <returns></returns>
        /// <remarks>from time n-1 to t+1</remarks>
        private List <double> EstimateInteriorLength(CRegion crg, CRegion lscrg)
        {
            var dblSegLengthSS = new SortedSet <double>(new CCmpDbl());

            foreach (var pCorrCphs in crg.AdjCorrCphsSD.Keys)
            {
                dblSegLengthSS.Add(pCorrCphs.dblSharedSegLength);
            }
            IEnumerator <double> dblSegLengthSSEt = dblSegLengthSS.GetEnumerator();


            int intEstCount = crg.GetCphCount();

            //if intEstCount == lscrg.GetCphCount(), we are estimating from the start map (t==1)
            //we define that the estimation value of the start map is 0, therefore we skip intEstCount == lscrg.GetCphCount()
            if (crg.GetCphCount() == lscrg.GetCphCount())
            {
                intEstCount--;
            }

            //from time n-1 to t+1
            //we compute from the last step (only one interior boundary) to the current step (many interior boundaries).
            double dblInteriorLength   = 0;
            var    dblInteriorLengthLt = new List <double>(intEstCount - 1);

            for (int i = 0; i < intEstCount - 2; i++)
            {
                dblSegLengthSSEt.MoveNext();
                dblInteriorLength += dblSegLengthSSEt.Current;

                dblInteriorLengthLt.Add(dblInteriorLength);
            }

            return(dblInteriorLengthLt);

            //for (int i = 0; i < dblInteriorLengthLt.Count; i++)
            //{
            //    yield return dblInteriorLengthLt[dblInteriorLengthLt.Count - i - 1];
            //}
        }
Esempio n. 28
0
 public IEnumerable <CRegion> AggregateAndUpdateQ(CRegion crg, CRegion lscrg, CRegion sscrg, SortedSet <CRegion> Q,
                                                  string strAreaAggregation,
                                                  List <SortedDictionary <CRegion, CRegion> > ExistingCrgSDLt, List <SortedDictionary <CPatch, CPatch> > ExistingCphSDLt,
                                                  SortedDictionary <CCorrCphs, CCorrCphs> ExistingCorrCphsSD, double[,] padblTD, int intEstSteps)
 {
     if (strAreaAggregation == "Smallest")
     {
         foreach (var item in AggregateSmallestAndUpdateQ(crg, lscrg, sscrg, Q,
                                                          ExistingCrgSDLt, ExistingCphSDLt, ExistingCorrCphsSD, padblTD, intEstSteps))
         {
             yield return(item);
         }
     }
     else
     {
         foreach (var item in AggregateAllAndUpdateQ(crg, lscrg, sscrg, Q,
                                                     ExistingCrgSDLt, ExistingCphSDLt, ExistingCorrCphsSD, padblTD, intEstSteps))
         {
             yield return(item);
         }
     }
 }
Esempio n. 29
0
        private double BalancedEstType(CRegion crg, int intFinalTypeIndex, double[,] padblTD, int intEstSteps)
        {
            int    intOverestimationCount = Math.Min(intEstSteps, crg.GetCphCount());
            var    pCphTypeIndexEt        = crg.CphTypeIndexSD_Area_CphGID.GetEnumerator();
            double dblCostEst             = 0;

            for (int i = 0; i < intOverestimationCount; i++)
            {
                pCphTypeIndexEt.MoveNext();

                dblCostEst += pCphTypeIndexEt.Current.Key.dblArea *
                              padblTD[pCphTypeIndexEt.Current.Value, intFinalTypeIndex] * intEstSteps; //overestimation
            }

            for (int i = intOverestimationCount; i < crg.GetCphCount(); i++)
            {
                pCphTypeIndexEt.MoveNext();
                dblCostEst += pCphTypeIndexEt.Current.Key.dblArea *
                              padblTD[pCphTypeIndexEt.Current.Value, intFinalTypeIndex]; //estimation
            }

            return(dblCostEst);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="LSCrg"></param>
        /// <param name="SSCrg"></param>
        /// <param name="StrObjLtDt"></param>
        /// <param name="adblTD"></param>
        /// <param name="EstStepsCostVPDt">Results from A*</param>
        /// <param name="strAreaAggregation"></param>
        /// <returns></returns>
        public CRegion Greedy(CRegion LSCrg, CRegion SSCrg, CStrObjLtDt StrObjLtDt, double[,] adblTD,
                              Dictionary <int, CValPair <int, double> > EstStepsCostVPDt, string strAreaAggregation)
        {
            long lngStartMemory     = GC.GetTotalMemory(true);
            var  pStopwatchOverHead = Stopwatch.StartNew();

            var ExistingCorrCphsSD0 = LSCrg.SetInitialAdjacency();  //also count the number of edges

            AddLineToStrObjLtDt(StrObjLtDt, LSCrg);


            Console.WriteLine();
            Console.WriteLine("Crg:  ID  " + LSCrg.ID + ";    n  " + LSCrg.GetCphCount() + ";    m  " +
                              LSCrg.AdjCorrCphsSD.Count + "   " + CConstants.strShapeConstraint + "   " + strAreaAggregation);


            long lngTimeOverHead = pStopwatchOverHead.ElapsedMilliseconds;

            pStopwatchOverHead.Stop();

            var  pStopwatchLast = new Stopwatch();
            long lngTime        = 0;

            CRegion resultcrg = new CRegion(-2);

            try
            {
                pStopwatchLast.Restart();
                var ExistingCorrCphsSD = new SortedDictionary <CCorrCphs, CCorrCphs>
                                             (ExistingCorrCphsSD0, ExistingCorrCphsSD0.Comparer);
                LSCrg.cenumColor = CEnumColor.white;

                resultcrg = Compute(LSCrg, SSCrg, SSCrg.GetSoloCphTypeIndex(),
                                    strAreaAggregation, ExistingCorrCphsSD, StrObjLtDt, adblTD);
            }
            catch (System.OutOfMemoryException ex)
            {
                Console.WriteLine(ex.Message);
            }
            lngTime = pStopwatchLast.ElapsedMilliseconds + lngTimeOverHead;


            Console.WriteLine("d: " + resultcrg.d
                              + "            Type: " + resultcrg.dblCostExactType
                              + "            Compactness: " + resultcrg.dblCostExactComp);

            EstStepsCostVPDt.TryGetValue(LSCrg.ID, out CValPair <int, double> outEstStepsCostVP);
            if (outEstStepsCostVP.val1 == 0 &&
                CCmpMethods.CmpDbl_CoordVerySmall(outEstStepsCostVP.val2, resultcrg.d) == 0)
            {
                StrObjLtDt.SetLastObj("EstSteps/Gap%", 0); //optimal solutions
            }
            else
            {
                StrObjLtDt.SetLastObj("EstSteps/Gap%", 100); //not sure, at least feasible solutions
            }
            //we don't need to +1 because +1 is already included in _intStaticGID
            //int intExploredRegionAll = CRegion._intStaticGID - CRegion._intStartStaticGIDLast;
            StrObjLtDt.SetLastObj("#Edges", CRegion._intEdgeCount);
            StrObjLtDt.SetLastObj("Time_F(ms)", lngTime);
            StrObjLtDt.SetLastObj("Time_L(ms)", lngTime);
            StrObjLtDt.SetLastObj("Time(ms)", lngTime);
            StrObjLtDt.SetLastObj("Memory(MB)", CHelpFunc.GetConsumedMemoryInMB(false, lngStartMemory));

            Console.WriteLine("We have visited " +
                              CRegion._intNodeCount + " Nodes and " + CRegion._intEdgeCount + " Edges.");

            return(resultcrg);
        }