-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new profiles section to configure LM&CH preparations (#1922)
- Loading branch information
Showing
39 changed files
with
1,167 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
api/src/main/java/com/graphhopper/config/CHProfileConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
63
api/src/main/java/com/graphhopper/config/LMProfileConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
117
api/src/main/java/com/graphhopper/config/ProfileConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.