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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
 
namespace IStation.Calculation.temp
{
    public class EapnetHelper
    {
        public EapnetHelper() { }
 
        public EapnetHelper(string inpFile)
        {
            _fileName = inpFile;
        }
 
        private string _fileName;
 
        /// <summary>
        /// 方法1:获取节点压力
        /// </summary>
        /// <param name="modelInputs">模型算法输入参数</param> 
        public void GetPressByFlowAndPumpStatus(List<ModelInput> modelInputs, out List<ModelOutputNode> nodes_out, out List<ModelOutputLink> links_out)
        {
            nodes_out = new List<ModelOutputNode>();
            links_out = new List<ModelOutputLink>();
            try
            {
                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EpanetFile", _fileName); //inp文件
                var reportFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EpanetFile", "0.rpt");  //inp 报告文件
 
                Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "IStation.Epanet.dll");
                var type = assembly.GetType("IStation.StationHydrModelHelper");
                var helper = assembly.CreateInstance("IStation.StationHydrModelHelper");
 
 
                MethodInfo initial = type.GetMethod("Initial", new Type[] { typeof(string), typeof(string) });
                var initialStatus = (bool)initial.Invoke(helper, new object[] { filePath, reportFilePath });
                if (!initialStatus)
                    return;
 
                MethodInfo func = type.GetMethod("GetResultByFlowAndPumpStatus", new Type[] { typeof(List<ModelInput>), typeof(List<ModelOutputNode>), typeof(List<ModelOutputLink>) });
                func.Invoke(helper, new object[] { modelInputs, nodes_out, links_out });
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 方法2:获取节点流量
        /// </summary>
        /// <param name="modelInputs">模型算法输入参数</param> 
        public void GetFlowByPressAndPumpStatus(List<ModelInput> modelInputs, out List<ModelOutputNode> nodes_out, out List<ModelOutputLink> links_out)
        {
            nodes_out = new List<ModelOutputNode>();
            links_out = new List<ModelOutputLink>();
            try
            {
                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EpanetFile", _fileName); //inp文件
                var reportFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EpanetFile", "0.rpt");  //inp 报告文件
 
                Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "IStation.Epanet.dll");
                var type = assembly.GetType("IStation.StationHydrModelHelper");
                var helper = assembly.CreateInstance("IStation.StationHydrModelHelper");
 
 
                MethodInfo initial = type.GetMethod("Initial", new Type[] { typeof(string), typeof(string) });
                var initialStatus = (bool)initial.Invoke(helper, new object[] { filePath, reportFilePath });
                if (!initialStatus)
                    return;
 
                MethodInfo func = type.GetMethod("GetResultByPressAndPumpStatus", new Type[] { typeof(List<ModelInput>), typeof(List<ModelOutputNode>), typeof(List<ModelOutputLink>) });
                func.Invoke(helper, new object[] { modelInputs, nodes_out, links_out });
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 方法3: 获取开泵组合最优能耗信息
        /// </summary>
        /// <param name="modelInputs">模型算法输入参数</param> 
        public void GetResultByFlowAndPress
            (List<ModelInput> modelInputs,
            List<List<string>> openPumpCombin,
            out List<List<ModelOutputNode>> nodes_out,
            out List<List<ModelOutputLink>> links_out,
            out List<List<double>> opt_combines,
            out List<double> opt_energes,
            double rangeMin = 0,
            double rangeMax = 1,
            int populationSize = 40,
            int iterations = 20,
            double accuracy = 0.1)
        {
            nodes_out = new List<List<ModelOutputNode>>();
            links_out = new List<List<ModelOutputLink>>();
            opt_combines = new List<List<double>>();
            opt_energes = new List<double>();
            try
            {
                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EpanetFile", _fileName); //inp文件
                var reportFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EpanetFile", "0.rpt");  //inp 报告文件
 
                var dllFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "IStation.Epanet.dll");
                if (!File.Exists(dllFilePath))
                    return;
                Assembly assembly = Assembly.LoadFile(dllFilePath);
                var type = assembly.GetType("IStation.StationHydrModelHelper");
                var helper = assembly.CreateInstance("IStation.StationHydrModelHelper");
 
                /*   MethodInfo initial = type.GetMethod("Initial", new Type[] { typeof(string), typeof(string) });
                   var initialStatus = (bool)initial.Invoke(helper, new object[] { filePath, reportFilePath });*/
                MethodInfo initial = type.GetMethod("Initial", new Type[] { typeof(string) });
                var initialStatus = (bool)initial.Invoke(helper, new object[] { filePath });
                if (!initialStatus)
                    return;
 
                MethodInfo func = type.GetMethod("GetResultByPressAndPumpStatus",
                 new Type[] { typeof(List<ModelInput>), typeof(List<string>), typeof(List<List<ModelOutputNode>>), typeof(List<List<ModelOutputLink>>),
                 typeof(List<List<double>>),  typeof(List<double>), typeof(double), typeof(double),typeof(int),typeof(int), typeof(double) });
 
                func.Invoke(helper, new object[] { modelInputs, openPumpCombin, nodes_out, links_out, opt_energes, rangeMin, rangeMax, populationSize, iterations, accuracy });
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
            }
        }
 
    }
}