private void ProccessLoopByPhase(KeyValuePair <long, bool[]> loopInfo) { for (byte phaseIndex = 0; phaseIndex < 3; phaseIndex++) { if (loopInfo.Value[phaseIndex]) { long rightBranchLid = loopInfo.Key; CVisitedBranch rightBranch = visitedBranches[rightBranchLid]; long downNodeLid = (long)rightBranch.DownNode[phaseIndex]; CVisitedNode downNode = visitedNodes[downNodeLid]; downNode.Loop = true; long leftBranchLid = downNode.Parents[phaseIndex].First(); CVisitedBranch leftBranch = visitedBranches[leftBranchLid]; //Pronadji konturu CContourScanner contourIterator = new CContourScanner(); contourIterator.Begin(); contourIterator.MarkContour(phaseIndex, leftBranch, rightBranch, visitedBranches, visitedNodes); //Markiranje leve i desne strane petlje CVisitedBranch branch; CVisitedNode node; while (contourIterator.Next(out branch, out node, visitedNodes, phaseIndex) == true) { branch.Loop = true; node.Loop = true; } } } }
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 bool Next(out CVisitedBranch branch, out CVisitedNode node, Dictionary <long, CVisitedNode> visitedNodes, byte phaseIndex) { switch (sideOfContour) { case (sbyte)EContourSide.LEFT: { branch = branchInContour[0][index]; node = visitedNodes[branch.UpNode[phaseIndex]]; if (index < branchInContour[0].Count - 1) { index++; } else { sideOfContour = EContourSide.RIGHT; index = branchInContour[1].Count - 1; } return(true); } case EContourSide.RIGHT: { branch = branchInContour[1][index]; node = visitedNodes[branch.UpNode[phaseIndex]]; if (index > 0) { index--; } else { sideOfContour = EContourSide.UNKNOWN; } return(true); } default: { node = null; branch = null; return(false); } } }
private List <long> ProcessNodeInIsland(long upNodeInd, long phaseIndex) { // Dobavljaju se susedne grane i cvorovi iz odgovarajuceg reda matrice List <Neighbour> neighbours = GetNeighboursFromMatrix(upNodeInd); List <long> unvisitedNeighbours = new List <long>(neighbours.Count); foreach (var neighbour in neighbours) { long branchLid = neighbour.Branch; //susedni cvor //grana koja spaja ta dva cvora long downNodeLid = INDtoLID[(int)(neighbour.NodeIndex - phaseIndex)]; //susedni cvor CVisitedBranch visitedBranch; if (!visitedBranches.TryGetValue(branchLid, out visitedBranch)) // kreiraj ukoliko ne postoji { visitedBranch = new CVisitedBranch(branchLid); visitedBranches.Add(branchLid, visitedBranch); } if (visitedBranch.Visited[phaseIndex]) // proveri da li je grana prethodno posecena { continue; } visitedBranch.Visited[phaseIndex] = true; // poseti granu u toj fazi CVisitedNode visitedNode; if (!visitedNodes.TryGetValue(downNodeLid, out visitedNode)) // u koliko cvor do sada nije uopste posecivan { visitedNode = new CVisitedNode(downNodeLid); visitedNodes.Add(downNodeLid, visitedNode); } if (!visitedNode.Visited[phaseIndex]) //u koliko cvor do sada nije posecivan u fazi po kojoj se obradjuje { visitedNode.Visited[phaseIndex] = true; //poseti cvor unvisitedNeighbours.Add(neighbour.NodeIndex); //susedi koji jos nisu procesuirani dodaju se u listu za obradu } } return(unvisitedNeighbours); }
public void MarkContour(byte phaseIndex, CVisitedBranch leftBranch, CVisitedBranch rightBranch, Dictionary <long, CVisitedBranch> visitedBranches, Dictionary <long, CVisitedNode> visitedNodes) { //LEVI KRAJ PETLJE CVisitedBranch tempBranch = leftBranch; branchInContour[0].Add(tempBranch); CVisitedNode tempNode = visitedNodes[tempBranch.UpNode[phaseIndex]]; while (!(tempNode.Parents[phaseIndex].Count == 0)) { tempBranch = visitedBranches[tempNode.Parents[phaseIndex].First()]; branchInContour[0].Add(tempBranch); tempNode = visitedNodes[tempBranch.UpNode[phaseIndex]]; } //DESNI KRAJ PETLJE tempBranch = rightBranch; branchInContour[1].Add(tempBranch); tempNode = visitedNodes[tempBranch.UpNode[phaseIndex]]; while (!(tempNode.Parents[phaseIndex].Count == 0)) { tempBranch = visitedBranches[tempNode.Parents[phaseIndex].First()]; tempNode = visitedNodes[tempBranch.UpNode[phaseIndex]]; if (!branchInContour[0].Contains(tempBranch)) { branchInContour[1].Add(tempBranch); } else { int firstIndex = branchInContour[0].LastIndexOf(tempBranch); int count = branchInContour[0].Count - firstIndex; branchInContour[0].RemoveRange(firstIndex, count); break; } } }
private List <long> ProcessNeighboursInRoot(long upNodeInd, long phaseIndex, long rootLid) { // Dobavljaju se susedne grane i cvorovi iz odgovarajuceg reda matrice List <Neighbour> neighbours = GetNeighboursFromMatrix(upNodeInd); List <long> unvisitedNeigbours = new List <long>(neighbours.Count); // Neposeceni susedi datog cvora i faznost koju nose foreach (var neighbour in neighbours) { long upNodeLid = INDtoLID[(int)(upNodeInd - phaseIndex)]; // Polazni cvor long branchLid = neighbour.Branch; // Susedni cvor long downNodeLid = INDtoLID[(int)(neighbour.NodeIndex - phaseIndex)]; // Grana koja spaja ta dva cvora CVisitedBranch visitedBranch; if (!visitedBranches.TryGetValue(branchLid, out visitedBranch)) // Ukoliko grana ne postoji u evidenciji { visitedBranch = new CVisitedBranch(branchLid); visitedBranches.Add(branchLid, visitedBranch); // tada ju je potrebno dodati } if (visitedBranch.Visited[phaseIndex]) // Provera da li je grana prethodno posecena { continue; } // Proverava se da sused nije korenski cvor CheckAndReportRootsInParallel(downNodeLid, rootLid); // Obrada susedne grane visitedBranch.Visited[phaseIndex] = true; // Poseti granu za tu fazu visitedBranch.OwnerCircuit[phaseIndex] = rootLid; // Obelezi koren kome pripada visitedBranch.UpNode[phaseIndex] = upNodeLid; // Odredi gornji i donji cvor grane visitedBranch.DownNode[phaseIndex] = downNodeLid; visitedBranch.PrevInRoot[phaseIndex] = previousBranch[phaseIndex].Lid; // Povezi prethodnu i narednu granu u sloju previousBranch[phaseIndex].NextInRoot[phaseIndex] = branchLid; previousBranch[phaseIndex] = visitedBranch; // Trenutna grana ce biti prethodna grana narednoj grani CVisitedNode visitedNode; if (!visitedNodes.TryGetValue(downNodeLid, out visitedNode)) // Ukoliko cvor ne postoji u evidenciji... { visitedNode = new CVisitedNode(downNodeLid); visitedNodes.Add(downNodeLid, visitedNode); // ...tada ga je potrebno dodati } //DODAVANJE NEOBRADJENOG CVORA U GRUPU if (!visitedNode.Visited[phaseIndex]) // Ukoliko susedni cvor do sada nije posecivan u fazi po kojoj se obradjuje { visitedNode.Visited[phaseIndex] = true; // Poseti cvor visitedNode.OwnerCircuit[phaseIndex] = rootLid; // Obelezi koren kojem pripada unvisitedNeigbours.Add(neighbour.NodeIndex); //susedi koji jos nisu do sada procesuirani se dodaju u listu za obradu } //OBELEZAVANJE PETLJI //Ukoliko je cvor vec ranije posecen preko iste faze to je jasan pokazatelj postojanja petlje (cvor smo vec prethodno posetili preko neke druge grane) else { ReportLoop(branchLid, phaseIndex); } // Zabelezi susedne grane za gornji i donji cvor visitedNode.Parents[phaseIndex].Add(branchLid); visitedNodes[upNodeLid].Children[phaseIndex].Add(branchLid); } return(unvisitedNeigbours); }