/// <summary> /// 测试该支路加正电压会不会短路 /// </summary> public bool hasShortCircuit() { AppProject pro = AppProject.GetInstance(); if (branch.Count != 0) { Dijkstra dist = pro.getDijkstra(branch[0]); List <TNode> negative = pro.GetSetTerminal(p => p.Type == NamesManage.Negative); foreach (TNode nd in negative) { if (dist.getRouteWeight(nd.index) == 0) { return(true); } } } return(false); }
/// <summary> /// 获得与总负相连接的支路 /// </summary> public void LoadGndBranches() { AppProject pro = AppProject.GetInstance(); nets.Clear(); BranchNet net = new BranchNet(MaxNetNum + 1); List <TNode> gndnd = pro.GetSetTerminal(p => p.Type == NamesManage.Negative); List <TestBranch> gndbr = new List <TestBranch>(); gndnd.ForEach(p => { TestBranch br = new TestBranch(); br.TryAddNode(p); gndbr.Add(br); }); GetGndBranches(gndbr, ref net); //GetGndBranches(gndnd, ref net); nets.Add(net); pro.Nodes.ForEach(p => p.HasIncluded = false); }
/// <summary> /// 获得包含逻辑元件的回路 /// </summary> public void LoadLogicLoops() { AppProject pro = AppProject.GetInstance(); nets.Clear(); /*获得与CF点相连接、包含逻辑元件的回路*/ var cfs = pro.Nodes.Where(p => p.PartType == "接口连接器" && p.TNType == TerminalType.Normal && !pro.GndTbs.Contains(p, AppProject.cmpNode) ).ToList(); int Count = cfs.Count; for (int i = 0; i < Count; i++) { pro.Nodes.ForEach(p => p.HasIncluded = false); int netnum = MaxNetNum; BranchNet net = new BranchNet(++netnum); nets.Add(net); List <TestBranch> loopbr = new List <TestBranch>(); TestBranch branch = new TestBranch(); branch.TryAddNode(cfs[i]); loopbr.Add(branch); GetLogicRelations(loopbr, ref net); } /*获得与总正相连接、包含逻辑器件的回路*/ var vccs = pro.GetSetTerminal(p => p.Type == NamesManage.Positive); pro.Nodes.ForEach(p => p.HasIncluded = false); BranchNet vnet = new BranchNet(1 + MaxNetNum); nets.Add(vnet); for (int i = 0; i < vccs.Count; i++) { List <TestBranch> loopbr = new List <TestBranch>(); TestBranch branch = new TestBranch(); branch.TryAddNode(vccs[i]); loopbr.Add(branch); GetLogicRelations(loopbr, ref vnet); } }
/// <summary> /// 获得与总正相连接的支路 /// </summary> public LogicNet Load110VBranches(int logicMaxNetNum) { AppProject pro = AppProject.GetInstance(); nets.Clear(); BranchNet net = new BranchNet(MaxNetNum + 1); nets.Add(net); LogicNet pnet = new LogicNet(logicMaxNetNum + 1); List <TNode> vccnd = pro.GetSetTerminal(p => p.Type == NamesManage.Positive); List <TestBranch> vccbr = new List <TestBranch>(); vccnd.ForEach(p => { TestBranch br = new TestBranch(); br.TryAddNode(p); vccbr.Add(br); }); Get110VBranches(vccbr, ref net, ref pnet); pro.Nodes.ForEach(p => p.HasIncluded = false); return(pnet); }
/// <summary> /// 检查已找到的逻辑导通条件是否成立 /// </summary> public void CheckCondition() { AppProject pro = AppProject.GetInstance(); /*将所有条件注入点相关的所有回路都添加到relativeBrs集合中*/ List <TestBranch> relativeBrs = new List <TestBranch>(); foreach (var lp in loops) { BranchNet net = pro.LoopNets.Nets.FirstOrDefault(p => p.Branches.Contains(lp)); net.Branches.ForEach(p => { if (!relativeBrs.Contains(p)) { relativeBrs.Add(p); } }); } /*初始化所有节点的HasChanged属性为false * 触点没有发生动作*/ pro.Nodes.ForEach(p => p.HasChanged = false); /*将条件支路中得电的线圈对应的触点标记为动作*/ var query = pro.Nodes.Where(p => includedCoils.Contains(p.Part) && (p.TNType == TerminalType.ContactNormalOpen || p.TNType == TerminalType.ContactNormalClose)); foreach (var nd in query) { TNode another = nd.GetAnother(); if (another != null) { nd.HasChanged = true; another.HasChanged = true; } } /*将所有通电的线圈的触点标记为动作*/ List <TestBranch> rstBrs = new List <TestBranch>(); CheckCondition(relativeBrs, rstBrs); /*最后检查一下loops里的支路是否依然满足导通的条件*/ bool success = true;//没有问题 rstBrs.ForEach(p => loops.Add(p)); loops.Add(branches[0]);//将被测支路一起加入导通支路里检查 int[,] weight = new int[pro.Nodes.Count, pro.Nodes.Count]; Array.Copy(pro.weight, weight, weight.Length);//拷贝权重矩阵 foreach (var br in loops) { var noQuery = br.Branch.Where(p => p.TNType == TerminalType.ContactNormalOpen); var ncQuery = br.Branch.Where(p => p.TNType == TerminalType.ContactNormalClose); foreach (var no in noQuery) { TNode another = no.GetAnother(); if (br.Branch.Contains(another)) { if (!no.HasChanged) { success = false; weight[no.index, another.index] = 0; weight[another.index, no.index] = 0; } } } if (success) { foreach (var nc in ncQuery) { TNode another = nc.GetAnother(); if (br.Branch.Contains(another)) { if (nc.HasChanged) { success = false; weight[nc.index, another.index] = Dijkstra.infinite; weight[another.index, nc.index] = Dijkstra.infinite; } } } } //判断回路中是否可能存在短路情况 if (success) { Dijkstra dist = new Dijkstra(weight, br.Branch[0].index); List <TNode> negative = pro.GetSetTerminal(p => p.Type == NamesManage.Negative); success = !DijkstraUtil.hasShortCircuit(negative, dist); } if (!success) { break; } } loops.Remove(branches[0]);//检查完毕后从条件支路中移除 CanTest = success; if (!success) { loops.Clear(); includedCoils.Clear(); Debug.WriteLine("失败解析:{0}", Num); } else { Debug.WriteLine("成功解析:{0}", Num); kk += branches.Count; Debug.WriteLine(kk); Debug.WriteLine("条件支路个数:{0}", loops.Count); } }