I have a lot of different e-cars (car1 ... carN) with a state of charge (SOC) at the beginning ot a trip (start_trip) and the end (end_trip). Between to trips a car is loaded, to a maximum level. I know the charge capacity for the loading of a batterie (~0.35 /minute) an the needed capacity for every kilometer (0.22 / kilometer). Between two trips we have some minutes to load and during a trip the capacity decreases.
I want to estimate the necessary time between to trips to fulfill the need in 99% of the bookings, if i assume to deliver the same service with e-cars in the future.
I have a list of nearly 1 million bookings with combustion vehicles. carN starttime stoptime drivenkm ...
I calculate the possible time between the end of a trip and the start of the last use with loadtime = starttime - lag(stoptime) so i know, what`s the SOC_S at the start of a trip.
I calculate the needed capacity for a trip and substract it from SOC_S. So i get the SOC_E at the end of a trip.
Now i want to take in account, that a battery is not really empty at the end of a trip. So, the chargestate is SOC_E from the last trip + possible load between trips.
Now i have some problems:
the maximum load is 22 kWh. So the load is the max("loaded charge by time" or "maxLoad". The first is a vector and the secon a constant number. max(a, b) don`t work.
I want to set the first SOC_S for the first booking for every car to 22 kWh. It starts fully loaded. How to put a value in a special column of the first row of a group_by in R for evvery car?
How can I calculate a value for needed loadtime to fulfill 99% of the use? Something like teh solver in excel?
B_ES <- B_ES %>% arrange(car, start_trip) %>% group_by(car) %>% mutate( preTime <- (start_trip - lag(end_trip))/60, useTime <- (end_trip - start_trip)/60, postTime <- (lead(start_trip) - end_trip)/60, SOC_S <- preTime * ZOE_charge, E_consumption <- km * ZOE_consumption, SOC_E <- SOC_S - E_consumption SOC_S <- SOC_S + lag(SOC_E) )
This code don`t work. The problem are
How can i use the new variables? There have colnames like this: "preTime <- (Nutzungsbeginn - lag(Nutzungsende))/60"
The last two seems to come to an irregular loop.
Regards
Ruediger