Skip to content

Commit

Permalink
Integrates edge-based node contraction in PrepareContractionHierarchies.
Browse files Browse the repository at this point in the history
* Moves node priority calculation into NodeContractor.

* Extracts a common NodeContractor interface for node- and edge-based
cases.

* EdgeBasedNodeContractor does not implement any metric yet.

Signed-off-by: ammagamma <contactammagamma@gmail.com>
  • Loading branch information
easbar committed Dec 28, 2017
1 parent 9c6f3d2 commit 6fc656e
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 476 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Licensed to GraphHopper GmbH under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* GraphHopper GmbH licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.graphhopper.routing.ch;

import com.graphhopper.routing.util.DefaultEdgeFilter;
Expand All @@ -14,7 +31,7 @@
import java.util.Collections;
import java.util.List;

public class EdgeBasedNodeContractor {
public class EdgeBasedNodeContractor implements NodeContractor {
private static final Logger LOGGER = LoggerFactory.getLogger(EdgeBasedNodeContractor.class);
// todo: modify code such that logging does not alter performance
private final GraphHopperStorage ghStorage;
Expand All @@ -37,7 +54,8 @@ public EdgeBasedNodeContractor(GraphHopperStorage ghStorage, CHGraph prepareGrap
this.traversalMode = traversalMode;
}

void initFromGraph() {
@Override
public void initFromGraph() {
// todo: do we really need this method ? the problem is that ghStorage/prepareGraph can potentially be modified
// between the constructor call and contractNode,calcShortcutCount etc. ...
maxLevel = prepareGraph.getNodes() + 1;
Expand All @@ -53,7 +71,25 @@ void initFromGraph() {
loopAvoidanceOutEdgeExplorer = ghStorage.createEdgeExplorer(outEdgeFilter);
}

public void contractNode(int node) {
@Override
public void close() {
// todo: not sure if we need this yet
}

@Override
public void setMaxVisitedNodes(int maxVisitedNodes) {
// todo: limiting local searches is a bit more complicated in the edge-based case, because the local searches
// are also used to find the shortcut
}

@Override
public int calculatePriority(int node) {
// todo: return some metric that can be used, for example edge quotient to get started
return 0;
}

@Override
public long contractNode(int node) {
LOGGER.debug("Contracting node {}", node);
CHEdgeIterator incomingEdges = inEdgeExplorer.setBaseNode(node);
while (incomingEdges.next()) {
Expand Down Expand Up @@ -89,6 +125,36 @@ public void contractNode(int node) {
}
}
}
// todo: why do we need the degree again ?
return 0;
}

@Override
public int getAddedShortcutsCount() {
// todo
return 0;
}

@Override
public String getPrepareAlgoMemoryUsage() {
return "todo";
}

@Override
public long getDijkstraCount() {
// todo
return 0;
}

@Override
public void resetDijkstraTime() {
// todo
}

@Override
public float getDijkstraSeconds() {
// todo
return 0;
}

private List<CHEntry> getInitialEntriesForWitnessPaths(int fromNode, int firstOrigEdge) {
Expand Down Expand Up @@ -268,7 +334,6 @@ private static boolean bestPathIsValidAndRequiresNode(
return false;
}


// skip all edges as long as they represent loops at the given node
CHEntry parent = chEntry.getParent();
int loops = -1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Licensed to GraphHopper GmbH under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* GraphHopper GmbH licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.graphhopper.routing.ch;

import com.graphhopper.routing.AlgorithmOptions;
Expand All @@ -21,8 +38,10 @@
import java.util.Locale;

/**
* Dummy implementation to use edge based contraction hierarchies, sooner or later this class will be merged
* with {@link PrepareContractionHierarchies}, which then will handle both edge and node based cases.
* Dummy implementation to use edge based contraction hierarchies with manual contraction orders, only kept for testing
* and debugging purposes at the moment.
*
* @see PrepareContractionHierarchies
*/
public class EdgeBasedPrepareContractionHierarchies extends AbstractAlgoPreparation implements RoutingAlgorithmFactory {
private final GraphHopperStorage ghStorage;
Expand Down
Loading

0 comments on commit 6fc656e

Please sign in to comment.