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