private bool Intersect(LayerEdge e, LayerEdge m) { int a = layerArrays.X[e.Source] - layerArrays.X[m.Source]; int b = layerArrays.X[e.Target] - layerArrays.X[m.Target]; return(a > 0 && b < 0 || a < 0 && b > 0); //return (layerArrays.X[e.Source] - layerArrays.X[m.Source]) * (layerArrays.X[e.Target] - layerArrays.X[m.Target]) < 0; }
///// <summary> ///// mark the vertex as one representing a label ///// or a middle of a multi edge ///// </summary> ///// <param name="db"></param> ///// <param name="bucket"></param> ///// <param name="parent"></param> ///// <param name="i"></param> internal static void RegisterDontStepOnVertex(Database db, IntEdge parent) { if (db.Multiedges[new IntPair(parent.Source, parent.Target)].Count > 1) { LayerEdge e = parent.LayerEdges[parent.LayerEdges.Count / 2]; db.MultipleMiddles.Insert(e.Source); } }
LayerEdge InnerEdgeByTarget(int v) { if (IsVirtual(v)) { LayerEdge ie = InEdgeOfVirtualNode(v);//there is exactly one edge entering in to the dummy node if (IsVirtual(Source(ie))) { return(ie); } } return(null); }
private bool IntersectAbove(int u, int v) { while (true) { LayerEdge eu = IncomingEdge(u); LayerEdge ev = IncomingEdge(v); if (Intersect(eu, ev)) { return(true); } u = eu.Source; v = ev.Source; if (!(IsVirtualVertex(u) && IsVirtualVertex(v))) { if (u == v) { return(true); } return(false); } } }
///// <summary> ///// This function marks conflicting edges with targets positioned between innerEdge and newInnerEdge targets. ///// </summary> ///// <param name="lowerLayer"></param> ///// <param name="innerEdge"></param> ///// <param name="newInnerEdge"></param> ///// <param name="posInnerEdgeTarget"></param> ///// <param name="posNewInnerEdgeTarget"></param> void MarkEdgesBetweenInnerAndNewInnerEdges(int[] lowerLayer, LayerEdge innerEdge, LayerEdge newInnerEdge, int innerEdgeSourcePos, int newInnerEdgeSourcePos) { int u = NextRight(Pos(Target(innerEdge))); for (; IsLeftFrom(u, Pos(Target(newInnerEdge))); u = NextRight(u)) { foreach (LayerEdge ie in InEdges(lowerLayer[u])) { int ieSourcePos = Pos(Source(ie)); if (IsLeftFrom(ieSourcePos, innerEdgeSourcePos))//the equality is not possible { MarkEdge(ie); } else if (IsLeftFrom(newInnerEdgeSourcePos, ieSourcePos)) { MarkEdge(ie); } } } }
private bool IntersectBelow(int u, int v) { while (true) { LayerEdge eu = OutcomingEdge(u); LayerEdge ev = OutcomingEdge(v); if (Intersect(eu, ev)) { return(true); } u = eu.Target; v = ev.Target; if (!(IsVirtualVertex(u) && IsVirtualVertex(v))) { if (v == u) { return(true); } return(false); } } }
///// <summary> ///// Returns the inner non-conflicting edge incoming into i-th position ///// of the layer or null if there is no such edge ///// </summary> ///// <param name="layer"></param> ///// <param name="innerEdge"></param> ///// <param name="i"></param> ///// <returns></returns> private LayerEdge AlignmentToTheRightOfInner(int[] lowLayer, int i, int posInnerSource ) { int numOfInEdges = NumberOfInEdges(lowLayer[i]); if (numOfInEdges == 1) { LayerEdge ie = null; foreach (LayerEdge e in InEdges(lowLayer[i])) { ie = e; } if (IsInnerEdge(ie) && IsLeftFrom(posInnerSource, Pos(ie.Source))) { return(ie); } return(null); } return(null); }
bool IsInnerEdge(LayerEdge e) { return IsVirtual(e.Source) && IsVirtual(e.Target); }
int Target(LayerEdge edge) { return(BT ? edge.Target : edge.Source); }
int Source(LayerEdge edge) { return(BT ? edge.Source : edge.Target); }
private bool Intersect(LayerEdge e, LayerEdge m) { int a = layerArrays.X[e.Source] - layerArrays.X[m.Source]; int b = layerArrays.X[e.Target] - layerArrays.X[m.Target]; return a > 0 && b < 0 || a < 0 && b > 0; //return (layerArrays.X[e.Source] - layerArrays.X[m.Source]) * (layerArrays.X[e.Target] - layerArrays.X[m.Target]) < 0; }
//[System.Diagnostics.Conditional("DEBUGGLEE")] //private void TestYXLayers(LayerArrays layerArrays, int[] xLayers) { // foreach (IntEdge e in this.xLayoutGraph.Edges) { // int s = e.Source; int targ = e.Target; // if (e.Source >= layeredGraph.Nodes.Count) { // if (xLayoutGraph.OutEdges(s).Count != 2 || xLayoutGraph.InEdges(s).Count != 0) // Report("must be two out edges and none incoming"); // if (targ >= layeredGraph.Nodes.Count) // Report("an illegal edge"); // } else { // if (layerArrays.Y[s] != layerArrays.Y[targ]) // Report("layers don't coincide"); // if (layerArrays.X[s] - 1 != layerArrays.X[targ]) // Report("wrong input"); // if (xLayers[s] <= xLayers[targ]) // Report("wrong xlayering"); // } // } //} /// <summary> /// Creating a proper layered graph, a graph where each /// edge goes only one layer down from the i+1-th layer to the i-th layer. /// </summary> /// <param name="layering"></param> /// <param name="layerArrays"></param> void CreaeteProperLayeredGraph(int[] layering, out LayerArrays layerArrays) { int n = layering.Length; int nOfVV = 0; foreach (IntEdge e in database.SkeletonEdges()) { int span = EdgeSpan(layering, e); Debug.Assert(span >= 0); if (span > 0) e.LayerEdges = new LayerEdge[span]; int pe = 0; //offset in the string if (span > 1) { //we create span-2 dummy nodes and span new edges int d0 = n + nOfVV++; var layerEdge = new LayerEdge(e.Source, d0, e.CrossingWeight,e.Weight); e.LayerEdges[pe++] = layerEdge; //create span-2 internal edges all from dummy nodes for (int j = 0; j < span - 2; j++) { d0++; nOfVV++; layerEdge = new LayerEdge(d0 - 1, d0, e.CrossingWeight,e.Weight); e.LayerEdges[pe++] = layerEdge; } layerEdge = new LayerEdge(d0, e.Target, e.CrossingWeight, e.Weight); e.LayerEdges[pe] = layerEdge; } else if (span == 1) { var layerEdge = new LayerEdge(e.Source, e.Target, e.CrossingWeight, e.Weight); e.LayerEdges[pe] = layerEdge; } } var extendedVertexLayering = new int[originalGraph.Nodes.Count + nOfVV]; foreach (IntEdge e in database.SkeletonEdges()) if (e.LayerEdges != null) { int l = layering[e.Source]; extendedVertexLayering[e.Source] = l--; foreach (LayerEdge le in e.LayerEdges) extendedVertexLayering[le.Target] = l--; } else { extendedVertexLayering[e.Source] = layering[e.Source]; extendedVertexLayering[e.Target] = layering[e.Target]; } properLayeredGraph = new ProperLayeredGraph(new BasicGraph<Node, IntEdge>(database.SkeletonEdges(), layering.Length)); properLayeredGraph.BaseGraph.Nodes = IntGraph.Nodes; layerArrays = new LayerArrays(extendedVertexLayering); }
int Source(LayerEdge edge) { return BT ? edge.Source : edge.Target; }
private void MoveBundledSites(LayerEdge fromEdge, LayerEdge toEdge) { MoveBundledEdge(anchors[toEdge.Source].X - anchors[fromEdge.Source].X, anchors[toEdge.Target].X - anchors[fromEdge.Target].X); }
private bool Intersect(LayerEdge e, LayerEdge m) { return((layerArrays.X[e.Source] - layerArrays.X[m.Source]) * (layerArrays.X[e.Target] - layerArrays.X[m.Target]) < 0); }
private bool Intersect(LayerEdge e, LayerEdge m) { return (layerArrays.X[e.Source] - layerArrays.X[m.Source]) * (layerArrays.X[e.Target] - layerArrays.X[m.Target]) < 0; }
private void MoveBundledSites(LayerEdge fromEdge, LayerEdge toEdge) { MoveBundledEdge(anchors[toEdge.Source].X - anchors[fromEdge.Source].X, anchors[toEdge.Target].X - anchors[fromEdge.Target].X); }
/// <summary> /// overrides the equlity /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { LayerEdge ie = obj as LayerEdge; return(ie.source == this.source && ie.target == this.target); }
bool IsInnerEdge(LayerEdge e) { return(IsVirtual(e.Source) && IsVirtual(e.Target)); }
int Target(LayerEdge edge) { return BT ? edge.Target : edge.Source; }
private void MarkEdge(LayerEdge ie) { this.markedEdges.Insert(new IntPair(ie.Source, ie.Target)); }
///// <summary> ///// Eliminates conflicts with at least one inner edge inside of one layer ///// </summary> ///// <param name="i"></param> void ConflictsWithAtLeastOneInnerEdgeForALayer(int layerIndex) { if (layerIndex >= 0 && layerIndex < this.la.Layers.Length) { int[] lowerLayer = this.la.Layers[layerIndex]; LayerEdge innerEdge = null; //start looking for the first inner edge from the left of lowerLayer int targetPos = LeftMost(0, lowerLayer.Length - 1); int lastTargetPos = RightMost(0, lowerLayer.Length - 1);; for (; IsNotRightFrom(targetPos, lastTargetPos) && innerEdge == null; targetPos = NextRight(targetPos)) { innerEdge = InnerEdgeByTarget(lowerLayer[targetPos]); } //now targetPos points to the right of the innerEdge target at lowerLayer if (innerEdge != null) { int positionOfInnerEdgeSource = Pos(Source(innerEdge)); //We are still not in the main loop. //We mark conflicting edges with targets to the left of targetPos, //That of course means //that the sources of conflicting edges lie to the right of Source(innerEdge) for (int j = LeftMost(0, lowerLayer.Length - 1); IsLeftFrom(j, targetPos); j = NextRight(j)) { foreach (LayerEdge ie in InEdges(lowerLayer[j])) { if (IsLeftFrom(positionOfInnerEdgeSource, Pos(Source(ie)))) { MarkEdge(ie); } } } int innerSourcePos = Pos(Source(innerEdge)); //starting the main loop while (IsNotRightFrom(targetPos, lastTargetPos)) { //Now we look for the next inner edge in the alignment to the right of the current innerEdge, //and we mark the conflicts later. Marking the conflicts later makes sense. //We would have to go through positions between innerEdge and newInnerEdge targets //again anyway to resolve conflicts with not inner edges and newInnerEdge LayerEdge newInnerEdge = AlignmentToTheRightOfInner(lowerLayer, targetPos, positionOfInnerEdgeSource); targetPos = NextRight(targetPos); if (newInnerEdge != null) { int newInnerSourcePos = Pos(Source(newInnerEdge)); MarkEdgesBetweenInnerAndNewInnerEdges(lowerLayer, innerEdge, newInnerEdge, innerSourcePos, newInnerSourcePos); innerEdge = newInnerEdge; innerSourcePos = newInnerSourcePos; } } positionOfInnerEdgeSource = Pos(Source(innerEdge)); //look for conflicting edges with targets to the right from the target of innerEdge for (int k = NextRight(Pos(Target(innerEdge))); IsNotRightFrom(k, lastTargetPos); k = NextRight(k)) { foreach (LayerEdge ie in InEdges(lowerLayer[k])) { if (IsLeftFrom(Pos(Source(ie)), Pos(Source(innerEdge)))) { MarkEdge(ie); } } } } } }
///// <summary> ///// This function marks conflicting edges with targets positioned between innerEdge and newInnerEdge targets. ///// </summary> ///// <param name="lowerLayer"></param> ///// <param name="innerEdge"></param> ///// <param name="newInnerEdge"></param> ///// <param name="posInnerEdgeTarget"></param> ///// <param name="posNewInnerEdgeTarget"></param> void MarkEdgesBetweenInnerAndNewInnerEdges(int[] lowerLayer, LayerEdge innerEdge, LayerEdge newInnerEdge, int innerEdgeSourcePos, int newInnerEdgeSourcePos) { int u = NextRight(Pos(Target(innerEdge))); for (; IsLeftFrom(u, Pos(Target(newInnerEdge))); u = NextRight(u)) { foreach (LayerEdge ie in InEdges(lowerLayer[u])) { int ieSourcePos = Pos(Source(ie)); if (IsLeftFrom(ieSourcePos, innerEdgeSourcePos))//the equality is not possible MarkEdge(ie); else if (IsLeftFrom(newInnerEdgeSourcePos, ieSourcePos)) MarkEdge(ie); } } }
private void MarkEdge(LayerEdge ie) { this.markedEdges.Insert(new IntPair(ie.Source, ie.Target)); }