private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object>();

private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object>();

转载于:https://www.cnblogs.com/DTWolf/p/4602164.html

请帮我分析以下代码的结构和功能,using ClusterAlgorithm.commonType; using ClusterAlgorithm.utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClusterAlgorithm.common { class DeadLockTool { public static bool isEnableSeq(List<string> seq, PetriNet PN, ScheduleState scheduleState, SearchState searchState) { bool enable = true; if (PN.IsManuMode) { return enable; } List<int> mark = new List<int>(searchState.mark); Dictionary<string, List<int>> rotate_mark = CopyTool.CloneDictionaryList(searchState.rotate_mark); // <> weiwei 20250114 for deadlock misdetection problem in scenarios with revisit,conflict and complicated routes #if false foreach (string t in seq) { if (!isEnableT(t, PN, scheduleState, searchState, mark, rotate_mark)) { enable = false; break; } Tuple<List<int>, Dictionary<string, List<int>>> rlt2 = PN.FireT(mark, t, rotate_mark); mark = rlt2.Item1; rotate_mark = rlt2.Item2; } #else if(AlgorithmSwitcher.getInstance().strategy == Strategy.Pull && seq.Count>0 && isLastTPlace(seq, PN)) { //Pull模式下死锁控制(调度模式在Job过程中不能动态切换, push控制铺满片的情况下,切换成Pull会报死锁) if (!isSafeT(seq[seq.Count-1], PN, scheduleState, mark, rotate_mark, seq)) { enable = false; } } else { //Swap或Push模式下死锁控制 foreach (string t in seq) { if (!isSafeT(t, PN, scheduleState, mark, rotate_mark, new List<string>())) { enable = false; break; } Tuple<List<int>, Dictionary<string, List<int>>> rlt2 = PN.FireT(mark, t, rotate_mark); mark = rlt2.Item1; rotate_mark = rlt2.Item2; } } #endif return enable; } /// <summary> /// 是否tseq的最后一个是放片变迁 /// </summary> /// <param name="tseq"></param> /// <param name="PN"></param> /// <returns></returns> private static bool isLastTPlace(List<string> tseq, PetriNet PN) { if (tseq.Count <= 0) { return false; } bool isLastPlace = false; foreach (string m in PN.PredVertex[tseq[tseq.Count-1]]) { //前序是移动库所,则一定是放片变迁 if (m[0] == 'm') { isLastPlace = true; break; } } return isLastPlace; } // <> weiwei 20250114 for deadlock misdetection problem in scenarios with revisit,conflict and complicated routes /// <summary> /// 判断单个变迁或整个Pull序列是否安全 /// </summary> /// <param name="t">单个变迁(push)或Pull的最后一个变迁</param> /// <param name="PN">petri网对象</param> /// <param name="scheduleState"></param> /// <param name="mark"></param> /// <param name="rotate_mark"></param> /// <param name="fullSeq"></param> /// <returns></returns> public static bool isSafeT(string tEnd, PetriNet PN, ScheduleState scheduleState, List<int> mark, Dictionary<string, List<int>> rotate_mark, List<string> fullSeq) { List<int> newMark = new List<int>(); bool isEndOfPull = false; if (fullSeq==null || fullSeq.Count<=0) { Tuple<List<int>, Dictionary<string, List<int>>> rlt2 = PN.FireT(mark, tEnd, rotate_mark); newMark = rlt2.Item1; isEndOfPull = false; } else { //pull模式下整个Pull序列更新 Tuple<List<int>, Dictionary<string, List<int>>> rlt2 = PN.FireSeq(mark, fullSeq, rotate_mark); newMark = rlt2.Item1; isEndOfPull = true; } return IsSafeDeepSearch(tEnd, PN, scheduleState, newMark, new SortedDictionary<string, int>(), isEndOfPull); } // <> weiwei 20250114 for deadlock misdetection problem in scenarios with revisit,conflict and complicated routes /// <summary> /// 迭代死锁控制(暂未支持含中心资源的场景) /// </summary> /// <param name="PN"></param> /// <param name="markAfterT"></param> /// <param name="t"></param> /// <param name="rListSaturate"></param> /// <returns></returns> private static bool IsSafeDeepSearch(string t, PetriNet PN, ScheduleState scheduleState, List<int> markAfterT, SortedDictionary<string, int> rListSaturate, bool isEndOfPull) { if (PN.TpredR.ContainsKey(t) == false) { //安全 return true; } string res_t = PN.TpredR[t]; if (markAfterT[PN.Ps.IndexOf(res_t)] > 0) { //安全 return true; } else { if (rListSaturate.ContainsKey(res_t)) { //饱和站点第二次出现,已饱和 return false; } rListSaturate[res_t] = 0; bool anyRtPathUnsaturated = false; foreach (string t1_retnRes in PN.PredVertex[res_t]) { //impossible if (t1_retnRes[0] != 't' || PN.TpredP.ContainsKey(t1_retnRes) ==false){continue;} //获得PullSeq列表 List<List<string>> pullSeqsofT1 = new List<List<string>>(); bool nextIsEndOfPull = false; if (isEndOfPull && scheduleState.PullSeqs.ContainsKey(t1_retnRes)) { nextIsEndOfPull = true; foreach (string seqStr in scheduleState.PullSeqs[t1_retnRes]) { if (seqStr.Contains("pull")) { List<string> pullSeq = seqStr.Split(';')[0].Split(',').ToList(); pullSeqsofT1.Add(pullSeq); } } } if (pullSeqsofT1.Count <= 0) { //非Pull模式下死锁控制 pullSeqsofT1.Add(new List<string> { t1_retnRes }); } foreach(List<string> t1seq in pullSeqsofT1) { if (markAfterT[PN.Ps.IndexOf(PN.TpredP[t1seq[0]])] <= 0) { //前置过程库所没有占用rest中的资源 continue; } //分支 SortedDictionary<string, int> tempRListSaturate = new SortedDictionary<string, int>(rListSaturate); if (IsSafeDeepSearch(t1seq[t1seq.Count-1], PN, scheduleState, markAfterT, tempRListSaturate, nextIsEndOfPull)) { //找到任何一个变迁后续可以走得通 anyRtPathUnsaturated = true; break; } } } return anyRtPathUnsaturated; } }
最新发布
06-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值