double ComputeCostDeltaAfterEdgeGluing(Station node, Station a, Station b, Point newp)
        {
            double gain = 0;

            //ink
            double oldInk = metroGraphData.Ink;
            double newInk = metroGraphData.Ink - (node.Position - b.Position).Length - (node.Position - a.Position).Length +
                            (node.Position - newp).Length + (newp - a.Position).Length + (newp - b.Position).Length;

            gain += CostCalculator.InkError(oldInk, newInk, bundlingSettings);

            //path lengths
            foreach (var metroline in metroGraphData.GetIjInfo(node, b).Metrolines)
            {
                double oldLength = metroline.Length;
                double newLength = metroline.Length - (node.Position - b.Position).Length +
                                   (node.Position - newp).Length + (newp - b.Position).Length;
                gain += CostCalculator.PathLengthsError(oldLength, newLength, metroline.IdealLength, bundlingSettings);
            }
            foreach (var metroline in metroGraphData.GetIjInfo(node, a).Metrolines)
            {
                double oldLength = metroline.Length;
                double newLength = metroline.Length - (node.Position - a.Position).Length +
                                   (node.Position - newp).Length + (newp - a.Position).Length;
                gain += CostCalculator.PathLengthsError(oldLength, newLength, metroline.IdealLength, bundlingSettings);
            }

            //also compute radii gain
            //double nowR = Math.Min(GetCurrentHubRadius(node), (node.Position - newp).Length);
            //double id2 = HubRadiiCalculator.CalculateIdealHubRadiusWithNeighbors(metroGraphData, bundlingSettings, node);
            double id2    = node.cachedIdealRadius;
            double nowR   = GetCurrentHubRadius(node);
            double idealR = HubRadiiCalculator.GetMinRadiusForTwoAdjacentBundles(nowR, node, node.Position, a, b, metroGraphData, bundlingSettings);

            if (idealR > nowR)
            {
                gain += CostCalculator.RError(idealR, nowR, bundlingSettings);
            }

            if (id2 > (node.Position - newp).Length && !node.IsRealNode)
            {
                gain -= CostCalculator.RError(id2, (node.Position - newp).Length, bundlingSettings);
            }

            return(gain);
        }
        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 #3
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);
        }
        /// <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;
        }