Skip to content

Commit

Permalink
style refs #12
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Sep 24, 2024
1 parent fcf4890 commit 4432ee5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions tests/complex/traci/person/setSpeedFactor/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
traci.person.appendWalkingStage(pID, ["SC"], arrivalPos="-20")

while traci.simulation.getMinExpectedNumber() > 0:

if traci.simulation.getTime() == 10:
traci.person.setSpeedFactor(pID, 0.5)
elif traci.simulation.getTime() == 20:
traci.person.setSpeedFactor(pID, 2)

traci.simulationStep()

traci.close()
12 changes: 7 additions & 5 deletions tools/distributeChargingStations.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ def main(options):

# iterate edges with parkingArea groups and randomly select a charging point count
totalChargingPoints = math.floor(totalCapacity * options.probability * options.density)
totalExistingCount = sum(edge2chargingPointCount.values())
if options.verbose:
print("Charging points to distribute using a density of %.2f: %.0f on %.0f parking spaces (%.2f%%)" %
(options.density, totalChargingPoints, totalCapacity, totalChargingPoints/totalCapacity*100 if totalCapacity > 0 else 0))
(options.density, totalChargingPoints, totalCapacity,
totalChargingPoints/totalCapacity*100 if totalCapacity > 0 else 0))
csIndex = 0
rootParking = None
with sumolib.openz(options.outFile, 'w') as outf:
Expand All @@ -184,7 +184,8 @@ def main(options):
unchangedParkings = []
unvisitedEdges = []
for edge, parkingAreas in edge2parkingArea.items():
if (checkSelection and not edge.isSelected()) or len(parkingAreas) == 0 or (options.skipEquippedEdges and edge in edge2chargingPointCount and edge2chargingPointCount[edge] > 0):
if ((checkSelection and not edge.isSelected()) or len(parkingAreas) == 0 or
(options.skipEquippedEdges and edge in edge2chargingPointCount and edge2chargingPointCount[edge] > 0)):
if len(parkingAreas) > 0:
unchangedParkings.extend([pa[0] for pa in parkingAreas])
continue
Expand All @@ -200,7 +201,7 @@ def main(options):
parkingAreas = edge2parkingArea[selectedEdge]
capacities = [p[1] for p in parkingAreas]
parkingSum = sum(capacities)
chargingPointDiscount = edge2chargingPointCount[selectedEdge] if options.includeExisting and selectedEdge in edge2chargingPointCount else 0
chargingPointDiscount = edge2chargingPointCount[selectedEdge] if options.includeExisting and selectedEdge in edge2chargingPointCount else 0 # noqa
wishedChargingPointCount = max(0, math.floor(options.density * parkingSum) - chargingPointDiscount)
if parkingSum < options.min:
assignBalance -= wishedChargingPointCount
Expand Down Expand Up @@ -229,7 +230,8 @@ def main(options):
if options.entireParkings:
closestCapacityIndex = min(range(len(capacities)), key=lambda i: abs(
capacities[i]-remainingChargingPoints))
addChargingStation(options, rootCharging, rootParking, selectedEdge, parkingAreas[closestCapacityIndex][0],
addChargingStation(options, rootCharging, rootParking, selectedEdge,
parkingAreas[closestCapacityIndex][0],
capacities[closestCapacityIndex], "%s%d" % (options.prefix, csIndex))
csIndex += 1
remainingChargingPoints = 0
Expand Down
10 changes: 6 additions & 4 deletions tools/drt/orToolsDataModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,23 @@ def get_id(self) -> str:

def get_persons(self) -> list[str]:
return self.reservation.persons

def get_earliest_pickup(self) -> int:
person_id = self.get_persons()[0]
pickup_earliest = traci.person.getParameter(person_id, "pickup_earliest") or traci.person.getParameter(person_id, "earliestPickupTime")
pickup_earliest = (traci.person.getParameter(person_id, "pickup_earliest")
or traci.person.getParameter(person_id, "earliestPickupTime"))
if pickup_earliest:
pickup_earliest = round(float(pickup_earliest))
return pickup_earliest

def get_dropoff_latest(self) -> int:
person_id = self.get_persons()[0]
dropoff_latest = traci.person.getParameter(person_id, "dropoff_latest") or traci.person.getParameter(person_id, "latestDropoffTime")
dropoff_latest = (traci.person.getParameter(person_id, "dropoff_latest")
or traci.person.getParameter(person_id, "latestDropoffTime"))
if dropoff_latest:
dropoff_latest = round(float(dropoff_latest))
return dropoff_latest

def update_direct_route_cost(self, type_vehicle: str, cost_matrix: list[list[int]] = None,
cost_type: CostType = CostType.DISTANCE):
if self.direct_route_cost:
Expand Down

0 comments on commit 4432ee5

Please sign in to comment.