Skip to content

Commit

Permalink
feat: record duration in charge station connectivity.
Browse files Browse the repository at this point in the history
issue: #326
  • Loading branch information
CodeBear801 committed May 6, 2020
1 parent c890f0c commit 292383c
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 141 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Changes from v10.2.0
- CHANGED for internal refactoring, rename `cmd/osrm-ranking` to `cmd/osrm-rankd` []()
- CHANGED for internal refactoring, rename `cmd/osrm-ranking` to `cmd/osrm-rankd` [#317](https://github.com/Telenav/osrm-backend/pull/317)
- ADDED package `stationconnquerier` which builds station connectivity graph based on pre-build data [#323](https://github.com/Telenav/osrm-backend/pull/323)
- ADDED `Duration` for pre-generated charge station connectivity data [#326](https://github.com/Telenav/osrm-backend/issues/326)

- Bugfix:
- CHANGED `osrm-ranking` parsing of OSRM route response to compatible with `string` array `annotation/nodes` [#296](https://github.com/Telenav/osrm-backend/pull/296)
Expand Down
28 changes: 18 additions & 10 deletions integration/service/oasis/connectivitymap/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func newConnectivityMapBuilder(iterator spatialindexer.PointsIterator, finder sp
Input Iterator(channel) ---> worker (fetch task -> find -> rank) ---> aggregatorChannel -> feed to map
\ /
\ /
-> worker (fetch task -> find -> rank)
-> worker (fetch task -> find -> rank)
. . .(more workers)
*/

func (builder *connectivityMapBuilder) build() ID2NearByIDsMap {
Expand Down Expand Up @@ -80,11 +82,14 @@ func (builder *connectivityMapBuilder) work(workerID int, source <-chan spatiali
nearbyIDs := builder.finder.FindNearByPointIDs(p.Location, builder.distanceLimit, spatialindexer.UnlimitedCount)
rankedResults := builder.ranker.RankPointIDsByShortestDistance(p.Location, nearbyIDs)

ids := make([]IDAndDistance, 0, len(rankedResults))
ids := make([]IDAndWeight, 0, len(rankedResults))
for _, r := range rankedResults {
ids = append(ids, IDAndDistance{
ID: r.ID,
Distance: r.Distance,
ids = append(ids, IDAndWeight{
ID: r.ID,
Weight: Weight{
Distance: r.Distance,
Duration: r.Duration,
},
})
}

Expand Down Expand Up @@ -120,7 +125,7 @@ func (builder *connectivityMapBuilder) wait() {

type placeIDWithNearByPlaceIDs struct {
id spatialindexer.PointID
ids []IDAndDistance
ids []IDAndWeight
}

func (builder *connectivityMapBuilder) buildInSerial() ID2NearByIDsMap {
Expand All @@ -133,11 +138,14 @@ func (builder *connectivityMapBuilder) buildInSerial() ID2NearByIDsMap {
nearbyIDs := builder.finder.FindNearByPointIDs(p.Location, builder.distanceLimit, spatialindexer.UnlimitedCount)
rankedResults := builder.ranker.RankPointIDsByGreatCircleDistance(p.Location, nearbyIDs)

ids := make([]IDAndDistance, 0, len(rankedResults))
ids := make([]IDAndWeight, 0, len(rankedResults))
for _, r := range rankedResults {
ids = append(ids, IDAndDistance{
ID: r.ID,
Distance: r.Distance,
ids = append(ids, IDAndWeight{
ID: r.ID,
Weight: Weight{
Distance: r.Distance,
Duration: r.Duration,
},
})
}
internalResult <- placeIDWithNearByPlaceIDs{
Expand Down
94 changes: 62 additions & 32 deletions integration/service/oasis/connectivitymap/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,82 @@ func TestBuilderWithMockIteratorAndFinder(t *testing.T) {
// construct expect map
expect := make(ID2NearByIDsMap)

var idAndDistanceArray = []IDAndDistance{
IDAndDistance{
ID: 3,
Distance: 345.220003472554,
var idAndWeightArray = []IDAndWeight{
{
3,
Weight{
345.220003472554,
15.550450606871804,
},
},
IDAndDistance{
ID: 2,
Distance: 402.8536530341791,
{
2,
Weight{
402.8536530341791,
18.146560947485547,
},
},
IDAndDistance{
ID: 4,
Distance: 1627.1858848458571,
{
4,
Weight{
1627.1858848458571,
73.29666147954312,
},
},
IDAndDistance{
ID: 5,
Distance: 4615.586636153461,
{
5,
Weight{
4615.586636153461,
207.9093079348406,
},
},
IDAndDistance{
ID: 1,
Distance: 5257.70008125706,
{
1,
Weight{
5257.70008125706,
236.8333369935613,
},
},
IDAndDistance{
ID: 6,
Distance: 6888.7486674247,
{
6,
Weight{
6888.7486674247,
310.30399402813964,
},
},
IDAndDistance{
ID: 7,
Distance: 7041.893747628621,
{
7,
Weight{
7041.893747628621,
317.2024210643523,
},
},
IDAndDistance{
ID: 10,
Distance: 8622.213424347745,
{
10,
Weight{
8622.213424347745,
388.3879920877363,
},
},
IDAndDistance{
ID: 9,
Distance: 9438.804320070916,
{
9,
Weight{
9438.804320070916,
425.1713657689602,
},
},
IDAndDistance{
ID: 8,
Distance: 9897.44482638937,
{
8,
Weight{
9897.44482638937,
445.8308480355572,
},
},
}

for i := 0; i < 100; i++ {
index := i + 1000
expect[(spatialindexer.PointID(index))] = idAndDistanceArray
expect[(spatialindexer.PointID(index))] = idAndWeightArray
}

if !reflect.DeepEqual(actual, expect) {
Expand Down
18 changes: 12 additions & 6 deletions integration/service/oasis/connectivitymap/connectivity_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import (
"github.com/golang/glog"
)

// IDAndDistance wraps ID and distance information
type IDAndDistance struct {
ID spatialindexer.PointID
// Weight represent weight information
type Weight struct {
Distance float64
Duration float64
}

// IDAndWeight wraps ID and weight information
type IDAndWeight struct {
ID spatialindexer.PointID
Weight Weight
}

// ID2NearByIDsMap is a mapping between ID and its nearby IDs
type ID2NearByIDsMap map[spatialindexer.PointID][]IDAndDistance
type ID2NearByIDsMap map[spatialindexer.PointID][]IDAndWeight

// Connectivity Map used to query connectivity for given placeID
type ConnectivityMap struct {
Expand Down Expand Up @@ -69,8 +75,8 @@ func (cm *ConnectivityMap) Load(folderPath string) *ConnectivityMap {
}

// QueryConnectivity answers connectivity query for given placeID
// Return true and IDAndDistance array for given placeID, otherwise false and nil
func (cm *ConnectivityMap) QueryConnectivity(placeID spatialindexer.PointID) ([]IDAndDistance, bool) {
// Return true and IDAndWeight array for given placeID, otherwise false and nil
func (cm *ConnectivityMap) QueryConnectivity(placeID spatialindexer.PointID) ([]IDAndWeight, bool) {
if result, ok := cm.id2nearByIDs[placeID]; ok {
return result, true
}
Expand Down
136 changes: 89 additions & 47 deletions integration/service/oasis/connectivitymap/connectivity_map_mock.go
Original file line number Diff line number Diff line change
@@ -1,81 +1,123 @@
package connectivitymap

var fakeID2NearByIDsMap1 = ID2NearByIDsMap{
1: []IDAndDistance{
IDAndDistance{
ID: 2,
Distance: 3,
1: []IDAndWeight{
{
ID: 2,
Weight: Weight{
Distance: 3,
Duration: 3,
},
},
IDAndDistance{
ID: 5,
Distance: 4,
{
ID: 5,
Weight: Weight{
Distance: 4,
Duration: 4,
},
},
IDAndDistance{
ID: 7,
Distance: 6,
{
ID: 7,
Weight: Weight{
Distance: 6,
Duration: 61,
},
},
IDAndDistance{
ID: 8,
Distance: 12,
{
ID: 8,
Weight: Weight{
Distance: 12,
Duration: 12,
},
},
},

2: []IDAndDistance{
IDAndDistance{
ID: 1,
Distance: 3,
2: []IDAndWeight{
{
ID: 1,
Weight: Weight{
Distance: 3,
Duration: 3,
},
},
IDAndDistance{
ID: 7,
Distance: 23,
{
ID: 7,
Weight: Weight{
Distance: 23,
Duration: 23,
},
},
},

5: []IDAndDistance{
IDAndDistance{
ID: 1,
Distance: 4,
5: []IDAndWeight{
{
ID: 1,
Weight: Weight{
Distance: 4,
Duration: 4,
},
},
IDAndDistance{
ID: 8,
Distance: 5,
{
ID: 8,
Weight: Weight{
Distance: 5,
Duration: 5,
},
},
},

7: []IDAndDistance{
IDAndDistance{
ID: 1,
Distance: 6,
7: []IDAndWeight{
{
ID: 1,
Weight: Weight{
Distance: 6,
Duration: 6,
},
},
IDAndDistance{
ID: 2,
Distance: 23,
{
ID: 2,
Weight: Weight{
Distance: 23,
Duration: 23,
},
},
},

8: []IDAndDistance{
IDAndDistance{
ID: 5,
Distance: 5,
8: []IDAndWeight{
{
ID: 5,
Weight: Weight{
Distance: 5,
Duration: 5,
},
},
IDAndDistance{
ID: 1,
Distance: 12,
{
ID: 1,
Weight: Weight{
Distance: 12,
Duration: 12,
},
},
},
}

var fakeID2NearByIDsMap2 = ID2NearByIDsMap{
1: []IDAndDistance{
1: []IDAndWeight{
{
ID: 2,
Distance: 1,
ID: 2,
Weight: Weight{
Distance: 1,
Duration: 1,
},
},
},
2: []IDAndDistance{
2: []IDAndWeight{
{
ID: 3,
Distance: 2,
ID: 3,
Weight: Weight{
Distance: 2,
Duration: 2,
},
},
},
}
Expand Down
Loading

0 comments on commit 292383c

Please sign in to comment.