using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Calculation.Epanet
|
{
|
public class GetPumpStatusByFlowAndPressHelper : IGetPumpStatusByFlowAndPress
|
{
|
EpanetHelper _helper = null;
|
|
public string Initial(string fileName)
|
{
|
_helper = new EpanetHelper();
|
return _helper.Initial(fileName);
|
}
|
|
public List<EpanetScheme> GetPumpStatusByFlowAndPress(List<EpanetNode> nodes, List<List<string>> openPumpCombineIds, double rangeMin = 0, double rangeMax = 1, int populationSize = 40, int iterations = 20, double accuracy = 0.1)
|
{
|
if (_helper == null)
|
return default;
|
if (nodes == null || nodes.Count < 1)
|
return default;
|
var inputs = nodes.Select(x => new ModelInput(x.ObjectID, (int)x.Type, x.Value)).ToList();
|
var err = _helper.GetResultByFlowAndPress
|
(inputs, openPumpCombineIds, out List<List<ModelOutputNode>> modelOutputNodeCombines,
|
out List<List<ModelOutputLink>> modelOutputLinkCombines, out List<List<double>> opt_combines,
|
out List<double> opt_energes, rangeMin, rangeMax, populationSize, iterations, accuracy);
|
if (!string.IsNullOrEmpty(err))
|
return default;
|
var list = new List<EpanetScheme>();
|
for (int i = 0; i < openPumpCombineIds.Count; i++)
|
{
|
var scheme = new EpanetScheme();
|
scheme.Energy = opt_energes[i];
|
scheme.FrequencyCombine = opt_combines[i];
|
scheme.OutputNodeList = new List<EpanetNodeOutputNode>();
|
scheme.OutputLinkList = new List<EpanetNodeOutputLink>();
|
var nodeCombine = modelOutputNodeCombines[i];
|
if (nodeCombine == null)
|
continue;
|
foreach (var node in nodeCombine)
|
{
|
var outputNode = new EpanetNodeOutputNode();
|
outputNode.ObjectID = node.ObjectID;
|
outputNode.Type = (EpanetNodeOutput.eType)node.Type;
|
if (node.result != null)
|
{
|
var result = node.result;
|
outputNode.EN_ELEVATION = result.EN_ELEVATION;
|
outputNode.EN_BASEDEMAND = result.EN_BASEDEMAND;
|
outputNode.EN_DEMAND = result.EN_DEMAND;
|
outputNode.EN_HEAD = result.EN_HEAD;
|
outputNode.EN_PRESSURE = result.EN_PRESSURE;
|
}
|
scheme.OutputNodeList.Add(outputNode);
|
}
|
var linkCombine = modelOutputLinkCombines[i];
|
foreach (var link in linkCombine)
|
{
|
var outputLink = new EpanetNodeOutputLink();
|
outputLink.ObjectID = link.ObjectID;
|
outputLink.Type = (EpanetNodeOutputLink.eType)link.Type;
|
if (link.result != null)
|
{
|
var result = link.result;
|
outputLink.EN_DIAMETER = result.EN_DIAMETER;
|
outputLink.EN_LENGTH = result.EN_LENGTH;
|
outputLink.EN_FLOW = result.EN_FLOW;
|
outputLink.EN_VELOCITY = result.EN_VELOCITY;
|
outputLink.EN_HEADLOSS = result.EN_HEADLOSS;
|
outputLink.EN_STATUS = result.EN_STATUS;
|
outputLink.EN_SETTING = result.EN_SETTING;
|
outputLink.EN_ENERGY = result.EN_ENERGY;
|
}
|
scheme.OutputLinkList.Add(outputLink);
|
}
|
list.Add(scheme);
|
}
|
return list;
|
}
|
}
|
}
|