Skip to content

Commit

Permalink
Feature/Generate connectivity between charge stations near to low ene…
Browse files Browse the repository at this point in the history
…rgy point (#189)

* feat: implement logic for finding charge stations when energy is low
           - implement logic to calculate weight between charge stations around low energy locations.
            - implement related unit tests
issue: #183
  • Loading branch information
CodeBear801 authored Mar 5, 2020
1 parent ba7f7e6 commit 6462a11
Show file tree
Hide file tree
Showing 16 changed files with 798 additions and 211 deletions.
6 changes: 6 additions & 0 deletions integration/oasis/reachable_by_multiple_charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package oasis

import (
"github.com/Telenav/osrm-backend/integration/oasis/haversine"
"github.com/Telenav/osrm-backend/integration/oasis/osrmconnector"
"github.com/Telenav/osrm-backend/integration/oasis/searchconnector"
"github.com/Telenav/osrm-backend/integration/oasis/stationfinder"
"github.com/Telenav/osrm-backend/integration/pkg/api/oasis"
"github.com/Telenav/osrm-backend/integration/pkg/api/osrm/route"
Expand All @@ -10,6 +12,10 @@ import (
"github.com/twpayne/go-polyline"
)

func pickChargeStationsWithEarlistArrival(oasisReq *oasis.Request, routeResp *route.Response, oc *osrmconnector.OSRMConnector, sc *searchconnector.TNSearchConnector) {
// TBD
}

// For each route response, will generate an array of *stationfinder.StationCoordinate
// Each array contains: start point, first charge point(could also be start point), second charge point, ..., end point
func chargeLocationSelection(oasisReq *oasis.Request, routeResp *route.Response) [][]*stationfinder.StationCoordinate {
Expand Down
4 changes: 2 additions & 2 deletions integration/oasis/reachable_by_single_charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func getOverlapChargeStations4OrigDest(req *oasis.Request, routedistance float64
return nil
}

origStations := stationfinder.NewOrigStationFinder(osrmConnector, tnSearchConnector, req)
destStations := stationfinder.NewDestStationFinder(osrmConnector, tnSearchConnector, req)
origStations := stationfinder.NewOrigStationFinder(tnSearchConnector, req)
destStations := stationfinder.NewDestStationFinder(tnSearchConnector, req)
overlap := stationfinder.FindOverlapBetweenStations(origStations, destStations)

if len(overlap) == 0 {
Expand Down
190 changes: 2 additions & 188 deletions integration/oasis/stationfinder/basic_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,192 +8,6 @@ import (
"github.com/Telenav/osrm-backend/integration/pkg/api/search/nearbychargestation"
)

var mockSearchResponse1 *nearbychargestation.Response = &nearbychargestation.Response{
Results: []*nearbychargestation.Result{
&nearbychargestation.Result{
ID: "station1",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: 32.333,
Longitude: 122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: 32.333,
Longitude: 122.333,
},
},
},
},
},
},
&nearbychargestation.Result{
ID: "station2",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: -32.333,
Longitude: -122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: -32.333,
Longitude: -122.333,
},
},
},
},
},
},
&nearbychargestation.Result{
ID: "station3",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: 32.333,
Longitude: -122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: 32.333,
Longitude: -122.333,
},
},
},
},
},
},
&nearbychargestation.Result{
ID: "station4",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: -32.333,
Longitude: 122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: -32.333,
Longitude: 122.333,
},
},
},
},
},
},
},
}

var mockSearchResponse2 *nearbychargestation.Response = &nearbychargestation.Response{
Results: []*nearbychargestation.Result{
&nearbychargestation.Result{
ID: "station1",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: 32.333,
Longitude: 122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: 32.333,
Longitude: 122.333,
},
},
},
},
},
},
&nearbychargestation.Result{
ID: "station2",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: -32.333,
Longitude: -122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: -32.333,
Longitude: -122.333,
},
},
},
},
},
},
&nearbychargestation.Result{
ID: "station5",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: -12.333,
Longitude: 122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: -12.333,
Longitude: 122.333,
},
},
},
},
},
},
},
}

var mockSearchResponse3 *nearbychargestation.Response = &nearbychargestation.Response{
Results: []*nearbychargestation.Result{
&nearbychargestation.Result{
ID: "station6",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: 30.333,
Longitude: 122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: 30.333,
Longitude: 122.333,
},
},
},
},
},
},
&nearbychargestation.Result{
ID: "station7",
Place: nearbychargestation.Place{
Address: []*nearbychargestation.Address{
&nearbychargestation.Address{
GeoCoordinate: nearbychargestation.Coordinate{
Latitude: -10.333,
Longitude: 122.333,
},
NavCoordinates: []*nearbychargestation.Coordinate{
&nearbychargestation.Coordinate{
Latitude: -10.333,
Longitude: 122.333,
},
},
},
},
},
},
},
}

var mockChargeStationInfo1 []ChargeStationInfo = []ChargeStationInfo{
ChargeStationInfo{
ID: "station1",
Expand Down Expand Up @@ -272,7 +86,7 @@ func TestBasicFinderCorrectness(t *testing.T) {
expect []ChargeStationInfo
}{
{
mockSearchResponse1.Results,
nearbychargestation.MockSearchResponse1.Results,
mockChargeStationInfo1,
},
}
Expand Down Expand Up @@ -309,7 +123,7 @@ func TestBasicFinderAsync(t *testing.T) {
expect []ChargeStationInfo
}{
{
mockSearchResponse1.Results,
nearbychargestation.MockSearchResponse1.Results,
&sync.RWMutex{},
mockChargeStationInfo1,
},
Expand Down
28 changes: 28 additions & 0 deletions integration/oasis/stationfinder/dest_iterator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package stationfinder

const destLocationID string = "dest_location"

type destIterator struct {
location *StationCoordinate
}

func NewDestIter(location *StationCoordinate) *destIterator {
return &destIterator{
location: location,
}
}

func (di *destIterator) iterateNearbyStations() <-chan ChargeStationInfo {
c := make(chan ChargeStationInfo, 1)

go func() {
defer close(c)
station := ChargeStationInfo{
ID: destLocationID,
Location: *di.location,
}
c <- station
}()

return c
}
6 changes: 4 additions & 2 deletions integration/oasis/stationfinder/dest_station_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"reflect"
"sync"
"testing"

"github.com/Telenav/osrm-backend/integration/pkg/api/search/nearbychargestation"
)

func createMockDestStationFinder1() *destStationFinder {
obj := &destStationFinder{
oasisReq: nil,
bf: &basicFinder{
tnSearchConnector: nil,
searchResp: mockSearchResponse1,
searchResp: nearbychargestation.MockSearchResponse1,
searchRespLock: &sync.RWMutex{},
},
}
Expand All @@ -23,7 +25,7 @@ func createMockDestStationFinder2() *destStationFinder {
oasisReq: nil,
bf: &basicFinder{
tnSearchConnector: nil,
searchResp: mockSearchResponse2,
searchResp: nearbychargestation.MockSearchResponse2,
searchRespLock: &sync.RWMutex{},
},
}
Expand Down
4 changes: 3 additions & 1 deletion integration/oasis/stationfinder/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
// based on safe energy level and distance to nearest charge station(todo).
// - lowEnergyLocationStationFinder holds logic for how to find reachable
// charge station near certain location.
// - orig_iterator and dest_iterator wraps single point of orig/dest which could
// be used for algorithms

// Algorithm:
// - Each finder provide iterator to iterate charge station candidates.
// - The choice of channel as response makes algorithm could be asynchronous func.
// - FindOverlapBetweenStations provide functionality to find overlap
// between two iterator.
// - CalcCostBetweenChargeStationsPair provide functionality to calculate
// - CalcWeightBetweenChargeStationsPair provide functionality to calculate
// cost between two group of charge stations which could construct a new
// graph as edges.
package stationfinder
Loading

0 comments on commit 6462a11

Please # to comment.