using Accord; using Accord.Genetic; using IStation; using System; using System.Collections.Generic; using static IStation.EpanetHelper; namespace Optimization1D { public class EPAFunctionGUI : OptimizationFunctionXD { List combine; EpanetHelper helper; calcParms parms; public EPAFunctionGUI(Accord.DoubleRange[] doubleRanges, int Length_D, calcParms parms, EpanetHelper helper, List combine) : base(doubleRanges, Length_D) { this.parms = parms; this.helper = helper; this.combine = combine; } /// /// Ä¿±êº¯Êý¶¨Òå /// /// Ë®±ÃƵÂʵÄ×éºÏ /// public override double OptimizationFunction(double[] array) { List modelOutputNodes = null; List modelOutputLinks = null; List pumpFlows = null; List 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; } /// /// »ñÈ¡¼ÆËã½á¹û /// /// Ë®±ÃƵÂʵÄ×éºÏ /// public string GetResult(double[] array, out List modelOutputNodes, out List modelOutputLinks, out List 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 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; } } }