using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using AForge;
|
using System.Drawing;
|
using System.Text.RegularExpressions;
|
using AForge.Genetic;
|
//using NPOI.SS.Formula.Eval;
|
using System.Runtime.Serialization;
|
using Newtonsoft.Json;
|
using System.Collections.Concurrent;
|
using Dapper;
|
using NPOI.SS.Formula.Functions;
|
//using NPOI.Util.Collections;
|
|
namespace Hydro.CommonBase
|
{
|
[Serializable]
|
public class GeneticParams
|
{
|
static int Count = 0;
|
public GeneticParams(int Level)
|
{
|
this.Level = Level;
|
this.ID = Count;
|
Count++;
|
}
|
|
public void Init(string ConfigPath)
|
{
|
if (Db == null) Db = new Db();
|
if (!string.IsNullOrEmpty(ConfigPath)) Db.Init(ConfigPath);
|
if (Quene!=null) Quene.Dispose();
|
Quene = new Quene();
|
this.Quene= Quene;
|
//»ñȡȫ¾ÖĬÈÏÉèÖÃ
|
var globalConfig = Db.Connection.QueryFirstOrDefault<string>("SELECT FValue FROM MyConfig WHERE FKey='GlobalConfig'");
|
GlobalConfig = JsonConvert.DeserializeObject<GlobalConfig>(globalConfig) ?? new GlobalConfig();
|
this.GlobalConfig = GlobalConfig;
|
isInited = true;
|
//return gParam;
|
}
|
public void Dispose()
|
{
|
onReportProgress = null;
|
Db.Close();
|
Db = null;
|
|
}
|
|
|
public List<double> list_BestEnerge;
|
public List<double> list_AvgHz;
|
public List<DRange> ranges;
|
public List<int> DLengths;
|
public List<double?> accuracys;
|
public List<int> Dependencies;
|
public double[] list_AtemtpArr;
|
|
public string SolutionSaveName;
|
public int populationSize;
|
public int iterations;
|
public int populationSize_full;
|
public int iterations_full;
|
public List<ulong> Upopulations = null;
|
|
|
public int selectionMethod;
|
public int optimizationMode;
|
public bool Ç¿ÖÆÖØ¼ÆËã;
|
|
public int iterations_min;
|
public double accuracyNum;
|
//public int MultiTimes=0;
|
|
public int MaxRobot;
|
public int RuningRobot;
|
|
public int num;
|
public double BestOptValue;
|
public DRange tolerance;
|
public FinishEvent onFinished;
|
public FinishEvent onError;
|
public FinishEvent onReportProgress;
|
public SetEvent setVars;
|
|
public Db Db;
|
public dynamic SolutionDBHelper = null;
|
public GlobalConfig GlobalConfig;
|
public bool isInited=false;
|
public Quene Quene;
|
public int Level;
|
public int ID;
|
|
public bool isNeedOutput = true;
|
|
public double CurrentTotalDemand = -1;
|
public GeneticParams DeepCopy()
|
{
|
var copy = new GeneticParams(this.Level);
|
copy.list_BestEnerge = this.list_BestEnerge?.ToList();
|
copy.list_AvgHz = this.list_AvgHz?.ToList();
|
copy.ranges = this.ranges?.Select(range => new DRange(range.Min, range.Max))?.ToList();
|
copy.DLengths = this.DLengths?.ToList();
|
copy.accuracys = this.accuracys?.ToList();
|
copy.Dependencies = this.Dependencies?.ToList();
|
copy.list_AtemtpArr = this.list_AtemtpArr?.ToArray();
|
copy.SolutionSaveName = this.SolutionSaveName;
|
copy.populationSize = this.populationSize;
|
copy.iterations = this.iterations;
|
copy.populationSize_full = this.populationSize_full;
|
copy.iterations_full = this.iterations_full;
|
copy.Upopulations = this.Upopulations?.ToList();
|
copy.selectionMethod = this.selectionMethod;
|
copy.optimizationMode = this.optimizationMode;
|
copy.Ç¿ÖÆÖØ¼ÆËã = this.Ç¿ÖÆÖØ¼ÆËã;
|
copy.iterations_min = this.iterations_min;
|
copy.accuracyNum = this.accuracyNum;
|
copy.MaxRobot = this.MaxRobot;
|
copy.RuningRobot = this.RuningRobot;
|
copy.num = this.num;
|
copy.BestOptValue = this.BestOptValue;
|
copy.tolerance = tolerance==null?null: new DRange(this.tolerance.Min, this.tolerance.Max);
|
copy.onFinished = this.onFinished;
|
copy.onError = this.onError;
|
copy.onReportProgress = this.onReportProgress;
|
copy.setVars = this.setVars;
|
copy.Db = this.Db; // Assuming Db is a reference type
|
copy.SolutionDBHelper = this.SolutionDBHelper; // Assuming SolutionDBHelper is a reference type
|
copy.GlobalConfig = this.GlobalConfig.DeepCopyByBin<GlobalConfig>(); // Assuming GlobalConfig has a copy constructor
|
copy.isInited = this.isInited;
|
copy.Quene = this.Quene; // Assuming Quene has a copy constructor
|
copy.ID = this.ID;
|
copy.isNeedOutput = this.isNeedOutput;
|
copy.CurrentTotalDemand = this.CurrentTotalDemand;
|
|
return copy;
|
}
|
}
|
public class Result
|
{
|
public double[] arrayTryValue = null;
|
public float Demand;
|
public double ObjFunctionValue;
|
public int it_Times = 0;
|
public dict<long, int> unitNum = null;
|
}
|
public class uvalue
|
{
|
public uvalue(int UID, double value)
|
{
|
this.UID = UID;
|
this.value = value;
|
}
|
public int UID;
|
public double value;
|
}
|
public class Quene
|
{
|
|
public System.Collections.Generic.Queue<WdnmoParam> RequestQueues;
|
public HashSet<Guid> RequestFinished;
|
public Dictionary<ulong, double> ResultHash;
|
public int Level;
|
public Dictionary<Guid, double?> ResultDictionary;
|
public Dictionary<Guid, ChromosomeBase> ResultChrome;
|
public int MissionQueneCount;
|
public List<calcParam> MissionQuene;
|
public DateTime ScadaTime;
|
//public List<TimePoint> TimePoints;
|
public double BestResult=double.MaxValue;
|
public void Dispose()
|
{
|
if (RequestQueues != null)
|
{
|
RequestQueues.Clear();
|
RequestQueues = null;
|
}
|
if (RequestFinished != null)
|
{
|
RequestFinished.Clear();
|
RequestFinished = null;
|
}
|
|
if (ResultHash != null)
|
{
|
ResultHash.Clear();
|
ResultHash = null;
|
}
|
if (ResultDictionary != null)
|
{
|
ResultDictionary.Clear();
|
ResultDictionary = null;
|
}
|
if (ResultChrome != null)
|
{
|
ResultChrome.Clear();
|
ResultChrome = null;
|
}
|
if (MissionQuene != null)
|
{
|
MissionQuene.Clear();
|
MissionQuene = null;
|
}
|
|
|
}
|
}
|
[Serializable]
|
public class UvalueSetting
|
{
|
public UvalueSetting(long uID, double min, double max)
|
{
|
this.ID = uID;
|
Min = min;
|
Max = max;
|
}
|
public double Min;
|
public double Max;
|
public long ID;
|
}
|
public class USetting
|
{
|
public string Name;
|
public int ID;
|
public List<Ivariable> VSet;
|
public List<UvalueSetting> UList;
|
public float TotalDemand;
|
}
|
public class vSet
|
{
|
public string Name;
|
public string Tag;
|
public bool isNode=true;
|
public List<string> IDs;
|
|
public int ID;
|
public string defaultExpress;
|
|
public string IndicatorType;
|
public string ObjectType;
|
}
|
public class WdnmoParam
|
{
|
|
public List<Result> results;
|
public double DistriDemand;
|
|
public List<vSet> VarSets_Import = new List<vSet>();
|
public List<variable> Vars_Import = new List<variable>();
|
public Guid ID;
|
public List<TimePoint> ScadaPoints { get; set; } = new List<TimePoint>();
|
public List<TimePoint> ConfigPoints { get; set; } = new List<TimePoint>();
|
public List<TimePoint> ResultPoints { get; set; } = new List<TimePoint>();
|
[JsonIgnore]
|
public Dictionary<string, double> dict_ScadaPoints = null;
|
[JsonIgnore]
|
public Dictionary<string, double> dict_ConfigPoints = null;
|
[JsonIgnore]
|
public Dictionary<string, double> dict_ResultPoints = null;
|
[JsonIgnore]
|
public Dictionary<string, double[]> dict_ScadaPointsPattern = null;
|
public Dictionary<string, double[]> dict_ConfigPointsPattern = null;
|
public Dictionary<string, double[]> dict_ResultPointsPattern = null;
|
|
public bool isBuildDict = false;
|
public void buildDict()
|
{
|
dict_ScadaPoints=new Dictionary<string, double>();
|
dict_ScadaPointsPattern = new Dictionary<string, double[]>();
|
ScadaPoints.ForEach(vv =>
|
{
|
if (!string.IsNullOrEmpty(vv.Key) && !dict_ScadaPoints.ContainsKey(vv.Key))
|
{
|
dict_ScadaPoints.Add(vv.Key, vv.Value);
|
if (vv.Pattern!=null)
|
{
|
dict_ScadaPointsPattern.Add(vv.Key, vv.Pattern);
|
}
|
}
|
});
|
|
dict_ConfigPoints = new Dictionary<string, double>();
|
dict_ConfigPointsPattern = new Dictionary<string, double[]>();
|
ConfigPoints.ForEach(vv =>
|
{
|
if (!string.IsNullOrEmpty(vv.Key) && !dict_ConfigPoints.ContainsKey(vv.Key))
|
{
|
dict_ConfigPoints.Add(vv.Key, vv.Value);
|
if (vv.Pattern != null)
|
{
|
dict_ConfigPointsPattern.Add(vv.Key, vv.Pattern);
|
}
|
}
|
});
|
|
|
dict_ResultPoints = new Dictionary<string, double>();
|
dict_ResultPointsPattern = new Dictionary<string, double[]>();
|
ResultPoints.ForEach(vv =>
|
{
|
if (!string.IsNullOrEmpty(vv.Key) && !dict_ResultPoints.ContainsKey(vv.Key))
|
{
|
dict_ResultPoints.Add(vv.Key, vv.Value);
|
if (vv.Pattern != null)
|
{
|
dict_ResultPointsPattern.Add(vv.Key, vv.Pattern);
|
}
|
}
|
});
|
isBuildDict = true;
|
}
|
public double Fitness = -1;
|
public DateTime time { get; set; } = default(DateTime);
|
//public int RunTimes = 0;
|
public int Period { get; set; } = 0;
|
public string ErrorMessage { get; set; } = null;
|
|
public bool fullSearchMode = false;
|
public FinishEvent onFinish;
|
public bool isNeedOutPut = false;
|
public Dictionary<string, double[]> ToSearchDict()
|
{
|
Dictionary<string, double[]> dict = new Dictionary<string, double[]>();
|
foreach (var point in ScadaPoints)
|
{
|
if (!dict.ContainsKey(point.Key))
|
dict.Add(point.Key, new double[] { point.Value - point.SearchRange / 2, point.Value + point.SearchRange / 2 });
|
else
|
dict[point.Key] = new double[] { point.Value - point.SearchRange / 2, point.Value + point.SearchRange / 2 };
|
}
|
if (!dict.ContainsKey("period"))
|
dict.Add("period", new double[] { Period - 8, Period + 8 });
|
else
|
dict["period"] = new double[] { Period - 8, Period + 8 };
|
return dict;
|
}
|
//public ulong Toulong(string childSaveName)
|
//{
|
|
//}
|
public string ToSearchSring()
|
{
|
Dictionary<string, double> dict = new Dictionary<string, double>();
|
|
foreach (var point in ScadaPoints)
|
{
|
if (!dict.ContainsKey(point.Key))
|
dict.Add(point.Key, point.Value);
|
else
|
dict[point.Key] = point.Value;
|
}
|
if (!dict.ContainsKey("period"))
|
dict.Add("period", Period);
|
StringBuilder sb = new StringBuilder();
|
foreach (var point in dict)
|
{
|
sb.AppendLine(point.Key + "\t" + point.Value);
|
}
|
return sb.ToString();
|
|
}
|
public Dictionary<string, double> ToResultDict()
|
{
|
Dictionary<string, double> dict = new Dictionary<string, double>();
|
foreach (var point in ScadaPoints)
|
{
|
if (!dict.ContainsKey(point.Key))
|
dict.Add(point.Key, point.Value);
|
else
|
dict[point.Key] = point.Value;
|
}
|
if (!dict.ContainsKey("period"))
|
dict.Add("period", Period);
|
else
|
dict["period"] = Period;
|
foreach (var point in ResultPoints)
|
{
|
if (!point.isNeedtoSave) continue;
|
if (!CheckExpandoVariableName(point.SaveKey)) continue;
|
if (!dict.ContainsKey(point.SaveKey))
|
{
|
dict.Add(point.SaveKey, point.Value);
|
}
|
else
|
dict[point.SaveKey] = point.Value;
|
}
|
return dict;
|
// ÖØÔØ == ÔËËã·û
|
|
}
|
private bool CheckExpandoVariableName(string name)
|
{
|
if (name == null) return false;
|
// ÕýÔò±í´ïʽ£ºÒÔ×Öĸ»òÏ»®Ïß¿ªÍ·£¬ºóÃæ¸ú×ÅÈÎÒâ¸ö×Öĸ¡¢Êý×Ö»òÏ»®Ïß
|
string pattern = @"^[a-zA-Z_]\w*$";
|
return Regex.IsMatch(name, pattern);
|
}
|
|
public void Dispose()
|
{
|
results?.Clear();
|
ScadaPoints?.Clear();
|
ConfigPoints?.Clear();
|
ResultPoints?.Clear();
|
onFinish = null;
|
}
|
|
public WdnmoParam Copy()
|
{
|
//»ñȡһ¸öеÄʵÀý£¬½«Õâ¸öÀàµÄÊôÐÔÖµ¸³Öµ¸øÐÂʵÀý
|
WdnmoParam v = new WdnmoParam();
|
v.ID = this.ID;
|
v.Fitness = this.Fitness;
|
v.time = this.time;
|
//v.RunTimes = this.RunTimes;
|
v.Period = this.Period;
|
v.ErrorMessage = this.ErrorMessage;
|
v.fullSearchMode = this.fullSearchMode;
|
v.onFinish = this.onFinish;
|
v.isNeedOutPut = this.isNeedOutPut;
|
v.results = this.results;
|
v.ScadaPoints = new List<TimePoint>();
|
foreach (var point in this.ScadaPoints)
|
{
|
v.ScadaPoints.Add(new TimePoint( point));
|
}
|
v.ConfigPoints = this.ConfigPoints;
|
v.ResultPoints = new List<TimePoint>();
|
foreach (var point in this.ResultPoints)
|
{
|
v.ResultPoints.Add(new TimePoint(point));
|
}
|
|
v.buildDict();
|
return v;
|
}
|
}
|
|
public class calcParam
|
{
|
|
public double[] vars;
|
|
public Guid ID;
|
|
public IChromosome chromosome;
|
|
public List<SetVar> setVars = new List<SetVar>();
|
|
}
|
public class SetVar
|
{
|
public string ID;
|
public bool isNode = true;
|
public int type;
|
public float value;
|
public SetVar(string ID,bool isNode,int type,float value)
|
{
|
this.ID= ID;
|
this.isNode = isNode;
|
this.type = type;
|
this.value = value;
|
}
|
}
|
|
[Serializable]
|
|
public class TimePoint
|
{
|
public TimePoint()
|
{
|
|
}
|
public TimePoint(string key, double value)
|
{
|
Key = key;
|
Value = value;
|
}
|
public TimePoint(TimePoint point)
|
{
|
this.Key= point.Key;
|
this.Value = point.Value;
|
this.Name = point.Name;
|
this.ValueTime = point.ValueTime;
|
this.SearchRange = point.SearchRange;
|
this.isNeedtoSave = point.isNeedtoSave;
|
this.SaveKey = point.SaveKey;
|
if (point.Pattern!=null) this.Pattern= point.Pattern.ToArray();
|
|
}
|
public string Name;
|
public DateTime ValueTime { get; set; }
|
public string Key { get; set; }
|
public double Value { get; set; }
|
public double[] Pattern { get; set; } = null;
|
|
public double SearchRange = 0;
|
|
public bool isNeedtoSave = false;
|
|
public string SaveKey = null;
|
|
public override string ToString()
|
{
|
return $"{Name}\t[{Key}]\t{Value}";
|
}
|
}
|
|
|
[Serializable]
|
public delegate void FinishEvent(dynamic txt);
|
public delegate void SetEvent(string name, WdnmoParam param);
|
//public event FinishEvent ss;
|
|
|
[Serializable]
|
|
public enum SettingCalcType
|
{
|
Add = 0,
|
Const = 1
|
}
|
|
|
|
[Serializable]
|
public class LogicModelParams
|
{
|
|
|
public Guid ID = new Guid();
|
public List<variable> ¼¯ºÏ = new List<variable>();
|
public List<variable> ³õʼÌõ¼þ = new List<variable>();
|
public List<variable> Ͻ׶ÎÌõ¼þ = new List<variable>();
|
public List<variable> Ô¼Êø±äÁ¿ = new List<variable>();
|
public List<variable> ÊÔËã±äÁ¿ = new List<variable>();
|
public List<variable> Ë®Á¿·ÖÅä±äÁ¿ = new List<variable>();
|
//public List<variable> Ë®Á¿·ÖÅ伯ºÏ = new List<variable>();
|
public List<variable> ±äÁ¿ = new List<variable>();
|
public List<variable> ±í´ïʽ = new List<variable>();
|
public List<variable> Ô¤´¦Àí²å¼þ = new List<variable>();
|
public List<variable> Êä³ö±äÁ¿
|
{
|
get
|
{
|
List<variable> all = new List<variable>();
|
all.AddRange(±äÁ¿);
|
all.AddRange(³õʼÌõ¼þ);
|
all.AddRange(Ͻ׶ÎÌõ¼þ);
|
all.AddRange(±í´ïʽ);
|
all.AddRange(Ë®Á¿·ÖÅä±äÁ¿);
|
all.AddRange(¼¯ºÏ);
|
return all;
|
}
|
}
|
public List<variable> ½Ó¿Ú±äÁ¿
|
{
|
get
|
{
|
List<variable> all = new List<variable>();
|
all.AddRange(±äÁ¿);
|
all.AddRange(³õʼÌõ¼þ);
|
all.AddRange(Ͻ׶ÎÌõ¼þ);
|
all.AddRange(±í´ïʽ);
|
all.AddRange(Ë®Á¿·ÖÅä±äÁ¿);
|
return all;
|
}
|
}
|
public List<variable> É趨±äÁ¿
|
{
|
get
|
{
|
List<variable> all = new List<variable>();
|
all.AddRange(³õʼÌõ¼þ);
|
all.AddRange(Ͻ׶ÎÌõ¼þ);
|
return all;
|
}
|
}
|
|
public List<variable> ±äÁ¿È«¼¯
|
{
|
get
|
{
|
List<variable> all = new List<variable>();
|
all.AddRange(³õʼÌõ¼þ);
|
all.AddRange(Ͻ׶ÎÌõ¼þ);
|
all.AddRange(±äÁ¿);
|
all.AddRange(ÊÔËã±äÁ¿);
|
all.AddRange(¼¯ºÏ);
|
all.AddRange(±í´ïʽ);
|
all.AddRange(Ô¼Êø±äÁ¿);
|
all.AddRange(Ë®Á¿·ÖÅä±äÁ¿);
|
//all.AddRange(Ë®Á¿·ÖÅ伯ºÏ);
|
all.AddRange(Ô¤´¦Àí²å¼þ);
|
if (OFunction?.variable!=null) all.Add(OFunction.variable);
|
|
return all;
|
}
|
}
|
//[NonSerialized]
|
[JsonIgnore]
|
public Dictionary<string, variable> dict_Name { get; set; }
|
//[NonSerialized]
|
[JsonIgnore]
|
public Dictionary<int, variable> dict_ID { get; set; }
|
public Dictionary<string, variable> dict_Tag { get; private set; }
|
|
//[NonSerialized]
|
/// <summary>
|
/// ´æ´¢Êä³ö±äÁ¿µÄË÷Òý£¬Èç¹ûValueµÄ³¤¶È>1£¬ÔòValue[0]Ϊ¸¸½Úµã±äÁ¿£¬Value[1]Ϊ×Ó½Úµã±äÁ¿
|
/// </summary>
|
[JsonIgnore]
|
public Dictionary<string, Ivariable[]> dict_OutPut { get; set; }
|
//public string inputFileString;
|
|
[JsonIgnore]
|
public dict<string,dict> map_node { get;set;}
|
[JsonIgnore]
|
public dict<string, dict> map_link { get; set; }
|
/// <summary>
|
/// µ±Ç°¼ÆËãʱ¿Ì£¬Ä¬ÈÏֵΪ0£»Í϶¯½ø¶ÈÌõ¿Ø¼þʱ£¬»áÐ޸ĵ±Ç°¼ÆËãʱ¿Ì£»
|
/// </summary>
|
public int Period { get; set; } = 0;
|
|
public void buildDict()
|
{
|
|
//BookMark £º½¨Á¢±äÁ¿×Öµä
|
dict_Name = new Dictionary<string, variable>();
|
dict_ID=new Dictionary<int, variable>();
|
dict_Tag=new Dictionary<string, variable>();
|
dict_OutPut = new Dictionary<string, Ivariable[]>();
|
|
±äÁ¿È«¼¯.ForEach(vv => { if (!string.IsNullOrEmpty(vv.Name) && !dict_Name.ContainsKey(vv.Name)) dict_Name.Add(vv.Name, vv); });
|
±äÁ¿È«¼¯.ForEach(vv => { if (!dict_ID.ContainsKey(vv.ID)) dict_ID.Add(vv.ID, vv); });
|
±äÁ¿È«¼¯.ForEach(vv => { if (!string.IsNullOrEmpty(vv.Tag) && !dict_Tag.ContainsKey(vv.Tag)) dict_Tag.Add(vv.Tag, vv); });
|
|
Êä³ö±äÁ¿.ForEach(vv =>
|
{
|
if (!string.IsNullOrEmpty(vv.Tag) && !dict_OutPut.ContainsKey(vv.Tag))
|
dict_OutPut.Add(vv.Tag, new Ivariable[] { vv });
|
if (!string.IsNullOrEmpty(vv.expressString) &&!dict_OutPut.ContainsKey(vv.expressString))
|
dict_OutPut.Add(vv.expressString,new Ivariable[] { vv });
|
});
|
|
}
|
|
[NonSerialized]
|
[JsonIgnore]
|
public Dictionary<string, childSolutionParam> ChildParam = new Dictionary<string, childSolutionParam>();
|
|
public OBJFunction OFunction;
|
public EN_Times ʱ¼ä¿Ì¶È;
|
//public List<PointF> results = new List<PointF>();
|
public List<Result> results;
|
//public int times;
|
|
public LogicModelParams CloneResult()
|
{
|
var param_new = new LogicModelParams();
|
±äÁ¿È«¼¯.ForEach(v => param_new.±äÁ¿È«¼¯.Add(new variable(v.PeriodCount) { ID = v.ID, Values_Set = v.Values, LogicValues = v.LogicValues, objListString = v.objListString }));
|
//³õʼÌõ¼þ.ForEach(v => param_new.³õʼÌõ¼þ.Add(new variable(v.PeriodCount) {ID=v.ID,Values_Set=v.Values,LogicValues=v.LogicValues,objListString=v.objListString })) ;
|
//Ͻ׶ÎÌõ¼þ.ForEach(v => param_new.Ͻ׶ÎÌõ¼þ.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
//Ô¼Êø±äÁ¿.ForEach(v => param_new.Ô¼Êø±äÁ¿.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
//ÊÔËã±äÁ¿.ForEach(v => param_new.ÊÔËã±äÁ¿.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
//Ë®Á¿·ÖÅä±äÁ¿.ForEach(v => param_new.Ë®Á¿·ÖÅä±äÁ¿.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
//Ë®Á¿·ÖÅ伯ºÏ.ForEach(v => param_new.Ë®Á¿·ÖÅ伯ºÏ.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
//±äÁ¿.ForEach(v => param_new.±äÁ¿.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
//¼¯ºÏ.ForEach(v => param_new.¼¯ºÏ.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
//±í´ïʽ.ForEach(v => param_new.±í´ïʽ.Add(new variable(v.PeriodCount) { ID = v.ID, Value_Set = v.Value0, LogicValue = v.LogicValue, objListString = v.objListString }));
|
param_new.OFunction = new OBJFunction();
|
param_new.OFunction.value = OFunction.value;
|
param_new.buildDict();
|
return param_new;
|
}
|
|
}
|
/// <summary>
|
/// ×Ó·½°¸²ÎÊý¼¯
|
/// </summary>
|
public class childSolutionParam
|
{
|
/// <summary>
|
///¼ÆËã²ÎÊý
|
/// </summary>
|
public WdnmoParam wParam;
|
public List<variable> childVars_In;
|
public List<variable> childVars_Out;
|
public string childSaveName;
|
public variable childFitness_Out;
|
//public SaveSettings saveSettings;
|
//public string savePath;
|
}
|
public class EN_Times
|
{
|
public int duration;
|
public int step;
|
public int Ntimes;
|
}
|
public interface Ivariable
|
{
|
|
//bool isNode { get; set; }
|
//string modelObjectID { get; set; }
|
int modelIndex { get; set; }
|
|
//string expressType { get; set; }
|
}
|
public class VarSimple: Ivariable
|
{
|
|
//public bool isNode { get; set; }
|
//public string modelObjectID { get;set; }
|
public int modelIndex { get; set; }
|
|
//public string expressType { get; set; }
|
}
|
|
public class VarDistri : Ivariable
|
{
|
public string modelObjectID { get; set; }
|
public int modelIndex { get; set; }
|
//public bool isNode { get; set; }
|
public List<uvalue> uvalues { get; set; } = null;
|
}
|
|
[Serializable]
|
public class variable: Ivariable
|
{
|
public static List<string> list_indicatorTypeName
|
{
|
get
|
{
|
if (_list_indicatorTypeName == null)
|
{
|
_list_indicatorTypeName = new List<string>() { "ÒÑ֪ѹÁ¦", "½ÚµãÓÃË®Á¿", "½ÚµãÓÃˮģʽ", "Ë®³ØË®Î»", "Ë®±ÃתËÙ±È", "¹ÜÏß×èÁ¦ÏµÊý", "·§ÃÅ¿ª¶È", "Ë®±Ã¿ª¹Ø", "·§ÃÅ¿ª¹Ø", "¹ÜÏß¿ª¹Ø", "¹ÜÏßÖ±¾¶", "¹ÜÏß³¤¶È", "×ÜË®Á¿", "½ÚµãѹÁ¦", "½Úµã×ÔÓÉѹÁ¦", "½ÚµãÐèË®Á¿", "½Úµã±ê¸ß", "½ÚµãË®Áä", "½ÚµãË®ÖÊ", "¹ÜÏßÁ÷Á¿", "¹ÜÏßÁ÷ËÙ", "ˮͷËðʧ", "µ±Ç°×´Ì¬", "Ë®±ÃÄܺÄ", "Ë®±Ã¿ª¹Ø", "Ë®±ÃתËÙ±È", "³õʼ¼°ÔËÐд«²Î", "³õʼ´«²Î", "ÔËÐд«²Î", "ÖÖȺÉú³ÉÆ÷", "·½°¸É¸Ñ¡Æ÷", "¼ÆËãǰ´¦Àí", "½á¹û´¦Àí", "µ±Á¿·ÖÅä", "Ëæ»ú·ÖÅä" };
|
}
|
return _list_indicatorTypeName;
|
}
|
|
|
}
|
|
private static List<string> _list_indicatorTypeName = null;
|
public static List<string> listUsedInitValue = new List<string>() { "³õʼ¼ÆËãÖµ", "±ä»¯Öµ", "¾ø¶Ô±ä»¯Öµ" };
|
//public static List<string> list_ÊäÈëÖµ = new List<string>() { "»ù×¼Öµ(½çÃæ)", "¶¨ÒåÖµ", "»ù×¼Öµ(½Ó¿Ú)", "ģʽϵÊý(½çÃæ)", "ģʽϵÊý(½Ó¿Ú)" };
|
public static HashSet<string> list_ÊäÈëÖµ = new HashSet<string>() { "»ù×¼Öµ(½çÃæ)", "¶¨ÒåÖµ", "»ù×¼Öµ(½Ó¿Ú)", "ģʽϵÊý(½çÃæ)", "ģʽϵÊý(½Ó¿Ú)" };
|
public static List<string> listUsedScadaValue = new List<string> { "¶¨ÒåÖµ", "»ù×¼Öµ(½Ó¿Ú)" };
|
|
public static List<string> list_½Ó¿ÚÊä³öÖµ = new List<string>() { "±í´ïʽ¼ÆËã", "¼ÆËãÖµ", "±ä»¯Öµ", "³õʼ¼ÆËãÖµ", "×Ó·½°¸Öµ" };
|
public static List<string> list_½Ó¿ÚÊäÈëÖµ = new List<string>() { "»ù×¼Öµ(½Ó¿Ú)", "ģʽϵÊý(½Ó¿Ú)" };
|
|
public static List<string> list_NoNeedModelIndex = new List<string>() { "»ù×¼Öµ(½çÃæ)", "¶¨ÒåÖµ", "»ù×¼Öµ(½Ó¿Ú)", "ģʽϵÊý(½çÃæ)", "ģʽϵÊý(½Ó¿Ú)" };
|
public int ID;
|
public string modelObjectID { get; set; }
|
public string Name;
|
public int modelIndex { get; set; }
|
public int PeriodCount
|
{
|
get
|
{
|
return _Values.Length;
|
}
|
set
|
{
|
|
LogicValues=new double[value];
|
//³õʼֵÉèÖÃΪdouble.NaN
|
for (int i = 0; i < value; i++)
|
{
|
LogicValues[i] = double.NaN;
|
}
|
_Values = new double[value];
|
//³õʼֵÉèÖÃΪdouble.NaN
|
for (int i = 0; i < value; i++)
|
{
|
_Values[i] = double.NaN;
|
}
|
}
|
}
|
|
public variable(int maxTimes=1)
|
{
|
this.PeriodCount = maxTimes;
|
}
|
|
//CFÐÞ¶© 2023Äê7ÔÂ10ÈÕ ´¦ÀíÐòÁл¯Ê§°ÜµÄÎÊÌâ
|
|
[NonSerialized]
|
public List<Ivariable> Vars = new List<Ivariable>();
|
|
/// <summary>
|
/// ÓÃÀ´×÷Ϊ±äÁ¿µÄÆ«ÒÆË÷ÒýµÄ¾²Ì¬Öµ£¬ÀýÈçfixNum+1,fixNum+2,fixNum+3·Ö±ð´ú±íºóһλ¡¢ºóÁ½Î»¡¢ºóÈý룬fixNum-1´ú±íǰһλ
|
/// </summary>
|
public static int fixNum { get; set; } = -1000000;
|
/// <summary>
|
/// ×÷ΪPatternVarsµÄË÷Òý
|
/// </summary>
|
[NonSerialized]
|
public Dictionary<int, int> VarIndexs = new Dictionary<int, int>();
|
/// <summary>
|
/// ¼Ç¼ÐèÒªµ÷ÓõÄPatternVars
|
/// </summary>
|
[NonSerialized]
|
public List<variable> PatternVars = new List<variable>();
|
|
// public int ParentID;
|
public bool isInput
|
{
|
get;
|
private set;
|
} = false;
|
public bool isNode { get; set; }
|
//public bool? isOutput;
|
public dynamic Type { get; set; }
|
public dynamic resultType;
|
public DRange doubleRange;
|
|
public double? accuracy = null;
|
public string expressString;
|
public string expressType { get; set; }
|
public int arrgFuncType;
|
public string defaultExpress;
|
private int _indicatorType;
|
|
public string IndicatorType
|
{
|
get
|
{
|
|
if (_indicatorType<0)
|
{
|
return list_indicatorTypeName[0];
|
}
|
else
|
return list_indicatorTypeName[_indicatorType];
|
}
|
set
|
{
|
if (list_indicatorTypeName == null) return;
|
_indicatorType = list_indicatorTypeName.IndexOf(value);
|
}
|
}
|
/// <summary>
|
/// ÖµµÄÀàÐÍ£¬Êǵ¥Öµ»¹ÊÇÊý×飬½öÕë¶Ô³õʼÌõ¼þ
|
/// </summary>
|
public bool isArrInput { get; set; } = false;
|
|
|
public int ObjType;
|
public string logicType;
|
|
|
#region ºËÐijÐÔØ±äÁ¿
|
/// <summary>
|
/// ÊýѧģÐÍÄ¿±êÖµ¶àʱ¿Ì
|
/// </summary>
|
private double[] _Values = null;
|
|
public double[] Values
|
{
|
get
|
{
|
return _Values;
|
}
|
private set
|
{
|
_Values = value;
|
}
|
}
|
|
/// <summary>
|
/// ³õʼ״̬¼ÆËãÖµ
|
/// </summary>
|
public double CalcValue_Init { get; set; }
|
#endregion
|
|
|
#region ¸¨Öú±äÁ¿ÊôÐÔ
|
/// <summary>
|
/// É趨ֵ£¨²»Ð޸ĵľ²Ì¬Öµ£©
|
/// </summary>
|
public double? LogicValue
|
{
|
get
|
{
|
return LogicValues[0];
|
}
|
set
|
{
|
isInput = true;
|
if (value==null)
|
LogicValues[0]=double.NaN;
|
else
|
LogicValues[0] = (double)value;
|
}
|
}
|
/// <summary>
|
/// É趨ģʽ
|
/// </summary>
|
public double[] LogicValues
|
{
|
get;set;
|
}
|
|
|
/// <summary>
|
/// ÐèÒªÌí¼Óº¯Êý
|
/// </summary>
|
public string Value_Set(int period,double value)
|
{
|
_Values[period] = value;
|
return null;
|
string result = null;
|
double formatValue = value;
|
//if (value!=double.NaN) formatValue = Math.Round(value, СÊýλÊý);
|
/*[CloudflightÐÞ¸Ä]2024-6-3
|
½âËø
|
*/
|
//lock (this)
|
{
|
_Values[period] = formatValue;
|
}
|
|
return result;
|
}
|
/// <summary>
|
/// ÐèÒªÌí¼Óº¯Êý
|
/// </summary>
|
public double[] Values_Set
|
{
|
set
|
{
|
//lock (this)
|
//{
|
// _Values = value;
|
//}
|
_Values = value;
|
}
|
|
}
|
/// <summary>
|
/// ÊýѧģÐÍÄ¿±êÖµ
|
/// </summary>
|
public double? Value0
|
{
|
get
|
{
|
return _Values[0];
|
}
|
private set
|
{
|
if (value == null)
|
_Values[0] = double.NaN;
|
else
|
_Values[0] = (double)value;
|
}
|
}
|
#endregion
|
|
|
#region ÉèÖñäÁ¿
|
/// <summary>
|
/// ÏÔʾµÄСÊýλÊý
|
/// </summary>
|
public int СÊýλÊý = 3;
|
|
/// <summary>
|
/// ±ê¸ß
|
/// </summary>
|
public double elevation = -9099;
|
|
public int sort = 0;
|
#endregion
|
|
|
public string childSolution = "";
|
|
public string childTag = "";
|
|
public string childType = "´«Èë";
|
|
public double SearchRange = -1;
|
|
public bool isNeedToSave = false;
|
|
public string SaveKey = null;
|
|
|
|
/// <summary>
|
/// ÊÇ·ñÊÇÐéÄâ±äÁ¿£¨Óɼ¯ºÏ²úÉú£©
|
/// </summary>
|
public bool virturl = false;
|
|
|
[NonSerialized]
|
public dynamic Eval = null;
|
|
/// <summary>
|
/// ¶ÔÏóÇåµ¥
|
/// </summary>
|
public string objListString;
|
|
/// <summary>
|
/// ¶ÔÏó±àºÅ£¨×îÓÅ£©
|
/// </summary>
|
public string obj_Best;
|
|
public static double ErrNum = -9999999;
|
|
private int _level = 0;
|
|
[JsonIgnore]
|
public int Level
|
{
|
get
|
{
|
if (_level!=0) return _level;
|
int tempLevel = 1;
|
if (Vars!=null)
|
foreach (var v in Vars)
|
{
|
if (v!=this && v is variable vv && tempLevel < vv.Level + 1) tempLevel = vv.Level + 1;
|
}
|
_level= tempLevel;
|
return _level;
|
}
|
|
}
|
|
public string Tag { get; set; }
|
|
public override string ToString()
|
{
|
string value = Value0 == null ? LogicValue.ToString() : Value0.ToString();
|
return $"[{Name}]{value}";
|
}
|
|
//public double GetValue(Func<variable, double> GetModelValue = null, int? period = 0, bool forceReCalc = false)
|
//{
|
// double Value;
|
// var v = this;
|
// // is double dd
|
// if (v.expressType == "×Ó·½°¸Öµ"|| v.logicType=="Ä¿±êº¯Êý" )
|
// {
|
// if (!v.Value0.HasValue)
|
// Value = ErrNum; //throw (new Exception("Òì³£"));
|
// else
|
// Value = (double)v.Value0;//v.GetCalcValue(GetCalcValue, period, false);
|
// }
|
// else if(v.logicType=="ÊÔËã²ÎÊý")//²»Çå³ý»º´æ
|
// {
|
// if (!v.Value0.HasValue)
|
// Value = variable.ErrNum;
|
// else
|
// Value = (double)v.Value0;//v.GetCalcValue(GetCalcValue, period, false);
|
|
// }
|
|
// else if (variable.list_ÊäÈëÖµ.IndexOf(v.expressType) < 0)
|
// {
|
// Value = v.GetCalcValue(GetModelValue, forceReCalc);
|
// }
|
// else
|
// {
|
// double? d;
|
// if ((d = v.GetLogicValue(period)) == null)
|
// {
|
// //result = $"±äÁ¿[{v.Name}]ÅäÖôíÎó,±àºÅ[{v.modelObjectID}]ȡֵʧ°Ü";
|
// Value = variable.ErrNum;
|
// }
|
// else
|
// {
|
// Value = (double)(v.GetLogicValue(period) ?? (variable.ErrNum));
|
// }
|
// }
|
// return Value;
|
//}
|
//public double GetCalcValue(Func<variable, double> GetModelValue = null, bool forceReCalc = false)
|
//{
|
|
|
// if (forceReCalc)
|
// {
|
// Value0 = null;
|
// }
|
// else
|
// {
|
// if (Value0!=null) return (double)Value0;
|
// }
|
|
|
|
// double CalcValue_Calc;
|
// double result;
|
// if (expressType == listUsedInitValue[0])//³õʼ¼ÆËãÖµ
|
// {
|
// result = CalcValue_Init;
|
// }
|
// else if (expressType == listUsedInitValue[1])//±ä»¯Öµ
|
// {
|
// CalcValue_Calc = GetModelValue(this);
|
// result = CalcValue_Calc - CalcValue_Init;
|
// }
|
// else if (expressType == listUsedInitValue[2])//¾ø¶Ô±ä»¯Öµ
|
// {
|
// CalcValue_Calc = GetModelValue(this);
|
// result = CalcValue_Calc - CalcValue_Init;
|
// if (result < 0) result *= -1;
|
// }
|
// else
|
// {
|
// CalcValue_Calc = GetModelValue(this);
|
// result = CalcValue_Calc;
|
// }//¼ÆËãÖµ
|
|
// Value0 = result;
|
// return result;
|
//}
|
public double GetLogicValue(int period=0)
|
{
|
if ( period >= 0 && period<LogicValues.Length)
|
return LogicValues[period];
|
else
|
return double.NaN;
|
}
|
|
public double[] GetShowValue_Arr()
|
{
|
|
if (variable.list_ÊäÈëÖµ.Contains(expressType))
|
//return LogicPattern;
|
return Values;
|
else
|
return Values;
|
}
|
|
|
public variable Copy()
|
{
|
//»ñȡһ¸öеÄʵÀý£¬½«Õâ¸öÀàµÄÊôÐÔÖµ¸³Öµ¸øÐÂʵÀý
|
variable v = new variable(this.PeriodCount);
|
v.ID = this.ID;
|
v.IndicatorType = this.IndicatorType;
|
v.Type = this.Type;
|
v.expressType = this.expressType;
|
v.expressString = this.expressString;
|
v.Tag=this.Tag;
|
v.arrgFuncType = this.arrgFuncType;
|
v.isNode = this.isNode;
|
v.ObjType = this.ObjType;
|
v.logicType = this.logicType;
|
v.LogicValue = this.LogicValue;
|
v.LogicValues = this.LogicValues;
|
v.СÊýλÊý = this.СÊýλÊý;
|
v.virturl = this.virturl;
|
v.doubleRange =new DRange( this.doubleRange);
|
v.accuracy = this.accuracy;
|
//v.Vars = this.Vars;
|
v.Name = this.Name;
|
v.modelObjectID = this.modelObjectID;
|
v.modelIndex = this.modelIndex;
|
v.PeriodCount = this.PeriodCount;
|
v.childSolution = this.childSolution;
|
v.childTag = this.childTag;
|
v.childType = this.childType;
|
v.SearchRange = this.SearchRange;
|
v.SaveKey = this.SaveKey;
|
v.objListString = this.objListString;
|
v.obj_Best=this.obj_Best;
|
v._level=this._level;
|
return v;
|
}
|
}
|
|
[Serializable]
|
public class OBJFunction
|
{
|
public string Text_origin;
|
public string Text_change;
|
public string Text;
|
public string ExpressType;
|
public string Name;
|
|
public double value;
|
public DRange tolerance;
|
public variable variable;
|
//public List<variable> paramVariables;
|
//public List<double> paramValues;
|
[NonSerialized]
|
public dynamic eval;
|
public bool isUseOriginValue = false;
|
/// <summary>
|
/// true£ºÊ¹Óñí´ïʽģʽ£¬false£ºÊ¹ÓñàºÅģʽ
|
/// </summary>
|
public bool? isUseExpression = true;
|
//public bool isUseScadaValue = false;
|
|
}
|
|
|
|
|
}
|