コード例 #1
0
        public double energy(string[] vsol)
        {
            double[] vcost = new double[pumps.Count + 1];
            int[]    soli  = new int[25];

            int[,] msol = new int[pumps.Count + 1, 25];
            for (int j = 1; j <= 24; j++)
            {
                int[] vint = ConverterInt(vsol[j - 1]);
                for (int i = 1; i <= pumps.Count; i++)
                {
                    msol[i, j] = vint[i];
                }
            }

            Epanet.ENopen(f1, f2, "");


            Epanet.ENsettimeparam(0, 86400);


            int tstep_hid = 0;

            Epanet.ENgettimeparam(1, ref tstep_hid);


            Epanet.ENsettimeparam(4, 0);


            int cont = 0;

            foreach (pump p in pumps)
            {
                cont++;
                for (int h = 1; h <= 24; h++)
                {
                    Epanet.ENsetpatternvalue(p.indexpattern, h, msol[cont, h]);
                }
            }


            Epanet.ENopenH();
            Epanet.ENinitH(1);
            long tstep = 1;
            long t     = 0;

            while (tstep > 0)
            {
                Epanet.ENrunH(ref t);
                Epanet.ENnextH(ref tstep);
                double db1  = t / 3600;
                int    hora = Convert.ToInt16(Math.Truncate(db1)) + 1;
                cont = 0;
                foreach (pump p in pumps)
                {
                    cont++;
                    float pot = 0;
                    Epanet.ENgetlinkvalue(p.index, 13, ref pot);
                    float tariff = 0;
                    Epanet.ENgetpatternvalue(p.indextariff, hora, ref tariff);
                    vcost[cont] += (tstep / 3600.0) * pot * tariff;
                }
            }
            double re = 0;

            cont = 0;
            double soma = 0;

            foreach (pump p in pumps)
            {
                cont++;
                soma = soma + vcost[cont];
            }
            re = soma;
            Epanet.ENcloseH();
            Epanet.ENclose();
            return(re);
        }
コード例 #2
0
        public string[] simulation1h(string solh, int h, string niveli)
        {
            Epanet.ENopen(f1, f2, "");


            Epanet.ENsettimeparam(0, 3600);


            int tstep_hid = 0;

            Epanet.ENgettimeparam(1, ref tstep_hid);


            float[] cod     = solhtof(solh);
            float[] vniveis = ConvertFloat(niveli);

            int cont = 0;

            foreach (pump b in pumps)
            {
                cont++;
                Epanet.ENsetpatternvalue(b.indexpattern, h, cod[cont]);
            }


            cont = 0;
            foreach (tank tk in tanks)
            {
                cont++;
                Epanet.ENsetnodevalue(tk.index, 8, vniveis[cont]);
            }


            Epanet.ENsettimeparam(4, (h - 1) * 3600);


            Epanet.ENopenH();
            Epanet.ENinitH(1);
            int  erro  = 0;
            long tstep = 1;
            long t     = 0;
            bool v     = true;


            while (tstep > 0)
            {
                erro = Epanet.ENrunH(ref t);
                if (erro > 0)
                {
                    v = false;
                }

                if (v)
                {
                    float pressure = 0;
                    //n170
                    Epanet.ENgetnodevalue(13, 11, ref pressure);
                    if (pressure < 30 + 0.0001)
                    {
                        feasible = false;
                    }
                    //n50
                    Epanet.ENgetnodevalue(9, 11, ref pressure);
                    if (pressure < 42 + 0.0001)
                    {
                        feasible = false;
                    }
                    //n90
                    Epanet.ENgetnodevalue(6, 11, ref pressure);
                    if (pressure < 51 + 0.0001)
                    {
                        feasible = false;
                    }
                }

                if (v)
                {
                    foreach (tank tk in tanks)
                    {
                        float nivel = 0;
                        Epanet.ENgetnodevalue(tk.index, 11, ref nivel);
                        if ((nivel < tk.nivelmin + 0.0001) || (nivel > tk.nivelmax - 0.0001))
                        {
                            v = false;
                        }
                    }
                }
                if (v && t == 3600 && h == 24)
                {
                    foreach (tank tk in tanks)
                    {
                        float nivel = 0;
                        Epanet.ENgetnodevalue(tk.index, 11, ref nivel);
                        if (nivel < tk.nivelini + 0.0001)
                        {
                            v = false;
                        }
                        if ((nivel < tk.nivelmin + 0.0001) || (nivel > tk.nivelmax - 0.0001))
                        {
                            v = false;
                        }
                    }
                }
                if (v)
                {
                    int erro2 = Epanet.ENnextH(ref tstep);
                    if (tstep > 0 && tstep < tstep_hid)
                    {
                        v = false;
                    }
                }
                if (v == false)
                {
                    break;
                }
            }

            float[] re = new float[this.tanks.Count + 1];
            re[0] = 0;


            if (v)
            {
                re[0] = 1;
                cont  = 0;
                foreach (tank tk in tanks)
                {
                    cont++;
                    Epanet.ENgetnodevalue(tk.index, 11, ref re[cont]);
                }
            }
            Epanet.ENcloseH();
            Epanet.ENclose();
            string[] vst = new string[2];
            vst[1] = ConvertString(re);
            if (v)
            {
                vst[0] = "T";
            }
            else
            {
                vst[0] = "F";
            }
            return(vst);
        }