Пример #1
0
        private void AddBranch(Dictionary <long, ResourceDescription> cimTerminals, Dictionary <long, MPBranch> branches, Dictionary <long, MPNode> nodes, long branchId, List <long> terminalsID)
        {
            if (terminalsID.Count < 1)
            {
                string message = "Invalid CIM model. Connectivity node must have at least one terminal";
                Logger.LogError(message);
                throw new Exception(message);
            }
            //TODO: za sada, slucaj kada ima vise
            ResourceDescription firstTerminal  = cimTerminals[terminalsID[0]];
            ResourceDescription secondTerminal = cimTerminals[terminalsID[1]];

            EPhaseCode phaseCode    = (EPhaseCode)firstTerminal.GetProperty(ModelCode.TERMINAL_PHASES).AsEnum();
            long       firstNodeId  = firstTerminal.GetProperty(ModelCode.TERMINAL_CONNECTIVITYNODE).AsLong();
            long       secondNodeId = secondTerminal.GetProperty(ModelCode.TERMINAL_CONNECTIVITYNODE).AsLong();

            if (nodes.ContainsKey(firstNodeId) && nodes.ContainsKey(secondNodeId))
            {
                MPLine branch = new MPLine(branchId, phaseCode, firstNodeId, secondNodeId);

                branches.Add(branchId, branch);
            }
            else
            {
                string message = $"Invalid CIM model. There is(are) not node(s) with specific lid(s). First node: {firstNodeId}, Second node {secondNodeId}";
                Logger.LogError(message);
                throw new Exception(message);
            }
        }
Пример #2
0
        public void ReadSources(Dictionary <long, ResourceDescription> cimSources, Dictionary <long, ResourceDescription> cimTerminals)
        {
            Dictionary <long, MPNode>   nodes    = internalModel.Nodes;
            Dictionary <long, MPRoot>   roots    = internalModel.Roots;
            Dictionary <long, MPBranch> branches = internalModel.Branches;

            foreach (ResourceDescription source in cimSources.Values)
            {
                long        rootId      = source.Id;
                List <long> terminalsID = source.GetProperty(ModelCode.CONDEQ_TERMINALS).AsReferences();

                if (terminalsID.Count < 1)
                {
                    string message = "Invalid CIM model. Root must have at least one terminal";
                    Logger.LogError(message);
                    throw new Exception(message);
                }
                //TODO: svi treba da imaju istu faznost
                ResourceDescription firstTerminal = cimTerminals[terminalsID[0]];

                EPhaseCode phaseCode = (EPhaseCode)firstTerminal.GetProperty(ModelCode.TERMINAL_PHASES).AsEnum();
                if (nodes.ContainsKey(rootId))
                {
                    string message = $"Bad input file. There is already root node with specific gid ({rootId:X16}).";
                    Logger.LogError(message);
                    throw new Exception(message);
                }

                if (!roots.ContainsKey(rootId))
                {
                    MPRootNode rootNode = new MPRootNode(rootId, rootId, phaseCode);
                    nodes.Add(rootId, rootNode);

                    MPRoot root = new MPRoot(rootId, rootId);
                    roots.Add(rootId, root);

                    long     rootConnNode = firstTerminal.GetProperty(ModelCode.TERMINAL_CONNECTIVITYNODE).AsReference();
                    MPBranch rootBranch   = new MPLine(rootId, phaseCode, rootId, rootConnNode);
                    branches.Add(rootId, rootBranch);
                }
            }

            isRootsInitialized = true;
        }
Пример #3
0
        public void ReadBranchesFromFile()
        {
            Dictionary <long, MPNode>   listOfNodes    = internalModel.Nodes;
            Dictionary <long, MPBranch> listOfBranches = internalModel.Branches;
            String file_name = "Branches.xml";

            XmlDocument xml_doc = new XmlDocument();

            xml_doc.Load(file_path + file_name);


            XmlNodeList xnList = xml_doc.SelectNodes("/Branches/Line");

            foreach (XmlElement xml_elem in xnList)
            {
                long       branchLID = UInt32.Parse(xml_elem.GetAttribute("LID"));
                long       node1_lid = UInt32.Parse(xml_elem["End1_Node"].InnerText);
                long       node2_lid = UInt32.Parse(xml_elem["End2_Node"].InnerText);
                EPhaseCode phases    = (EPhaseCode)Byte.Parse(xml_elem["Phases"].InnerText);

                if (listOfBranches.ContainsKey(branchLID))
                {
                    throw new Exception("Bad input file. There is already branch with same key " + branchLID + ".");
                }
                else
                {
                    if (!listOfNodes.ContainsKey(node1_lid) || !listOfNodes.ContainsKey(node2_lid))
                    {
                        throw new Exception("Bad input file. There is(are) not node(s) with specific lid(s).");
                    }
                    else
                    {
                        MPLine branch = new MPLine(branchLID, phases, node1_lid, node2_lid);


                        listOfBranches.Add(branchLID, branch);
                    }
                }
            }
        }