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; /// /// 方法1:获取节点压力 /// /// 模型算法输入参数 public void GetPressByFlowAndPumpStatus(List modelInputs, out List nodes_out, out List links_out) { nodes_out = new List(); links_out = new List(); 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), typeof(List), typeof(List) }); func.Invoke(helper, new object[] { modelInputs, nodes_out, links_out }); } catch (Exception ex) { LogHelper.Error(ex.Message); } } /// /// 方法2:获取节点流量 /// /// 模型算法输入参数 public void GetFlowByPressAndPumpStatus(List modelInputs, out List nodes_out, out List links_out) { nodes_out = new List(); links_out = new List(); 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), typeof(List), typeof(List) }); func.Invoke(helper, new object[] { modelInputs, nodes_out, links_out }); } catch (Exception ex) { LogHelper.Error(ex.Message); } } /// /// 方法3: 获取开泵组合最优能耗信息 /// /// 模型算法输入参数 public void GetResultByFlowAndPress (List modelInputs, List> openPumpCombin, out List> nodes_out, out List> links_out, out List> opt_combines, out List opt_energes, double rangeMin = 0, double rangeMax = 1, int populationSize = 40, int iterations = 20, double accuracy = 0.1) { nodes_out = new List>(); links_out = new List>(); opt_combines = new List>(); opt_energes = new List(); 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), typeof(List), typeof(List>), typeof(List>), typeof(List>), typeof(List), 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); } } } }