예제 #1
0
        /// <summary>
        /// 普通导通测试支路
        /// </summary>
        public LogicNet[] Load24VBranches(int logicMaxNetNum)
        {
            AppProject pro = AppProject.GetInstance();

            nets.Clear();
            List <TNode> cfs   = pro.GetCFNodes();
            int          Count = cfs.Count;

            BranchNet[] _nets = new BranchNet[Count];
            LogicNet[]  pnets = new LogicNet[Count];
            for (int i = 0; i < Count; i++)
            {
                BranchNet net = new BranchNet(MaxNetNum + 1);
                this.nets.Add(net);
                LogicNet          pnet   = new LogicNet(++logicMaxNetNum);
                List <TestBranch> normbr = new List <TestBranch>();
                TestBranch        branch = new TestBranch();
                branch.TryAddNode(cfs[i]);
                normbr.Add(branch);
                Get24VBranches(normbr, ref net, ref pnet);
                _nets[i] = net;
                pnets[i] = pnet;
            }
            pro.Nodes.ForEach(p => p.HasIncluded = false);
            return(pnets);
        }
예제 #2
0
        /// <summary>
        /// 获得与总负相连接的支路(递归广度)
        /// </summary>
        private void GetGndBranches(List <TestBranch> branches, ref BranchNet net)
        {
            AppProject        pro          = AppProject.GetInstance();
            List <TestBranch> nextBranches = new List <TestBranch>();

            foreach (var branch in branches)
            {
                TNode node = branch.LastNode;
                foreach (var child in node.Nodes)
                {
                    TestBranch cbranch = branch.Clone();
                    if (!child.HasIncluded)
                    {
                        if (child.PartType == "端子排" &&
                            child.TNType != TerminalType.Block &&
                            !(node.TNType == TerminalType.DiodePositive && child.TNType == TerminalType.DiodeNegative))
                        {
                            if (!pro.GndTbs.Contains(child, AppProject.cmpNode))
                            {
                                pro.GndTbs.Add(child);
                            }
                            if (cbranch.AllTB)
                            {
                                cbranch.Clear();
                            }
                            cbranch.TryAddNode(child);
                            nextBranches.Add(cbranch);
                        }
                        else if (child.TNType == TerminalType.RE)
                        {
                            if (!pro.GndTbs.Contains(child, AppProject.cmpNode))
                            {
                                pro.GndTbs.Add(child);
                            }
                            cbranch.TryAddNode(child);
                            nextBranches.Add(cbranch);
                        }
                        else if (child.PartType == "接口连接器")
                        {
                            if (!pro.GndTbs.Contains(child, AppProject.cmpNode))
                            {
                                pro.GndTbs.Add(child);
                            }
                            cbranch.TryAddNode(child);
                            net.Branches.Add(cbranch);
                            cbranch = new TestBranch();
                            cbranch.TryAddNode(child);
                            nextBranches.Add(cbranch);
                        }
                    }
                }
                node.HasIncluded = true;
            }
            if (nextBranches.Count != 0)
            {
                GetGndBranches(nextBranches, ref net);
            }
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <summary>
        /// 获得与CF点相连接、包含逻辑元件的回路
        /// </summary>
        private void GetLogicRelations(List <TestBranch> branches, ref BranchNet net)
        {
            AppProject        pro          = AppProject.GetInstance();
            List <TestBranch> nextBranches = new List <TestBranch>();

            foreach (var branch in branches)
            {
                TNode node = branch.LastNode;
                foreach (var child in node.Nodes)
                {
                    TestBranch cbranch = branch.Clone();
                    if (!child.HasIncluded)
                    {
                        if (child.TNType != TerminalType.Block &&
                            child.PartType != "设备连接器" &&
                            !pro.GndTbs.Contains(child, AppProject.cmpNode))
                        {
                            bool success = cbranch.TryAddNode(child);
                            if (success)
                            {
                                nextBranches.Add(cbranch);
                            }
                        }
                        else if (pro.GndTbs.Contains(child, AppProject.cmpNode) && cbranch.HasLogicElement)
                        {
                            cbranch.TryAddNode(child);
                            bool condict = cbranch.BranchContradict();
                            if (!condict)
                            {
                                net.Branches.Add(cbranch);
                            }
                        }
                    }
                }
                node.HasIncluded = true;
            }
            if (nextBranches.Count != 0)
            {
                GetLogicRelations(nextBranches, ref net);
            }
        }
예제 #5
0
        /// <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);
            }
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <summary>
        /// 获得与总负相连接的支路(Dijkstra)
        /// </summary>
        public void GetGndBranches(List <TNode> sources, ref BranchNet net)
        {
            AppProject pro = AppProject.GetInstance();
            IReadOnlyCollection <TNode> cfs = pro.CFNodes;

            foreach (var nd in sources)
            {
                Dijkstra dist = pro.getDijkstra(nd);
                foreach (var cf in cfs)
                {
                    if (dist.getRouteWeight(cf.index) == 0)
                    {
                        List <int> paths   = dist.getPath(cf.index);
                        TestBranch cbranch = new TestBranch();
                        if (paths.Count > 0)
                        {
                            cbranch.TryAddNode(pro.Nodes[paths[paths.Count - 1]]);
                        }
                        net.Branches.Add(cbranch);
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// 获得与总正相连接的支路(递归广度)
        /// </summary>
        private void Get110VBranches(List <TestBranch> branches, ref BranchNet net, ref LogicNet positiveNet)
        {
            AppProject        pro          = AppProject.GetInstance();
            List <TestBranch> nextBranches = new List <TestBranch>();

            foreach (var branch in branches)
            {
                TNode node = branch.LastNode;
                if (node.HasIncluded)
                {
                    continue;
                }
                foreach (var child in node.Nodes)
                {
                    TestBranch cbranch = branch.Clone();
                    if (!child.HasIncluded)
                    {
                        if (child.PartType == "端子排" && child.TNType != TerminalType.Block)
                        {
                            if (cbranch.AllTB)
                            {
                                cbranch.Clear();
                            }
                            bool success = cbranch.TryAddNode(child);
                            if (success)
                            {
                                nextBranches.Add(cbranch);
                            }
                        }
                        else if (child.TNType == TerminalType.RE ||
                                 child.TNType == TerminalType.BreakerContact ||
                                 child.TNType == TerminalType.DiodePositive ||
                                 child.TNType == TerminalType.DiodeNegative ||
                                 child.TNType == TerminalType.Coil ||
                                 child.TNType == TerminalType.ContactNormalClose ||
                                 child.TNType == TerminalType.ContactNormalOpen ||
                                 child.TNType == TerminalType.ContactCom ||
                                 child.TNType == TerminalType.Switch ||
                                 child.TNType == TerminalType.Indicator)
                        {
                            bool success = cbranch.TryAddNode(child);
                            if (success)
                            {
                                nextBranches.Add(cbranch);
                            }
                        }
                        else if (child.PartType == "接口连接器")
                        {
                            bool success = cbranch.TryAddNode(child);
                            /*是否含有逻辑元件*/
                            if (cbranch.HasLogicElement)
                            {
                                if (success)
                                {
                                    positiveNet.Branches.Add(cbranch);
                                }
                            }
                            else
                            {
                                if (success)
                                {
                                    net.Branches.Add(cbranch);
                                }
                            }
                            cbranch = new TestBranch();
                            success = cbranch.TryAddNode(child);
                            if (success)
                            {
                                nextBranches.Add(cbranch);
                            }
                        }
                    }
                }
                node.HasIncluded = true;
            }
            if (nextBranches.Count != 0)
            {
                Get110VBranches(nextBranches, ref net, ref positiveNet);
            }
        }
예제 #9
0
        /// <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);
            }
        }