/// <summary> /// 已经成交了的订单 /// </summary> /// <param name="item"></param> public void _TradedOrder(RecordTransItem item) { List <RecordTransItem> removeItems = new List <RecordTransItem>(); foreach (var it in PositionRecords) { if (it.direction != item.direction) { removeItems.Add(it); break; } } if (removeItems.Count() > 0) { foreach (var it in removeItems) { Invoke_OnRemovePosition(it); PositionRecords.Remove(it); } } else { Invoke_OnInsertPosition(item); PositionRecords.Add(item); } Invoke_OnInsertOrder(item); HistoryRecords.Add(item); }
async Task ExecuteLoadRecordsCommand() { if (IsBusy) { return; } IsBusy = true; try { HistoryRecords.Clear(); var items = await DataStore.GetRecordsAsync(); foreach (var item in items) { HistoryRecords.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public void Record(int bookId, int tocID, NavigationType type = NavigationType.TOCDocument, int pageNum = 0, object tag = null) { NavigationRecord record = new NavigationRecord { BookId = bookId, TOCId = tocID, PageNum = pageNum, Type = type, Tag = tag }; if (CurrenRecordIndex == HistoryRecords.Count - 1) { CurrenRecordIndex++; HistoryRecords.Add(record); } else if (CurrenRecordIndex < HistoryRecords.Count - 1) { CurrenRecordIndex++; HistoryRecords.RemoveRange(CurrenRecordIndex, HistoryRecords.Count - CurrenRecordIndex); HistoryRecords.Add(record); } BackWard = CurrenRecordIndex > 0 ? true : false; ForWard = false; }
public void Record(string words) { if (CurrenRecordIndex == HistoryRecords.Count - 1) { CurrenRecordIndex++; HistoryRecords.Add(words); } else if (CurrenRecordIndex < HistoryRecords.Count - 1) { CurrenRecordIndex++; HistoryRecords.RemoveRange(CurrenRecordIndex, HistoryRecords.Count - CurrenRecordIndex); HistoryRecords.Add(words); } IsCanBackWard = CurrenRecordIndex > 0 ? true : false; IsCanForWard = false; }
public void Read(BinaryReader binaryReader) { HistoryRecords.Clear(); IsNull = binaryReader.ReadBoolean(); if (IsNull) { return; } else { var length = binaryReader.ReadInt32(); for (var i = 0; length > i; i++) { var historyRecord = new ROCMaster_HistoryRecord(); historyRecord.Read(binaryReader); HistoryRecords.Add(historyRecord); } } }
public ROCMaster_HistoryRecordArray AddHistoryRecord(ROCMaster_HistoryRecord historyRecord) { HistoryRecords.Add(historyRecord); return(this); }
public override string ToString() { return(string.Join("|", HistoryRecords.Select(parameter => parameter.ToString()))); }
//计算适应度函数值 public static double Fitness(int[] decoded) { //数组无法作为key,需要转换成字符串或重写GetHashCode及Equales方法 var decodedStr = string.Join(",", decoded); double fitness; if (HistoryRecords.TryGetValue(decodedStr, out fitness))//如果存在历史记录,就返回历史记录 { //Console.WriteLine("重复"); return(fitness); } else { List <Ship> finshed = new List <Ship>(); //int para = 0; foreach (var index in decoded) { var i = ships[index]; //todo 暂不需要克隆 //Console.WriteLine("船舶"+finshed.Count); int ss = i.a; int b = 0; double greedy = ran.NextDouble(); if (greedy < 0.5) { int position = 0; while (position == 0) { i.b = 0; i.s = ss; ss = T * T; //Console.WriteLine("代数0:"+i); while (i.b + i.l <= L) { List <Ship> A = new List <Ship>(); List <Ship> B = new List <Ship>(); A = finshed.FindAll(j => j.b <i.b + i.l && j.b + j.l> i.b); //Console.WriteLine("泊位冲突:"+A.Count); B = A.FindAll(j => j.s <i.s + i.p && j.s + j.p> i.s); //Console.WriteLine("时间冲突:"+B.Count); if (B.Count == 0) { //i.s = s; position = 1; finshed.Add(i); break; } else { var j = B.OrderBy(j => j.b + j.l).Last(); i.b = j.b + j.l; var k = B.OrderBy(k => k.GetD()).First(); if (ss >= k.GetD()) { ss = k.GetD(); } } } } } else { int position = 0; while (position == 0) { i.b = L - i.l; i.s = ss; ss = T * T; while (i.b >= 0) { List <Ship> A = new List <Ship>(); List <Ship> B = new List <Ship>(); A = finshed.FindAll(j => j.b <i.b + i.l && j.b + j.l> i.b); //Console.WriteLine("泊位冲突2:"+A.Count); B = A.FindAll(j => j.s <i.s + i.p && j.s + j.p> i.s); //Console.WriteLine("时间冲突2:"+B.Count); if (B.Count == 0) { //i.s = s; position = 1; finshed.Add(i); break; } else { var j = B.OrderBy(j => j.b).First(); i.b = j.b - i.l; var k = B.OrderBy(k => k.GetD()).First(); if (ss >= k.GetD()) { ss = k.GetD(); } } } } } } // for (int jj = 0; jj < V; jj++) // { // Console.WriteLine("b:" + finshed[jj].b + ",l:" + finshed[jj].l + ",a:" + finshed[jj].a + ",s:" + finshed[jj].s+ ",d:" + finshed[jj].GetD()); // } double[] f = new double[M]; finshed = finshed.OrderBy(i => i.s).ToList();//按照si从小到大排列船舶 for (var k = 0; k < f.Length; k++) { finshed.ForEach(i => i.GenR()); //随机生成所有船舶实际到达时间ar 和实际作业时间pr //finshed.ForEach(i => i.sr = 0); foreach (var i in finshed) //todo 暂不需要克隆? { //i.sr = 0; int time = Math.Max(i.ar, i.s); List <Ship> A = finshed.FindAll(j => j.s < i.s && j.b <i.b + i.l && j.b + j.l> i.b); if (A.Count == 0) { i.sr = time; } else { if (time < A.Max(j => j.sr + j.pr)) { time = A.Max(j => j.sr + j.pr); } } i.sr = time; f[k] = f[k] + i.sr + i.pr - i.ar; //Console.WriteLine("Sr:" + i.sr+",ar:"+i.ar+";pr:"+i.pr+";S:"+i.s); } } double mean = f.Average(); //Console.WriteLine("mean:" + mean); double devi = StDev(f); fitness = mean + λ * devi; HistoryRecords[decodedStr] = mean + λ * devi; //Console.WriteLine("Mean" + mean); //Console.WriteLine("devi" + devi); return(fitness); } }
public HistoryRecordArray AddHistoryRecord(HistoryRecord historyRecord) { HistoryRecords.Add(historyRecord); return(this); }