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); } }
public void ClosePhaseOfSwitch(MPSwitchDevice switchDevice, EPhaseCode phaseToChange) { MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch]; AddBranchToModel(statebranch, phaseToChange); switchDevice.State = switchDevice.State | phaseToChange; }
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 CloseSwitch(MPSwitchDevice switchDevice, EPhaseCode phasesToAdd) { MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch]; AddBranchToModel(statebranch, phasesToAdd); switchDevice.State = switchDevice.OriginalPhases; }
public void OpenSwitch(MPSwitchDevice switchDevice, EPhaseCode phasesToRemove) { MPConnectivityBranch statebranch = (MPConnectivityBranch)internalModel.Branches[switchDevice.StateBranch]; RemoveBranchFromModel(statebranch, phasesToRemove); switchDevice.State = EPhaseCode.NONE; }
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; }
private void InsertSwitchDeviceInMatrixModel(MPSwitchDevice bay) { MPBranch oldBranch = internalModel.Branches[bay.EndBranch]; // Krajevi grane na kojoj se nalazi prekidac long node2Lid = bay.EndNode; long node1Lid = oldBranch.EndNodes[0] == node2Lid ? oldBranch.EndNodes[1] : oldBranch.EndNodes[0]; // Kreiranje novog cvora sa faznoscu stare grane long connNodeLid = internalModel.LidManager.FindFreeTemporaryIndex("MPConnectivityNode"); MPConnectivityNode connNode = new MPConnectivityNode(connNodeLid, oldBranch.OriginalPhases); AddNodeInModel(connNodeLid); internalModel.Nodes.Add(connNodeLid, connNode); // Kreiranje prve grane sa faznoscu stare grane long connBranch1Lid = internalModel.LidManager.FindFreeTemporaryIndex("MPConnectivityBranch"); MPConnectivityBranch connBranch1 = new MPConnectivityBranch(connBranch1Lid, oldBranch.Lid, oldBranch.OriginalPhases, node1Lid, connNodeLid); AddBranchToModel(connBranch1); internalModel.Branches.Add(connBranch1Lid, connBranch1); // Kreiranje druge grane sa faznoscu i stanjem prekidaca long connBranch2Lid = internalModel.LidManager.FindFreeTemporaryIndex("MPConnectivityBranch"); MPConnectivityBranch connBranch2 = new MPConnectivityBranch(connBranch2Lid, oldBranch.Lid, bay.OriginalPhases, connNodeLid, node2Lid); AddBranchToModel(connBranch2, bay.State); internalModel.Branches.Add(connBranch2Lid, connBranch2); // Povezivanje prekidaca sa granom koja modelira njegovo stanje bay.StateBranch = connBranch2Lid; // Brisanje stare grane RemoveBranchFromModel(oldBranch); internalModel.Branches.Remove(oldBranch.Lid); }