private void GetKtuple(SequenceIntList sil, int k) { act(0, "\r\n\t正在计算ktuple\r\n\t......\r\n"); Stopwatch sp = new Stopwatch(); sp.Start(); //序列名字节点 //Parallel.ForEach(list, (item) => // { // string seqName = Path.GetFileNameWithoutExtension(item); // KtupleCount kc = new KtupleCount(item, k); // kc.GetKtupleList(); // dicKtuple[seqName].Add(k, kc.ListCount); // dicTotal[seqName].Add(k, kc.Total); // act(1, ""); // }); Parallel.For(0, sil.Count, (i) => { KtupleCount kc = new KtupleCount(sil.ListSequenceIntList[i], k); kc.GetKtupleList(); dicKtuple[sil.ListSeqName[i]].Add(k, kc.ListCount); dicTotal[sil.ListSeqName[i]].Add(k, kc.Total); act(1, ""); }); sp.Stop(); act(0, "\tk = " + k + " 计算完毕,用时 " + sp.ElapsedMilliseconds * 1.0 / 1000 + " s\r\n\r\n"); }
public void Star(string saveDir, TreeNodeCollection nodes, ProgressBar p, bool b, string oneSeqPath = "") { Stopwatch sp = new Stopwatch(); sp.Start(); GetListNode(nodes); InitalState(p, b); #region 准备工作 List <string> listEuMaChD2 = new List <string>(); List <string> listD2SD2Star = new List <string>(); List <Action <string, int> > listAct = new List <Action <string, int> >(); Action <string, int> act1 = (string saveTmp, int kTmp) => { GetEuMaChD2(saveTmp, kTmp, listEuMaChD2, b); }; Action <string, int> act2 = (string saveTmp, int kTmp) => { if (kTmp > 2) { GetMarkovHao(kTmp); GetHao(saveTmp, kTmp, b); } }; Action <string, int> act3 = (string saveTmp, int kTmp) => { if (kTmp > 2) { GetMarkovZeroToTwo(kTmp); GetD2SD2Star(saveTmp, kTmp, listD2SD2Star, b); } }; bool bHao = false; foreach (string item in ListFun) { if (item == "Eu" || item == "Ma" || item == "Ch" || item == "D2") { listEuMaChD2.Add(item); } if (item == "Hao") { listAct.Add(act2); bHao = true; } if (item == "D2S" || item == "D2Star") { listD2SD2Star.Add(item); } } if (listEuMaChD2.Count != 0) { listAct.Add(act1); } if (listD2SD2Star.Count != 0) { listAct.Add(act3); } #endregion int i = 1; //分组节点 foreach (TreeNode node in ListNode) { act(0, "第" + i + "组:\r\n"); i++; string savePath = saveDir + "\\" + node.FullPath; List <string> list = GetPathList(node, oneSeqPath); GetMarkovHaoReady(); GetMarkovZeroToTwoReady(); SequenceIntList sil = new SequenceIntList(list); foreach (int k in ListK) { GetKtuple(sil, k); Parallel.For(0, listAct.Count, (j) => { listAct[j](savePath, k); }); //foreach (var item in listAct) //{ // item(savePath, k); //} if (k > 3) { DictionaryRemove(k, bHao); } } dicKtuple.Clear(); dicTotal.Clear(); dicMarkov.Clear(); dicMarkovHao.Clear(); act(0, "\r\n\r\n"); } sp.Stop(); MessageBox.Show("o(* ̄▽ ̄*)ブ总算算完了" + (sp.ElapsedMilliseconds * 1.0 / 1000).ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); Process.Start(saveDir); }