Example #1
0
        static IEnumerable <DebugCurve> DebugSegs(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroMapOrdering)
        {
            var ls = new List <ICurve>();

            foreach (var s in metroGraphData.VirtualNodes())
            {
                foreach (var b in s.BundleBases.Values)
                {
                    foreach (var h in b.OrientedHubSegments)
                    {
                        if (h == null)
                        {
                            continue;
                        }
                        if (h.Segment == null)
                        {
                            var uBase = h.Other.BundleBase;
                            var i     = h.Index;
                            var j     = h.Other.Index;
                            ls.Add(new LineSegment(b.Points[i], uBase.Points[j]));
                        }
                        else
                        {
                            ls.Add(h.Segment);
                        }
                    }
                }
            }

            return(ls.Select(s => new DebugCurve(100, 0.01, "green", s)));
        }
        bool FixRouting(HashSet <Point> changedPoints)
        {
            stationsForOptimizations = GetStationsForOptimizations(changedPoints);

            cache.InitializeCostCache();

            double step   = MaxStep;
            double energy = double.PositiveInfinity;

            List <Point> x         = new List <Point>(metroGraphData.VirtualNodes().Select(v => v.Position));
            int          iteration = 0;

            while (iteration++ < MaxIterations)
            {
                bool coordinatesChanged = TryMoveNodes();
                //TimeMeasurer.DebugOutput("  #iter = " + iteration + " moved: " + cnt + "/" + metroGraphData.VirtualNodes().Count() + " step: " + step);

                if (iteration <= 1 && !coordinatesChanged)
                {
                    return(false);
                }
                if (!coordinatesChanged)
                {
                    break;
                }

                double oldEnergy = energy;
                energy = CostCalculator.Cost(metroGraphData, bundlingSettings);
                //TimeMeasurer.DebugOutput("energy: " + energy);

                step = UpdateMaxStep(step, oldEnergy, energy);
                List <Point> oldX = x;
                x = new List <Point>(metroGraphData.VirtualNodes().Select(v => v.Position));
                if (step < MinStep || Converged(step, oldX, x))
                {
                    break;
                }
            }

            //TimeMeasurer.DebugOutput("SA completed after " + iteration + " iterations");
            return(true);
        }
        RectangleNode <Station> GetCirclesHierarchy()
        {
            foreach (var v in metroGraphData.VirtualNodes())
            {
                v.Radius = GetCurrentHubRadius(v);
            }

            return(RectangleNode <Station> .CreateRectangleNodeOnEnumeration(from i in metroGraphData.VirtualNodes()
                                                                             let p = i.Position
                                                                             let r = Math.Max(i.Radius, 5)
                                                                             let del = new Point(r, r)
                                                                             let b = new Rectangle(p + del, p - del)
                                                                             select new RectangleNode <Station>(i, b)));
        }
Example #4
0
        /// <summary>
        /// calculate node radii with fixed hubs
        /// </summary>
        internal void CreateNodeRadii()
        {
            //set radii to zero
            foreach (var v in metroGraphData.VirtualNodes())
            {
                v.Radius            = 0;
                v.cachedIdealRadius = CalculateIdealHubRadiusWithNeighbors(metroGraphData, bundlingSettings, v);
                ;
            }

            //TimeMeasurer.DebugOutput("Initial cost of radii: " + Cost());

            GrowHubs(false);
            //maximally use free space
            GrowHubs(true);

            //TimeMeasurer.DebugOutput("Optimized cost of radii: " + Cost());

            //ensure radii are not zero
            foreach (var v in metroGraphData.VirtualNodes())
            {
                v.Radius = Math.Max(v.Radius, bundlingSettings.MinHubRadius);
            }
        }
        internal void InitializeCostCache()
        {
            foreach (var v in metroGraphData.VirtualNodes())
            {
                v.cachedIdealRadius = HubRadiiCalculator.CalculateIdealHubRadiusWithNeighbors(metroGraphData, bundlingSettings, v);
                v.cachedRadiusCost  = costCalculator.RadiusCost(v, v.Position);
                v.cachedBundleCost  = 0;
            }

            foreach (var edge in metroGraphData.VirtualEdges())
            {
                var             v        = edge.Item1;
                var             u        = edge.Item2;
                StationEdgeInfo edgeInfo = metroGraphData.GetIjInfo(v, u);
                edgeInfo.cachedBundleCost = costCalculator.BundleCost(v, u, v.Position);
                v.cachedBundleCost       += edgeInfo.cachedBundleCost;
                u.cachedBundleCost       += edgeInfo.cachedBundleCost;
            }
        }
Example #6
0
        /// <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);
        }
        static IEnumerable<DebugCurve> DebugSegs(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroMapOrdering) {

            var ls = new List<ICurve>();
            foreach (var s in metroGraphData.VirtualNodes()) {
                foreach (var b in s.BundleBases.Values) {
                    foreach (var h in b.OrientedHubSegments) {
                        if (h == null) continue;
                        if (h.Segment == null) {
                            var uBase = h.Other.BundleBase;
                            var i = h.Index;
                            var j = h.Other.Index;
                            ls.Add(new LineSegment(b.Points[i], uBase.Points[j]));
                        }
                        else {
                            ls.Add(h.Segment);
                        }
                    }
                }
            }

            return ls.Select(s => new DebugCurve(100, 0.01, "green", s));
        }
 IEnumerable <DebugCurve> IdealHubs()
 {
     return(mgd.VirtualNodes().Select(station => new DebugCurve(100, 1, "black",
                                                                CurveFactory.CreateCircle(HubRadiiCalculator.CalculateIdealHubRadiusWithNeighbors(mgd, bundlingSettings, station), station.Position))));
 }
        /// <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;
        }