| | |
| | | using Hydro.CommonBase; |
| | | using Hydro.CodeProvider; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Collections.Concurrent; |
| | | |
| | | namespace Hydro.HydraulicOptimizer |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | #if DEBUG |
| | | Eval.本地项目编译 = gParam.GlobalConfig.Ext.本地项目编译; |
| | | #endif |
| | | |
| | | |
| | | if ((result = loadGeneticParam(onFinished, onError, onReportProgress, SetVars)) != null) { return result; } |
| | | if ((result = gParam.Load_Settings(param,onFinished, onError, onReportProgress, SetVars)) != null) { return result; } |
| | | |
| | | |
| | | if (isGUILoading) return null; |
| | |
| | | |
| | | if ((result = controllerInit(isGUI, wParam)) != null) return result; |
| | | |
| | | if ((result = load试算参数_gParam()) != null) return result; |
| | | if ((result = gParam.Load_GeneticSettings(param)) != null) return result; |
| | | //StartChild |
| | | lock (GlobalProgress.Instance) |
| | | { |
| | |
| | | { |
| | | EPAController.needToStop = true; |
| | | EPAController.StopRobot(); |
| | | } |
| | | } |
| | | if (workerThread != null) |
| | | workerThread.Abort(); |
| | | StopRunQuene(); |
| | | if (Quene.RequestQueues!=null) Quene.RequestQueues.Clear(); |
| | | if (Quene.MissionQuene!=null)Quene.MissionQuene.Clear(); |
| | | if (Quene.MissionQuene != null) Quene.MissionQuene = new ConcurrentQueue<calcParam>();//.Clear(); |
| | | if (CSM != null) |
| | | { |
| | | foreach (var name in ChildSolutionName) |
| | |
| | | EPAController.Close(); |
| | | } |
| | | |
| | | if (workerThread!=null) |
| | | workerThread.Abort(); |
| | | //if (workerThread!=null) |
| | | //workerThread.Abort(); |
| | | |
| | | |
| | | if (CSM!=null) |
| | |
| | | { |
| | | var accuracy = double.Parse(host.Ext.accurary == "" ? "0.1" : host.Ext.accurary); |
| | | var doubleRange = new DRange(double.Parse(host.Expression.Split(',')[0]), double.Parse(host.Expression.Split(',')[1])); |
| | | host.Ext.doubleRange = doubleRange; |
| | | var v = GetVarByHost(host, accuracy, doubleRange); |
| | | param.试算变量.Add(v); |
| | | } |
| | |
| | | // sort = o.Sort, |
| | | //} |
| | | }; |
| | | param.表达式.Add(v); |
| | | param.OFunction = OFunction; |
| | | } |
| | | |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static string UpdateExpress(LogicModelParams param, HashSet<int> list_express) |
| | | { |
| | | //if (host.ExpressionType == "表达式计算") |
| | | |
| | | return HydraulicHelper.CreateExpressAssembly(param); |
| | | |
| | | |
| | | //var resultBuilder=new StringBuilder(); |
| | | //var flag=true; |
| | | //param.表达式.ForEach(s => |
| | | //{ |
| | | // string text = HydraulicHelper.GetExVarText(s, param, result); |
| | | // if (!list_express.Contains(s.ID)) return; |
| | | // string text = HydraulicHelper.GetExVarText(s, param, resultBuilder); |
| | | // if (resultBuilder.Length != 0) |
| | | // { |
| | | // flag = false; |
| | | // return; |
| | | // } |
| | | // try |
| | | // { |
| | | // Eval val = new Hydro.CodeProvider.Eval(text, s.Vars.Count); |
| | | // if (!val.isInit) { result.AppendLine($"表达式[{s.Name}]公式错误," + val.errString); } |
| | | // if (!val.isInit) { resultBuilder.AppendLine($"表达式[{s.Name}]公式错误," + val.errString); } |
| | | // s.Eval = val; |
| | | // s.Value_Set(param.Period, double.NaN); |
| | | // } |
| | | // catch (Exception ee) |
| | | // catch (Exception e) |
| | | // { |
| | | // { result.AppendLine(ee.Message); } |
| | | // resultBuilder.AppendLine(e.Message); |
| | | // flag = false; |
| | | // return; |
| | | // } |
| | | //}); |
| | | |
| | | //} |
| | | var resultBuilder=new StringBuilder(); |
| | | var flag=true; |
| | | param.表达式.ForEach(s => |
| | | { |
| | | if (!list_express.Contains(s.ID)) return; |
| | | string text = HydraulicHelper.GetExVarText(s, param, resultBuilder); |
| | | if (resultBuilder.Length != 0) |
| | | { |
| | | flag = false; |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | Eval val = new Hydro.CodeProvider.Eval(text, s.Vars.Count); |
| | | if (!val.isInit) { resultBuilder.AppendLine($"表达式[{s.Name}]公式错误," + val.errString); } |
| | | s.Eval = val; |
| | | s.Value_Set(param.Period, double.NaN); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | resultBuilder.AppendLine(e.Message); |
| | | flag = false; |
| | | return; |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | param.表达式.Sort((a, b) => a.Level > b.Level ? 1 : (a.Level == b.Level ? 0 : -1)); |
| | | return resultBuilder.ToString(); |
| | | //param.预处理插件.ForEach(v => |
| | | //{ |
| | | |
| | | // //BookMark :处理预处理插件 |
| | | // if (!flag) return; |
| | | // Eval val; |
| | | // val = new Eval(v.modelObjectID, EvalTemplate.TempCode_PreTreat); |
| | | // if (val.errString != null) { resultBuilder.AppendLine( $"预处理插件[{v.Name}]函数编写错误," + val.errString); flag = false; return; } |
| | | // v.Eval = val; |
| | | //}); |
| | | |
| | | |
| | | //param.表达式.Sort((a, b) => a.Level > b.Level ? 1 : (a.Level == b.Level ? 0 : -1)); |
| | | //return resultBuilder.ToString(); |
| | | } |
| | | public static HashSet<int> UpdateVarByHost(variable s,LogicPoint host,LogicModelParams param,bool isDelete=false) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | if (host.ExpressionType == "表达式计算") |
| | | if (host.LogicType == "表达式" || host.LogicType=="预处理插件") |
| | | { |
| | | list_express.Add(s.ID); |
| | | } |
| | |
| | | logicType = host.LogicType, |
| | | accuracy = accuracy, |
| | | doubleRange = doubleRange, |
| | | isInput = variable.list_输入值.Contains(host.ExpressionType), |
| | | AnFrom = host.Ext.AnFrom, |
| | | AnValue =host.Ext.AnValue, |
| | | MuRange =host.Ext.MuRange, |
| | | MuRate =host.Ext.MuRate, |
| | | |
| | | }; |
| | | |
| | | |
| | |
| | | public static void UpdateVarByHost(variable v,LogicPoint host, double? accuracy = null, DRange doubleRange = null) |
| | | { |
| | | double d; |
| | | var s= GetVarByHost(host, accuracy, doubleRange); |
| | | v.ID = s.ID; |
| | | v.modelObjectID = s.modelObjectID; |
| | | v.IndicatorType = s.IndicatorType; |
| | | v.Type = s.Type; |
| | | v.Name = s.Name; |
| | | v.expressType = s.expressType; |
| | | v.expressString = s.expressString; |
| | | v.Tag = s.Tag; |
| | | v.arrgFuncType = s.arrgFuncType; |
| | | v.defaultExpress = s.defaultExpress; |
| | | v.isNode = s.isNode; |
| | | v.ObjType = s.ObjType; |
| | | v.小数位数 = s.小数位数; |
| | | v.childSolution = s.childSolution; |
| | | v.childTag = s.childTag; |
| | | v.childType = s.childType; |
| | | v.SearchRange = s.SearchRange; |
| | | v.isNeedToSave = s.isNeedToSave; |
| | | v.SaveKey = s.SaveKey; |
| | | v.sort = s.sort; |
| | | v.logicType = s.logicType; |
| | | v.accuracy = s.accuracy; |
| | | v.doubleRange = s.doubleRange; |
| | | v.isInput = s.isInput; |
| | | v.AnFrom = s.AnFrom; |
| | | v.AnValue = s.AnValue; |
| | | v.MuRange = s.MuRange; |
| | | v.MuRate = s.MuRate; |
| | | |
| | | /*[Cloudflight修改]2024-5-21 |
| | | * 迁移方法--集合 |
| | | */ |
| | | if (host.LogicType == "集合") |
| | | { |
| | | List<string> list = new List<string>() { "最大值", "最小值", "平均值", "累计值", "计数" }; |
| | | if (list.IndexOf(host.ExpressionType) >= 0) |
| | | { |
| | | host.accurary = host.ExpressionType; |
| | | host.ExpressionType = "计算值"; |
| | | } |
| | | } |
| | | //if (host.LogicType == "集合") |
| | | //{ |
| | | // List<string> list = new List<string>() { "最大值", "最小值", "平均值", "累计值", "计数" }; |
| | | // if (list.IndexOf(host.ExpressionType) >= 0) |
| | | // { |
| | | // host.accurary = host.ExpressionType; |
| | | // host.ExpressionType = "计算值"; |
| | | // } |
| | | //} |
| | | |
| | | |
| | | //if (!GlobalModel.dict_StringToType.ContainsKey(host.IndicatorType)) GlobalModel.dict_StringToType[host.IndicatorType] = (GlobalModel.DEFINE_INDICATOR.Find(ind => ind.Name == host.IndicatorType) ?? new TypeIndicator()).Type; |
| | | //var VarType = GlobalModel.dict_StringToType[host.IndicatorType]; |
| | | |
| | | //if (!GlobalModel.dict_StringToObjType.ContainsKey(host.Ext.ObjectType)) GlobalModel.dict_StringToObjType[host.Ext.ObjectType] = (int)(GlobalModel.DEFINE_OBJECT.Find(obj => obj.Name == host.Ext.ObjectType) ?? new TypeObject()).Type; |
| | | //int ObjType =GlobalModel.dict_StringToObjType[host.Ext.ObjectType]; |
| | | |
| | | //if (!GlobalModel.dict_StringToisNode.ContainsKey(host.IndicatorType)) GlobalModel.dict_StringToisNode[host.IndicatorType] = (GlobalModel.DEFINE_INDICATOR.Find(ind => ind.Name == host.IndicatorType) ?? new TypeIndicator()).isNode; |
| | | //bool isNode = GlobalModel.dict_StringToisNode[host.IndicatorType]; |
| | | |
| | | //if (!GlobalModel.dict_StringToFuncType.ContainsKey(host.Ext.accurary)) GlobalModel.dict_StringToFuncType[host.Ext.accurary] = GlobalModel.DEFIND_AGGFUNC.FindIndex(func => func.Name == host.Ext.accurary); |
| | | //int arrgFuncType = GlobalModel.dict_StringToFuncType[host.Ext.accurary]; |
| | | |
| | | dynamic VarType = HydraulicInputType.None; |
| | | if (GlobalModel.dict_StringToType.TryGetValue(host.IndicatorType, out dynamic vartype)) |
| | | VarType = vartype; |
| | | |
| | | |
| | | int ObjType = 0; |
| | | if (GlobalModel.dict_StringToObjType.TryGetValue(host.Ext.ObjectType, out int objType)) |
| | | ObjType = objType; |
| | | //dynamic VarType = HydraulicInputType.None; |
| | | //if (GlobalModel.dict_StringToType.TryGetValue(host.IndicatorType, out dynamic vartype)) |
| | | // VarType = vartype; |
| | | |
| | | |
| | | bool isNode = true; |
| | | if (GlobalModel.dict_StringToisNode.TryGetValue(host.IndicatorType, out bool isnode)) |
| | | isNode = isnode; |
| | | //int ObjType = 0; |
| | | //if (GlobalModel.dict_StringToObjType.TryGetValue(host.Ext.ObjectType, out int objType)) |
| | | // ObjType = objType; |
| | | |
| | | |
| | | int arrgFuncType = -1; |
| | | if (GlobalModel.dict_StringToFuncType.TryGetValue(host.Ext.accurary, out int FuncInt)) |
| | | arrgFuncType = FuncInt; |
| | | //bool isNode = true; |
| | | //if (GlobalModel.dict_StringToisNode.TryGetValue(host.IndicatorType, out bool isnode)) |
| | | // isNode = isnode; |
| | | |
| | | |
| | | v.ID = host.Id; |
| | | v.modelObjectID = host.ModelObjectID; |
| | | v.IndicatorType = host.IndicatorType; |
| | | v.Type = VarType; |
| | | v.Name = host.Name; |
| | | v.expressType = host.ExpressionType; |
| | | v.expressString = host.Expression; |
| | | v.Tag = host.Ext.Tag; |
| | | v.arrgFuncType = arrgFuncType; |
| | | v.defaultExpress = host.Ext.accurary; |
| | | v.isNode = isNode; |
| | | v.ObjType = (int)ObjType; |
| | | v.小数位数 = host.Ext.小数位数; |
| | | v.childSolution = host.Ext.childSolution; |
| | | v.childTag = host.Ext.childTag; |
| | | v.childType = host.Ext.childType; |
| | | v.SearchRange = double.TryParse(host.Ext.SaveAcc, out d) ? d : 0; |
| | | v.isNeedToSave = host.Ext.isSave == "是" ? true : false; |
| | | v.SaveKey = host.Ext.SaveRange; |
| | | v.sort = host.Sort; |
| | | v.logicType = host.LogicType; |
| | | v.accuracy = accuracy; |
| | | v.doubleRange = doubleRange; |
| | | //int arrgFuncType = -1; |
| | | //if (GlobalModel.dict_StringToFuncType.TryGetValue(host.Ext.accurary, out int FuncInt)) |
| | | // arrgFuncType = FuncInt; |
| | | |
| | | |
| | | //v.ID = host.Id; |
| | | //v.modelObjectID = host.ModelObjectID; |
| | | //v.IndicatorType = host.IndicatorType; |
| | | //v.Type = VarType; |
| | | //v.Name = host.Name; |
| | | //v.expressType = host.ExpressionType; |
| | | //v.expressString = host.Expression; |
| | | //v.Tag = host.Ext.Tag; |
| | | //v.arrgFuncType = arrgFuncType; |
| | | //v.defaultExpress = host.Ext.accurary; |
| | | //v.isNode = isNode; |
| | | //v.ObjType = (int)ObjType; |
| | | //v.小数位数 = host.Ext.小数位数; |
| | | //v.childSolution = host.Ext.childSolution; |
| | | //v.childTag = host.Ext.childTag; |
| | | //v.childType = host.Ext.childType; |
| | | //v.SearchRange = double.TryParse(host.Ext.SaveAcc, out d) ? d : 0; |
| | | //v.isNeedToSave = host.Ext.isSave == "是" ? true : false; |
| | | //v.SaveKey = host.Ext.SaveRange; |
| | | //v.sort = host.Sort; |
| | | //v.logicType = host.LogicType; |
| | | //v.accuracy = accuracy; |
| | | //v.doubleRange = doubleRange; |
| | | //v.isInput = variable.list_输入值.Contains(host.ExpressionType); |
| | | //v.AnFrom = host.Ext.AnFrom; |
| | | //v.AnValue=host.Ext.AnValue; |
| | | //v.MuRange=host.Ext.MuRange; |
| | | //v.MuRate=host.Ext.MuRate; |
| | | } |
| | | |
| | | private string loadGeneticParam(FinishEvent onFinished, FinishEvent onError, FinishEvent onReportProgress, SetEvent SetVarsMethod) |
| | | { |
| | | |
| | | |
| | | //string result = null; |
| | | |
| | | |
| | | //DLengths.ForEach(m => chromosomeLength += m); |
| | | |
| | | #if DEBUG |
| | | Eval.本地项目编译=gParam.GlobalConfig.Ext.本地项目编译; |
| | | #endif |
| | | gParam.populationSize = gParam.GlobalConfig.Ext.populationNum; |
| | | gParam.iterations = gParam.GlobalConfig.Ext.iterationNum; |
| | | gParam.populationSize_full = gParam.GlobalConfig.Ext.populationNum_full; |
| | | gParam.populationSize_min = gParam.GlobalConfig.Ext.populationNum_full; |
| | | gParam.iterations_full = gParam.GlobalConfig.Ext.iterationNum_full; |
| | | |
| | | |
| | | gParam.selectionMethod = 0; |
| | | gParam.optimizationMode = param.OFunction.ExpressType=="最大"?1:0; |
| | | gParam.强制重计算 = gParam.GlobalConfig.Ext.是否优选方案; |
| | | |
| | | gParam.iterations_min = gParam.GlobalConfig.Ext.iterationNum_Min; |
| | | //gParam.MultiTimes = gParam.GlobalConfig.Ext.MultiTimes; |
| | | |
| | | |
| | | //gParam.accuracyNum = accuracyNum; |
| | | |
| | | //gParam.onReportProgress += OnReportProgress; |
| | | //gParam.onFinished += ControlunLocking; |
| | | //gParam.onError += ControlunLocking; |
| | | //EPAController = new EPAParrelController(); |
| | | //EPAController.gParam = gParam; |
| | | //Ehelper.SearchSolution(); |
| | | gParam.onReportProgress = onReportProgress; |
| | | gParam.onFinished = onFinished; |
| | | gParam.onError = onError; |
| | |
| | | { |
| | | string savePath = GlobalPath.savePath + $@"\{solution.存储位置}"; |
| | | var settings = gParam.GlobalConfig.saveSettings[key] = solution.settings; |
| | | //kp.Value.saveSettings = solution.settings; |
| | | settings.savePath = savePath; |
| | | //if (!isGUILoading) |
| | | //{ |
| | | // if (File.Exists(savePath)) |
| | | // { |
| | | // settings.saveDatas = Base64Helper.ReadCompressedBase64FromFile<SaveDict>(savePath); |
| | | // } |
| | | // else |
| | | // { |
| | | // settings.saveDatas = new SaveDict(); |
| | | // } |
| | | //} |
| | | |
| | | |
| | | } |
| | | }); |
| | |
| | | |
| | | } |
| | | |
| | | private string load试算参数_gParam() |
| | | { |
| | | var ranges = new List<DRange>(); |
| | | var accuracys = new List<Double?>(); |
| | | var DLengths = new List<int>(); |
| | | //chromosomeLength = 0; |
| | | param.试算变量.ForEach(v => |
| | | { |
| | | ranges.Add(v.doubleRange); |
| | | DLengths.Add(getDLength(v.doubleRange, v.accuracy)); |
| | | accuracys.Add(v.accuracy); |
| | | }); |
| | | gParam.ranges = ranges; |
| | | gParam.DLengths = DLengths; |
| | | gParam.accuracys = accuracys; |
| | | return null; |
| | | } |
| | | |
| | | |
| | | int getDLength(DRange dr, double? accur) |
| | | { |
| | | if (accur == null) accur = 0.1; |
| | | var num_Total = dr.Length / (double)accur; |
| | | var Dlength = 0; |
| | | var value = 1; |
| | | var i = 0; |
| | | //判断需要多少位二进制数 |
| | | Dlength=Math.Log(num_Total, 2) > 0 ? (int)Math.Ceiling( Math.Log(num_Total, 2)) : 0; |
| | | //while (value <= num_Total && i < 1000) |
| | | //{ |
| | | // value *= 2; |
| | | // Dlength += 1; |
| | | // i++; |
| | | //} |
| | | return Dlength; |
| | | } |
| | | |
| | | |
| | | private string controllerInit(bool isGUI=false,WdnmoParam wParam=null) |
| | | { |
| | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |