From 3068da0d2c3cefef04b56f1c453a0c3d914c9542 Mon Sep 17 00:00:00 2001 From: codebear801 Date: Fri, 22 May 2020 10:27:34 -0700 Subject: [PATCH] fix: Change representation of `stationID` to `PlaceID` issue: https://github.com/Telenav/osrm-backend/issues/350 --- .../oasis/connectivitymap/interface.go | 10 +- .../service/oasis/internal/common/place.go | 3 +- .../service/oasis/internal/mock/doc.go | 2 +- .../oasis/internal/solution/solution.go | 2 +- .../station_conn_querier.go | 56 +++++------ .../station_conn_querier_test.go | 30 +++--- ...pl.go => querier_impl_by_stationfinder.go} | 34 +++---- ... => querier_impl_by_stationfinder_test.go} | 22 ++--- .../stationfinder/stationfindertype/type.go | 12 +-- .../oasis/stationgraph/graph_interface.go | 9 +- .../service/oasis/stationgraph/graph_mock.go | 95 ++++++++++--------- .../oasis/stationgraph/node_container.go | 24 ++--- .../oasis/stationgraph/node_container_test.go | 55 +++++------ .../service/oasis/stationgraph/node_graph.go | 30 +++--- .../oasis/stationgraph/node_graph_test.go | 76 +++++++-------- .../oasis/stationgraph/station_graph.go | 16 ++-- .../oasis/stationgraph/station_graph_test.go | 88 ++++++++--------- 17 files changed, 278 insertions(+), 286 deletions(-) rename integration/service/oasis/stationfinder/stationfinderalg/{querier_interface_impl.go => querier_impl_by_stationfinder.go} (59%) rename integration/service/oasis/stationfinder/stationfinderalg/{querier_interface_impl_test.go => querier_impl_by_stationfinder_test.go} (95%) diff --git a/integration/service/oasis/connectivitymap/interface.go b/integration/service/oasis/connectivitymap/interface.go index 963156a37aa..99a8e57e795 100644 --- a/integration/service/oasis/connectivitymap/interface.go +++ b/integration/service/oasis/connectivitymap/interface.go @@ -8,11 +8,11 @@ import ( // Querier used to return topological information of charge stations type Querier interface { - // NearByStationQuery finds near by stations by given stationID and return them in recorded sequence - // Returns nil if given stationID is not found or no connectivity - NearByStationQuery(stationID string) []*common.RankedPlaceInfo + // NearByStationQuery finds near by stations by given placeID and return them in recorded sequence + // Returns nil if given placeID is not found or no connectivity + NearByStationQuery(placeID common.PlaceID) []*common.RankedPlaceInfo // GetLocation returns location of given station id - // Returns nil if given stationID is not found - GetLocation(stationID string) *nav.Location + // Returns nil if given placeID is not found + GetLocation(placeID common.PlaceID) *nav.Location } diff --git a/integration/service/oasis/internal/common/place.go b/integration/service/oasis/internal/common/place.go index 8c3951e092e..a120ff081ae 100644 --- a/integration/service/oasis/internal/common/place.go +++ b/integration/service/oasis/internal/common/place.go @@ -24,7 +24,8 @@ type RankedPlaceInfo struct { } // PlaceID defines ID for given place(location, point of interest) -// The data used for pre-processing should contain valid PlaceID +// The data used for pre-processing must contain valid PlaceID, which means it +// either a int64 directly or be processed as int64 type PlaceID int64 // String converts PlaceID to string diff --git a/integration/service/oasis/internal/mock/doc.go b/integration/service/oasis/internal/mock/doc.go index 00cbe9564c3..a4484926dbf 100644 --- a/integration/service/oasis/internal/mock/doc.go +++ b/integration/service/oasis/internal/mock/doc.go @@ -1,2 +1,2 @@ -// Package mock provides mock object(e.g., OSRM Table) that may be shared for OASIS' testing. +// Package mock provides mock object(e.g., OSRM Table) that will be shared for OASIS' testing. package mock diff --git a/integration/service/oasis/internal/solution/solution.go b/integration/service/oasis/internal/solution/solution.go index f7d0fcc7aff..017d70fa567 100644 --- a/integration/service/oasis/internal/solution/solution.go +++ b/integration/service/oasis/internal/solution/solution.go @@ -18,7 +18,7 @@ type Solution struct { // ChargeStation contains all information related with specific charge station type ChargeStation struct { Location nav.Location - StationID string + PlaceID string ArrivalEnergy float64 WaitTime float64 ChargeTime float64 diff --git a/integration/service/oasis/stationconnquerier/station_conn_querier.go b/integration/service/oasis/stationconnquerier/station_conn_querier.go index 3ccc66a2f59..2dd26c223ed 100644 --- a/integration/service/oasis/stationconnquerier/station_conn_querier.go +++ b/integration/service/oasis/stationconnquerier/station_conn_querier.go @@ -2,7 +2,6 @@ package stationconnquerier import ( "sort" - "strconv" "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/service/oasis/connectivitymap" @@ -17,7 +16,7 @@ type StationConnectivityQuerier struct { stationLocationQuerier spatialindexer.PlaceLocationQuerier stationConnectivity *connectivitymap.ConnectivityMap reachableStationsByStart []*common.RankedPlaceInfo - reachableStationToEnd map[string]*common.RankedPlaceInfo + reachableStationToEnd map[common.PlaceID]*common.RankedPlaceInfo startLocation *nav.Location endLocation *nav.Location } @@ -58,9 +57,9 @@ func (querier *StationConnectivityQuerier) connectEndIntoStationGraph(stationFin nearByPoints := stationFinder.FindNearByPlaceIDs(center, maxEnergyLevel, spatialindexer.UnlimitedCount) rankedPoints := stationRanker.RankPlaceIDsByShortestDistance(center, nearByPoints) - reachableStationToEnd := make(map[string]*common.RankedPlaceInfo) + reachableStationToEnd := make(map[common.PlaceID]*common.RankedPlaceInfo) for _, rankedPointInfo := range rankedPoints { - reachableStationToEnd[rankedPointInfo.ID.String()] = &common.RankedPlaceInfo{ + reachableStationToEnd[rankedPointInfo.ID] = &common.RankedPlaceInfo{ PlaceInfo: common.PlaceInfo{ ID: stationfindertype.DestLocationID, Location: end, @@ -73,29 +72,23 @@ func (querier *StationConnectivityQuerier) connectEndIntoStationGraph(stationFin glog.Infof("Add %d stations connects End node.\n", len(querier.reachableStationToEnd)) } -// NearByStationQuery finds near by stations by given stationID and return them in recorded sequence -// Returns nil if given stationID is not found or no connectivity +// NearByStationQuery finds near by stations by given placeID and return them in recorded sequence +// Returns nil if given placeID is not found or no connectivity // For start point, directly returns reachableStationsByStart which is generated by considering current energy level. // For end point, return nil, no connectivity expected from end to others // For charge stations, it retrieves connectivity from pre-build data. If a charge station is reachable to destination/end point, it must connects that into graph. -func (querier *StationConnectivityQuerier) NearByStationQuery(stationID string) []*common.RankedPlaceInfo { +func (querier *StationConnectivityQuerier) NearByStationQuery(placeID common.PlaceID) []*common.RankedPlaceInfo { - if stationID == stationfindertype.OrigLocationIDStr { + if placeID == stationfindertype.OrigLocationID { return querier.reachableStationsByStart } - if stationID == stationfindertype.DestLocationIDStr { + if placeID == stationfindertype.DestLocationID { return nil } - placeID, err := strconv.Atoi(stationID) - if err != nil { - glog.Errorf("Incorrect station ID passed to NearByStationQuery %+v, got error %#v", stationID, err) - return nil - } - - if connectivityResults, ok := querier.stationConnectivity.QueryConnectivity((common.PlaceID)(placeID)); ok { - if !querier.isStationConnectsToEnd(stationID) { + if connectivityResults, ok := querier.stationConnectivity.QueryConnectivity(placeID); ok { + if !querier.isStationConnectsToEnd(placeID) { return connectivityResults } else { size := len(connectivityResults) + 1 @@ -103,13 +96,14 @@ func (querier *StationConnectivityQuerier) NearByStationQuery(stationID string) for _, result := range connectivityResults { results = append(results, result) } - return querier.connectEndIntoGraph(stationID, results) + return querier.connectEndIntoGraph(placeID, results) } } else { - // end position just find one charge station, and this charge station didn't has other conductivities - if querier.isStationConnectsToEnd(stationID) { + // end position just find one charge station, and this charge station didn't has other conductivities. + // this only exists theoretically or in mock environment + if querier.isStationConnectsToEnd(placeID) { results := make([]*common.RankedPlaceInfo, 0, 1) - return querier.connectEndIntoGraph(stationID, results) + return querier.connectEndIntoGraph(placeID, results) } } @@ -117,25 +111,25 @@ func (querier *StationConnectivityQuerier) NearByStationQuery(stationID string) } // GetLocation returns location of given station id -// Returns nil if given stationID is not found -func (querier *StationConnectivityQuerier) GetLocation(stationID string) *nav.Location { - switch stationID { - case stationfindertype.OrigLocationIDStr: +// Returns nil if given placeID is not found +func (querier *StationConnectivityQuerier) GetLocation(placeID common.PlaceID) *nav.Location { + switch placeID { + case stationfindertype.OrigLocationID: return querier.startLocation - case stationfindertype.DestLocationIDStr: + case stationfindertype.DestLocationID: return querier.endLocation default: - return querier.stationLocationQuerier.GetLocation(stationID) + return querier.stationLocationQuerier.GetLocation(placeID.String()) } } -func (querier *StationConnectivityQuerier) isStationConnectsToEnd(stationID string) bool { - _, ok := querier.reachableStationToEnd[stationID] +func (querier *StationConnectivityQuerier) isStationConnectsToEnd(placeID common.PlaceID) bool { + _, ok := querier.reachableStationToEnd[placeID] return ok } -func (querier *StationConnectivityQuerier) connectEndIntoGraph(stationID string, results []*common.RankedPlaceInfo) []*common.RankedPlaceInfo { - if queryResult4End, ok := querier.reachableStationToEnd[stationID]; ok { +func (querier *StationConnectivityQuerier) connectEndIntoGraph(placeID common.PlaceID, results []*common.RankedPlaceInfo) []*common.RankedPlaceInfo { + if queryResult4End, ok := querier.reachableStationToEnd[placeID]; ok { return appendIntoSortedSlice(queryResult4End, results) } return results diff --git a/integration/service/oasis/stationconnquerier/station_conn_querier_test.go b/integration/service/oasis/stationconnquerier/station_conn_querier_test.go index 30fc26237c2..8dd89a52812 100644 --- a/integration/service/oasis/stationconnquerier/station_conn_querier_test.go +++ b/integration/service/oasis/stationconnquerier/station_conn_querier_test.go @@ -262,37 +262,37 @@ func TestStationConnQuerier(t *testing.T) { // verify location locationCases := []struct { - queryStr string + queryID common.PlaceID expectLocation *nav.Location }{ { - stationfindertype.OrigLocationIDStr, + stationfindertype.OrigLocationID, mockOrigLocation, }, { - stationfindertype.DestLocationIDStr, + stationfindertype.DestLocationID, mockDestLocation, }, { - "1", + 1, mockStation1Location, }, { - "2", + 2, mockStation2Location, }, { - "3", + 3, mockStation3Location, }, { - "incorrect_station_id", + stationfindertype.InvalidPlaceID, nil, }, } for _, c := range locationCases { - actualLocation := querier.GetLocation(c.queryStr) + actualLocation := querier.GetLocation(c.queryID) if !reflect.DeepEqual(actualLocation, c.expectLocation) { t.Errorf("Incorrect result for connectivitymap.Querier.GetLocation, expect %+v but got %+v\n", c.expectLocation, actualLocation) } @@ -300,11 +300,11 @@ func TestStationConnQuerier(t *testing.T) { // verify connectivity connectivityCases := []struct { - stationID string + placeID common.PlaceID expectQueryResult []*common.RankedPlaceInfo }{ { - stationfindertype.OrigLocationIDStr, + stationfindertype.OrigLocationID, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -339,11 +339,11 @@ func TestStationConnQuerier(t *testing.T) { }, }, { - stationfindertype.DestLocationIDStr, + stationfindertype.DestLocationID, nil, }, { - "1", + 1, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -368,7 +368,7 @@ func TestStationConnQuerier(t *testing.T) { }, }, { - "3", + 3, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -383,7 +383,7 @@ func TestStationConnQuerier(t *testing.T) { }, }, { - "2", + 2, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -410,7 +410,7 @@ func TestStationConnQuerier(t *testing.T) { } for _, c := range connectivityCases { - actualQueryResult := querier.NearByStationQuery(c.stationID) + actualQueryResult := querier.NearByStationQuery(c.placeID) if !reflect.DeepEqual(actualQueryResult, c.expectQueryResult) { for _, r := range c.expectQueryResult { fmt.Printf("+++ %v, %v, %v, %v, %v\n", r.ID, r.Location.Lat, r.Location.Lon, r.Weight.Distance, r.Weight.Duration) diff --git a/integration/service/oasis/stationfinder/stationfinderalg/querier_interface_impl.go b/integration/service/oasis/stationfinder/stationfinderalg/querier_impl_by_stationfinder.go similarity index 59% rename from integration/service/oasis/stationfinder/stationfinderalg/querier_interface_impl.go rename to integration/service/oasis/stationfinder/stationfinderalg/querier_impl_by_stationfinder.go index ed6089c0fdd..15dfd23dc8d 100644 --- a/integration/service/oasis/stationfinder/stationfinderalg/querier_interface_impl.go +++ b/integration/service/oasis/stationfinder/stationfinderalg/querier_impl_by_stationfinder.go @@ -8,19 +8,19 @@ import ( "github.com/golang/glog" ) -type stationID2QueryResults map[string][]*common.RankedPlaceInfo -type stationID2Location map[string]*nav.Location +type placeID2QueryResults map[common.PlaceID][]*common.RankedPlaceInfo +type placeID2Location map[common.PlaceID]*nav.Location type querier struct { - id2QueryResults stationID2QueryResults - id2Location stationID2Location + id2QueryResults placeID2QueryResults + id2Location placeID2Location } // NewQuerierBasedOnWeightBetweenNeighborsChan creates connectivitymap.Querier based on channel of charge station's WeightBetweenNeighbors func NewQuerierBasedOnWeightBetweenNeighborsChan(c chan stationfindertype.WeightBetweenNeighbors) connectivitymap.Querier { querier := &querier{ - id2QueryResults: make(stationID2QueryResults), - id2Location: make(stationID2Location), + id2QueryResults: make(placeID2QueryResults), + id2Location: make(placeID2Location), } for item := range c { @@ -31,11 +31,11 @@ func NewQuerierBasedOnWeightBetweenNeighborsChan(c chan stationfindertype.Weight for _, neighborInfo := range item.NeighborsInfo { - if _, ok := querier.id2QueryResults[neighborInfo.FromID]; !ok { + if _, ok := querier.id2QueryResults[neighborInfo.FromPlaceID()]; !ok { results := make([]*common.RankedPlaceInfo, 0, 10) - querier.id2QueryResults[neighborInfo.FromID] = results + querier.id2QueryResults[neighborInfo.FromPlaceID()] = results } - querier.id2QueryResults[neighborInfo.FromID] = append(querier.id2QueryResults[neighborInfo.FromID], + querier.id2QueryResults[neighborInfo.FromPlaceID()] = append(querier.id2QueryResults[neighborInfo.FromPlaceID()], &common.RankedPlaceInfo{ PlaceInfo: common.PlaceInfo{ ID: neighborInfo.ToPlaceID(), @@ -50,15 +50,15 @@ func NewQuerierBasedOnWeightBetweenNeighborsChan(c chan stationfindertype.Weight }, }) - if _, ok := querier.id2Location[neighborInfo.FromID]; !ok { - querier.id2Location[neighborInfo.FromID] = &nav.Location{ + if _, ok := querier.id2Location[neighborInfo.FromPlaceID()]; !ok { + querier.id2Location[neighborInfo.FromPlaceID()] = &nav.Location{ Lat: neighborInfo.FromLocation.Lat, Lon: neighborInfo.FromLocation.Lon, } } - if _, ok := querier.id2Location[neighborInfo.ToID]; !ok { - querier.id2Location[neighborInfo.ToID] = &nav.Location{ + if _, ok := querier.id2Location[neighborInfo.ToPlaceID()]; !ok { + querier.id2Location[neighborInfo.ToPlaceID()] = &nav.Location{ Lat: neighborInfo.ToLocation.Lat, Lon: neighborInfo.ToLocation.Lon, } @@ -69,16 +69,16 @@ func NewQuerierBasedOnWeightBetweenNeighborsChan(c chan stationfindertype.Weight return querier } -func (q *querier) NearByStationQuery(stationID string) []*common.RankedPlaceInfo { - if results, ok := q.id2QueryResults[stationID]; ok { +func (q *querier) NearByStationQuery(placeID common.PlaceID) []*common.RankedPlaceInfo { + if results, ok := q.id2QueryResults[placeID]; ok { return results } else { return nil } } -func (q *querier) GetLocation(stationID string) *nav.Location { - if location, ok := q.id2Location[stationID]; ok { +func (q *querier) GetLocation(placeID common.PlaceID) *nav.Location { + if location, ok := q.id2Location[placeID]; ok { return location } else { return nil diff --git a/integration/service/oasis/stationfinder/stationfinderalg/querier_interface_impl_test.go b/integration/service/oasis/stationfinder/stationfinderalg/querier_impl_by_stationfinder_test.go similarity index 95% rename from integration/service/oasis/stationfinder/stationfinderalg/querier_interface_impl_test.go rename to integration/service/oasis/stationfinder/stationfinderalg/querier_impl_by_stationfinder_test.go index 078f35b1ff8..a47d2557bbf 100644 --- a/integration/service/oasis/stationfinder/stationfinderalg/querier_interface_impl_test.go +++ b/integration/service/oasis/stationfinder/stationfinderalg/querier_impl_by_stationfinder_test.go @@ -19,12 +19,12 @@ import ( // station7 -> destination func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { cases := []struct { - stationID string + placeID common.PlaceID expectQueryResult []*common.RankedPlaceInfo expectLocation *nav.Location }{ { - stationfindertype.OrigLocationIDStr, + stationfindertype.OrigLocationID, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -85,7 +85,7 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { }, }, { - "station1", + 1, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -120,7 +120,7 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { }, }, { - "station2", + 2, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -155,7 +155,7 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { }, }, { - "station3", + 3, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -190,7 +190,7 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { }, }, { - "station4", + 4, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -225,7 +225,7 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { }, }, { - "station6", + 6, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -247,7 +247,7 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { }, }, { - "station7", + 7, []*common.RankedPlaceInfo{ { PlaceInfo: common.PlaceInfo{ @@ -269,7 +269,7 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { }, }, { - stationfindertype.DestLocationIDStr, + stationfindertype.DestLocationID, nil, &nav.Location{ Lat: 4.4, @@ -283,12 +283,12 @@ func TestQuerierBasedOnWeightBetweenNeighborsChan(t *testing.T) { q := NewQuerierBasedOnWeightBetweenNeighborsChan(c) for _, c := range cases { - acturalQueryResult := q.NearByStationQuery(c.stationID) + acturalQueryResult := q.NearByStationQuery(c.placeID) if !reflect.DeepEqual(acturalQueryResult, c.expectQueryResult) { t.Errorf("Generate incorrect for NearByStationQuery, expect \n%#v\n but got \n%#v\n", c.expectQueryResult, acturalQueryResult) } - actualLocation := q.GetLocation(c.stationID) + actualLocation := q.GetLocation(c.placeID) if !reflect.DeepEqual(actualLocation, c.expectLocation) { t.Errorf("Generate incorrect for GetLocation, expect \n%#v\n but got \n%#v\n", c.expectLocation, actualLocation) } diff --git a/integration/service/oasis/stationfinder/stationfindertype/type.go b/integration/service/oasis/stationfinder/stationfindertype/type.go index 7d072163763..87b69d79d3f 100644 --- a/integration/service/oasis/stationfinder/stationfindertype/type.go +++ b/integration/service/oasis/stationfinder/stationfindertype/type.go @@ -69,26 +69,24 @@ func convertIDFromStringToPlaceID(s string) common.PlaceID { placeID := (common.PlaceID)(num) if !isPredefinedValueTakenPlaceIDValue(placeID) { return placeID - } - // else: assert false + } // else: Fatal assert inside isPredefinedValueTakenPlaceIDValue } else { // from Web Service re := regexp.MustCompile("[0-9]+") idStrArray := re.FindAllString(s, -1) if len(idStrArray) != 1 { - glog.Fatalf("Assumption of ID from search response is wrong, expect format is b- with number, but got %v.\n", s) + glog.Fatalf("Assumption of ID from search response is wrong, expect pattern is b- with single group of number, but got %v.\n", s) } if num, err := strconv.ParseInt(idStrArray[0], 10, 64); err == nil { placeID := (common.PlaceID)(num) if !isPredefinedValueTakenPlaceIDValue(placeID) { return placeID - } - // else: assert false + } // else: Fatal assert inside isPredefinedValueTakenPlaceIDValue } else { - glog.Fatalf("Assumption of ID from search response is wrong, expect format is b- with number, but got %v.\n", s) + glog.Fatalf("Assumption of ID from search response is wrong, expect format is b- with number, but when converting %v got error %#v.\n", s, err) } } } - glog.Fatalf("PlaceID %v could not be decodinged", s) + glog.Fatalf("PlaceID %v could not be decodinged\n", s) return InvalidPlaceID } diff --git a/integration/service/oasis/stationgraph/graph_interface.go b/integration/service/oasis/stationgraph/graph_interface.go index 0dee803ce9d..ce6f37b11c7 100644 --- a/integration/service/oasis/stationgraph/graph_interface.go +++ b/integration/service/oasis/stationgraph/graph_interface.go @@ -3,6 +3,7 @@ package stationgraph import ( "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/service/oasis/chargingstrategy" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/common" ) // Graph defines interface used for Graph @@ -19,10 +20,10 @@ type Graph interface { Edge(from, to nodeID) *edgeMetric // SetStart generates start node for the graph - SetStart(stationID string, targetState chargingstrategy.State, location *nav.Location) Graph + SetStart(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph // SetEnd generates end node for the graph - SetEnd(stationID string, targetState chargingstrategy.State, location *nav.Location) Graph + SetEnd(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph // StartNodeID returns start node's ID for given graph StartNodeID() nodeID @@ -33,6 +34,6 @@ type Graph interface { // ChargeStrategy returns charge strategy used for graph construction ChargeStrategy() chargingstrategy.Strategy - // StationID returns original stationID from internal nodeID - StationID(id nodeID) string + // PlaceID returns original placeID from internal nodeID + PlaceID(id nodeID) common.PlaceID } diff --git a/integration/service/oasis/stationgraph/graph_mock.go b/integration/service/oasis/stationgraph/graph_mock.go index 6e8201fb7d7..3e8d37a5e7b 100644 --- a/integration/service/oasis/stationgraph/graph_mock.go +++ b/integration/service/oasis/stationgraph/graph_mock.go @@ -3,6 +3,7 @@ package stationgraph import ( "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/service/oasis/chargingstrategy" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/common" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfindertype" ) @@ -77,12 +78,12 @@ func newMockGraph1() Graph { // }, }, }, - []string{ - "node_0", - "node_1", - "node_2", - "node_3", - "node_4", + []common.PlaceID{ + 0, + 1, + 2, + 3, + 4, }, map[nodeID][]*edge{ // node_0 -> node_1, duration = 30, distance = 30 @@ -238,16 +239,16 @@ func newMockGraph2() Graph { // }, }, }, - []string{ - "node_0", - "node_1", - "node_2", - "node_3", - "node_4", - "node_5", - "node_6", - "node_7", - "node_8", + []common.PlaceID{ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, }, map[nodeID][]*edge{ // node_0 -> node_1, duration = 30, distance = 30 @@ -564,16 +565,16 @@ func newMockGraph3() Graph { // }, }, }, - []string{ - "node_0", - "node_1", - "node_2", - "node_3", - "node_4", - "node_5", - "node_6", - "node_7", - "node_8", + []common.PlaceID{ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, }, map[nodeID][]*edge{ // node_0 -> node_1, duration = 15, distance = 15 @@ -891,16 +892,16 @@ func newMockGraph4() Graph { // }, }, }, - []string{ - "node_0", - "node_1", - "node_2", - "node_3", - "node_4", - "node_5", - "node_6", - "node_7", - "node_8", + []common.PlaceID{ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, }, map[nodeID][]*edge{ // node_0 -> node_1, duration = 15, distance = 15 @@ -1090,10 +1091,10 @@ func newMockGraph4() Graph { } type mockGraph struct { - nodes []*node - stationIDs []string - edges map[nodeID][]*edge - strategy chargingstrategy.Strategy + nodes []*node + placeIDs []common.PlaceID + edges map[nodeID][]*edge + strategy chargingstrategy.Strategy } // Node returns node object by its nodeID @@ -1137,12 +1138,12 @@ func (graph *mockGraph) Edge(from, to nodeID) *edgeMetric { } // SetStart generates start node for the graph -func (graph *mockGraph) SetStart(stationID string, targetState chargingstrategy.State, location *nav.Location) Graph { +func (graph *mockGraph) SetStart(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph { return graph } // SetEnd generates end node for the graph -func (graph *mockGraph) SetEnd(stationID string, targetState chargingstrategy.State, location *nav.Location) Graph { +func (graph *mockGraph) SetEnd(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph { return graph } @@ -1161,12 +1162,12 @@ func (graph *mockGraph) ChargeStrategy() chargingstrategy.Strategy { return graph.strategy } -// StationID returns original stationID from internal nodeID -func (graph *mockGraph) StationID(id nodeID) string { - if id < 0 || int(id) >= len(graph.stationIDs) { - return stationfindertype.InvalidPlaceIDStr +// PlaceID returns original placeID from internal nodeID +func (graph *mockGraph) PlaceID(id nodeID) common.PlaceID { + if id < 0 || int(id) >= len(graph.placeIDs) { + return stationfindertype.InvalidPlaceID } - return graph.stationIDs[id] + return graph.placeIDs[id] } func (graph *mockGraph) isValidNodeID(id nodeID) bool { diff --git a/integration/service/oasis/stationgraph/node_container.go b/integration/service/oasis/stationgraph/node_container.go index e453aa506da..e05eef9a103 100644 --- a/integration/service/oasis/stationgraph/node_container.go +++ b/integration/service/oasis/stationgraph/node_container.go @@ -2,17 +2,18 @@ package stationgraph import ( "github.com/Telenav/osrm-backend/integration/service/oasis/chargingstrategy" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/common" "github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfindertype" ) type logicNodeIdentifier2NodePtr map[logicNodeIdentifier]*node type nodeID2NodePtr []*node -type nodeID2StationID map[nodeID]string +type nodeID2PlaceID map[nodeID]common.PlaceID type nodeContainer struct { logicNode2NodePtr logicNodeIdentifier2NodePtr id2NodePtr nodeID2NodePtr - id2StationID nodeID2StationID + id2StationID nodeID2PlaceID counter int } @@ -20,13 +21,13 @@ func newNodeContainer() *nodeContainer { return &nodeContainer{ logicNode2NodePtr: make(logicNodeIdentifier2NodePtr, 15000), id2NodePtr: make(nodeID2NodePtr, 0, 15000), - id2StationID: make(nodeID2StationID, 15000), + id2StationID: make(nodeID2PlaceID, 15000), counter: 0, } } -func (nc *nodeContainer) addNode(stationID string, targetState chargingstrategy.State) *node { - key := logicNodeIdentifier{stationID, targetState} +func (nc *nodeContainer) addNode(placeID common.PlaceID, targetState chargingstrategy.State) *node { + key := logicNodeIdentifier{placeID, targetState} if n, ok := nc.logicNode2NodePtr[key]; ok { return n @@ -40,9 +41,8 @@ func (nc *nodeContainer) addNode(stationID string, targetState chargingstrategy. }, } nc.logicNode2NodePtr[key] = n - //nc.id2NodePtr[n.id] = n nc.id2NodePtr = append(nc.id2NodePtr, n) - nc.id2StationID[n.id] = stationID + nc.id2StationID[n.id] = placeID nc.counter++ return n @@ -64,15 +64,15 @@ func (nc *nodeContainer) isNodeVisited(id nodeID) bool { return false } -func (nc *nodeContainer) stationID(id nodeID) string { - if stationID, ok := nc.id2StationID[id]; ok { - return stationID +func (nc *nodeContainer) nodeID2PlaceID(id nodeID) common.PlaceID { + if placeID, ok := nc.id2StationID[id]; ok { + return placeID } else { - return stationfindertype.InvalidPlaceIDStr + return stationfindertype.InvalidPlaceID } } type logicNodeIdentifier struct { - stationID string + placeID common.PlaceID targetState chargingstrategy.State } diff --git a/integration/service/oasis/stationgraph/node_container_test.go b/integration/service/oasis/stationgraph/node_container_test.go index 478e4dcde86..0b8c5a557a8 100644 --- a/integration/service/oasis/stationgraph/node_container_test.go +++ b/integration/service/oasis/stationgraph/node_container_test.go @@ -8,16 +8,17 @@ import ( "github.com/Telenav/osrm-backend/integration/api/nav" "github.com/Telenav/osrm-backend/integration/service/oasis/chargingstrategy" + "github.com/Telenav/osrm-backend/integration/service/oasis/internal/common" ) func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { input := []struct { - stationID string + placeID common.PlaceID chargeState chargingstrategy.State location nav.Location }{ { - "station1", + 1, chargingstrategy.State{ Energy: 10.0, }, @@ -27,7 +28,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { }, }, { - "station1", + 1, chargingstrategy.State{ Energy: 20.0, }, @@ -37,7 +38,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { }, }, { - "station1", + 1, chargingstrategy.State{ Energy: 30.0, }, @@ -47,7 +48,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { }, }, { - "station2", + 2, chargingstrategy.State{ Energy: 10.0, }, @@ -57,7 +58,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { }, }, { - "station2", + 2, chargingstrategy.State{ Energy: 20.0, }, @@ -67,7 +68,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { }, }, { - "station3", + 3, chargingstrategy.State{ Energy: 15.0, }, @@ -79,8 +80,8 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { } expect := []struct { - n *node - stationID string + n *node + placeID common.PlaceID }{ { &node{ @@ -95,7 +96,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { // Lon: 1.1, // }, }, - "station1", + 1, }, { &node{ @@ -110,7 +111,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { // Lon: 1.1, // }, }, - "station1", + 1, }, { &node{ @@ -125,7 +126,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { // Lon: 1.1, // }, }, - "station1", + 1, }, { &node{ @@ -140,7 +141,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { // Lon: 2.2, // }, }, - "station2", + 2, }, { &node{ @@ -155,7 +156,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { // Lon: 2.2, // }, }, - "station2", + 2, }, { &node{ @@ -170,7 +171,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { // Lon: 3.3, // }, }, - "station3", + 3, }, } @@ -181,7 +182,7 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { nc := newNodeContainer() for i := 0; i < len(input); i++ { - tmpNode := nc.addNode(input[i].stationID, input[i].chargeState /*, input[i].location*/) + tmpNode := nc.addNode(input[i].placeID, input[i].chargeState /*, input[i].location*/) if !reflect.DeepEqual(tmpNode, expect[i].n) { t.Errorf("Calling nodeContainer's addNode() generate incorrect result, expect %#v but got %#v.\n", expect[i].n, tmpNode) @@ -199,9 +200,9 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { t.Errorf("Calling nodeContainer's getNode() generate incorrect result, expect %#v but got %#v.\n", expect[i].n, tmpNode) } - tmpStationID := nc.stationID((nodeID)(i)) - if !reflect.DeepEqual(tmpStationID, expect[i].stationID) { - t.Errorf("Calling nodeContainer's stationID() generate incorrect result, expect %#v but got %#v.\n", expect[i].stationID, tmpStationID) + tmpStationID := nc.nodeID2PlaceID((nodeID)(i)) + if !reflect.DeepEqual(tmpStationID, expect[i].placeID) { + t.Errorf("Calling nodeContainer's placeID() generate incorrect result, expect %#v but got %#v.\n", expect[i].placeID, tmpStationID) } } @@ -221,12 +222,12 @@ func TestAddAndGetFunctionsForNodeContainer(t *testing.T) { func TestAddDuplicateNodeForNodeContainer(t *testing.T) { input := []struct { - stationID string + placeID common.PlaceID chargeState chargingstrategy.State location nav.Location }{ { - "station1", + 1, chargingstrategy.State{ Energy: 10.0, }, @@ -236,7 +237,7 @@ func TestAddDuplicateNodeForNodeContainer(t *testing.T) { }, }, { - "station1", + 1, chargingstrategy.State{ Energy: 10.0, }, @@ -246,7 +247,7 @@ func TestAddDuplicateNodeForNodeContainer(t *testing.T) { }, }, { - "station1", + 1, chargingstrategy.State{ Energy: 10.0, }, @@ -258,8 +259,8 @@ func TestAddDuplicateNodeForNodeContainer(t *testing.T) { } expect := struct { - n *node - stationID string + n *node + placeID common.PlaceID }{ &node{ 0, @@ -273,13 +274,13 @@ func TestAddDuplicateNodeForNodeContainer(t *testing.T) { // Lon: 1.1, // }, }, - "station1", + 1, } nc := newNodeContainer() for i := 0; i < len(input); i++ { - tmpNode := nc.addNode(input[i].stationID, input[i].chargeState /*, input[i].location*/) + tmpNode := nc.addNode(input[i].placeID, input[i].chargeState /*, input[i].location*/) if !reflect.DeepEqual(tmpNode, expect.n) { t.Errorf("Calling nodeContainer's addNode() generate incorrect result, expect %#v but got %#v.\n", expect.n, tmpNode) diff --git a/integration/service/oasis/stationgraph/node_graph.go b/integration/service/oasis/stationgraph/node_graph.go index e794c1dcc92..998778fc83e 100644 --- a/integration/service/oasis/stationgraph/node_graph.go +++ b/integration/service/oasis/stationgraph/node_graph.go @@ -69,15 +69,15 @@ func (g *nodeGraph) Edge(from, to nodeID) *edgeMetric { } // SetStart generates start node for the nodeGraph -func (g *nodeGraph) SetStart(stationID string, targetState chargingstrategy.State, location *nav.Location) Graph { - n := g.nodeContainer.addNode(stationID, targetState) +func (g *nodeGraph) SetStart(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph { + n := g.nodeContainer.addNode(placeID, targetState) g.startNodeID = n.id return g } // SetEnd generates end node for the nodeGraph -func (g *nodeGraph) SetEnd(stationID string, targetState chargingstrategy.State, location *nav.Location) Graph { - n := g.nodeContainer.addNode(stationID, targetState) +func (g *nodeGraph) SetEnd(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph { + n := g.nodeContainer.addNode(placeID, targetState) g.endNodeID = n.id return g } @@ -97,26 +97,26 @@ func (g *nodeGraph) ChargeStrategy() chargingstrategy.Strategy { return g.strategy } -// StationID returns original stationID from internal nodeID -func (g *nodeGraph) StationID(id nodeID) string { - return g.nodeContainer.stationID(id) +// PlaceID returns original placeID from internal nodeID +func (g *nodeGraph) PlaceID(id nodeID) common.PlaceID { + return g.nodeContainer.nodeID2PlaceID(id) } func (g *nodeGraph) getPhysicalAdjacentNodes(id nodeID) []*common.RankedPlaceInfo { - stationID := g.nodeContainer.stationID(id) - if stationID == stationfindertype.InvalidPlaceIDStr { + placeID := g.nodeContainer.nodeID2PlaceID(id) + if placeID == stationfindertype.InvalidPlaceID { glog.Errorf("Query getPhysicalAdjacentNodes with invalid node %#v and result %#v\n", id, stationfindertype.InvalidPlaceIDStr) return nil } - return g.querier.NearByStationQuery(stationID) + return g.querier.NearByStationQuery(placeID) } -func (g *nodeGraph) createLogicalNodes(from nodeID, toStationID string, toLocation *nav.Location, distance, duration float64) []*node { +func (g *nodeGraph) createLogicalNodes(from nodeID, toPlaceID common.PlaceID, toLocation *nav.Location, distance, duration float64) []*node { results := make([]*node, 0, 3) - // if toStationID equals endNode, direct return since there is no need to create charge candidates for endNode + // if toPlaceID equals endNode, direct return since there is no need to create charge candidates for endNode endNodeID := g.EndNodeID() - if toStationID == g.StationID(endNodeID) { + if toPlaceID == g.PlaceID(endNodeID) { results = append(results, g.Node(endNodeID)) g.edgeMetric[edgeID{from, endNodeID}] = &edgeMetric{ distance: distance, @@ -126,7 +126,7 @@ func (g *nodeGraph) createLogicalNodes(from nodeID, toStationID string, toLocati // creates logical nodes for each physical node, different logical node means charge for different level of energy at charge station for _, state := range g.strategy.CreateChargingStates() { - n := g.nodeContainer.addNode(toStationID, state) + n := g.nodeContainer.addNode(toPlaceID, state) results = append(results, n) g.edgeMetric[edgeID{from, n.id}] = &edgeMetric{ @@ -161,7 +161,7 @@ func (g *nodeGraph) buildAdjacentList(id nodeID) []nodeID { break } - nodes := g.createLogicalNodes(id, physicalNode.ID.String(), physicalNode.Location, + nodes := g.createLogicalNodes(id, physicalNode.ID, physicalNode.Location, physicalNode.Weight.Distance, physicalNode.Weight.Duration) for _, node := range nodes { diff --git a/integration/service/oasis/stationgraph/node_graph_test.go b/integration/service/oasis/stationgraph/node_graph_test.go index d4646eb9136..bec1d8f128a 100644 --- a/integration/service/oasis/stationgraph/node_graph_test.go +++ b/integration/service/oasis/stationgraph/node_graph_test.go @@ -24,15 +24,15 @@ func TestAddAndGetStartAndEndNodeForNodeGraph(t *testing.T) { Lat: 34.44, Lon: -124.44} - graph.SetStart(stationfindertype.OrigLocationID.String(), expectStartChargeState, expectStartLocation). - SetEnd(stationfindertype.DestLocationID.String(), expectEndChargeState, expectEndLocation) + graph.SetStart(stationfindertype.OrigLocationID, expectStartChargeState, expectStartLocation). + SetEnd(stationfindertype.DestLocationID, expectEndChargeState, expectEndLocation) - if graph.StationID(graph.StartNodeID()) != stationfindertype.OrigLocationID.String() { - t.Errorf("Incorrect result for start's stationID, expect %s but got %s.\n", stationfindertype.OrigLocationID.String(), graph.StationID(graph.StartNodeID())) + if graph.PlaceID(graph.StartNodeID()) != stationfindertype.OrigLocationID { + t.Errorf("Incorrect result for start's placeID, expect %s but got %s.\n", stationfindertype.OrigLocationID.String(), graph.PlaceID(graph.StartNodeID())) } - if graph.StationID(graph.EndNodeID()) != stationfindertype.DestLocationID.String() { - t.Errorf("Incorrect result for end's stationID, expect %s but got %s.\n", stationfindertype.DestLocationID.String(), graph.StationID(graph.EndNodeID())) + if graph.PlaceID(graph.EndNodeID()) != stationfindertype.DestLocationID { + t.Errorf("Incorrect result for end's placeID, expect %s but got %s.\n", stationfindertype.DestLocationID.String(), graph.PlaceID(graph.EndNodeID())) } startNode := graph.Node(graph.StartNodeID()) @@ -241,24 +241,24 @@ func TestStationIDInterfaceForNodeGraph(t *testing.T) { graph := generateMockNodeGraph() nodeIDs := graph.AdjacentNodes(graph.StartNodeID()) - expectStationIDs := []string{ - testStationID2.String(), - testStationID2.String(), - testStationID2.String(), - testStationID3.String(), - testStationID3.String(), - testStationID3.String(), - testStationID4.String(), - testStationID4.String(), - testStationID4.String(), + expectStationIDs := []common.PlaceID{ + testStationID2, + testStationID2, + testStationID2, + testStationID3, + testStationID3, + testStationID3, + testStationID4, + testStationID4, + testStationID4, } - actualStationIDs := make([]string, 0, len(nodeIDs)) + actualStationIDs := make([]common.PlaceID, 0, len(nodeIDs)) for _, nodeID := range nodeIDs { - actualStationIDs = append(actualStationIDs, graph.StationID(nodeID)) + actualStationIDs = append(actualStationIDs, graph.PlaceID(nodeID)) } if !reflect.DeepEqual(actualStationIDs, expectStationIDs) { - t.Errorf("Incorrect StationID() result for NodeGraph, expect %#v but got %#v\n", expectStationIDs, actualStationIDs) + t.Errorf("Incorrect PlaceID() result for NodeGraph, expect %#v but got %#v\n", expectStationIDs, actualStationIDs) } } @@ -269,21 +269,21 @@ func generateMockNodeGraph() Graph { querier := newMockQuerier() graph := NewNodeGraph(strategy, querier) - origLocation := querier.GetLocation(testStationID1Str) - graph.SetStart(testStationID1Str, chargingstrategy.State{Energy: currEnergyLevel}, &nav.Location{Lat: origLocation.Lat, Lon: origLocation.Lon}) + origLocation := querier.GetLocation(testStationID1) + graph.SetStart(testStationID1, chargingstrategy.State{Energy: currEnergyLevel}, &nav.Location{Lat: origLocation.Lat, Lon: origLocation.Lon}) return graph } type mockQuerier4NodeGraph struct { - mockStationID2QueryResult map[string][]*common.RankedPlaceInfo - mockStationID2Location map[string]*nav.Location + mockStationID2QueryResult map[common.PlaceID][]*common.RankedPlaceInfo + mockStationID2Location map[common.PlaceID]*nav.Location } func newMockQuerier() connectivitymap.Querier { return &mockQuerier4NodeGraph{ - mockStationID2QueryResult: map[string][]*common.RankedPlaceInfo{ - testStationID1Str: { + mockStationID2QueryResult: map[common.PlaceID][]*common.RankedPlaceInfo{ + testStationID1: { { PlaceInfo: common.PlaceInfo{ ID: testStationID2, @@ -316,28 +316,28 @@ func newMockQuerier() connectivitymap.Querier { }, }, }, - mockStationID2Location: map[string]*nav.Location{ - testStationID1Str: {Lat: 1.1, Lon: 1.1}, - testStationID2Str: {Lat: 2.2, Lon: 2.2}, - testStationID3Str: {Lat: 3.3, Lon: 3.3}, - testStationID4Str: {Lat: 4.4, Lon: 4.4}, + mockStationID2Location: map[common.PlaceID]*nav.Location{ + testStationID1: {Lat: 1.1, Lon: 1.1}, + testStationID2: {Lat: 2.2, Lon: 2.2}, + testStationID3: {Lat: 3.3, Lon: 3.3}, + testStationID4: {Lat: 4.4, Lon: 4.4}, }, } } -func (querier *mockQuerier4NodeGraph) NearByStationQuery(stationID string) []*common.RankedPlaceInfo { - if stationID == testStationID1Str { - return querier.mockStationID2QueryResult[testStationID1Str] +func (querier *mockQuerier4NodeGraph) NearByStationQuery(placeID common.PlaceID) []*common.RankedPlaceInfo { + if placeID == testStationID1 { + return querier.mockStationID2QueryResult[testStationID1] } - glog.Fatalf("Un-implemented mapping key %v for mockStationID2QueryResult.\n", stationID) + glog.Fatalf("Un-implemented mapping key %v for mockStationID2QueryResult.\n", placeID) return nil } -func (querier *mockQuerier4NodeGraph) GetLocation(stationID string) *nav.Location { - if stationID == testStationID1Str { - return querier.mockStationID2Location[testStationID1Str] +func (querier *mockQuerier4NodeGraph) GetLocation(placeID common.PlaceID) *nav.Location { + if placeID == testStationID1 { + return querier.mockStationID2Location[testStationID1] } - glog.Fatalf("Un-implemented mapping key for mockStationID2Location id = %v.\n", stationID) + glog.Fatalf("Un-implemented mapping key for mockStationID2Location id = %v.\n", placeID) return nil } diff --git a/integration/service/oasis/stationgraph/station_graph.go b/integration/service/oasis/stationgraph/station_graph.go index 6238d45593d..c67cc3d48b6 100644 --- a/integration/service/oasis/stationgraph/station_graph.go +++ b/integration/service/oasis/stationgraph/station_graph.go @@ -29,25 +29,25 @@ func NewStationGraph(currEnergyLevel, maxEnergyLevel float64, strategy chargings } func (sg *stationGraph) setStartAndEndForGraph(currEnergyLevel, maxEnergyLevel float64) bool { - startLocation := sg.querier.GetLocation(stationfindertype.OrigLocationID.String()) + startLocation := sg.querier.GetLocation(stationfindertype.OrigLocationID) if startLocation == nil { glog.Errorf("Failed to find %#v from Querier GetLocation()\n", stationfindertype.OrigLocationID.String()) return false } - endLocation := sg.querier.GetLocation(stationfindertype.DestLocationID.String()) + endLocation := sg.querier.GetLocation(stationfindertype.DestLocationID) if startLocation == nil { glog.Errorf("Failed to find %#v from Querier GetLocation()\n", stationfindertype.DestLocationID.String()) return false } - sg.g = sg.g.SetStart(stationfindertype.OrigLocationID.String(), + sg.g = sg.g.SetStart(stationfindertype.OrigLocationID, chargingstrategy.State{ Energy: currEnergyLevel, }, startLocation) - sg.g = sg.g.SetEnd(stationfindertype.DestLocationID.String(), + sg.g = sg.g.SetEnd(stationfindertype.DestLocationID, chargingstrategy.State{}, endLocation) @@ -58,10 +58,6 @@ func (sg *stationGraph) setStartAndEndForGraph(currEnergyLevel, maxEnergyLevel f func (sg *stationGraph) GenerateChargeSolutions() []*solution.Solution { stationNodes := dijkstra(sg.g, sg.g.StartNodeID(), sg.g.EndNodeID()) - // to be removed - //nodeGraph := sg.g.(*nodeGraph) - //glog.Infof("+++ len(nodeGraph.adjacentList) = %v, len(nodeGraph.edgeMetric) = %v\n", len(nodeGraph.adjacentList), len(nodeGraph.edgeMetric)) - if nil == stationNodes { glog.Warning("Failed to generate charge stations for stationGraph.\n") return nil @@ -99,7 +95,7 @@ func (sg *stationGraph) generateSolutionsBasedOnStationCandidates(stationNodes [ Lat: sg.getLocationInfo(sg.g, stationNodes[i]).Lat, Lon: sg.getLocationInfo(sg.g, stationNodes[i]).Lon, } - station.StationID = sg.g.StationID(stationNodes[i]) + station.PlaceID = sg.g.PlaceID(stationNodes[i]).String() sol.ChargeStations = append(sol.ChargeStations, station) } @@ -154,7 +150,7 @@ func (sg *stationGraph) getLocationInfo(g Graph, n nodeID) *nav.Location { glog.Fatalf("While calling getLocationInfo, incorrect nodeID passed into graph %v\n", n) } - return sg.querier.GetLocation(sg.g.StationID(g.Node(n).id)) + return sg.querier.GetLocation(sg.g.PlaceID(g.Node(n).id)) } func (sg *stationGraph) isStart(id string) bool { diff --git a/integration/service/oasis/stationgraph/station_graph_test.go b/integration/service/oasis/stationgraph/station_graph_test.go index f3d232397d1..ec8146fa893 100644 --- a/integration/service/oasis/stationgraph/station_graph_test.go +++ b/integration/service/oasis/stationgraph/station_graph_test.go @@ -81,14 +81,14 @@ var testSGStationID4 common.PlaceID = 4 var testSGStationID5 common.PlaceID = 5 type mockQuerier4StationGraph struct { - mockStationID2QueryResult map[string][]*common.RankedPlaceInfo - mockStationID2Location map[string]*nav.Location + mockStationID2QueryResult map[common.PlaceID][]*common.RankedPlaceInfo + mockStationID2Location map[common.PlaceID]*nav.Location } func newMockQuerier4StationGraph() connectivitymap.Querier { querier := &mockQuerier4StationGraph{ - mockStationID2QueryResult: map[string][]*common.RankedPlaceInfo{ - stationfindertype.OrigLocationID.String(): { + mockStationID2QueryResult: map[common.PlaceID][]*common.RankedPlaceInfo{ + stationfindertype.OrigLocationID: { { PlaceInfo: common.PlaceInfo{ ID: testSGStationID2, @@ -120,7 +120,7 @@ func newMockQuerier4StationGraph() connectivitymap.Querier { }, }, }, - testSGStationID1Str: { + testSGStationID1: { { PlaceInfo: common.PlaceInfo{ ID: testSGStationID5, @@ -142,7 +142,7 @@ func newMockQuerier4StationGraph() connectivitymap.Querier { }, }, }, - testSGStationID2Str: { + testSGStationID2: { { PlaceInfo: common.PlaceInfo{ ID: testSGStationID4, @@ -164,7 +164,7 @@ func newMockQuerier4StationGraph() connectivitymap.Querier { }, }, }, - testSGStationID3Str: { + testSGStationID3: { { PlaceInfo: common.PlaceInfo{ ID: testSGStationID5, @@ -186,7 +186,7 @@ func newMockQuerier4StationGraph() connectivitymap.Querier { }, }, }, - testSGStationID4Str: { + testSGStationID4: { { PlaceInfo: common.PlaceInfo{ ID: stationfindertype.DestLocationID, @@ -198,7 +198,7 @@ func newMockQuerier4StationGraph() connectivitymap.Querier { }, }, }, - testSGStationID5Str: { + testSGStationID5: { { PlaceInfo: common.PlaceInfo{ ID: stationfindertype.DestLocationID, @@ -210,35 +210,35 @@ func newMockQuerier4StationGraph() connectivitymap.Querier { }, }, }, - stationfindertype.DestLocationID.String(): {}, + stationfindertype.DestLocationID: {}, }, - mockStationID2Location: map[string]*nav.Location{ - stationfindertype.OrigLocationID.String(): {Lat: 0.0, Lon: 0.0}, - testSGStationID1Str: {Lat: 1.1, Lon: 1.1}, - testSGStationID2Str: {Lat: 2.2, Lon: 2.2}, - testSGStationID3Str: {Lat: 3.3, Lon: 3.3}, - testSGStationID4Str: {Lat: 4.4, Lon: 4.4}, - testSGStationID5Str: {Lat: 5.5, Lon: 5.5}, - stationfindertype.DestLocationID.String(): {Lat: 6.6, Lon: 6.6}, + mockStationID2Location: map[common.PlaceID]*nav.Location{ + stationfindertype.OrigLocationID: {Lat: 0.0, Lon: 0.0}, + testSGStationID1: {Lat: 1.1, Lon: 1.1}, + testSGStationID2: {Lat: 2.2, Lon: 2.2}, + testSGStationID3: {Lat: 3.3, Lon: 3.3}, + testSGStationID4: {Lat: 4.4, Lon: 4.4}, + testSGStationID5: {Lat: 5.5, Lon: 5.5}, + stationfindertype.DestLocationID: {Lat: 6.6, Lon: 6.6}, }, } return querier } -func (querier *mockQuerier4StationGraph) NearByStationQuery(stationID string) []*common.RankedPlaceInfo { - if queryResult, ok := querier.mockStationID2QueryResult[stationID]; ok { +func (querier *mockQuerier4StationGraph) NearByStationQuery(placeID common.PlaceID) []*common.RankedPlaceInfo { + if queryResult, ok := querier.mockStationID2QueryResult[placeID]; ok { return queryResult } - glog.Fatalf("Un-implemented mapping key %v for mockStationID2QueryResult.\n", stationID) + glog.Fatalf("Un-implemented mapping key %v for mockStationID2QueryResult.\n", placeID) return nil } -func (querier *mockQuerier4StationGraph) GetLocation(stationID string) *nav.Location { - if location, ok := querier.mockStationID2Location[stationID]; ok { +func (querier *mockQuerier4StationGraph) GetLocation(placeID common.PlaceID) *nav.Location { + if location, ok := querier.mockStationID2Location[placeID]; ok { return location } - glog.Fatalf("Un-implemented mapping key for mockStationID2Location id = %v.\n", stationID) + glog.Fatalf("Un-implemented mapping key for mockStationID2Location id = %v.\n", placeID) return nil } @@ -278,7 +278,7 @@ func TestStationGraphGenerateSolutions1(t *testing.T) { Lat: 2.2, Lon: 2.2, }, - StationID: "2", + PlaceID: "2", ArrivalEnergy: 8.9, WaitTime: 0, ChargeTime: 2532, @@ -293,7 +293,7 @@ func TestStationGraphGenerateSolutions1(t *testing.T) { Lat: 5.5, Lon: 5.5, }, - StationID: "5", + PlaceID: "5", ArrivalEnergy: 15.6, WaitTime: 0, ChargeTime: 5328, @@ -527,24 +527,24 @@ var mockedGraph4StationGraph = mockGraph{ // }, }, }, - []string{ - stationfindertype.OrigLocationID.String(), - stationfindertype.DestLocationID.String(), - "station1", - "station1", - "station1", - "station2", - "station2", - "station2", - "station3", - "station3", - "station3", - "station4", - "station4", - "station4", - "station5", - "station5", - "station5", + []common.PlaceID{ + stationfindertype.OrigLocationID, + stationfindertype.DestLocationID, + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, }, map[nodeID][]*edge{ 0: {