예제 #1
0
        public void ReadConnectivityNodes(Dictionary <long, ResourceDescription> cimConnNodes, Dictionary <long, ResourceDescription> cimTerminals)
        {
            Dictionary <long, MPNode> nodes = internalModel.Nodes;


            foreach (ResourceDescription node in cimConnNodes.Values)
            {
                if (!nodes.ContainsKey(node.Id))
                {
                    //TODO: svi treba da imaju istu faznost
                    List <long> terminalsID = node.GetProperty(ModelCode.CONNECTIVITYNODE_TERMINALS).AsReferences();

                    if (terminalsID.Count < 1)
                    {
                        string message = "Invalid CIM model. Connectivity node must have at least one terminal";
                        Logger.LogError(message);
                        throw new Exception(message);
                    }
                    ResourceDescription firstTerminal = cimTerminals[terminalsID[0]];
                    EPhaseCode          phaseCode     = (EPhaseCode)firstTerminal.GetProperty(ModelCode.TERMINAL_PHASES).AsEnum();

                    MPBusNode newNode = new MPBusNode(node.Id, phaseCode);

                    nodes.Add(node.Id, newNode);
                }
                else
                {
                    string errMessage = $"Invalid CIM model. There is already node with same key: {node.Id:X16}";
                    Logger.LogError(errMessage);
                    throw new Exception(errMessage);
                }
            }

            isNodesInitialized = true;
        }
예제 #2
0
        private long[] ownerCircuit;            // Celina (koren ili ostrvo) kojoj elemenat pripada

        public MPGraphElem(long lid, EPhaseCode phaseCode) : base(lid)
        {
            this.phases       = phaseCode;
            this.phaseMarker  = EPhaseCode.NONE;
            this.marker       = EEnergizationStatus.TA_UNENERGIZED;
            this.ownerCircuit = new long[3];
        }
예제 #3
0
        public void ReadSwitchesFromFile()
        {
            Dictionary <long, MPNode>         listOfNodes         = internalModel.Nodes;
            Dictionary <long, MPBranch>       listOfBranches      = internalModel.Branches;
            Dictionary <long, MPSwitchDevice> listOfSwitchDevices = internalModel.SwitchDevices;

            String file_name = "Switches.xml";

            XmlDocument xml_doc = new XmlDocument();

            xml_doc.Load(file_path + file_name);

            XmlNodeList xnList = xml_doc.SelectNodes("/Switches/Switch");

            foreach (XmlElement xml_elem in xnList)
            {
                ESwitchStatus[] active = new ESwitchStatus[3];

                long       switch_lid = UInt32.Parse(xml_elem.GetAttribute("LID"));
                long       branchLid  = UInt32.Parse(xml_elem["Branch"].InnerText);
                long       nodeLid    = UInt32.Parse(xml_elem["Node"].InnerText);
                EPhaseCode state      = (EPhaseCode)Byte.Parse(xml_elem["SwitchState"].InnerText);
                EPhaseCode phases     = (EPhaseCode)Byte.Parse(xml_elem["Phases"].InnerText);

                if (!listOfNodes.ContainsKey(nodeLid) && !listOfBranches.ContainsKey(nodeLid))
                {
                    throw new Exception("Bad input file. There is(are) not graph elem(s) with specific lid(s).");
                }

                MPSwitchDevice switchDevice = new MPSwitchDevice(switch_lid, branchLid, nodeLid, phases, state);

                listOfSwitchDevices.Add(switch_lid, switchDevice);
            }
        }
예제 #4
0
 public MPSwitchDevice(long lid, long branchLid, long nodeLid, EPhaseCode phaseCode, EPhaseCode state)
     : base(lid, phaseCode)
 {
     this.State     = state;
     this.EndBranch = branchLid;
     this.EndNode   = nodeLid;
 }
예제 #5
0
        public void ReadNodesFromFile()
        {
            Dictionary <long, MPNode> listOfNodes = internalModel.Nodes;
            String file_name = "Nodes.xml";

            XmlDocument xml_doc = new XmlDocument();

            xml_doc.Load(file_path + file_name);

            XmlNodeList xnList = xml_doc.SelectNodes("/Nodes/BusNode");

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

                if (!listOfNodes.ContainsKey(nodeLID))
                {
                    MPBusNode node = new MPBusNode(nodeLID, phases);


                    listOfNodes.Add(nodeLID, node);
                }
                else
                {
                    throw new Exception("Bad input file. There is already node with same key " + nodeLID + ".");
                }
            }
        }
