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);
|
}
|
}
|
|
}
|
}
|