Beispiel #1
0
        /// <summary>
        /// 保存转化成的表格到Excel中
        /// </summary>
        protected DataView SaveBranchesToExcel(string tbName)
        {
            AppProject pro = AppProject.GetInstance();

            if (nets.Count() == 0)
            {
                return(null);
            }
            int    columns = getColumnCount();
            string cmd     = "CREATE TABLE " + tbName + " (";

            cmd += "网络号 VARCHAR(100),";
            for (int i = 0; i < columns; i++)
            {
                cmd += string.Format("部位{0} VARCHAR(100),端子号{1} VARCHAR(100),端口类型{2} VARCHAR(100),", i, i, i);
            }
            cmd = cmd.Substring(0, cmd.Length - 1) + ")";
            using (OleDbConnection cnn = AccessAndExcelOp.GetExcelConnect(pro.OriginFileName + "(测试支路).xls"))
            {
                List <string> tbnames   = AccessAndExcelOp.GetTableNames(cnn);
                string        deleteCmd = "Drop Table " + tbName;
                if (tbnames.Contains(tbName))
                {
                    AccessAndExcelOp.ExecuteNoQueryCmd(cnn, deleteCmd);
                }
                AccessAndExcelOp.CreateTable(cnn, cmd);
                DataTable table = AccessAndExcelOp.GetTable(cnn, tbName);
                fillTable(table);
                AccessAndExcelOp.UpdateSourceTable(cnn, table);
                return(table.AsDataView());
            }
        }
Beispiel #2
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);
        }
        /// <summary>
        /// 保存到excel
        /// </summary>
        public System.Data.DataView SaveBranchesToExcel()
        {
            AppProject pro    = AppProject.GetInstance();
            string     tbName = "接口配置";

            if (linkerRelation.Count() == 0)
            {
                return(null);
            }
            string cmd = "CREATE TABLE 接口配置 (连接器 VARCHAR(100),连接器端口 VARCHAR(100),测试箱 VARCHAR(100),测试箱端口 VARCHAR(100),线号 VARCHAR(100))";

            using (OleDbConnection cnn = AccessAndExcelOp.GetExcelConnect(pro.OriginFileName + "(测试支路).xls"))
            {
                List <string> tbnames = AccessAndExcelOp.GetTableNames(cnn);
                if (tbnames.Contains(tbName))
                {
                    string deleteCmd = "Drop Table " + tbName;
                    AccessAndExcelOp.ExecuteNoQueryCmd(cnn, deleteCmd);
                }
                AccessAndExcelOp.CreateTable(cnn, cmd);
                DataTable table = AccessAndExcelOp.GetTable(cnn, tbName);
                foreach (var link in linkerRelation)
                {
                    DataRow row = table.NewRow();
                    row[0] = link.Key.LinkerName;
                    row[1] = link.Key.LinkerPort;
                    row[2] = link.Value.TestBoxNum;
                    row[3] = link.Value.TestBoxPort;
                    row[4] = link.Value.LineNum;
                    table.Rows.Add(row);
                }
                AccessAndExcelOp.UpdateSourceTable(cnn, table);
                return(table.AsDataView());
            }
        }
        /// <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);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 筛选出所有导通的支路
        /// </summary>
        /// <param name="rstBrs">支路集合</param>
        private void SelectLoops(ref List <TestBranch> rstBrs)
        {
            AppProject        pro = AppProject.GetInstance();
            List <TestBranch> rst = new List <TestBranch>();

            /*遍历rstBrs中的回路是否闭合*/
            foreach (var br in rstBrs)
            {
                /*判断常开、常闭触点的当前状态*/
                var noQuery = br.Branch.Where(p => p.TNType == TerminalType.ContactNormalOpen);
                var ncQuery = br.Branch.Where(p => p.TNType == TerminalType.ContactNormalClose);

                bool nomark = true;
                bool ncmark = true;
                foreach (var no in noQuery)
                {
                    TNode another = no.GetAnother();
                    if (!br.Branch.Contains(another))
                    {
                        continue;
                    }
                    else
                    {
                        if (!no.HasChanged)
                        {
                            nomark = false;
                            break;
                        }
                    }
                }
                if (nomark)
                {
                    foreach (var nc in ncQuery)
                    {
                        TNode another = nc.GetAnother();
                        if (!br.Branch.Contains(another))
                        {
                            continue;
                        }
                        else
                        {
                            if (nc.HasChanged)
                            {
                                ncmark = false;
                                break;
                            }
                        }
                    }
                }
                if (nomark && ncmark)
                {
                    rst.Add(br);
                }
            }
            rstBrs = rst;
        }
