forked from Project-OSRM/osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
166 additions
and
62 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,76 @@ | ||
package chargingstrategy | ||
|
||
type fakeChargingStrategyCreator struct { | ||
maxEnergyLevel float64 | ||
arrivalEnergyLevel float64 | ||
maxEnergyLevel float64 | ||
} | ||
|
||
// NewFakeChargingStrategyCreator creates fake charging strategy | ||
func NewFakeChargingStrategyCreator(maxEnergyLevel float64) *fakeChargingStrategyCreator { | ||
func NewFakeChargingStrategyCreator(arrivalEnergyLevel, maxEnergyLevel float64) *fakeChargingStrategyCreator { | ||
return &fakeChargingStrategyCreator{ | ||
maxEnergyLevel: maxEnergyLevel, | ||
arrivalEnergyLevel: arrivalEnergyLevel, | ||
maxEnergyLevel: maxEnergyLevel, | ||
} | ||
} | ||
|
||
// @todo: | ||
// - Influence of returning candidate with no charge time and additional energy | ||
|
||
// CreateChargingStrategies returns different charging strategy | ||
// Initial implementation: 1 hour charge for 60% of max energy, | ||
// 2 hour charge for 80% | ||
// 4 hour charge for 100% | ||
// Initial implementation: | ||
// 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 | ||
func (f *fakeChargingStrategyCreator) CreateChargingStrategies() []ChargingStrategy { | ||
sixtyPercentOfMaxEnergy := f.maxEnergyLevel * 0.6 | ||
eightyPercentOfMaxEnergy := f.maxEnergyLevel * 0.8 | ||
var result []ChargingStrategy | ||
|
||
if f.arrivalEnergyLevel < sixtyPercentOfMaxEnergy { | ||
energy4Stage1 := sixtyPercentOfMaxEnergy - f.arrivalEnergyLevel | ||
time4Stage1 := energy4Stage1 / sixtyPercentOfMaxEnergy * 3600.0 | ||
result = append(result, ChargingStrategy{ | ||
ChargingTime: time4Stage1, | ||
ChargingEnergy: energy4Stage1, | ||
}) | ||
|
||
energy4Stage2 := eightyPercentOfMaxEnergy - sixtyPercentOfMaxEnergy + energy4Stage1 | ||
time4Stage2 := 3600.0 + time4Stage1 | ||
result = append(result, ChargingStrategy{ | ||
ChargingTime: time4Stage2, | ||
ChargingEnergy: energy4Stage2, | ||
}) | ||
|
||
return []ChargingStrategy{ | ||
ChargingStrategy{ | ||
ChargingTime: 3600, | ||
ChargingEnergy: f.maxEnergyLevel * 0.6, | ||
}, | ||
ChargingStrategy{ | ||
ChargingTime: 7200, | ||
ChargingEnergy: f.maxEnergyLevel * 0.8, | ||
}, | ||
ChargingStrategy{ | ||
ChargingTime: 14400, | ||
ChargingEnergy: f.maxEnergyLevel, | ||
}, | ||
energy4Stage3 := f.maxEnergyLevel - sixtyPercentOfMaxEnergy + energy4Stage1 | ||
time4Stage3 := 7200.0 + 3600.0 + time4Stage1 | ||
result = append(result, ChargingStrategy{ | ||
ChargingTime: time4Stage3, | ||
ChargingEnergy: energy4Stage3, | ||
}) | ||
} else if f.arrivalEnergyLevel < eightyPercentOfMaxEnergy { | ||
energy4Stage2 := eightyPercentOfMaxEnergy - f.arrivalEnergyLevel | ||
time4Stage2 := energy4Stage2 / (eightyPercentOfMaxEnergy - sixtyPercentOfMaxEnergy) * 3600 | ||
|
||
result = append(result, ChargingStrategy{ | ||
ChargingTime: time4Stage2, | ||
ChargingEnergy: energy4Stage2, | ||
}) | ||
|
||
energy4Stage3 := f.maxEnergyLevel - eightyPercentOfMaxEnergy + energy4Stage2 | ||
time4Stage3 := 7200.0 + time4Stage2 | ||
result = append(result, ChargingStrategy{ | ||
ChargingTime: time4Stage3, | ||
ChargingEnergy: energy4Stage3, | ||
}) | ||
} else { | ||
energy4Stage3 := f.maxEnergyLevel - f.arrivalEnergyLevel | ||
time4Stage3 := energy4Stage3 / (f.maxEnergyLevel - eightyPercentOfMaxEnergy) * 7200 | ||
result = append(result, ChargingStrategy{ | ||
ChargingTime: time4Stage3, | ||
ChargingEnergy: energy4Stage3, | ||
}) | ||
} | ||
|
||
return result | ||
} |
64 changes: 64 additions & 0 deletions
64
integration/oasis/chargingstrategy/chargingstrategy_test.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package chargingstrategy | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestFakeChargingStrategyCreator(t *testing.T) { | ||
cases := []struct { | ||
arrivalEnergyLevel float64 | ||
maxEnergyLevel float64 | ||
expectResult []ChargingStrategy | ||
}{ | ||
{ | ||
10000, | ||
50000, | ||
[]ChargingStrategy{ | ||
ChargingStrategy{ | ||
ChargingTime: 2400, | ||
ChargingEnergy: 20000, | ||
}, | ||
ChargingStrategy{ | ||
ChargingTime: 6000, | ||
ChargingEnergy: 30000, | ||
}, | ||
ChargingStrategy{ | ||
ChargingTime: 13200, | ||
ChargingEnergy: 40000, | ||
}, | ||
}, | ||
}, | ||
{ | ||
32000, | ||
50000, | ||
[]ChargingStrategy{ | ||
ChargingStrategy{ | ||
ChargingTime: 2880, | ||
ChargingEnergy: 8000, | ||
}, | ||
ChargingStrategy{ | ||
ChargingTime: 10080, | ||
ChargingEnergy: 18000, | ||
}, | ||
}, | ||
}, | ||
{ | ||
41000, | ||
50000, | ||
[]ChargingStrategy{ | ||
ChargingStrategy{ | ||
ChargingTime: 6480, | ||
ChargingEnergy: 9000, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
actualResult := NewFakeChargingStrategyCreator(c.arrivalEnergyLevel, c.maxEnergyLevel).CreateChargingStrategies() | ||
if !reflect.DeepEqual(actualResult, c.expectResult) { | ||
t.Errorf("parse case %#v, expect %#v but got %#v", c, c.expectResult, actualResult) | ||
} | ||
} | ||
} |
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