Skip to content

Commit

Permalink
Use new profiles section to configure LM&CH preparations (#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
easbar committed Feb 25, 2020
1 parent 7c1d048 commit e656101
Show file tree
Hide file tree
Showing 39 changed files with 1,167 additions and 369 deletions.
56 changes: 53 additions & 3 deletions api/src/main/java/com/graphhopper/GraphHopperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,25 @@

package com.graphhopper;

import com.graphhopper.config.CHProfileConfig;
import com.graphhopper.config.LMProfileConfig;
import com.graphhopper.config.ProfileConfig;
import com.graphhopper.util.PMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* This class represents the global configuration for the GraphHopper class, which is typically configured via the
* `config.yml` file. So far we are mapping the key-value pairs in the config file to a string-string map, but soon
* we will start adding hierarchical configurations (lists, nested objects etc.). We will also start adding the
* different configuration options as fields of this class including the default values.
* `config.yml` file. Certain fields are mapped to dedicated config objects to allow a hierarchical configuration and
* to include lists. All other fields are mapped to a key-value (string-string) map. In the future we will start adding
* the different configuration options as fields of this class including the default values.
*/
public class GraphHopperConfig {
private List<ProfileConfig> profiles = new ArrayList<>();
private List<CHProfileConfig> chProfiles = new ArrayList<>();
private List<LMProfileConfig> lmProfiles = new ArrayList<>();
private final PMap map;

public GraphHopperConfig() {
Expand All @@ -39,6 +47,33 @@ public GraphHopperConfig(PMap pMap) {
this.map = pMap;
}

public List<ProfileConfig> getProfiles() {
return profiles;
}

public GraphHopperConfig setProfiles(List<ProfileConfig> profiles) {
this.profiles = profiles;
return this;
}

public List<CHProfileConfig> getCHProfiles() {
return chProfiles;
}

public GraphHopperConfig setCHProfiles(List<CHProfileConfig> chProfiles) {
this.chProfiles = chProfiles;
return this;
}

public List<LMProfileConfig> getLMProfiles() {
return lmProfiles;
}

public GraphHopperConfig setLMProfiles(List<LMProfileConfig> lmProfiles) {
this.lmProfiles = lmProfiles;
return this;
}

public GraphHopperConfig put(String key, Object value) {
map.put(key, value);
return this;
Expand Down Expand Up @@ -79,6 +114,21 @@ public PMap asPMap() {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("profiles:\n");
for (ProfileConfig profile : profiles) {
sb.append(profile);
sb.append("\n");
}
sb.append("profiles_ch:\n");
for (CHProfileConfig profile : chProfiles) {
sb.append(profile);
sb.append("\n");
}
sb.append("profiles_lm:\n");
for (LMProfileConfig profile : lmProfiles) {
sb.append(profile);
sb.append("\n");
}
sb.append("properties:\n");
for (Map.Entry<String, String> entry : map.toMap().entrySet()) {
sb.append(entry.getKey()).append(": ").append(entry.getValue());
Expand Down
69 changes: 69 additions & 0 deletions api/src/main/java/com/graphhopper/config/CHProfileConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.config;

import java.util.Objects;

import static com.graphhopper.config.ProfileConfig.validateProfileName;

/**
* Corresponds to an entry in the `profiles_ch` section in config.yml and specifies a routing profile that shall be
* prepared using Contraction Hierarchies (CH)
*
* @see ProfileConfig
*/
public class CHProfileConfig {
private String profile = "";

private CHProfileConfig() {
// default constructor needed for jackson
}

public CHProfileConfig(String profile) {
setProfile(profile);
}

public String getProfile() {
return profile;
}

CHProfileConfig setProfile(String profile) {
validateProfileName(profile);
this.profile = profile;
return this;
}

@Override
public String toString() {
return profile;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CHProfileConfig that = (CHProfileConfig) o;
return Objects.equals(profile, that.profile);
}

@Override
public int hashCode() {
return profile.hashCode();
}
}
63 changes: 63 additions & 0 deletions api/src/main/java/com/graphhopper/config/LMProfileConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.config;

import static com.graphhopper.config.ProfileConfig.validateProfileName;

/**
* Corresponds to an entry in the `profiles_lm` section in config.yml and specifies a routing profile that shall be
* prepared using Landmarks (LM)
*
* @see ProfileConfig
*/
public class LMProfileConfig {
private String profile = "";
private double maximumLMWeight = -1;

private LMProfileConfig() {
// default constructor needed for jackson
}

public LMProfileConfig(String profile) {
setProfile(profile);
}

public String getProfile() {
return profile;
}

void setProfile(String profile) {
validateProfileName(profile);
this.profile = profile;
}

public double getMaximumLMWeight() {
return maximumLMWeight;
}

public LMProfileConfig setMaximumLMWeight(double maximumLMWeight) {
this.maximumLMWeight = maximumLMWeight;
return this;
}

@Override
public String toString() {
return profile + "|maximum_lm_weight=" + maximumLMWeight;
}
}
117 changes: 117 additions & 0 deletions api/src/main/java/com/graphhopper/config/ProfileConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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.config;

import com.graphhopper.util.PMap;

/**
* Corresponds to the `profile` section in `config.yml` and specifies the properties of a routing profile. The name
* used here needs to be used when setting up CH/LM preparations. See also the documentation in `config-example.yml'
*
* @see CHProfileConfig
* @see LMProfileConfig
*/
public class ProfileConfig {
private String name = "car";
private String vehicle = "car";
private String weighting = "fastest";
private boolean turnCosts = false;
private PMap hints = new PMap();

public static void validateProfileName(String profileName) {
// currently allowing dash/minus, maybe remove later
// https://github.com/graphhopper/graphhopper/pull/1922#discussion_r383033522
if (!profileName.matches("^[a-z0-9_\\-]*$")) {
throw new IllegalArgumentException("Profile names may only contain lower case letters, numbers, underscores and dashs, given: " + profileName);
}
}

private ProfileConfig() {
// default constructor needed for jackson
}

public ProfileConfig(String name) {
setName(name);
}

public String getName() {
return name;
}

public ProfileConfig setName(String name) {
validateProfileName(name);
this.name = name;
return this;
}

public String getVehicle() {
return vehicle;
}

public ProfileConfig setVehicle(String vehicle) {
this.vehicle = vehicle;
return this;
}

public String getWeighting() {
return weighting;
}

public ProfileConfig setWeighting(String weighting) {
this.weighting = weighting;
return this;
}

public boolean isTurnCosts() {
return turnCosts;
}

public ProfileConfig setTurnCosts(boolean turnCosts) {
this.turnCosts = turnCosts;
return this;
}

public PMap getHints() {
return hints;
}

public ProfileConfig putHint(String key, Object value) {
this.hints.put(key, value);
return this;
}

@Override
public String toString() {
return "name=" + name + "|vehicle=" + vehicle + "|weighting=" + weighting + "|turnCosts=" + turnCosts + "|hints=" + hints;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProfileConfig profile = (ProfileConfig) o;
return name.equals(profile.name);
}

@Override
public int hashCode() {
return name.hashCode();
}

}
14 changes: 8 additions & 6 deletions benchmark/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ measurement.clean=true \
measurement.summaryfile=${RESULTS_DIR}summary_small.dat \
measurement.repeats=1 \
measurement.run_slow_routing=true \
prepare.ch.weightings=fastest \
prepare.lm.weightings=no \
measurement.weighting=fastest \
measurement.ch.node=true \
measurement.ch.edge=true \
measurement.lm=false \
"graph.flag_encoders=car|turn_costs=true" \
prepare.ch.edge_based=edge_and_node \
graph.location=${TMP_DIR}measurement-small-gh \
prepare.min_network_size=10000 \
prepare.min_oneway_network_size=10000 \
Expand All @@ -63,10 +64,11 @@ measurement.clean=true \
measurement.summaryfile=${RESULTS_DIR}summary_big.dat \
measurement.repeats=1 \
measurement.run_slow_routing=false \
prepare.ch.weightings=fastest \
prepare.lm.weightings=fastest \
measurement.weighting=fastest \
measurement.ch.node=true \
measurement.ch.edge=false \
measurement.lm=true \
"graph.flag_encoders=car|turn_costs=true" \
prepare.ch.edge_based=off \
graph.location=${TMP_DIR}measurement-big-gh \
prepare.min_network_size=10000 \
prepare.min_oneway_network_size=10000 \
Expand Down
Loading

0 comments on commit e656101

Please sign in to comment.