Beispiel #6
0
        public LogicNet(int netNum)
            : base(netNum)
        {
            AppProject pro = AppProject.GetInstance();

            loops         = new List <TestBranch>();
            includedCoils = new List <string>();
            bits          = new BitArray(pro.CFNodes.Count);
            bits.SetAll(false);
            faults = new List <ComponentFault>();
        }
        /// <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);
        }
Beispiel #8
0
        /// <summary>
        /// 标记包含屏蔽节点的回路
        /// </summary>
        /// <param name="blockNodes">屏蔽节点集合</param>
        private void BlockBranches(List <TNode> blockNodes)
        {
            AppProject pro = AppProject.GetInstance();
            /*屏蔽不符合的支路*/
            var nodes = blockNodes.Where(p => p.TNType == TerminalType.ContactNormalClose ||
                                         p.TNType == TerminalType.ContactNormalOpen).ToList();
            var coils = blockNodes.Where(p => p.TNType == TerminalType.Coil).ToList();

            foreach (var net in pro.LoopNets.Nets)
            {
                foreach (var branch in net.Branches)
                {
                    /*屏蔽常开、常闭触点*/
                    if (branch.hasBlock)
                    {
                        break;
                    }
                    foreach (var nd in nodes)
                    {
                        TNode athr = nd.GetAnother();
                        if (branch.LogicNodes.Contains(nd) && branch.LogicNodes.Contains(athr))
                        {
                            branch.hasBlock = true;
                            break;
                        }
                    }
                    /*屏蔽线圈*/
                    if (branch.hasBlock)
                    {
                        break;
                    }
                    foreach (var cl in coils)
                    {
                        TNode athr = coils.FirstOrDefault(p => p.Part == cl.Part && p.TNType == cl.TNType && !p.Equals(cl));
                        if (branch.LogicNodes.Contains(cl) && branch.LogicNodes.Contains(athr))
                        {
                            branch.hasBlock = true;
                            break;
                        }
                    }
                }
            }
        }
        /// <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);
        }
Beispiel #10
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);
            }
        }
Beispiel #11
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);
            }
        }
Beispiel #12
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);
        }
