Skip to content

Commit 2fe6b05

Browse files
author
Karl Hübner
committed
Added the possibility to set one additional value for both edges and
nodes. By default no additional values will be stored and current graphs are still valid. Any implementation of ExtendedStorage can be put into GraphHopperStorage, which take care of any additional storages, which depends on nodes or edges ( e.g. turn cost tables) by reading/writing those additional values. An example implementation can be found in TurnCostStorage. This will be mandandatory to implement support of turn restrictions later.
1 parent 512752a commit 2fe6b05

File tree

11 files changed

+790
-11
lines changed

11 files changed

+790
-11
lines changed

core/src/main/java/com/graphhopper/routing/QueryGraph.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
import com.graphhopper.util.*;
2525
import com.graphhopper.util.shapes.BBox;
2626
import com.graphhopper.util.shapes.GHPoint;
27+
2728
import gnu.trove.list.array.TIntArrayList;
2829
import gnu.trove.map.TIntObjectMap;
2930
import gnu.trove.map.hash.TIntObjectHashMap;
3031
import gnu.trove.procedure.TIntProcedure;
3132
import gnu.trove.procedure.TObjectProcedure;
3233
import gnu.trove.set.hash.TIntHashSet;
34+
3335
import java.util.ArrayList;
3436
import java.util.Collections;
3537
import java.util.Comparator;
@@ -69,8 +71,9 @@ public QueryGraph( Graph graph )
6971
}
7072

7173
/**
72-
* For all specified query results calculate snapped point and set closest node and edge to a
73-
* virtual one if necessary. Additionally the wayIndex can change if an edge is swapped.
74+
* For all specified query results calculate snapped point and set closest
75+
* node and edge to a virtual one if necessary. Additionally the wayIndex
76+
* can change if an edge is swapped.
7477
*/
7578
public void lookup( List<QueryResult> resList )
7679
{
@@ -281,6 +284,12 @@ public double getLongitude( int nodeId )
281284
return mainGraph.getLongitude(nodeId);
282285
}
283286

287+
@Override
288+
public int getAdditionalNodeField( int nodeId )
289+
{
290+
return mainGraph.getAdditionalNodeField(nodeId);
291+
}
292+
284293
@Override
285294
public BBox getBounds()
286295
{
@@ -448,6 +457,12 @@ public void setNode( int node, double lat, double lon )
448457
throw exc();
449458
}
450459

460+
@Override
461+
public void setAdditionalNodeField( int nodeId, int additionalValue )
462+
{
463+
exc();
464+
}
465+
451466
@Override
452467
public EdgeIteratorState edge( int a, int b )
453468
{
@@ -587,6 +602,18 @@ public String toString()
587602
{
588603
return edges.toString();
589604
}
605+
606+
@Override
607+
public int getAdditionalField()
608+
{
609+
return edges.get(current).getAdditionalField();
610+
}
611+
612+
@Override
613+
public EdgeIteratorState setAdditionalField( int value )
614+
{
615+
return edges.get(current).setAdditionalField(value);
616+
}
590617
}
591618

