forked from Project-OSRM/osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Performance tune for OASIS service #353
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7ec7522
feat: add logic to profile oasis service
CodeBear801 f79cfb8
feat: reserve large size for several map in stationgraph
CodeBear801 5bcc4e2
fix: record pre-calculate object to avoid calculation in the running …
CodeBear801 16c80f1
fix: adjust code in stationgraph, remove location
CodeBear801 1328354
refactor: Retire multiple definition of `weight` in oasis
CodeBear801 6bc2486
refactor: Optimize implementation of nearbyquery, remove definition o…
CodeBear801 3068da0
fix: Change representation of `stationID` to `PlaceID`
CodeBear801 d0f2f94
feat: implement Edge's map based on placeID mapping
CodeBear801 bd1b43a
refactor: abstract edgeid2weight and related operation together
CodeBear801 0578ccb
fix: update change log and refine names.
CodeBear801 a06300a
fix: adjust code based on comments from review.
CodeBear801 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 70 additions & 40 deletions
110
integration/service/oasis/chargingstrategy/fake_charge_strategy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,121 @@ | ||
package chargingstrategy | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/Telenav/osrm-backend/integration/util" | ||
"github.com/golang/glog" | ||
) | ||
|
||
type fakeChargeStrategy struct { | ||
maxEnergyLevel float64 | ||
maxEnergyLevel float64 | ||
sixtyPercentOFMaxEnergy float64 | ||
eightyPercentOfMaxEnergy float64 | ||
costFrom60PercentTo80Percent float64 | ||
costFrom60PercentTo100Percent float64 | ||
costFrom80PercentTo100Percent float64 | ||
stateCandidates []State | ||
} | ||
|
||
// NewFakeChargingStrategy creates fake charge strategy | ||
func NewFakeChargingStrategy(maxEnergyLevel float64) *fakeChargeStrategy { | ||
sixtyPercentOFMaxEnergy := math.Round(maxEnergyLevel*0.6*100) / 100 | ||
eightyPercentOfMaxEnergy := math.Round(maxEnergyLevel*0.8*100) / 100 | ||
maxEnergyLevel = math.Round(maxEnergyLevel*100) / 100 | ||
costFrom60PercentTo80Percent := 3600.0 | ||
costFrom60PercentTo100Percent := 10800.0 | ||
costFrom80PercentTo100Percent := 7200.0 | ||
stateCandidates := []State{ | ||
{ | ||
Energy: sixtyPercentOFMaxEnergy, | ||
}, | ||
{ | ||
Energy: eightyPercentOfMaxEnergy, | ||
}, | ||
{ | ||
Energy: maxEnergyLevel, | ||
}, | ||
} | ||
|
||
return &fakeChargeStrategy{ | ||
maxEnergyLevel: maxEnergyLevel, | ||
maxEnergyLevel: maxEnergyLevel, | ||
sixtyPercentOFMaxEnergy: sixtyPercentOFMaxEnergy, | ||
eightyPercentOfMaxEnergy: eightyPercentOfMaxEnergy, | ||
costFrom60PercentTo80Percent: costFrom60PercentTo80Percent, | ||
costFrom60PercentTo100Percent: costFrom60PercentTo100Percent, | ||
costFrom80PercentTo100Percent: costFrom80PercentTo100Percent, | ||
stateCandidates: stateCandidates, | ||
} | ||
} | ||
|
||
// @todo: | ||
// - Influence of returning candidate with no charge time and additional energy | ||
// CreateChargingStates returns different charging strategy | ||
func (f *fakeChargeStrategy) CreateChargingStates() []State { | ||
return []State{ | ||
State{ | ||
Energy: f.maxEnergyLevel * 0.6, | ||
}, | ||
State{ | ||
Energy: f.maxEnergyLevel * 0.8, | ||
}, | ||
State{ | ||
Energy: f.maxEnergyLevel, | ||
}, | ||
} | ||
return f.stateCandidates | ||
} | ||
|
||
var zeroChargeCost = ChargingCost{ | ||
Duration: 0.0, | ||
} | ||
|
||
// Fake charge strategy | ||
// From empty energy: | ||
// 1 hour charge to 60% of max energy | ||
// 2 hour charge to 80%, means from 60% ~ 80% need 1 hour | ||
// 4 hour charge to 100%, means from 80% ~ 100% need 2 hours | ||
// 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 { | ||
sixtyPercentOfMaxEnergy := f.maxEnergyLevel * 0.6 | ||
eightyPercentOfMaxEnergy := f.maxEnergyLevel * 0.8 | ||
noNeedCharge := ChargingCost{ | ||
Duration: 0.0, | ||
} | ||
sixtyPercentOfMaxEnergy := f.sixtyPercentOFMaxEnergy | ||
eightyPercentOfMaxEnergy := f.eightyPercentOfMaxEnergy | ||
|
||
if arrivalEnergy > targetState.Energy || | ||
util.Float64Equal(targetState.Energy, 0.0) { | ||
return noNeedCharge | ||
return zeroChargeCost | ||
} | ||
|
||
totalTime := 0.0 | ||
currentEnergy := arrivalEnergy | ||
|
||
if arrivalEnergy < sixtyPercentOfMaxEnergy { | ||
energyNeeded4Stage1 := sixtyPercentOfMaxEnergy - arrivalEnergy | ||
totalTime += energyNeeded4Stage1 / sixtyPercentOfMaxEnergy * 3600.0 | ||
currentEnergy = sixtyPercentOfMaxEnergy | ||
} | ||
|
||
if util.Float64Equal(targetState.Energy, sixtyPercentOfMaxEnergy) { | ||
if util.Float64Equal(targetState.Energy, sixtyPercentOfMaxEnergy) { | ||
return ChargingCost{ | ||
Duration: totalTime, | ||
} | ||
} else if util.Float64Equal(targetState.Energy, eightyPercentOfMaxEnergy) { | ||
return ChargingCost{ | ||
Duration: totalTime + f.costFrom60PercentTo80Percent, | ||
} | ||
} | ||
return ChargingCost{ | ||
Duration: totalTime, | ||
Duration: totalTime + f.costFrom60PercentTo100Percent, | ||
} | ||
} | ||
|
||
if arrivalEnergy < eightyPercentOfMaxEnergy { | ||
energyNeeded4Stage2 := eightyPercentOfMaxEnergy - currentEnergy | ||
energyNeeded4Stage2 := eightyPercentOfMaxEnergy - arrivalEnergy | ||
totalTime += energyNeeded4Stage2 / (eightyPercentOfMaxEnergy - sixtyPercentOfMaxEnergy) * 3600.0 | ||
currentEnergy = eightyPercentOfMaxEnergy | ||
} | ||
if util.Float64Equal(targetState.Energy, eightyPercentOfMaxEnergy) { | ||
|
||
if util.Float64Equal(targetState.Energy, eightyPercentOfMaxEnergy) { | ||
return ChargingCost{ | ||
Duration: totalTime, | ||
} | ||
} | ||
return ChargingCost{ | ||
Duration: totalTime, | ||
Duration: totalTime + f.costFrom80PercentTo100Percent, | ||
} | ||
} | ||
|
||
if arrivalEnergy < f.maxEnergyLevel { | ||
energyNeeded4Stage3 := f.maxEnergyLevel - currentEnergy | ||
energyNeeded4Stage3 := f.maxEnergyLevel - arrivalEnergy | ||
totalTime += energyNeeded4Stage3 / (f.maxEnergyLevel - eightyPercentOfMaxEnergy) * 7200.0 | ||
} | ||
|
||
if util.Float64Equal(targetState.Energy, f.maxEnergyLevel) { | ||
return ChargingCost{ | ||
Duration: totalTime, | ||
if util.Float64Equal(targetState.Energy, f.maxEnergyLevel) { | ||
return ChargingCost{ | ||
Duration: totalTime, | ||
} | ||
} | ||
} | ||
|
||
glog.Fatalf("Invalid charging state %#v\n", targetState) | ||
return noNeedCharge | ||
return zeroChargeCost | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still common? Aha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change it to
domain/entity
:)