Exemple #1
0
        static void geracao2d(object sender, GaEventArgs e)
        {
            var sol = e.Population.GetTop(1)[0];

            tagg = sol.Tag as tag;
            if (tagg != null)
            {
                //  tagg2 = sol2.Tag as tag;
                tagg.generation              = e.Generation;
                mevolution[e.Generation, 1]  = tagg.generation.ToString("F4");
                mevolution[e.Generation, 2]  = tagg.fobj.ToString("F4");
                mevolution[e.Generation, 3]  = tagg.angle.ToString("F4");
                mevolution[e.Generation, 4]  = tagg.tol.ToString("F4");
                mevolution[e.Generation, 5]  = tagg.bwh.ToString("F4");
                mevolution[e.Generation, 6]  = tagg.lsd.ToString("F4");
                mevolution[e.Generation, 7]  = tagg.nl.ToString();
                mevolution[e.Generation, 8]  = tagg.C0.ToString("F4");
                mevolution[e.Generation, 9]  = tagg.C.ToString("F4");
                mevolution[e.Generation, 10] = tagg.a.ToString("F4");
                mevolution[e.Generation, 11] = tagg.ns.ToString("F4");
                mevolution[e.Generation, 12] = tagg.curve.ToString();
                mevolution[e.Generation, 13] = tagg.floss.ToString("F4");
                string stx  = "";
                string sty  = "";
                int    lvar = tagg.vx.Length;
                for (int i = 1; i <= lvar - 1; i++)
                {
                    string sep = "";
                    if (i < lvar - 1)
                    {
                        sep = "-";
                    }
                    else
                    {
                        sep = " ";
                    }
                    stx += tagg.vx[i].ToString("F4") + sep;
                    sty += tagg.vy[i].ToString("F4") + sep;
                }
                mevolution[e.Generation, 14] = stx;
                mevolution[e.Generation, 15] = sty;
                t2 = DateTime.Now;
                var duracao = (t2 - t1).Minutes;

                Console.WriteLine("Generation: {0}", tagg.generation);
                Console.WriteLine("Objective Function: {0}", tagg.fobj);
                Console.WriteLine("Angle - Tolerance - BandWidth: {0} - {1} - {2}", tagg.angle, tagg.tol, tagg.bwh);
                Console.WriteLine("Lag - Nlag: {0} - {1}", tagg.lsd, tagg.nl);
                Console.WriteLine("Nugget - Sill - Range: {0} - {1} - {2}", tagg.C0, tagg.C, tagg.a);
                Console.WriteLine("Nugget/Sill: {0}", tagg.ns);
                Console.WriteLine("Curve: {0}", tagg.curve);
                Console.WriteLine("Loss Function: {0}", tagg.floss);
                Console.WriteLine("Total Time (min): {0}", duracao);
                Console.WriteLine("--------------------------");
            }
            else
            {
                Console.WriteLine("Generation: {0}", e.Generation);
                Console.WriteLine("Not Viable Solution");
            }
        }
Exemple #2
0
        static double fapt2d(Chromosome sol)
        {
            string[] vcurve = { "shp", "exp", "gaus" };
            double[] vsol   = bintoreal2D(sol);
            double[,] mvar = variograma2D(vsol);
            int nvar = Convert.ToInt32(mvar[0, 0]);

            double[] vvarx = new double[nvar + 1];
            double[] vvary = new double[nvar + 1];
            double   r     = 0;

            for (int i = 1; i <= nvar; i++)
            {
                vvarx[i] = mvar[i, 1];
                vvary[i] = mvar[i, 2];
            }
            double soma    = 0;
            bool   vario   = true;
            double somavar = vvary.Sum();

            if (somavar < 0.1)
            {
                vario = false;
            }
            int cont = 0;

            for (int i = 2; i <= nvar; i++)
            {
                if (vvary[i] == 0)
                {
                    cont++;
                }
            }
            if (cont > 0)
            {
                vario = false;
            }
            if (vario == false)
            {
                r = 0;
                goto fim;
            }
            double[] param = sa.simulated(vvarx, vvary);
            int      tipo  = Convert.ToInt32(param[0]);
            double   floss = param[1];
            double   C0    = param[2];
            double   C     = param[3];
            double   a     = param[4];
            //--------penalty 1
            double fp1 = 1;

            if (C0 / C > p.ga_ns)
            {
                fp1 = System.Math.Exp(2 * p.ga_ns);
            }
            //--------penalty 2
            double fp2 = 1;
            double R   = System.Math.Abs((2 * vsol[4] * (int)vsol[5] - maxdim) / maxdim);

            if (R > rp)
            {
                fp2 = 2 * System.Math.Log(30 * R);
            }
            //--------penalty 3
            //double fp3 = System.Math.Sqrt(floss / nvar);
            //------------------------
            for (int i = 1; i <= npontos; i++)
            {
                double x    = mpontos[i, 1];
                double y    = mpontos[i, 2];
                double z    = mpontos[i, 3];
                double zest = krigagem.krigagem2D(x, y, mpontos, tipo, C0, C, a);
                soma = soma + (z - zest) * (z - zest);
                //soma2 = soma2 + (z - mediaobs)* (z - mediaobs);
            }
            soma = soma / npontos;

            soma = soma * fp1 * fp2;

            //string st = vsol[1].ToString("F2")+"/"+ vsol[2].ToString("F2") + "/" + vsol[3].ToString("F2") + "/" + vsol[4].ToString("F2") + "/" + Convert.ToInt32(vsol[5]).ToString() + "/" +C0.ToString("F2")+"/"+C.ToString("F2")+ "/" + a.ToString("F2")+ "/"+vcurve[tipo-1]+"/" +floss.ToString("F2")+"/"+soma.ToString("F2");
            //string st = soma.ToString("F4") + "/" + tipo.ToString() + "/" + C0.ToString("F4") + "/" + C.ToString("F4") + "/" + a.ToString("F4");
            tag Tag = new tag();

            Tag.ns    = C0 / C;
            Tag.angle = vsol[1]; Tag.tol = vsol[2]; Tag.bwh = vsol[3]; Tag.lsd = vsol[4];
            Tag.nl    = (int)vsol[5]; Tag.C0 = C0; Tag.C = C; Tag.a = a;
            Tag.curve = vcurve[tipo - 1]; Tag.floss = floss; Tag.fobj = soma;
            Tag.vx    = vvarx; Tag.vy = vvary; Tag.curvetipo = tipo;
            sol.Tag   = Tag;



            double gama = 0.1;
            double aux1 = 1 / (1 + System.Math.Exp(-gama * soma));

            r = 2 * (1 - aux1);
fim:
            if (r < 0)
            {
                r = 0;
            }
            //Console.WriteLine(r.ToString());
            return(r);
        }