Skip to content

Commit

Permalink
refactor: adapt value range of CsvGraphStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Fendrich authored and TheGreatRefrigerator committed Feb 14, 2025
1 parent 6cf11db commit 3f08540
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class CsvGraphStorageBuilder extends AbstractGraphStorageBuilder {
private CsvGraphStorage storage;
private final Map<Long, Integer[]> id2Value = new HashMap<>();
private static final int MAX_VALUE = 100;
private static final int MIN_VALUE = -100;
private final byte defaultValue = 50; // TODO: make configurable
private String[] columnNames;

Expand Down Expand Up @@ -105,9 +106,9 @@ private byte[] getValues(long id) {
} else {
int index = 0;
for (Integer i : gi) {
if (i > MAX_VALUE) {
throw new AssertionError("Value too large (way id " + id
+ " at index " + index + "):" + i + " > " + MAX_VALUE);
if (i > MAX_VALUE || i < MIN_VALUE) {
throw new AssertionError("Value out of range (way id " + id
+ " at index " + index + "):" + i + " not in [" + MIN_VALUE + "," + MAX_VALUE + "]");
}
byteValues[index] = i.byteValue();
index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ public HeatStressWeighting(FlagEncoder encoder, PMap map, GraphHopperStorage gra

@Override
public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse) {
// TODO: this is a short term solution to be adapted when
// AdditionWeighting will be replaced
if (heatStressStorage != null) {
int stressLevel = heatStressStorage.getEdgeValue(EdgeIteratorStateHelper.getOriginalEdge(edgeState), columnIndex, buffer);
// Convert value range from [0,100] to [1,2] to avoid large detours and multiply by user weighting in API request
return (stressLevel * 0.01 * weightingFactor) + 1;
return stressLevel * weightingFactor / 100 + 1.0;
}

return 1.0;
Expand Down

0 comments on commit 3f08540

Please sign in to comment.