예제 #6
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);
            }
        }
        public void OpenSwitch(MPSwitchDevice switchDevice, EPhaseCode phasesToRemove)
        {
            MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch];

            RemoveBranchFromModel(statebranch, phasesToRemove);

            switchDevice.State = EPhaseCode.NONE;
        }
        public void CloseSwitch(MPSwitchDevice switchDevice, EPhaseCode phasesToAdd)
        {
            MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch];

            AddBranchToModel(statebranch, phasesToAdd);

            switchDevice.State = switchDevice.OriginalPhases;
        }
        public void OpenPhaseOfSwitch(MPSwitchDevice switchDevice, EPhaseCode phaseToChange)
        {
            MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch];

            RemoveBranchFromModel(statebranch, phaseToChange);

            switchDevice.State = switchDevice.State & (~phaseToChange & EPhaseCode.ABC);
        }
        public void ClosePhaseOfSwitch(MPSwitchDevice switchDevice, EPhaseCode phaseToChange)
        {
            MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch];

            AddBranchToModel(statebranch, phaseToChange);

            switchDevice.State = switchDevice.State | phaseToChange;
        }
        //public void UpdateCompositeSwitch(MPSwitchDevice switchDevice, EPhaseCode newState)
        //{
        //    switchDevice.State = newState;

        //    MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch];

        //    EPhaseCode removePhases = statebranch.OriginalPhases & ((~newState) & EPhaseCode.ABC);
        //    RemoveBranchFromModel(statebranch, removePhases);

        //    EPhaseCode addPhases = newState & ((~statebranch.OriginalPhases) & EPhaseCode.ABC);
        //    AddBranchToModel(statebranch, addPhases);
        //}

        #endregion

        #region Temporary Jumper
        public long AddJumper(long node1, long node2, EPhaseCode phaseCode)
        {
            long     jumperLid = internalModel.LidManager.FindFreeTemporaryIndex("MPTempJumper");
            MPJumper jumper    = new MPJumper(jumperLid, phaseCode, node1, node2);

            internalModel.Branches.Add(jumperLid, jumper);
            AddBranchToModel(jumper);

            return(jumperLid);
        }
 public static bool PhaseExistInPhaseCode(EPhaseCode ePhaseCode, EPhaseIndex phaseIndex)
 {
     if (((uint)ePhaseCode & (uint)Math.Pow(2, 3 - (byte)phaseIndex)) != 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #13
0
 public MPBranch(long lid, EPhaseCode phaseCode, long firstNode, long secondNode)
     : base(lid, phaseCode)
 {
     this.endNodes = new long[2] {
         firstNode, secondNode
     };
     this.NextInRoot    = new long[3];
     this.PrevInRoot    = new long[3];
     this.DownNode      = new long[3];
     this.UpNode        = new long[3];
     this.BothDirection = false;
 }
예제 #14
0
        public void ReadSwitches(Dictionary <long, ResourceDescription> cimSwitches, Dictionary <long, ResourceDescription> cimTerminals)
        {
            if (!isRootsInitialized || !isBranchesInitialized || !isNodesInitialized)
            {
                return;
            }

            Dictionary <long, MPBranch>       branches = internalModel.Branches;
            Dictionary <long, MPNode>         nodes    = internalModel.Nodes;
            Dictionary <long, MPSwitchDevice> switches = internalModel.SwitchDevices;

            foreach (ResourceDescription cimSwitch in cimSwitches.Values)
            {
                long switchId = cimSwitch.Id;
                if (!branches.ContainsKey(switchId))
                {
                    List <long> terminalsID = cimSwitch.GetProperty(ModelCode.CONDEQ_TERMINALS).AsReferences();
                    AddBranch(cimTerminals, branches, nodes, switchId, terminalsID);
                    if (!switches.ContainsKey(switchId))
                    {
                        ResourceDescription firstTerminal = cimTerminals[terminalsID[0]];
                        long       nodeId       = firstTerminal.GetProperty(ModelCode.TERMINAL_CONNECTIVITYNODE).AsReference();
                        EPhaseCode switchPhases = (EPhaseCode)firstTerminal.GetProperty(ModelCode.TERMINAL_PHASES).AsEnum();
                        EPhaseCode switchState  = GetSwitchState(switchPhases, cimSwitch.GetProperty(ModelCode.SWITCH_NORMALOPEN).AsBool());

                        MPSwitchDevice newSwitch = new MPSwitchDevice(switchId, switchId, nodeId, switchPhases, switchState);

                        switches.Add(switchId, newSwitch);
                    }
                    else
                    {
                        string errMessage = $"Switch with id {switchId} already exists in intenal model.";
                        Logger.LogError(errMessage);
                        throw new Exception(errMessage);
                    }
                }
                else
                {
                    string errMessage = $"Switch (branch) with id {switchId} already exists in intenal model.";
                    Logger.LogError(errMessage);
                    throw new Exception(errMessage);
                }
            }

            isSwitchesInitialized = true;
        }
        public static EPhaseIndex PhaseCodeToIndex(EPhaseCode phaseCode)
        {
            switch (phaseCode)
            {
            case EPhaseCode.A:
                return(EPhaseIndex.A);

            case EPhaseCode.B:
                return(EPhaseIndex.B);

            case EPhaseCode.C:
                return(EPhaseIndex.C);

            default:
                throw new ArgumentException();
            }
        }
예제 #16
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;
        }
예제 #17
0
        public void UpdateTopologyAfterOpeningPhaseOfSwitch(long branch, EPhaseCode phaseToClose)
        {
            MPBranch stateBranch = internalModel.Branches[branch];

            if (stateBranch.Marker != EEnergizationStatus.TA_UNENERGIZED)
            {
                FindRootsToUpdate(branch);

                EPhaseIndex phaseIndex = PhaseHelper.PhaseCodeToIndex(phaseToClose);

                long nodeLid = stateBranch.DownNode[(long)phaseIndex];
                bfScanner.Init();
                bfScanner.Add(new ActiveNodeInfo(LIDtoIND[nodeLid] + (long)phaseIndex, (long)phaseIndex));

                ProcessIsland();

                AnalyzeTopology(internalModel.Roots);
            }
        }
예제 #18
0
 private EEnergizationStatus CalculateEnergization(EPhaseCode originalPhases, EPhaseCode activePhases, bool loop)
 {
     if (loop)
     {
         return(EEnergizationStatus.TA_MESHED);
     }
     if (activePhases == originalPhases)
     {
         return(EEnergizationStatus.TA_ENERGIZED);
     }
     if ((activePhases & originalPhases) == activePhases)
     {
         return(EEnergizationStatus.TA_PARTIAL);
     }
     if (activePhases == EPhaseCode.NONE)
     {
         return(EEnergizationStatus.TA_UNENERGIZED);
     }
     return(EEnergizationStatus.TA_UNKNOWN);
 }
예제 #19
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);
                    }
                }
            }
        }