Beispiel #13
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);
                    }
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// 逆推逻辑导通的条件
        /// 这是深度递归函数
        /// </summary>
        /// <param name="branches">最后找到的条件支路</param>
        /// <param name="destCoil">目的线圈的部件名称</param>
        /// <param name="blockNodes">会产生矛盾,应该屏蔽的节点</param>
        /// <param name="parentCoils">当前要寻找的线圈的祖先辈线圈</param>
        /// <param name="includedCoils">已经找到的条件支路中所有的线圈</param>
        /// <returns>是否搜索到合适导通条件</returns>
        private bool GetConditions(List <TestBranch> branches, string destCoil, List <TNode> blockNodes, List <string> parentCoils)
        {
            AppProject pro = AppProject.GetInstance();

            /*没有需要得电的线圈了就停止搜索*/
            if (string.IsNullOrEmpty(destCoil))
            {
                return(true);
            }

            /*如果寻找的线圈不在父支路中但在已经搜索过的其他支路里
             * 父支路已有的线圈如果再次出现就产生了矛盾
             * 那么不用重复寻找
             */
            if (!parentCoils.Contains(destCoil) && includedCoils.Contains(destCoil))
            {
                return(true);
            }
            else if (parentCoils.Contains(destCoil))
            {
                return(false);
            }
            /*遍历该网络中的每一条支路*/
            TestBranch br = null;

            if (pro.LoopNets.Nets.Count > 0)
            {
                foreach (var branch in pro.LoopNets.Nets[pro.LoopNets.Nets.Count - 1].Branches)
                {
                    if (!branch.hasBlock)
                    {
                        int num = branch.LogicNodes.Count(p => p.Part == destCoil && p.TNType == TerminalType.Coil);
                        if (num == 2)
                        {
                            if (br == null)
                            {
                                br = branch;
                            }
                            else
                            {
                                int brNcNum = br.Branch.Count(p => p.TNType == TerminalType.ContactNormalClose);
                                int NcNum   = branch.Branch.Count(p => p.TNType == TerminalType.ContactNormalClose);
                                if (brNcNum > NcNum)
                                {
                                    br = branch;
                                }
                            }
                        }
                    }
                }
            }
            if (br == null)
            {
                foreach (var net in pro.LoopNets.Nets)
                {
                    foreach (var branch in net.Branches)
                    {
                        if (!branch.hasBlock)
                        {
                            int num = branch.LogicNodes.Count(p => p.Part == destCoil && p.TNType == TerminalType.Coil);
                            if (num == 2)
                            {
                                if (br == null)
                                {
                                    br = branch;
                                }
                                else
                                {
                                    int brNcNum = br.Branch.Count(p => p.TNType == TerminalType.ContactNormalClose);
                                    int NcNum   = branch.Branch.Count(p => p.TNType == TerminalType.ContactNormalClose);
                                    if (brNcNum > NcNum)
                                    {
                                        br = branch;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
            }
            /*找到就更新屏蔽的节点、查找下一步寻找的线圈*/
            if (br != null)
            {
                List <string>        destCoils = new List <string>();
                IEnumerable <string> coils     = UpdateRelation(br, destCoils, blockNodes);
                if (!branches.Contains(br))
                {
                    branches.Add(br);
                }
                foreach (var cl in coils)
                {
                    parentCoils.Add(cl);
                    includedCoils.Add(cl);
                }
                foreach (var cl in destCoils)
                {
                    List <string> parentcls = new List <string>();
                    parentCoils.ForEach(p => parentcls.Add(p));
                    bool success = GetConditions(branches, cl, blockNodes, parentcls);
                    if (!success)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                /*没有找到符合条件的支路*/
                return(false);
            }
            return(true);
        }
Beispiel #15
0
        /// <summary>
        /// 从条件支路中提取出,下一次要寻找的线圈、新增的屏蔽节点
        /// </summary>
        /// <param name="br">一条条件支路</param>
        /// <param name="destCoils">存放下一次要寻找的线圈</param>
        /// <param name="blockNodes">屏蔽节点的集合</param>
        /// <returns>本条件支路中包含的线圈的名称</returns>
        private IEnumerable <string> UpdateRelation(TestBranch br, List <string> destCoils, List <TNode> blockNodes)
        {
            AppProject    pro           = AppProject.GetInstance();
            List <string> includedCoils = new List <string>();

            foreach (var node in br.LogicNodes)
            {
                var another = node.GetAnother();
                if (br.LogicNodes.Contains(another) && node.TNType == TerminalType.ContactNormalOpen)
                {
                    /*常开触点的线圈作为寻找的目标*/
                    var query = pro.Nodes.Where(p =>
                                                p.Part == node.Part && p.TNType == TerminalType.Coil);
                    foreach (var coil in query)
                    {
                        if (!destCoils.Contains(coil.Part))
                        {
                            destCoils.Add(coil.Part);
                        }
                    }
                    /*常开触点对应的常闭触点需要屏蔽*/
                    query = pro.Nodes.Where(p =>
                                            p.Part == node.Part && p.TNType == TerminalType.ContactNormalClose);
                    foreach (var nc in query)
                    {
                        TNode athr = nc.GetAnother();
                        if (athr != null && !blockNodes.Contains(nc))
                        {
                            blockNodes.Add(nc);
                            blockNodes.Add(athr);
                        }
                    }
                }
                if (br.LogicNodes.Contains(another) && node.TNType == TerminalType.ContactNormalClose)
                {
                    /*常闭触点的线圈需要屏蔽*/
                    var query = pro.Nodes.Where(p =>
                                                p.Part == node.Part && p.TNType == TerminalType.Coil);
                    foreach (var coil in query)
                    {
                        blockNodes.Add(coil);
                    }
                    /*常闭触点对应的常开触点需要屏蔽*/
                    query = pro.Nodes.Where(p =>
                                            p.Part == node.Part && p.TNType == TerminalType.ContactNormalOpen);
                    foreach (var no in query)
                    {
                        TNode athr = no.GetAnother();
                        if (athr != null && !blockNodes.Contains(no))
                        {
                            blockNodes.Add(no);
                            blockNodes.Add(athr);
                        }
                    }
                }
                if (node.TNType == TerminalType.Coil)
                {
                    var coilpair = br.LogicNodes.Where(p => p.TNType == TerminalType.Coil && p.Part == node.Part).ToList();
                    if (coilpair.Count == 2)
                    {
                        foreach (var coil in coilpair)
                        {
                            if (!blockNodes.Contains(coil))
                            {
                                blockNodes.Add(coil);
                            }
                            if (!includedCoils.Contains(coil.Part))
                            {
                                includedCoils.Add(coil.Part);
                            }
                        }
                        var query = pro.Nodes.Where(p =>
                                                    p.Part == node.Part && p.TNType == TerminalType.ContactNormalClose);
                        foreach (var nd in query)
                        {
                            TNode ather = nd.GetAnother();
                            if (ather != null && !blockNodes.Contains(nd))
                            {
                                blockNodes.Add(nd);
                                blockNodes.Add(ather);
                            }
                        }
                    }
                }
            }
            /*屏蔽不符合的支路*/
            BlockBranches(blockNodes);
            return(includedCoils);
        }
Beispiel #16
0
        /// <summary>
        /// 计算各故障模式的特征向量
        /// </summary>
        private void FaultVector()
        {
            if (CanTest)
            {
                AppProject pro = AppProject.GetInstance();
                int[,] weight = new int[pro.Nodes.Count, pro.Nodes.Count];
                Array.Copy(pro.weight, weight, weight.Length);//拷贝权重矩阵

                List <TestBranch> circuits = new List <TestBranch>(loops);
                circuits.Add(branches[0]);
                foreach (var br in circuits)
                {
                    var           coil  = br.Branch.Where(p => p.TNType == TerminalType.Coil);
                    ISet <string> names = new HashSet <string>();
                    foreach (var nd in coil)
                    {
                        if (names.Contains(nd.Part))
                        {
                            continue;
                        }
                        else
                        {
                            names.Add(nd.Part);
                            TNode another = nd.GetAnother();
                            if (br.Branch.Contains(another))
                            {
                                pro.Nodes.ForEach(p =>
                                {
                                    if (p.Part == nd.Part && p.TNType == TerminalType.ContactNormalOpen)
                                    {
                                        TNode ather = p.GetAnother();
                                        weight[p.index, ather.index] = 0;
                                        weight[ather.index, p.index] = 0;
                                    }
                                    else if (p.Part == nd.Part && p.TNType == TerminalType.ContactNormalClose)
                                    {
                                        TNode ather = p.GetAnother();
                                        weight[p.index, ather.index] = Dijkstra.infinite;
                                        weight[ather.index, p.index] = Dijkstra.infinite;
                                    }
                                });
                            }
                        }
                    }
                }
                /*无故障情况下的特征向量*/
                Dijkstra dist = new Dijkstra(weight, branches[0].Branch[0].index);
                for (int i = 0; i < pro.CFNodes.Count; i++)
                {
                    bits.Set(i, dist.getRouteWeight(pro.CFNodes[i].index) < Dijkstra.infinite);
                }
                /*有故障情况下的特征向量*/
                faults.Clear();
                ISet <TNode> pairs = new HashSet <TNode>();
                foreach (var br in branches)
                {
                    foreach (var nd in br.Branch)
                    {
                        pairs.Add(nd);
                    }
                }
                List <TNode> linkerNodes = new List <TNode>();
                foreach (var nd in pairs)
                {
                    TNode another = nd.GetAnother();
                    if (another == null || linkerNodes.Contains(nd))
                    {
                        continue;
                    }
                    if ((nd.TNType == TerminalType.BreakerContact && pairs.Contains(another)) ||
                        (nd.TNType == TerminalType.Coil && pairs.Contains(another)) ||
                        (nd.TNType == TerminalType.ContactNormalClose && pairs.Contains(another)) ||
                        (nd.TNType == TerminalType.ContactNormalOpen && pairs.Contains(another)) ||
                        ((nd.TNType == TerminalType.DiodePositive && another.TNType == TerminalType.DiodeNegative && pairs.Contains(another)) ||
                         (nd.TNType == TerminalType.DiodeNegative && another.TNType == TerminalType.DiodePositive && pairs.Contains(another))) ||
                        (nd.TNType == TerminalType.Indicator && pairs.Contains(another)))
                    {
                        linkerNodes.Add(nd);
                        linkerNodes.Add(another);
                    }
                }
                int pairCount = linkerNodes.Count / 2;
                for (int j = 0; j < pairCount; j++)
                {
                    TNode          nd1    = linkerNodes[j];
                    TNode          nd2    = linkerNodes[j + 1];
                    ComponentFault fault1 = new ComponentFault(nd1.Part + "短路", Tuple.Create <TNode, TNode>(nd1, nd2), FaultType.ShortCircuit);
                    ComponentFault fault2 = new ComponentFault(nd1.Part + "断路", Tuple.Create <TNode, TNode>(nd1, nd2), FaultType.BlockCircuit);
                    faults.Add(fault1);
                    faults.Add(fault2);
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// 找出所有导通的回路
        /// </summary>
        /// <param name="relativeBrs">所有可能导通的回路</param>
        /// <param name="rstBrs">导通的回路</param>
        /// <param name="weight">权重矩阵</param>
        private void CheckCondition(List <TestBranch> relativeBrs, List <TestBranch> rstBrs)
        {
            AppProject pro = AppProject.GetInstance();

            /*筛选出依然导通的回路*/
            SelectLoops(ref rstBrs);
            /*遍历relativeBrs中的回路是否闭合*/
            foreach (var br in relativeBrs)
            {
                if (loops.Contains(br) || rstBrs.Contains(br))
                {
                    continue;
                }
                else
                {
                    /*判断常开、常闭触点的当前状态,如果包含线圈,还要进一步判断线圈造成的影响*/
                    var noQuery   = br.Branch.Where(p => p.TNType == TerminalType.ContactNormalOpen);
                    var ncQuery   = br.Branch.Where(p => p.TNType == TerminalType.ContactNormalClose);
                    var coilQuery = br.Branch.Where(p => p.TNType == TerminalType.Coil).Select(p => p.Part).Distinct();

                    bool nomark = true;
                    bool ncmark = true;
                    foreach (var no in noQuery)
                    {
                        TNode another = no.GetAnother();
                        if (!br.Branch.Contains(another))
                        {
                            continue;
                        }
                        else
                        {
                            if (!no.HasChanged)
                            {
                                nomark = false;
                                break;
                            }
                        }
                    }
                    if (nomark)
                    {
                        foreach (var nc in ncQuery)
                        {
                            TNode another = nc.GetAnother();
                            if (!br.Branch.Contains(another))
                            {
                                continue;
                            }
                            else
                            {
                                if (nc.HasChanged)
                                {
                                    ncmark = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (nomark && ncmark)
                    {
                        rstBrs.Add(br);
                        /*导通的回路中若还有线圈应该重新查找*/
                        bool mark = false;
                        foreach (var cl in coilQuery)
                        {
                            int num = br.Branch.Count(p => p.Part == cl && p.TNType == TerminalType.Coil);
                            if (num == 2)
                            {
                                mark = true;
                                var query = pro.Nodes.Where(p => p.Part == cl &&
                                                            (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;
                                    }
                                }
                            }
                        }
                        /*如果含有线圈需要重新核查*/
                        if (mark)
                        {
                            CheckCondition(relativeBrs, rstBrs);
                            break;
                        }
                    }
                }
            }
        }
Beispiel #18
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);
            }
        }
Beispiel #19
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);
            }
        }
        /// <summary>
        /// 生成接口配置
        /// </summary>
        public bool GenerateLinkerConfig()
        {
            AppProject pro         = AppProject.GetInstance();
            int        boxnum      = 1;
            int        boxpoint    = 1;
            var        linkerNames = pro.Nodes.Where(p => p.PartType == "接口连接器" && p.TNType == TerminalType.Normal).Select(q => q.Part).Distinct();

            foreach (var name in linkerNames)
            {
                int port = Linker.GetMaxLinkerPort(pro.Nodes, name);
                if (port <= 56)
                {
                    /*小于56可以分配在任意插头上*/
                    bool FindEmpty = false;
                    for (int j = 1; j <= 5; j++)
                    {
                        var box = linkerRelation.Values.FirstOrDefault(p => p.TestBoxNum == ("#" + j) && p.TestBoxPort > 144);
                        if (box == null)
                        {
                            boxnum    = j;
                            boxpoint  = 145;
                            FindEmpty = true;
                            break;
                        }
                    }
                    if (!FindEmpty)
                    {
                        for (int j = 1; j <= 5; j++)
                        {
                            var box = linkerRelation.Values.FirstOrDefault(p => p.TestBoxNum == ("#" + j) && p.TestBoxPort <= 72);
                            if (box == null)
                            {
                                FindEmpty = true;
                                boxnum    = j;
                                boxpoint  = 1;
                                break;
                            }
                            else
                            {
                                box = linkerRelation.Values.FirstOrDefault(p => p.TestBoxNum == ("#" + j) && p.TestBoxPort > 72 && p.TestBoxPort <= 144);
                                if (box == null)
                                {
                                    FindEmpty = true;
                                    boxnum    = j;
                                    boxpoint  = 73;
                                    break;
                                }
                            }
                        }
                    }
                    if (!FindEmpty)
                    {
                        return(false);
                    }
                }
                else
                {
                    /*大于56必须分配在每个箱子的前两个插头上*/
                    bool FindEmpty = false;
                    for (int j = 1; j <= 5; j++)
                    {
                        var box = linkerRelation.Values.FirstOrDefault(p => p.TestBoxNum == ("#" + j) && p.TestBoxPort <= 72);
                        if (box == null)
                        {
                            FindEmpty = true;
                            boxnum    = j;
                            boxpoint  = 1;
                            break;
                        }
                        else
                        {
                            box = linkerRelation.Values.FirstOrDefault(p => p.TestBoxNum == ("#" + j) && p.TestBoxPort > 72 && p.TestBoxPort <= 144);
                            if (box == null)
                            {
                                FindEmpty = true;
                                boxnum    = j;
                                boxpoint  = 73;
                                break;
                            }
                        }
                    }
                    if (!FindEmpty)
                    {
                        return(false);
                    }
                }
                for (int i = 1; i <= port; i++)
                {
                    Linker  link = new Linker(name, i);
                    TestBox box  = new TestBox(link, "#" + boxnum, boxpoint++);
                    linkerRelation.Add(link, box);
                }
            }
            return(true);
        }