From a697b715ee409c0390766e650061af9c28885ada Mon Sep 17 00:00:00 2001 From: e-wai Date: Thu, 8 Apr 2021 18:53:39 -0400 Subject: [PATCH 1/2] Brief layout sketch of race class --- optimization/ASC_optimization.py | 124 +++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 optimization/ASC_optimization.py diff --git a/optimization/ASC_optimization.py b/optimization/ASC_optimization.py new file mode 100644 index 0000000..dc1289d --- /dev/null +++ b/optimization/ASC_optimization.py @@ -0,0 +1,124 @@ +""" +formula given: +S = (D / E) * C * T * P +optimize for S + +do i want to update everything on "get" -> ie. when we run optimization, or before? +if we're running multiple possibilities does this change anything + +let's initially approach this as a prediction _only_ thing +""" +import csv + +class ASC_Race: + + # Car information + PASSENGERS = 4 + BATTERY_CAPACITY_kWH = 20 + + distance_travelled_segments = [] + passengers = [] + time_elapsed_mins = 0 + + def __init__(self, race_data_csv): + # TODO: determine format of data passing and interacts + # TODO: how to change route? update during race? + with open(race_data_csv, 'r') as f: + route = csv.reader(f) + + start = next(route) + + for row in route: + # find distance -> hopefully a parameter; append to list + # if passengers not flagged + self.passengers.append(4) + + @property + def D(self): + ''' + Person-Mile Distance + ''' + d = 0 + for seg, passenger in zip(self.distance_travelled_segments, self.passengers): + d += seg * passenger + + return d + + @property + def E(self): + ''' + External Energy Usage + (n + 1) * Q * M + ''' + nights = 4 + charging_per_night = 100 + return nights * charging_per_night + + @property + def C(self): + ''' + Completion Factor + ''' + return 1 + + @property + def T(self): + ''' + Target Speed Derate + ''' + d = 0 + for seg in self.distance_travelled_segments: + d += seg + + return d / self.time_elapsed_mins / 60 + + @property + def P(self): + ''' + Practicality Score + ''' + return 1 + + def update_variables(self, velocity_profile): + pass + + def get_S(self, velocity_profile): + self.update_variables(velocity_profile) + return self.D / self.E * self.C * self.T * self.P + +''' +initial guess = all even, get S +next guess = all even, except when limited by speed limit, get S + +push in one direction (manage each segment?) + +''' + + +''' +what is the trial run going to send in - where are we sending velocity into it +calculate best velocities -> then find minutes? + +lat, lon, city name, city Id, time, temperature, efficiency correction, +wind speed, wind direction, precipitation, energy solar, energy corrected + +routemodel +speed limits, lat, lon, elevations +wind +weather?? + +solar + + +soc +?? +auxloss + +motor torque + +dynamics + + +some guess of S with a general profile of velocities +change velocities -> see how it affects S +''' From 93142eee57f5a425f49b5a3b012f4c2292c9aa86 Mon Sep 17 00:00:00 2001 From: e-wai Date: Tue, 13 Apr 2021 15:34:09 -0400 Subject: [PATCH 2/2] Start stop note and link to opt options --- optimization/ASC_opt_data.csv | 27 ++++++++++ optimization/ASC_optimization.py | 89 +++++++++++++++++++++++--------- 2 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 optimization/ASC_opt_data.csv diff --git a/optimization/ASC_opt_data.csv b/optimization/ASC_opt_data.csv new file mode 100644 index 0000000..ab1d3a8 --- /dev/null +++ b/optimization/ASC_opt_data.csv @@ -0,0 +1,27 @@ +Latitude,Longitude,Temperature,Wind Speed,Wind Direction,Energy Corrected +38.941960,-92.684750 +39.068140,-92.946070 +39.186270,-94.193590 +39.086830,-94.419420 +39.008310,-94.466870 +38.925354,-94.568639 +38.788531,-94.991618 +38.780561,-95.557203 +38.665916,-96.493941 +38.372787,-97.303086 +38.34501,-98.201727 +38.365832,-98.401643 +38.34863,-98.766032 +38.265291,-98.980929 +38.188527,-99.087184 +37.752798,-100.017079 +37.576617,-101.355375 +37.004007,-101.888395 +36.736418,-102.512726 +36.712246,-103.060209 +36.361145,-104.595267 +35.907481,-105.013186 +35.820597,-104.997503 +35.593625,-105.224615 +35.548633,-105.685455 +35.682273,-105.929828 diff --git a/optimization/ASC_optimization.py b/optimization/ASC_optimization.py index dc1289d..44ad623 100644 --- a/optimization/ASC_optimization.py +++ b/optimization/ASC_optimization.py @@ -1,14 +1,20 @@ """ -formula given: -S = (D / E) * C * T * P -optimize for S - do i want to update everything on "get" -> ie. when we run optimization, or before? if we're running multiple possibilities does this change anything let's initially approach this as a prediction _only_ thing """ import csv +import pandas as pd + +import sys +import os.path +sys.path.append(os.path.dirname(__file__), '..') + +from dynamics.motor_efficiency.motor_efficiency import MotorEfficiency +from dynamics.car_model import Car + +RACE_FILE = os.path.join(os.path.dirname(__file__), '../routemodel/data_retrieval/new_get_weather.csv') class ASC_Race: @@ -17,21 +23,17 @@ class ASC_Race: BATTERY_CAPACITY_kWH = 20 distance_travelled_segments = [] - passengers = [] + # passengers = [] time_elapsed_mins = 0 def __init__(self, race_data_csv): # TODO: determine format of data passing and interacts # TODO: how to change route? update during race? - with open(race_data_csv, 'r') as f: - route = csv.reader(f) - - start = next(route) + self.route_df = pd.read_csv(race_data_csv, delimiter=',') - for row in route: - # find distance -> hopefully a parameter; append to list - # if passengers not flagged - self.passengers.append(4) + # find distance -> hopefully a parameter; append to list + # if passengers not flagged + # self.passengers.append(4) @property def D(self): @@ -39,8 +41,11 @@ def D(self): Person-Mile Distance ''' d = 0 - for seg, passenger in zip(self.distance_travelled_segments, self.passengers): - d += seg * passenger + # for seg, passenger in zip(self.distance_travelled_segments, self.passengers): + # d += seg * passenger + + for seg in self.distance_travelled_segments: + d += seg return d @@ -82,25 +87,48 @@ def P(self): def update_variables(self, velocity_profile): pass - def get_S(self, velocity_profile): + def get_score(self, velocity_profile): self.update_variables(velocity_profile) return self.D / self.E * self.C * self.T * self.P -''' -initial guess = all even, get S -next guess = all even, except when limited by speed limit, get S +def energy_needed(): + # between two points, how much energy do we draw? + # ok so + # minus: + # energy needed to travel this distance * -> energy_used, but only between two points? + car_model = Car() # can add speed limit? + energy_needed = car_model.energy_used() -push in one direction (manage each segment?) + # efficiency of motors * (draw more energy than necessary) -> motor eff curves + low_curve = MotorEfficiency("LO") + high_curve = MotorEfficiency("HI") + # TODO what the fuck is this + # so we have speed, it will guess our torque based on test data + power_needed = low_curve.power_draw_needed(energy_needed, speed, torque) -''' + # efficiency of soc (how much energy is actually taken from batteries) -> soc + power_loss = power_needed * 0.5 + # auxloss to consider + power_loss += 0.5 + + # plus: energy gained from solar -> from solar + + power_loss -= 0.5 + + return power_loss + + # takeaway from this exercise is that carmodel, lowhigh, and our soc and solar objects can be fairly static? we will need to change the speed limit on the car as we go, which we can do hopefully + # how do we want this to happen wiht df -> either make calls per row, or just change the methods so they accept dfs + +if __name__ == '__main__': + race = ASC_Race(RACE_FILE) ''' -what is the trial run going to send in - where are we sending velocity into it -calculate best velocities -> then find minutes? lat, lon, city name, city Id, time, temperature, efficiency correction, wind speed, wind direction, precipitation, energy solar, energy corrected ++ mark stops (checkpoints) somehow routemodel speed limits, lat, lon, elevations @@ -118,7 +146,18 @@ def get_S(self, velocity_profile): dynamics +''' + -some guess of S with a general profile of velocities -change velocities -> see how it affects S ''' +also, comparison of fmin ++ https://www.mathworks.com/help/optim/ug/fmincon.html ++ https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html + + +Parameters +fun(x, *args) -> float ==> get_score() +initial guess ==> even within speed limits? +bounds (for each in x) ==> speed limits + +''' \ No newline at end of file