Skip to content

Commit

Permalink
Feature/oasis refactor phase3 step2 (#368)
Browse files Browse the repository at this point in the history
* refactor: add package of graph and place
issue: #364
  • Loading branch information
CodeBear801 authored Jul 29, 2020
1 parent 85f1a4f commit d21e5dd
Show file tree
Hide file tree
Showing 140 changed files with 1,518 additions and 1,516 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changes from v10.3.0
- CHANGED for internal refactoring, improve performance for OASIS service, more information please go to [#344](https://github.com/Telenav/osrm-backend/issues/344) [#353](https://github.com/Telenav/osrm-backend/pull/353)
- ADDED **Dockerfile** to generate OASIS data [#362](https://github.com/Telenav/osrm-backend/pull/362)
- CHANGED for internal refactoring, Create the layer of `entrypoint` and `solution`, more information please go to [#363](https://github.com/Telenav/osrm-backend/issues/363#issuecomment-662020248) [#365](https://github.com/Telenav/osrm-backend/pull/365)
- CHANGED for internal refactoring, Create the layer of `graph` and `place`, more information please go to [#352](https://github.com/Telenav/osrm-backend/issues/352) [#368](https://github.com/Telenav/osrm-backend/pull/368)
- Bugfix:
- Performance:
- Tools:
Expand Down
1 change: 1 addition & 0 deletions integration/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cmd/historicalspeed-timezone-builder/historicalspeed-timezone-builder
cmd/nodes2way-builder/nodes2way-builder
cmd/nodes2way-cli/nodes2way-cli
cmd/oasis/oasis
cmd/place-connectivity-gen/place-connectivity-gen

# test files
cmd/trafficproxy-cli/*_flows.csv
Expand Down
14 changes: 7 additions & 7 deletions integration/cmd/place-connectivity-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"os"
"time"

"github.com/Telenav/osrm-backend/integration/service/oasis/connectivitymap"
"github.com/Telenav/osrm-backend/integration/service/oasis/osrmconnector"
"github.com/Telenav/osrm-backend/integration/service/oasis/spatialindexer"
"github.com/Telenav/osrm-backend/integration/service/oasis/spatialindexer/ranker"
"github.com/Telenav/osrm-backend/integration/service/oasis/spatialindexer/s2indexer"
"github.com/Telenav/osrm-backend/integration/service/oasis/place"
"github.com/Telenav/osrm-backend/integration/service/oasis/place/spatialindexer/ranker"
"github.com/Telenav/osrm-backend/integration/service/oasis/place/spatialindexer/s2indexer"
"github.com/Telenav/osrm-backend/integration/service/oasis/place/topograph"
"github.com/Telenav/osrm-backend/integration/util/osrmconnector"
"github.com/golang/glog"
)

Expand All @@ -22,7 +22,7 @@ func main() {
glog.Fatal("Empty string for inputFile or outputFolder, please check your input.\n")
}

var rankerStrategy spatialindexer.Ranker
var rankerStrategy place.Ranker
if flags.osrmBackendEndpoint == "" {
glog.Warning("No information about OSRM Endpoint, can only init ranker with great circle distance.")
rankerStrategy = ranker.CreateRanker(ranker.SimpleRanker, nil)
Expand All @@ -37,7 +37,7 @@ func main() {
}
indexer.Dump(flags.outputFolder)

connectivitymap.New(flags.maxRange).
topograph.New(flags.maxRange).
Build(indexer, indexer, rankerStrategy, flags.numberOfWorkers).
Dump(flags.outputFolder)

Expand Down
4 changes: 2 additions & 2 deletions integration/doc/oasis/architecture_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type TopoQuerier interface {

// GetNearByPlaces finds near by stations by given placeID and return them in recorded sequence
// Returns nil if given placeID is not found or no connectivity
GetNearByPlaces(placeID common.PlaceID) []*common.RankedPlaceInfo
GetNearByPlaces(placeID entity.PlaceID) []*entity.TransferInfo

// LocationQuerier returns *nav.location for given placeID
LocationQuerier
Expand All @@ -70,7 +70,7 @@ Definition of `SpatialQuerier` interface
type SpatialQuerier interface {

// GetNearByPlaceIDs returns a group of places near to given center location
GetNearByPlaceIDs(center nav.Location, radius float64, limitCount int) []*common.PlaceInfo
GetNearByPlaceIDs(center nav.Location, radius float64, limitCount int) []*entity.PlaceWithLocation
}
```
Definition of `LocationQuerier` interface
Expand Down
17 changes: 0 additions & 17 deletions integration/service/oasis/chargingstrategy/null_charge_strategy.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package chargingstrategy

type fakeChargeStrategy struct {
}

// NewFakeChargeStrategy creates fakeChargeStrategy used to bypass unit tests
func NewFakeChargeStrategy() *fakeChargeStrategy {
return &fakeChargeStrategy{}
}

func (f *fakeChargeStrategy) CreateChargingStates() []State {
return []State{}
}

func (f *fakeChargeStrategy) EvaluateCost(arrivalEnergy float64, targetState State) ChargingCost {
return ChargingCost{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/Telenav/osrm-backend/integration/util"
)

type fakeChargeStrategy struct {
type simpleChargeStrategy struct {
maxEnergyLevel float64
sixtyPercentOFMaxEnergy float64
eightyPercentOfMaxEnergy float64
Expand All @@ -16,8 +16,8 @@ type fakeChargeStrategy struct {
stateCandidates []State
}

// NewFakeChargingStrategy creates fake charge strategy
func NewFakeChargingStrategy(maxEnergyLevel float64) *fakeChargeStrategy {
// NewSimpleChargingStrategy creates fake charge strategy
func NewSimpleChargingStrategy(maxEnergyLevel float64) *simpleChargeStrategy {
sixtyPercentOFMaxEnergy := math.Round(maxEnergyLevel*0.6*100) / 100
eightyPercentOfMaxEnergy := math.Round(maxEnergyLevel*0.8*100) / 100
maxEnergyLevel = math.Round(maxEnergyLevel*100) / 100
Expand All @@ -36,7 +36,7 @@ func NewFakeChargingStrategy(maxEnergyLevel float64) *fakeChargeStrategy {
},
}

return &fakeChargeStrategy{
return &simpleChargeStrategy{
maxEnergyLevel: maxEnergyLevel,
sixtyPercentOFMaxEnergy: sixtyPercentOFMaxEnergy,
eightyPercentOfMaxEnergy: eightyPercentOfMaxEnergy,
Expand All @@ -50,7 +50,7 @@ func NewFakeChargingStrategy(maxEnergyLevel float64) *fakeChargeStrategy {
// @todo:
// - Influence of returning candidate with no charge time and additional energy
// CreateChargingStates returns different charging strategy
func (f *fakeChargeStrategy) CreateChargingStates() []State {
func (f *simpleChargeStrategy) CreateChargingStates() []State {
return f.stateCandidates
}

Expand All @@ -63,7 +63,7 @@ var zeroChargeCost = ChargingCost{
// charge rule #1: 1 hour charge to 60% of max energy
// charge rule #2: 2 hour charge to 80%, means from 60% ~ 80% need 1 hour
// charge rule #3: 4 hour charge to 100%, means from 80% ~ 100% need 2 hours
func (f *fakeChargeStrategy) EvaluateCost(arrivalEnergy float64, targetState State) ChargingCost {
func (f *simpleChargeStrategy) EvaluateCost(arrivalEnergy float64, targetState State) ChargingCost {
sixtyPercentOfMaxEnergy := f.sixtyPercentOFMaxEnergy
eightyPercentOfMaxEnergy := f.eightyPercentOfMaxEnergy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestFakeChargingStrategyCreator(t *testing.T) {
func TestSimpleChargingStrategyCreator(t *testing.T) {
cases := []struct {
arrivalEnergyLevel float64
maxEnergyLevel float64
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestFakeChargingStrategyCreator(t *testing.T) {

for _, c := range cases {
var actualResult []ChargingCost
strategy := NewFakeChargingStrategy(c.maxEnergyLevel)
strategy := NewSimpleChargingStrategy(c.maxEnergyLevel)
for _, state := range strategy.CreateChargingStates() {
actualResult = append(actualResult, strategy.EvaluateCost(c.arrivalEnergyLevel, state))
}
Expand Down
1 change: 1 addition & 0 deletions integration/service/oasis/graph/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package graph
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Package stationgraph builds charge station based graph and provide optimum charg
+ strategy: Charge strategy be used for each charge station, it hides logic of different strategy of {time used for charging/wating, new energy got}.
+ querier: topological querier which generates connectivity for building graph
* querier could be implemented by querying OSRM or pre-build conductivities
* querier must contains stationfindertype.OrigLocationIDStr and stationfindertype.DestLocationIDStr
* querier must provide ways to integrate stationfindertype.OrigLocationIDStr and stationfindertype.DestLocationIDStr into connectivity graph
* querier must contains iteratortype.OrigLocationIDStr and iteratortype.DestLocationIDStr
* querier must provide ways to integrate iteratortype.OrigLocationIDStr and iteratortype.DestLocationIDStr into connectivity graph
- station graph returns
+ entity.Solution via GenerateChargeSolutions()
Expand All @@ -28,7 +28,7 @@ Data structure
* station 1, charge to 100% of maximum energy then left
* Logical node is identified by unique station ID + chargingStatus
+ connectivity: first built physical connectivity, then built logical
* physical connectivity is ansowered by interface of connectivitymap.Querier, eg, station 1 connects station 4 and station 5
* physical connectivity is ansowered by interface of place.TopoQuerier, eg, station 1 connects station 4 and station 5
* logical connectivity is build considering physical connection + final charging status
* logical connectivity's result is the final graph which algorithm runs on
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package stationgraph

import "github.com/Telenav/osrm-backend/integration/service/oasis/internal/common"
import "github.com/Telenav/osrm-backend/integration/service/oasis/internal/entity"

type edgeID struct {
fromNodeID nodeID
Expand All @@ -9,5 +9,5 @@ type edgeID struct {

type edge struct {
edgeId edgeID
edgeMetric *common.Weight
edgeMetric *entity.Weight
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package stationgraph

import "github.com/Telenav/osrm-backend/integration/service/oasis/internal/common"
import (
"github.com/Telenav/osrm-backend/integration/service/oasis/internal/entity"
)

type place2placeID struct {
from common.PlaceID
to common.PlaceID
from entity.PlaceID
to entity.PlaceID
}
type edgeID2EdgeData map[place2placeID]*common.Weight
type edgeID2EdgeData map[place2placeID]*entity.Weight

func newEdgeID2EdgeData() edgeID2EdgeData {
return make(edgeID2EdgeData, 5000000)
}

func (edge2Weight edgeID2EdgeData) get(id place2placeID) *common.Weight {
func (edge2Weight edgeID2EdgeData) get(id place2placeID) *entity.Weight {
return edge2Weight[id]
}

func (edge2Weight edgeID2EdgeData) add(id place2placeID, weight *common.Weight) {
func (edge2Weight edgeID2EdgeData) add(id place2placeID, weight *entity.Weight) {
edge2Weight[id] = weight
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import (
"reflect"
"testing"

"github.com/Telenav/osrm-backend/integration/service/oasis/internal/common"
"github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfindertype"
"github.com/Telenav/osrm-backend/integration/service/oasis/internal/entity"
"github.com/Telenav/osrm-backend/integration/service/oasis/place/iterator/iteratortype"
)

func TestEdgeID2EdgeDataGetResultShouldEqualsToSetValue(t *testing.T) {
cases := []struct {
key place2placeID
value *common.Weight
value *entity.Weight
}{
// case 1
{
place2placeID{
111,
222,
},
&common.Weight{
&entity.Weight{
Duration: 111.0,
Distance: 222.0,
},
},
// case 2
{
place2placeID{
stationfindertype.OrigLocationID,
stationfindertype.DestLocationID,
iteratortype.OrigLocationID,
iteratortype.DestLocationID,
},
&common.Weight{
&entity.Weight{
Duration: 333.0,
Distance: 444.0,
},
Expand All @@ -53,8 +53,8 @@ func TestEdgeID2EdgeDataGetResultShouldEqualsToSetValue(t *testing.T) {
func TestEdgeID2EdgeDataWhenGetUnsettedKeyShouldGetNil(t *testing.T) {
edgeID2Data := newEdgeID2EdgeData()
actualValue := edgeID2Data.get(place2placeID{
stationfindertype.OrigLocationID,
stationfindertype.DestLocationID})
iteratortype.OrigLocationID,
iteratortype.DestLocationID})
if actualValue != nil {
t.Errorf("Expect to get nil for unsetted key but got %#v\n", actualValue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ 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/graph/chargingstrategy"
"github.com/Telenav/osrm-backend/integration/service/oasis/internal/entity"
)

// Graph defines interface used for Graph
Expand All @@ -17,13 +17,13 @@ type Graph interface {
AdjacentNodes(id nodeID) []nodeID

// Edge returns edge information between given two nodes
Edge(from, to nodeID) *common.Weight
Edge(from, to nodeID) *entity.Weight

// SetStart generates start node for the graph
SetStart(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph
SetStart(placeID entity.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph

// SetEnd generates end node for the graph
SetEnd(placeID common.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph
SetEnd(placeID entity.PlaceID, targetState chargingstrategy.State, location *nav.Location) Graph

// StartNodeID returns start node's ID for given graph
StartNodeID() nodeID
Expand All @@ -35,5 +35,5 @@ type Graph interface {
ChargeStrategy() chargingstrategy.Strategy

// PlaceID returns original placeID from internal nodeID
PlaceID(id nodeID) common.PlaceID
PlaceID(id nodeID) entity.PlaceID
}
Loading

0 comments on commit d21e5dd

Please sign in to comment.