private SellingRecordList GenSrl(FileInfo srFile, PrimalArrivalList pal) { SellingRecordList srl = new SellingRecordList(); //c#文件流读文件 using (FileStream fsRead = srFile.OpenRead()) { StreamReader sr = new StreamReader(fsRead, System.Text.Encoding.Default); //读文件头 string s = sr.ReadLine(); s = s.Substring(1, s.Length - 2); string[] ss = s.Split(new char[] { ',', '=' }); if (ss[0] == "ID") { srl.PAL = pal; } while (!sr.EndOfStream) { s = sr.ReadLine(); ss = s.Split(new char[] { ';' }); string[] sss = ss[1].Split(new char[] { ',' }); SellingRecord sellrecord = new SellingRecord(); sellrecord.Product = new List <IProduct>(); sellrecord.ArriveTime = Convert.ToInt32(ss[0]); foreach (string ssss in sss) { sellrecord.Product.Add(this.ProSpace.FirstOrDefault(i => i.ProID == Convert.ToInt32(ssss))); } srl.Add(sellrecord); } } return(srl); }
public void ReadXml(XmlReader reader) { XmlSerializer serializer = new XmlSerializer(typeof(SellingRecordList)); reader.ReadStartElement("SellingRecordData"); while (reader.NodeType != XmlNodeType.EndElement) { SellingRecordList sdi = serializer.Deserialize(reader) as SellingRecordList; this.SrData.Add(sdi); } reader.ReadEndElement(); }
public bool Process(PrimalArrivalList arr, out SellingRecordList Srlist, out ControlRecordList Crlist) { //初始化记录 Srlist = new SellingRecordList() { PAL = arr }; Crlist = new ControlRecordList() { PAL = arr }; //初始化资源 MetaResouceState rs = new MetaResouceState(InitState); //生成动态策略 IConOL conol = Controller.GenConOL(); if (conol != null) { conol.Update(rs); } List <IProduct> openProductList = Controller.OpenProductList(0, rs, conol);//初始开放产品 Crlist.UpdateOpenProducts(0, openProductList); for (int i = 0; i < arr.Count; i++)//顺序读取到达列表 { //生成开放产品集 openProductList = Controller.OpenProductList(arr[i].ArriveTime, rs, conol); //模拟旅客购票 List <IProduct> pro = (MarketInfo[arr[i].IndexOfMS] as IChoiceAgent).Select(openProductList, arr[i].ChoosingParam); if (pro == null) { continue; } //出票 List <Ticket> tickets = Controller.PrintTickets(rs, pro, conol); //更新资源状态 rs.UpdateAfterSelling(tickets); if (conol != null) { conol.Update(rs); } //记录产品情况 Crlist.UpdateOpenProducts(arr[i].ArriveTime, openProductList); //加入SellingRecordList Srlist.AddRecord(arr[i].ArriveTime, arr[i], pro, tickets); } return(true); }
public void Add(SellingRecordList list) { this.SrData.Add(list); }
public void Dowork(string arrpath, string srpath, string ctlpath, string outpupath) { DirectoryInfo arrFolder = new DirectoryInfo(arrpath); DirectoryInfo srFolder = new DirectoryInfo(srpath); DirectoryInfo ctlFolder = new DirectoryInfo(ctlpath); FileInfo[] sr = srFolder.GetFiles(); FileInfo[] ctl = ctlFolder.GetFiles(); Dictionary <SimStatic, double> dic = new Dictionary <SimStatic, double>(); Dictionary <SimStatic, List <double> > listDic = new Dictionary <SimStatic, List <double> >(); foreach (SimStatic s in IndexList) { if (s.Cal != null) { dic.Add(s, 0); } else if (s.TCal != null) { listDic.Add(s, new List <double>()); } } int n = 0; int total = arrFolder.GetFiles("*.arr").Length; int step = (int)Math.Ceiling((double)arrFolder.GetFiles("*.arr").Length / 10000); Console.Write("进度 000.00%"); foreach (FileInfo file in arrFolder.GetFiles("*.arr")) { Task ta = factory.StartNew(() => { PrimalArrivalList pal = new PrimalArrivalList(); pal.ReadFromArrFile(file.FullName); FileInfo srFile = sr.FirstOrDefault(i => i.Name == file.Name.Substring(0, file.Name.IndexOf('.')) + ".sr"); FileInfo ctlFile = ctl.FirstOrDefault(i => i.Name == file.Name.Substring(0, file.Name.IndexOf('.')) + ".cr"); ControlRecordList crl = GenCrl(ctlFile, pal); SellingRecordList srl = GenSrl(srFile, pal); lock (dic) { foreach (SimStatic s in IndexList) { if (s.Cal != null) { dic[s] += s.Cal(pal, srl, crl); } else if (s.TCal != null) { List <double> temp = s.TCal(pal, srl, crl); for (int i = 0; i < temp.Count; i++) { if (listDic[s].Count <= i) { listDic[s].Add(0); } listDic[s][i] += temp[i]; } } } } if (n++ % step == 0) { lock (arrFolder) { Console.SetCursorPosition(Console.CursorLeft - 7, Console.CursorTop); Console.Write("{0}%", String.Format("{0:000.00}", Math.Round(((double)n / (double)total), 4) * 100)); } } }, cts.Token); tasks.Add(ta); } Task.WaitAll(tasks.ToArray()); tasks.Clear(); Console.SetCursorPosition(Console.CursorLeft - 7, Console.CursorTop); Console.WriteLine("100.00 % 完成!"); //输出 StreamWriter sw = new StreamWriter(outpupath, true); sw.Write("\r\n" + arrFolder.FullName + ","); foreach (SimStatic s in IndexList) { if (s.Cal != null) { if (s.IsAvg) { dic[s] = dic[s] / (double)total; } if (IndexList.IndexOf(s) < IndexList.Count - 1) { sw.Write("{0},", dic[s]); } else { sw.Write("{0}", dic[s]); } } else if (s.TCal != null) { if (s.IsAvg) { for (int i = 0; i < listDic[s].Count; i++) { listDic[s][i] = listDic[s][i] / (double)total; } } sw.WriteLine(); sw.WriteLine(s.Name); for (int i = 0; i < listDic[s].Count; i++) { sw.WriteLine("{0},", listDic[s][i]); } } } sw.Close(); }