static internal void ShowHubs(MetroGraphData mgd, BundlingSettings bundlingSettings, bool withIdeal) { if (!withIdeal) return; foreach (var v in mgd.Stations) { ShowHubs(mgd, bundlingSettings, v); } }
public IntersectionCache(MetroGraphData metroGraphData, BundlingSettings bundlingSettings, CostCalculator costCalculator, Cdt cdt) { Debug.Assert(cdt!=null); this.metroGraphData = metroGraphData; this.bundlingSettings = bundlingSettings; this.costCalculator = costCalculator; this.cdt = cdt; }
public Intersections(MetroGraphData metroGraphData, BundlingSettings bundlingSettings, RectangleNode<Polyline> obstacleTree, Func<Station, Set<Polyline>> obstaclesToIgnore) { this.metroGraphData = metroGraphData; this.obstaclesToIgnore = obstaclesToIgnore; this.bundlingSettings = bundlingSettings; this.obstacleTree = obstacleTree; }
static internal void ShowHubs(MetroGraphData mgd, BundlingSettings bundlingSettings, params ICurve[] iCurves ) { HubDebugger hd = new HubDebugger(mgd, bundlingSettings); if (iCurves != null) { var dc = hd.CreateDebugCurves(iCurves); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(dc); } }
internal MultiEdgeRouter(List<Edge[]> multiEdgeGeoms, InteractiveEdgeRouter interactiveEdgeRouter, IEnumerable<ICurve> nodeBoundaryCurves, BundlingSettings bundlingSettings, Func<EdgeGeometry, List<Shape>> transparentShapeSetter) { multiEdgeGeometries = multiEdgeGeoms.Select(l => l.Select(e => e.EdgeGeometry).ToArray()).ToList(); this.interactiveEdgeRouter = interactiveEdgeRouter; this.bundlingSettings = bundlingSettings; this.transparentShapeSetter = transparentShapeSetter; nodeTree = RectangleNode<ICurve>.CreateRectangleNodeOnData(nodeBoundaryCurves, c => c.BoundingBox); }
static internal void ShowHubs(MetroGraphData mgd, BundlingSettings bundlingSettings, Station highlightedNode) { HubDebugger hd = new HubDebugger(mgd, bundlingSettings); List<DebugCurve> debugCurves = hd.CreateDebugCurves(); debugCurves.Add(new DebugCurve(100,1, "magenta", CurveFactory.CreateCircle(3, highlightedNode.Position))); debugCurves.Add(new DebugCurve(100, 0.1, "green", highlightedNode.BoundaryCurve)); Console.WriteLine(highlightedNode.SerialNumber); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(debugCurves); }
void RerouteEdges(Graph graph, BundlingSettings bundleSettings) { bundleSettings.MonotonicityCoefficient = MonotoneBarValue; var iViewer = (IViewer)GViewer; foreach (var iEdge in iViewer.Entities.Where(edge => edge is IViewerEdge)) { iViewer.InvalidateBeforeTheChange(iEdge); } RouteBundledEdges(graph.GeometryGraph, false, graph.LayoutAlgorithmSettings.EdgeRoutingSettings); foreach (var iEdge in iViewer.Entities.Where(edge=>edge is IViewerEdge) ){ iViewer.Invalidate(iEdge); } }
/// <summary> /// Cost of the whole graph /// </summary> static internal double Cost(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { double cost = 0; //ink cost += bundlingSettings.InkImportance * metroGraphData.Ink; //path lengths foreach (var metroline in metroGraphData.Metrolines) { cost += bundlingSettings.PathLengthImportance * metroline.Length / metroline.IdealLength; } cost += CostOfForces(metroGraphData, bundlingSettings); return cost; }
/// <summary> /// apply a number of heuristics to improve current routing /// </summary> internal static void FixRouting(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { #if DEBUG && TEST_MSAGL Debug.Assert(metroGraphData.looseIntersections.HubPositionsAreOK()); #endif //TimeMeasurer.DebugOutput("Initial cost = " + CostCalculator.Cost(metroGraphData, bundlingSettings)); //TimeMeasurer.DebugOutput("Initial cost of forces: " + CostCalculator.CostOfForces(metroGraphData, bundlingSettings)); var adjuster = new NodePositionsAdjuster(metroGraphData, bundlingSettings); adjuster.GlueConflictingNodes(); adjuster.UnglueEdgesFromBundleToSaveInk(true); var step = 0; int MaxSteps = 10; while (++step < MaxSteps) { /*#if DEBUG && TEST_MSAGL Debug.Assert(metroGraphData.looseIntersections.HubPositionsAreOK()); #endif*/ //heuristics to improve routing bool progress = adjuster.GlueConflictingNodes(); progress |= adjuster.RelaxConstrainedEdges(); progress |= (step <= 3 && adjuster.UnglueEdgesFromBundleToSaveInk(false)); progress |= adjuster.GlueCollinearNeighbors(step); progress |= (step == 3 && adjuster.RemoveDoublePathCrossings()); if (!progress) break; } //one SA has to be executed with bundle forces metroGraphData.cdtIntersections.ComputeForcesForBundles = true; adjuster.RemoveDoublePathCrossings(); adjuster.UnglueEdgesFromBundleToSaveInk(true); while (adjuster.GlueConflictingNodes()) { } metroGraphData.Initialize(true); //this time initialize the tight enterables also // HubDebugger.ShowHubs(metroGraphData, bundlingSettings); //TimeMeasurer.DebugOutput("NodePositionsAdjuster stopped after " + step + " steps"); //HubDebugger.ShowHubs(metroGraphData, bundlingSettings, true); //TimeMeasurer.DebugOutput("Final cost: " + CostCalculator.Cost(metroGraphData, bundlingSettings)); //TimeMeasurer.DebugOutput("Final cost of forces: " + CostCalculator.CostOfForces(metroGraphData, bundlingSettings)); }
/// <summary> /// Cost of the whole graph (hubs and bundles) /// </summary> static internal double CostOfForces(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { double cost = 0; //hubs foreach (var v in metroGraphData.VirtualNodes()) { cost += v.cachedRadiusCost; } //bundles foreach (var edge in metroGraphData.VirtualEdges()) { var v = edge.Item1; var u = edge.Item2; cost += metroGraphData.GetIjInfo(v, u).cachedBundleCost; } return cost; }
internal BundleRouter(GeometryGraph geometryGraph, SdShortestPath shortestPathRouter, VisibilityGraph visibilityGraph, BundlingSettings bundlingSettings, double loosePadding, RectangleNode<Polyline> tightHierarchy, RectangleNode<Polyline> looseHierarchy, Dictionary<EdgeGeometry, Set<Polyline>> edgeLooseEnterable, Dictionary<EdgeGeometry, Set<Polyline>> edgeTightEnterable, Func<Port, Polyline> loosePolylineOfPort) { ValidateArg.IsNotNull(geometryGraph, "geometryGraph"); ValidateArg.IsNotNull(bundlingSettings, "bundlingSettings"); this.geometryGraph = geometryGraph; this.bundlingSettings = bundlingSettings; regularEdges = geometryGraph.Edges.Where(e => e.Source != e.Target).ToArray(); VisibilityGraph = visibilityGraph; this.shortestPathRouter = shortestPathRouter; LoosePadding = loosePadding; LooseHierarchy = looseHierarchy; TightHierarchy = tightHierarchy; EdgeLooseEnterable = edgeLooseEnterable; EdgeTightEnterable = edgeTightEnterable; this.loosePolylineOfPort = loosePolylineOfPort; }
internal MetroGraphData(EdgeGeometry[] regularEdges, RectangleNode<Polyline> looseTree, RectangleNode<Polyline> tightTree, BundlingSettings bundlingSettings, Cdt cdt, Dictionary<EdgeGeometry, Set<Polyline>> edgeLooseEnterable, Dictionary<EdgeGeometry, Set<Polyline>> edgeTightEnterable, Func<Port, Polyline> loosePolylineOfPort) { //Debug.Assert(cdt != null); this.regularEdges = regularEdges; if (cdt != null) Cdt = cdt; else Cdt = BundleRouter.CreateConstrainedDelaunayTriangulation(looseTree); EdgeLooseEnterable = edgeLooseEnterable; EdgeTightEnterable = edgeTightEnterable; LoosePolylineOfPort = loosePolylineOfPort; looseIntersections = new Intersections(this, bundlingSettings, looseTree, station => station.EnterableLoosePolylines); tightIntersections = new Intersections(this, bundlingSettings, tightTree, station => station.EnterableTightPolylines); cdtIntersections = new CdtIntersections(this, bundlingSettings); Initialize(false); }
public CdtIntersections(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { this.metroGraphData = metroGraphData; this.bundlingSettings = bundlingSettings; }
public void RouteSelectedEdges(int separation) { double nodeSeparation = Graph.LayoutAlgorithmSettings.NodeSeparation; double nodePadding = nodeSeparation / 3; double loosePadding = SplineRouter.ComputeLooseSplinePadding(nodeSeparation, nodePadding); BundlingSettings bundlingSettings = new BundlingSettings() { EdgeSeparation = separation, CreateUnderlyingPolyline = true }; EdgeRoutingSettings settings = new EdgeRoutingSettings() { BundlingSettings = bundlingSettings, EdgeRoutingMode = EdgeRoutingMode }; if (settings.EdgeRoutingMode == EdgeRoutingMode.SugiyamaSplines) settings.EdgeRoutingMode = EdgeRoutingMode.Spline; if (Nodes().Any(n => n.MarkedForDragging)) { Dictionary<DNode, GeometryNode> nodesThisToAux = new Dictionary<DNode, GeometryNode>(); Dictionary<DEdge, GeometryEdge> edgesThisToAux = new Dictionary<DEdge, GeometryEdge>(); GeometryGraph ggAux = new GeometryGraph(); foreach (DNode node in Nodes()) { var n = new GeometryNode() { BoundaryCurve = node.GeometryNode.BoundaryCurve, GeometryParent = ggAux, Padding = node.GeometryNode.Padding, }; ggAux.Nodes.Add(n); nodesThisToAux[node] = n; } foreach (DNode node in Nodes().Where(n => n.MarkedForDragging)) { foreach (DEdge edge in node.Edges) { if (!edgesThisToAux.ContainsKey(edge)) { var e = new GeometryEdge(nodesThisToAux[edge.Source], nodesThisToAux[edge.Target]); if (edge.Source == edge.Target) nodesThisToAux[edge.Source].AddSelfEdge(e); else { nodesThisToAux[edge.Source].AddOutEdge(e); nodesThisToAux[edge.Target].AddInEdge(e); } ggAux.Edges.Add(e); edgesThisToAux[edge] = e; } } /*ggAux.Nodes.Add(node.GeometryNode); if (node.MarkedForDragging) { foreach (DEdge edge in node.Edges) { if (!ggAux.Nodes.Contains(edge.Source.GeometryNode)) ggAux.Nodes.Add(edge.Source.GeometryNode); if (!ggAux.Nodes.Contains(edge.Target.GeometryNode)) ggAux.Nodes.Add(edge.Target.GeometryNode); if (!ggAux.Edges.Contains(edge.GeometryEdge)) ggAux.Edges.Add(edge.GeometryEdge); } }*/ } DoEdgeRouting(ggAux, settings, nodeSeparation); //BundledEdgeRouter.RouteEdgesInMetroMapStyle(ggAux, Math.PI / 6.0, nodePadding, loosePadding, settings); /*var router = new SplineRouter(ggAux, settings); router.Run(CancelToken); VerifyPolylines();*/ foreach (var kv in edgesThisToAux) kv.Key.GeometryEdge.EdgeGeometry = kv.Value.EdgeGeometry; } else { DoEdgeRouting(Graph.GeometryGraph, settings, nodeSeparation); //BundledEdgeRouter.RouteEdgesInMetroMapStyle(Graph.GeometryGraph, Math.PI / 6.0, nodePadding, loosePadding, settings); /*var router = new SplineRouter(Graph.GeometryGraph, settings); router.Run(CancelToken); VerifyPolylines();*/ } //Invalidate(); }
static void RouteEdges(GeometryGraph graph, double edgeSeparation) { var bs = new BundlingSettings(); bs.EdgeSeparation = edgeSeparation; var br = new SplineRouter(graph, 0.25, 10, Math.PI / 6, bs); br.Run(); }
internal FlipCollapser(MetroGraphData metroGraphData, BundlingSettings bundlingSettings, Cdt cdt) { this.metroGraphData = metroGraphData; this.bundlingSettings = bundlingSettings; this.cdt = cdt; }
/// <summary> /// Error of bundles /// </summary> static internal double BundleError(double idealWidth, double nowWidth, BundlingSettings bundlingSettings) { if (idealWidth <= nowWidth) return 0; double res = bundlingSettings.BundleRepulsionImportance * (1.0 - nowWidth / idealWidth) * (idealWidth - nowWidth); return res; }
/// <summary> /// Constructor /// </summary> internal EdgeNudger(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { this.metroGraphData = metroGraphData; this.bundlingSettings = bundlingSettings; }
internal static bool FixRouting(MetroGraphData metroGraphData, BundlingSettings bundlingSettings, HashSet<Point> changedPoints) { return new SimulatedAnnealing(metroGraphData, bundlingSettings).FixRouting(changedPoints); }
public void BundlingWithGroups() { var graph = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("graphWithGroups.msagl.geom")); var settings = new BundlingSettings(); var router = new SplineRouter(graph, 3, 1, Math.PI / 6, settings); router.Run(); }
/// <summary> /// Error of ink /// </summary> static internal double InkError(double oldInk, double newInk, BundlingSettings bundlingSettings) { return (oldInk - newInk) * bundlingSettings.InkImportance; }
public void BundlingBug1GeomGraph() { #if DEBUG && TEST_MSAGL DisplayGeometryGraph.SetShowFunctions(); #endif var graph = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("bug1.msagl.geom")); var settings = new BundlingSettings(); var router = new SplineRouter(graph, 0.1, 0.75, Math.PI / 6, settings); router.Run(); }
/// <summary> /// Error of path lengths /// </summary> static internal double PathLengthsError(double oldLength, double newLength, double idealLength, BundlingSettings bundlingSettings) { return (oldLength - newLength) * (bundlingSettings.PathLengthImportance / idealLength); }
internal BundleBasesCalculator(IMetroMapOrderingAlgorithm metroOrdering, MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { this.metroOrdering = metroOrdering; this.metroGraphData = metroGraphData; this.bundlingSettings = bundlingSettings; }
/// <summary> /// fix routing by simulated annealing algorithm /// </summary> internal static bool FixRouting(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { return FixRouting(metroGraphData, bundlingSettings, null); }
static BundlingSettings GetBundlingSettings(ArgsParser.ArgsParser argsParser) { if (!argsParser.OptionIsUsed(BundlingOption)) return null; var bs = new BundlingSettings(); string ink = argsParser.GetValueOfOptionWithAfterString(InkImportanceOption); double inkCoeff; if (ink != null && double.TryParse(ink, out inkCoeff)) { bs.InkImportance = inkCoeff; BundlingSettings.DefaultInkImportance = inkCoeff; } string esString = argsParser.GetValueOfOptionWithAfterString(EdgeSeparationOption); if (esString != null) { double es; if (double.TryParse(esString, out es)) { BundlingSettings.DefaultEdgeSeparation = es; bs.EdgeSeparation = es; } else { Console.WriteLine("cannot parse {0}", esString); Environment.Exit(1); } } string capacityCoeffString = argsParser.GetValueOfOptionWithAfterString(CapacityCoeffOption); if (capacityCoeffString != null) { double capacityCoeff; if (double.TryParse(capacityCoeffString, out capacityCoeff)) { bs.CapacityOverflowCoefficient = capacityCoeff; } else { Console.WriteLine("cannot parse {0}", capacityCoeffString); Environment.Exit(1); } } return bs; }
SimulatedAnnealing(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { this.metroGraphData = metroGraphData; this.bundlingSettings = bundlingSettings; costCalculator = new CostCalculator(metroGraphData, bundlingSettings); cache = new IntersectionCache(metroGraphData, bundlingSettings, costCalculator, metroGraphData.Cdt); }
internal CostCalculator(MetroGraphData metroGraphData, BundlingSettings bundlingSettings) { this.metroGraphData = metroGraphData; this.bundlingSettings = bundlingSettings; }
public void ComplexGeomGraph() { var graph = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("complex.msagl.geom")); var settings = new BundlingSettings(); var br = new SplineRouter(graph, 1, 1.5, Math.PI / 6, settings); br.Run(); }
/// <summary> /// Error of hubs /// </summary> static internal double RError(double idealR, double nowR, BundlingSettings bundlingSettings) { if (idealR <= nowR) return 0; double res = bundlingSettings.HubRepulsionImportance * (1.0 - nowR / idealR) * (idealR - nowR); return res; }