Skip to content

Commit

Permalink
fix: rebase branch with master
Browse files Browse the repository at this point in the history
issue: #238
  • Loading branch information
CodeBear801 committed Apr 7, 2020
2 parents 2b28e5b + d6075ca commit 81d20c8
Show file tree
Hide file tree
Showing 24 changed files with 515 additions and 268 deletions.
21 changes: 21 additions & 0 deletions integration/cmd/place-connectivity-gen/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Package main contains the tool of chargestation-connectivity generator
//
// stage 1:
// inputs is json file
// => convert to slice of [id:string,location: lat,lon]
// => calculate cellids for each point(for all levels)
// => build revese index for cellID -> ids
//
// stage 2:
// => iterate each point
// => generate a circle(s2::cap), find all cellids intersect with that circle
// => retrieve all ids
// => generate result of id(from), ids(all ids in certain distance)
//
// stage 3:
// => load data from file
// => for each line, its formid and all other ids
// => calculate distance between fromid and all other ids
// => sort result based on distance and write back to file
//
package main
27 changes: 27 additions & 0 deletions integration/cmd/place-connectivity-gen/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"flag"
"runtime"
)

var flags struct {
inputFile string
outputFolder string
numberOfWorkers int
maxRange float64
osrmBackendEndpoint string
}

// defaultRange indicates default max drive range in meters.
// This value always bigger than max driven ranges for existing vehicles.
// During query time could just take subset of pre-processed result based on real range.
const defaultMaxRange = 800000

func init() {
flag.StringVar(&flags.inputFile, "i", "", "path for input file in json format")
flag.StringVar(&flags.outputFolder, "o", "", "path for output folder")
flag.IntVar(&flags.numberOfWorkers, "num_of_workers", runtime.NumCPU(), "number of workers to build connectivity map")
flag.Float64Var(&flags.maxRange, "range", defaultMaxRange, "maximum drive range in meters used for preprocessing.")
flag.StringVar(&flags.osrmBackendEndpoint, "osrm", "", "OSRM-backend endpoint")
}
45 changes: 45 additions & 0 deletions integration/cmd/place-connectivity-gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"flag"
"os"
"time"

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

func main() {
flag.Parse()
defer glog.Flush()
startTime := time.Now()

if flags.inputFile == "" || flags.outputFolder == "" {
glog.Fatal("Empty string for inputFile or outputFolder, please check your input.\n")
}

var rankerStrategy spatialindexer.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)
} else {
rankerStrategy = ranker.CreateRanker(ranker.OSRMBasedRanker,
osrmconnector.NewOSRMConnector(flags.osrmBackendEndpoint))
}

indexer := s2indexer.NewS2Indexer().Build(flags.inputFile)
if indexer == nil {
glog.Fatalf("Failed to build indexer, stop %s\n", os.Args[0])
}
indexer.Dump(flags.outputFolder)

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

glog.Infof("%s totally takes %f seconds for processing.", os.Args[0], time.Since(startTime).Seconds())
}
2 changes: 1 addition & 1 deletion integration/cmd/poi-converter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Pipeline() {

buffer.WriteString("}")
if i < len(content)-1 {
buffer.WriteString(",")
buffer.WriteString(",\n")
}
}

Expand Down
18 changes: 10 additions & 8 deletions integration/oasis/osrmconnector/osrmhttpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strings"

"github.com/Telenav/osrm-backend/integration/pkg/api"
"github.com/Telenav/osrm-backend/integration/pkg/api/osrm/route"
"github.com/Telenav/osrm-backend/integration/pkg/api/osrm/table"
"github.com/Telenav/osrm-backend/integration/pkg/backend"
Expand All @@ -18,6 +19,8 @@ type osrmHTTPClient struct {
}

func newOsrmHTTPClient(osrmEndpoint string) *osrmHTTPClient {
osrmEndpoint = strings.TrimSuffix(osrmEndpoint, api.Slash)

return &osrmHTTPClient{
osrmBackendEndpoint: osrmEndpoint,
httpclient: http.Client{Timeout: backend.Timeout()},
Expand All @@ -34,7 +37,7 @@ func (oc *osrmHTTPClient) submitRouteReq(r *route.Request) <-chan RouteResponse

req := newOsrmRequest(url, OSRMRoute)
oc.requestC <- req
glog.Info("[osrmHTTPClient]Submit route request " + url)
glog.V(3).Infof("[osrmHTTPClient]Submit route request " + url + "\n")
return req.routeRespC
}

Expand All @@ -47,12 +50,12 @@ func (oc *osrmHTTPClient) submitTableReq(r *table.Request) <-chan TableResponse

req := newOsrmRequest(url, OSRMTable)
oc.requestC <- req
glog.Info("[osrmHTTPClient]Submit table request " + url)
glog.V(3).Infof("[osrmHTTPClient]Submit table request " + url + "\n")
return req.tableRespC
}