592619
/**
@@ -712,6 +739,12 @@ public boolean isShortcut()
712739
return false;
713740
}
714741

742+
@Override
743+
public int getAdditionalField()
744+
{
745+
throw new UnsupportedOperationException("Not supported.");
746+
}
747+
715748
@Override
716749
public int getSkippedEdge1()
717750
{
@@ -741,5 +774,11 @@ public EdgeIteratorState detach()
741774
{
742775
throw new UnsupportedOperationException("Not supported.");
743776
}
777+
778+
@Override
779+
public EdgeIteratorState setAdditionalField( int value )
780+
{
781+
throw new UnsupportedOperationException("Not supported.");
782+
}
744783
}
745784
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package com.graphhopper.storage;
2+
3+
/**
4+
* You need custom storages, like turn cost tables, or osmid tables for your
5+
* graph? Implement this interface now and put it in any graph storage you want.
6+
* It's that easy!
7+
*/
8+
public interface ExtendedStorage
9+
{
10+
11+
/**
12+
* @return true, if and only if, if an additional field at the graphs node
13+
* storage is required
14+
*/
15+
boolean isRequireNodeField();
16+
17+
/**
18+
* @return true, if and only if, if an additional field at the graphs edge
19+
* storage is required
20+
*/
21+
boolean isRequireEdgeField();
22+
23+
/**
24+
* @return the default field value which will be set for default when creating nodes
25+
*/
26+
int getDefaultNodeFieldValue();
27+
28+
/**
29+
* @return the default field value which will be set for default when creating edges
30+
*/
31+
int getDefaultEdgeFieldValue();
32+
33+
/**
34+
* initializes the extended storage by giving the graph storage
35+
*/
36+
void init( GraphStorage graph );
37+
38+
/**
39+
* creates all additional data storages
40+
*/
41+
void create( long initSize );
42+
43+
/**
44+
* loads from existing data storages
45+
*/
46+
boolean loadExisting();
47+
48+
/**
49+
* sets the segment size in all additional data storages
50+
*/
51+
void setSegmentSize( int bytes );
52+
53+
/**
54+
* flushes all additional data storages
55+
*/
56+
void flush();
57+
58+
/**
59+
* closes all additional data storages
60+
*/
61+
void close();
62+
63+
/**
64+
* returns the sum of all additional data storages capacity
65+
*/
66+
long getCapacity();
67+
68+
/**
69+
* creates a copy of this extended storage
70+
*/
71+
ExtendedStorage copyTo( ExtendedStorage extStorage );
72+
73+
/**
74+
* default implementation defines no additional fields or any logic. there's like nothing
75+
* , like the default behavior.
76+
*/
77+
public class NoExtendedStorage implements ExtendedStorage
78+
{
79+
80+
@Override
81+
public boolean isRequireNodeField()
82+
{
83+
return false;
84+
}
85+
86+
@Override
87+
public boolean isRequireEdgeField()
88+
{
89+
return false;
90+
}
91+
92+
@Override
93+
public int getDefaultNodeFieldValue()
94+
{
95+
return 0;
96+
}
97+
98+
@Override
99+
public int getDefaultEdgeFieldValue()
100+
{
101+
return 0;
102+
}
103+
104+
@Override
105+
public void init( GraphStorage grap )
106+
{
107+
// noop
108+
}
109+
110+
@Override
111+
public void create( long initSize )
112+
{
113+
// noop
114+
}
115+
116+
@Override
117+
public boolean loadExisting()
118+
{
119+
// noop
120+
return true;
121+
}
122+
123+
@Override
124+
public void setSegmentSize( int bytes )
125+
{
126+
// noop
127+
}
128+
129+
@Override
130+
public void flush()
131+
{
132+
// noop
133+
}
134+
135+
@Override
136+
public void close()
137+
{
138+
// noop
139+
}
140+
141+
@Override
142+
public long getCapacity()
143+
{
144+
return 0;
145+
}
146+
147+
@Override
148+
public ExtendedStorage copyTo( ExtendedStorage extStorage )
149+
{
150+
// noop
151+
return extStorage;
152+
}
153+
154+
}
155+
}

core/src/main/java/com/graphhopper/storage/Graph.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public interface Graph
5252
*/
5353
double getLongitude( int nodeId );
5454

55+
/**
56+
* @return the additional value at the specified node index
57+
* @throws AssertionError if, and only if, the extendedStorage does not require an additional node field
58+
*/
59+
int getAdditionalNodeField(int nodeId);
60+
61+
/**
62+
* Sets the additional value at the specified node index
63+
* @throws AssertionError if, and only if, the extendedStorage does not require an additional node field
64+
*/
65+
void setAdditionalNodeField(int nodeId, int additionalValue);
66+
5567
/**
5668
* Returns the implicit bounds of this graph calculated from the lat,lon input of setNode
5769
*/

0 commit comments

Comments
 (0)