private void SetUpProcessOfRoot(MPRoot currRoot) { // Init bfScanner.Init(); visitedNodes.Clear(); visitedBranches.Clear(); loops.Clear(); foreach (MPRoot parallelRoot in rootsInParallel.Values) { long rootNodeLid = parallelRoot.SourceObject.Value; CVisitedNode rootNode = new CVisitedNode(rootNodeLid, true); rootNode.OwnerCircuit = new long[] { rootNodeLid, rootNodeLid, rootNodeLid }; visitedNodes.Add(rootNodeLid, rootNode); long nodeIndex = LIDtoIND[rootNodeLid]; bfScanner.AddRange(new List <ActiveNodeInfo>(3) { new ActiveNodeInfo(nodeIndex + (long)EPhaseIndex.A, (long)EPhaseIndex.A), new ActiveNodeInfo(nodeIndex + (long)EPhaseIndex.B, (long)EPhaseIndex.B), new ActiveNodeInfo(nodeIndex + (long)EPhaseIndex.C, (long)EPhaseIndex.C) }); parallelRoot.InitTopology(); } long invalidIndex = 0; previousBranch = new CVisitedBranch[3] { new CVisitedBranch(invalidIndex), new CVisitedBranch(invalidIndex), new CVisitedBranch(invalidIndex) }; }
public void UpdateRootTopology(MPRoot root) { previousBranch = new CVisitedBranch[3]; bool oneMoreTime = true; rootsInParallel.Clear(); rootsInParallel.Add(root.Lid, root); do { SetUpProcessOfRoot(root); try { ProcessRoot(root); foreach (var processedRoot in rootsInParallel.Values) { processedRoot.UpToDate = true; } oneMoreTime = false; } catch (ParallelRootFoundException) { ; // Ponavlja se obrada korena zbog uocenog dodatnog paralelnog korena } } while (oneMoreTime == true); // Dok svi koreni ne budu uspesno procesuirani }
private void TraverseRoot(MPRoot currRoot) { while (bfScanner.HasNext()) // Da li su procesirani svi cvorovi koji bi trebali biti { ActiveNodeInfo nextNode = bfScanner.GetNext(); List <long> neigbours = ProcessNeighboursInRoot(nextNode.NodeIndex, nextNode.PhaseIndex, currRoot.Lid); // Uzima se novi cvor za procesiranje bfScanner.AddRange(neigbours.Select(neighbour => new ActiveNodeInfo(neighbour, nextNode.PhaseIndex)).ToList()); // Dodaju se pronadjeni susedi } }
private void ProcessRoot(MPRoot currRoot) { // Pretrazivanje grafa korena TraverseRoot(currRoot); // Bojenje pronadjenih petlji ProcessLoops(); // Cuvanje rezultata topologije SaveNodeResultsForRoot(visitedNodes, currRoot); SaveBranchResultsForRoot(visitedBranches, currRoot); return; }
private void CheckAndReportRootsInParallel(long downLid, long masterRoot) { if (internalModel.LidManager.CheckType("MPRootNode", downLid)) { long rootLid = internalModel.Nodes[downLid].OwnerCircuit[0]; MPRoot root = internalModel.Roots[rootLid]; rootsInParallel[root.Lid] = root; root.MasterRoot = masterRoot; rootsInParallel[masterRoot].SlaveRoots.Add(rootLid); throw new ParallelRootFoundException("Parallel root is founded. Process will be repeated."); } }
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; }
public Task <TopologyResult> AnalyzeTopology(CModelFramework internalModel, long rootId) { ServiceEventSource.Current.ServiceMessage(this.Context, $"TopologyStatelessService.Analyze started. PartitionID = {Context.PartitionId} Root id = 0x{rootId:x16}."); // Create matrix model CSparseMatrix matrixModel = new CSparseMatrix(); CMatrixModelBuilder matrixModelBuilder = new CMatrixModelBuilder(matrixModel, internalModel); matrixModelBuilder.CreateInitialLidDictionary(); matrixModelBuilder.CreateInitialMatrixModel(); matrixModelBuilder.InsertSwitchDeviceFromInternalToMatrixModel(); CTopologyAnalyzer topologyAnalyzer = new CTopologyAnalyzer(matrixModel, matrixModelBuilder.LIDtoIND, matrixModelBuilder.INDtoLID, internalModel); if (!internalModel.Roots.ContainsKey(rootId)) { Logger.LogError($"Root with id 0x{rootId:X16} is not in internal model"); } MPRoot root = internalModel.Roots[rootId]; if (!root.UpToDate) //obradjuju se samo neazurni koreni { topologyAnalyzer.UpdateRootTopology(root); } List <MPNode> nodes = topologyAnalyzer.InternalModel.Nodes.Values.Where(node => node.OwnerCircuit[0] == rootId || node.Lid == rootId).ToList(); List <MPBranch> branches = topologyAnalyzer.InternalModel.Branches.Values.Where(branch => branch.OwnerCircuit[0] == rootId || branch.Lid == rootId).ToList(); ServiceEventSource.Current.ServiceMessage(this.Context, $"TopologyStatelessService.Analyze finished for root 0x{rootId:x16} Nodes: {nodes.Count} Branches: {branches.Count}"); try { return(Task.FromResult(new TopologyResult(nodes, branches, rootId))); } catch (Exception e) { ServiceEventSource.Current.ServiceMessage(this.Context, $"{e.Message}"); return(null); } }
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); } } }
public MPIsland(long lid) : base(lid) { this.masterRoot = null; this.validFlag = true; }
private void SaveNodeResultsForRoot(Dictionary <long, CVisitedNode> visitedNodes, MPRoot root) { foreach (CVisitedNode visitedNode in visitedNodes.Values) { MPNode node = internalModel.Nodes[visitedNode.Lid]; node.Children = visitedNode.Children; node.Parents = visitedNode.Parents; node.OwnerCircuit = visitedNode.OwnerCircuit; node.ActivePhases = CalculateActivePhases(visitedNode.Visited); node.Marker = CalculateEnergization(node.OriginalPhases, node.ActivePhases, visitedNode.Loop); root.GraphElems.Add(visitedNode.Lid); } }
private void SaveBranchResultsForRoot(Dictionary <long, CVisitedBranch> visitedBranches, MPRoot root) { foreach (CVisitedBranch visitedbranch in visitedBranches.Values) { MPBranch branch = internalModel.Branches[visitedbranch.Lid]; branch.NextInRoot = visitedbranch.NextInRoot; branch.PrevInRoot = visitedbranch.PrevInRoot; branch.UpNode = visitedbranch.UpNode; branch.DownNode = visitedbranch.DownNode; branch.OwnerCircuit = visitedbranch.OwnerCircuit; branch.ActivePhases = CalculateActivePhases(visitedbranch.Visited); branch.Marker = CalculateEnergization(branch.OriginalPhases, branch.ActivePhases, visitedbranch.Loop); root.GraphElems.Add(visitedbranch.Lid); } }