lixiaojun
2023-03-20 14801a2e40bc79833c41151a37fe4cb0acbc5c7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Accord;
using Accord.Genetic;
using IStation;
using System;
using System.Collections.Generic;
using static IStation.EpanetHelper;
 
namespace Optimization1D
{
    public class EPAFunctionGUI : OptimizationFunctionXD
    {
        List<string> combine;
        EpanetHelper helper;
        calcParms parms;
        public EPAFunctionGUI(Accord.DoubleRange[] doubleRanges, int Length_D, calcParms parms, EpanetHelper helper, List<string> combine)
            : base(doubleRanges, Length_D)
        {
            this.parms = parms;
            this.helper = helper;
            this.combine = combine;
        }
 
        /// <summary>
        /// Ä¿±êº¯Êý¶¨Òå
        /// </summary>
        /// <param name="array">Ë®±ÃƵÂʵÄ×éºÏ</param>
        /// <returns></returns>
        public override double OptimizationFunction(double[] array)
        {
            List<ModelOutputNode> modelOutputNodes = null;
            List<ModelOutputLink> modelOutputLinks = null;
            List<double> pumpFlows = null;
            List<double> press;
            double energe;
            helper.getPressByPumps(combine, parms.list_isfrequence, array, parms.flowPointIndex, out press, out energe, out modelOutputNodes, out modelOutputLinks, out pumpFlows);
            for (int i = 0; i < press.Count; i++)
            {
                if (press[i] < parms.demandPress[i])
                {
                    //energe = energe * parms.demandPress * parms.demandPress / press / press * 1.3;
                    energe = 99999999f;
                    return energe;
                    //if (press[i] / parms.demandPress[i] < 0.8)
                    //{
                    //    energe = 99999999f;
                    //}
                    //else
                    //{
                    //    energe = energe * parms.demandPress * parms.demandPress / press / press * 1.3;
 
                    //}
                }
            }
 
 
            //else
            //{
            //    var k = 0;
            //}
            return energe;
            //return array[0]*0.1+array[1]* array[0]/ (array[0]+3* array[1]);
            //return Math.Cos(x / 23.0) * Math.Sin(x / 50.0) + 2.0;
            //return Math.Pow(Math.Cos(array / 23) * Math.Sin(array / 50), 2) + Math.Pow(Math.Cos(array / 23) * Math.Sin(array / 50), 5) + 2;
 
        }
        /// <summary>
        /// »ñÈ¡¼ÆËã½á¹û
        /// </summary>
        /// <param name="array">Ë®±ÃƵÂʵÄ×éºÏ</param>
        /// <returns></returns>
        public string GetResult(double[] array, out List<ModelOutputNode> modelOutputNodes, out List<ModelOutputLink> modelOutputLinks, out List<double> pumpFlows, bool openEPANET = false)
        {
 
            string result = null;
            string path_inp = System.IO.Directory.GetCurrentDirectory() + @"\epanetH\result.inp";
            string path_app = System.IO.Directory.GetCurrentDirectory() + @"\epanetH\Epanet2wH.exe";
            List<double> press;
            double energe;
            result = helper.getPressByPumps(combine, parms.list_isfrequence, array, parms.flowPointIndex, out press, out energe, out modelOutputNodes, out modelOutputLinks, out pumpFlows, true, path_inp);
            if (result != null) return result;
            if (openEPANET) System.Diagnostics.Process.Start(path_app, path_inp);
            return null;
            //return energe;
            //return array[0]*0.1+array[1]* array[0]/ (array[0]+3* array[1]);
            //return Math.Cos(x / 23.0) * Math.Sin(x / 50.0) + 2.0;
            //return Math.Pow(Math.Cos(array / 23) * Math.Sin(array / 50), 2) + Math.Pow(Math.Cos(array / 23) * Math.Sin(array / 50), 5) + 2;
 
        }
    }
 
 
}