예제 #20
0
        public void ReadRootsFromFile()
        {
            String file_name = "Roots.xml";

            Dictionary <long, MPNode> listOfNodes = internalModel.Nodes;

            Dictionary <long, MPBranch> listOfBranches = internalModel.Branches;
            Dictionary <long, MPRoot>   roots          = internalModel.Roots;

            XmlDocument xml_doc = new XmlDocument();

            xml_doc.Load(file_path + file_name);

            XmlNodeList xnList = xml_doc.SelectNodes("/Roots/Root");

            foreach (XmlElement xml_elem in xnList)
            {
                long       root_lid = UInt32.Parse(xml_elem.GetAttribute("LID"));
                long       node_lid = UInt32.Parse(xml_elem["Node"].InnerText);
                EPhaseCode phases   = (EPhaseCode)Byte.Parse(xml_elem["Phases"].InnerText);

                if (listOfNodes.ContainsKey(node_lid))
                {
                    throw new Exception("Bad input file. There is already root node with specific lid.");
                }

                if (!roots.ContainsKey(root_lid))
                {
                    MPRootNode rootNode = new MPRootNode(node_lid, root_lid, EPhaseCode.ABC);
                    listOfNodes.Add(node_lid, rootNode);

                    MPRoot root = new MPRoot(root_lid, node_lid);
                    roots.Add(root_lid, root);
                }
            }
        }
예제 #21
0
 public MPBusNode(long lid, EPhaseCode phaseCode)
     : base(lid, phaseCode)
 {
 }
예제 #22
0
        public void UpdateTopologyAfterClosingPhaseOfSwitch(long branch, EPhaseCode phaseToClose)
        {
            FindRootsToUpdate(branch);

            AnalyzeTopology(internalModel.Roots);
        }
예제 #23
0
 public MPLine(long lid, EPhaseCode phaseCode, long upNode, long downNode)
     : base(lid, phaseCode, upNode, downNode)
 {
 }
예제 #24
0
 public MPRootNode(long lid, long root, EPhaseCode phaseCode)
     : base(lid, phaseCode)
 {
     OwnerCircuit = new long[] { root, root, root };
 }
예제 #25
0
 public MPNode(long lid, EPhaseCode phaseCode)
     : base(lid, phaseCode)
 {
     this.Parents  = null;
     this.Children = null;
 }
예제 #26
0
 public MPJumper(long lid, EPhaseCode phaseCode, long firstNode, long secondNode) :
     base(lid, phaseCode, firstNode, secondNode)
 {
 }
 public MPConnectivityBranch(long lid, long originalBranchLid, EPhaseCode phaseCode, long upNode, long downNode)
     : base(lid, phaseCode, upNode, downNode)
 {
     OriginalBranchLid = originalBranchLid;
 }
 public MPConnectivityNode(long lid, EPhaseCode phaseCode)
     : base(lid, phaseCode)
 {
 }
예제 #29
0
        private EPhaseCode GetSwitchState(EPhaseCode phaseCode, bool open)
        {
            EPhaseCode mask = open ? EPhaseCode.NONE : EPhaseCode.ABCN;

            return(mask & phaseCode);
        }