func (oc *osrmHTTPClient) start() {
glog.Info("osrm connector started.\n")
glog.V(0).Info("osrm connector started.\n")
c := make(chan message)

for {
Expand All @@ -73,7 +76,7 @@ type message struct {

func (oc *osrmHTTPClient) send(req *request, c chan<- message) {
resp, err := oc.httpclient.Get(req.url)
glog.Infof("[osrmHTTPClient] send function succeed with request %s" + req.url)
glog.V(3).Infof("[osrmHTTPClient] send function succeed with request %s.\n" + req.url)
m := message{req: req, resp: resp, err: err}
c <- m
}
Expand All @@ -94,7 +97,7 @@ func (oc *osrmHTTPClient) response(m *message) {
tableResp.Err = m.err
m.req.tableRespC <- tableResp
} else {
glog.Fatal("Unsupported request type for osrmHTTPClient")
glog.Fatal("Unsupported request type for osrmHTTPClient.\n")
}

return
Expand All @@ -108,9 +111,8 @@ func (oc *osrmHTTPClient) response(m *message) {
tableResp.Err = json.NewDecoder(m.resp.Body).Decode(&tableResp.Resp)
m.req.tableRespC <- tableResp
} else {
glog.Fatal("Unsupported request type for osrmHTTPClient")
glog.Fatal("Unsupported request type for osrmHTTPClient.\n")
}
glog.Infof("[osrmHTTPClient] Response for request %s" + m.req.url + " is generated.")
glog.V(3).Infof("[osrmHTTPClient] Response for request %s" + m.req.url + " is generated.\n")

return
}
10 changes: 5 additions & 5 deletions integration/oasis/reachable_by_single_charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func pickChargeStationWithEarlistArrival(req *oasis.Request, overlapPoints coord
}
return &singleChargeStationCandidate{
location: overlapPoints[index],
distanceFromOrig: *respOrig.Resp.Distances[0][index],
durationFromOrig: *respOrig.Resp.Durations[0][index],
distanceToDest: *respDest.Resp.Distances[index][0],
durationToDest: *respDest.Resp.Durations[index][0],
distanceFromOrig: respOrig.Resp.Distances[0][index],
durationFromOrig: respOrig.Resp.Durations[0][index],
distanceToDest: respDest.Resp.Distances[index][0],
durationToDest: respDest.Resp.Durations[index][0],
}, nil
}

Expand All @@ -166,7 +166,7 @@ func rankingSingleChargeStation(orig2Stations, stations2Dest *table.Response) (i
var totalTimes []routePassSingleStation
for i := 0; i < size; i++ {
var route routePassSingleStation
route.time = *orig2Stations.Durations[0][i] + *stations2Dest.Durations[i][0]
route.time = orig2Stations.Durations[0][i] + stations2Dest.Durations[i][0]
route.index = i
totalTimes = append(totalTimes, route)
}
Expand Down
4 changes: 2 additions & 2 deletions integration/oasis/stationfinder/stations_iterator_alg.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func CalcWeightBetweenChargeStationsPair(from nearbyStationsIterator, to nearbyS
Lon: targetPoint.Lon,
},
Cost: Cost{
Duration: *resp.Resp.Durations[i][j],
Distance: *resp.Resp.Distances[i][j],
Duration: resp.Resp.Durations[i][j],
Distance: resp.Resp.Distances[i][j],
},
})
}
Expand Down
64 changes: 32 additions & 32 deletions integration/pkg/api/osrm/table/mock_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
// 1 * 4
var mockFloatArray1 []float64 = []float64{22.2, 11.1, 33.3, 44.4}
var Mock1ToNTableResponse1 Response = Response{
Durations: [][]*float64{
[]*float64{&mockFloatArray1[0], &mockFloatArray1[1], &mockFloatArray1[2], &mockFloatArray1[3]},
Durations: [][]float64{
[]float64{mockFloatArray1[0], mockFloatArray1[1], mockFloatArray1[2], mockFloatArray1[3]},
},
Distances: [][]*float64{
[]*float64{&mockFloatArray1[0], &mockFloatArray1[1], &mockFloatArray1[2], &mockFloatArray1[3]},
Distances: [][]float64{
[]float64{mockFloatArray1[0], mockFloatArray1[1], mockFloatArray1[2], mockFloatArray1[3]},
},
Sources: []*osrmtype.Waypoint{
&osrmtype.Waypoint{
Expand All @@ -37,17 +37,17 @@ var Mock1ToNTableResponse1 Response = Response{
// 4 * 1
var mockFloatArray2 []float64 = []float64{66.6, 11.1, 33.3, 33.3}
var MockNTo1TableResponse1 Response = Response{
Durations: [][]*float64{
[]*float64{&mockFloatArray2[0]},
[]*float64{&mockFloatArray2[1]},
[]*float64{&mockFloatArray2[2]},
[]*float64{&mockFloatArray2[3]},
},
Distances: [][]*float64{
[]*float64{&mockFloatArray2[0]},
[]*float64{&mockFloatArray2[1]},
[]*float64{&mockFloatArray2[2]},
[]*float64{&mockFloatArray2[3]},
Durations: [][]float64{
[]float64{mockFloatArray2[0]},
[]float64{mockFloatArray2[1]},
[]float64{mockFloatArray2[2]},
[]float64{mockFloatArray2[3]},
},
Distances: [][]float64{
[]float64{mockFloatArray2[0]},
[]float64{mockFloatArray2[1]},
[]float64{mockFloatArray2[2]},
[]float64{mockFloatArray2[3]},
},
Sources: []*osrmtype.Waypoint{
&osrmtype.Waypoint{
Expand Down Expand Up @@ -79,17 +79,17 @@ var mockFloatArray3 [][]float64 = [][]float64{
}

var Mock4To2TableResponse1 Response = Response{
Durations: [][]*float64{
[]*float64{&mockFloatArray3[0][0], &mockFloatArray3[0][1]},
[]*float64{&mockFloatArray3[1][0], &mockFloatArray3[1][1]},
[]*float64{&mockFloatArray3[2][0], &mockFloatArray3[2][1]},
[]*float64{&mockFloatArray3[3][0], &mockFloatArray3[3][1]},
},
Distances: [][]*float64{
[]*float64{&mockFloatArray3[0][0], &mockFloatArray3[0][1]},
[]*float64{&mockFloatArray3[1][0], &mockFloatArray3[1][1]},
[]*float64{&mockFloatArray3[2][0], &mockFloatArray3[2][1]},
[]*float64{&mockFloatArray3[3][0], &mockFloatArray3[3][1]},
Durations: [][]float64{
[]float64{mockFloatArray3[0][0], mockFloatArray3[0][1]},
[]float64{mockFloatArray3[1][0], mockFloatArray3[1][1]},
[]float64{mockFloatArray3[2][0], mockFloatArray3[2][1]},
[]float64{mockFloatArray3[3][0], mockFloatArray3[3][1]},
},
Distances: [][]float64{
[]float64{mockFloatArray3[0][0], mockFloatArray3[0][1]},
[]float64{mockFloatArray3[1][0], mockFloatArray3[1][1]},
[]float64{mockFloatArray3[2][0], mockFloatArray3[2][1]},
[]float64{mockFloatArray3[3][0], mockFloatArray3[3][1]},
},
Sources: []*osrmtype.Waypoint{
&osrmtype.Waypoint{
Expand Down Expand Up @@ -118,13 +118,13 @@ var Mock4To2TableResponse1 Response = Response{
// 2 * 1
var mockFloatArray4 []float64 = []float64{66.6, 11.1}
var Mock2To1TableResponse1 Response = Response{
Durations: [][]*float64{
[]*float64{&mockFloatArray4[0]},
[]*float64{&mockFloatArray4[1]},
Durations: [][]float64{
[]float64{mockFloatArray4[0]},
[]float64{mockFloatArray4[1]},
},
Distances: [][]*float64{
[]*float64{&mockFloatArray4[0]},
[]*float64{&mockFloatArray4[1]},
Distances: [][]float64{
[]float64{mockFloatArray4[0]},
[]float64{mockFloatArray4[1]},
},
Sources: []*osrmtype.Waypoint{
&osrmtype.Waypoint{
Expand Down
4 changes: 2 additions & 2 deletions integration/pkg/api/osrm/table/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ type Response struct {
Message string `json:"message,omitempty"`
Sources []*osrmtype.Waypoint `json:"sources"`
Destinations []*osrmtype.Waypoint `json:"destinations"`
Durations [][]*float64 `json:"durations"`
Distances [][]*float64 `json:"distances"`
Durations [][]float64 `json:"durations"`
Distances [][]float64 `json:"distances"`
}
Loading

0 comments on commit 81d20c8

Please sign in to comment.