/// <summary> /// Creates a new contracted graph and adds it to the router db for the given profile. /// </summary> public static void AddEdgeBasedContractedForTesting <T>(this RouterDb db, Profile profile, WeightHandler <T> weightHandler) where T : struct { // create the raw directed graph. ContractedDb contractedDb = null; var contracted = new DirectedDynamicGraph(weightHandler.DynamicSize); var directedGraphBuilder = new Itinero.Algorithms.Contracted.EdgeBased.DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted, weightHandler); directedGraphBuilder.Run(); // contract the graph. var priorityCalculator = new Itinero.Algorithms.Contracted.EdgeBased.EdgeDifferencePriorityCalculator <T>(contracted, weightHandler, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, 4, 64)); priorityCalculator.DifferenceFactor = 5; priorityCalculator.DepthFactor = 5; priorityCalculator.ContractedFactor = 8; var hierarchyBuilder = new Itinero.Algorithms.Contracted.EdgeBased.HierarchyBuilder <T>(contracted, priorityCalculator, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue, 64), weightHandler, db.GetGetRestrictions(profile, null)); hierarchyBuilder.Run(); contractedDb = new ContractedDb(contracted); // add the graph. db.AddContracted(profile, contractedDb); }
/// <summary> /// Adds a contracted graph in the old (broken) way, to test backwards compat. with previous itinero versions. /// </summary> /// <param name="db"></param> /// <param name="profile"></param> public static void AddContractedOldEdgeBased(this RouterDb db, Profile profile) { var weightHandler = profile.DefaultWeightHandlerCached(db); var contracted = new DirectedDynamicGraph(weightHandler.DynamicSize); var directedGraphBuilder = new Itinero.Algorithms.Contracted.EdgeBased.DirectedGraphBuilder <float>(db.Network.GeometricGraph.Graph, contracted, weightHandler); directedGraphBuilder.Run(); // contract the graph. var priorityCalculator = new Itinero.Algorithms.Contracted.EdgeBased.EdgeDifferencePriorityCalculator <float>(contracted, weightHandler, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <float>(weightHandler, 4, 64)); priorityCalculator.DifferenceFactor = 5; priorityCalculator.DepthFactor = 5; priorityCalculator.ContractedFactor = 8; var hierarchyBuilder = new Itinero.Algorithms.Contracted.EdgeBased.HierarchyBuilder <float>(contracted, priorityCalculator, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <float>(weightHandler, int.MaxValue, 64), weightHandler, db.GetGetRestrictions(profile, null)); hierarchyBuilder.Run(); var contractedDb = new ContractedDb(contracted); db.AddContracted(profile, contractedDb); }
/// <summary> /// Creates a new contracted graph and adds it to the router db for the given profile. /// </summary> public static void AddContracted <T>(this RouterDb db, Profiles.Profile profile, WeightHandler <T> weightHandler, bool forceEdgeBased = false) where T : struct { // create the raw directed graph. ContractedDb contractedDb = null; lock (db) { if (forceEdgeBased) { // edge-based is needed when complex restrictions found. var contracted = new DirectedDynamicGraph(weightHandler.DynamicSize); var directedGraphBuilder = new Itinero.Algorithms.Contracted.EdgeBased.DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted, weightHandler); directedGraphBuilder.Run(); // contract the graph. var priorityCalculator = new Itinero.Algorithms.Contracted.EdgeBased.EdgeDifferencePriorityCalculator <T>(contracted, weightHandler, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue)); priorityCalculator.DifferenceFactor = 5; priorityCalculator.DepthFactor = 5; priorityCalculator.ContractedFactor = 8; var hierarchyBuilder = new Itinero.Algorithms.Contracted.EdgeBased.HierarchyBuilder <T>(contracted, priorityCalculator, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue), weightHandler, db.GetGetRestrictions(profile, null)); hierarchyBuilder.Run(); contractedDb = new ContractedDb(contracted); } else { // vertex-based is ok when no complex restrictions found. var contracted = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, weightHandler.MetaSize); var directedGraphBuilder = new DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted, weightHandler); directedGraphBuilder.Run(); // contract the graph. var priorityCalculator = new EdgeDifferencePriorityCalculator(contracted, new DykstraWitnessCalculator(int.MaxValue)); priorityCalculator.DifferenceFactor = 5; priorityCalculator.DepthFactor = 5; priorityCalculator.ContractedFactor = 8; var hierarchyBuilder = new HierarchyBuilder <T>(contracted, priorityCalculator, new DykstraWitnessCalculator(int.MaxValue), weightHandler); hierarchyBuilder.Run(); contractedDb = new ContractedDb(contracted); } } // add the graph. lock (db) { db.AddContracted(profile, contractedDb); } }