0

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:

  1. 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.

  2. 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?

  3. 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

  1. How can i use the new variables? There have colnames like this: "preTime <- (Nutzungsbeginn - lag(Nutzungsende))/60"

  2. The last two seems to come to an irregular loop.

Regards

Ruediger

4

2 回答 2

1

Reproducible Example:

foo <- data_frame(group = c('A','A','A','B','B','C','C')
             , x1 = c(1,2,3,1,2,1,2)
             , SOC_S = c(4,5,6,4,5,4,5))

In regards to your second goal:

  1. 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?
library(tidyverse)

dd <- foo %>% group_by(group) %>%
    mutate(rownumber = 1:n()        ## a helper column to find first row
    , special = ifelse(rownumber == 1, 22, SOC_S)) ## vectorized edits based on rownumber

Note: You can also replace special with SOC_S if preferred.

Couldn't really follow the rest of the question but this might get you a little farther.

于 2017-09-30T04:16:46.010 回答
0

Based on the answers, i found the following solution:

ZOE_battery <- 22 # kWh
ZOE_consumption <- 0.233 # kWh/Kilometer
ZOE_chargeflow <- 0.366 # kWh/Minute

ZOE <- ZOE %>%
  arrange(car, start_trip) %>%
  group_by(car) %>%
  mutate(
    seq_id = row_number(),
    preTime = (start_trip - lag(end_trip))/60,
    useTime = (end_trip - start_trip)/60,
    postTime = (lead(start_trip) - end_trip)/60,
    SOC_S = ifelse(seq_id == 1, ZOE_battery, 
                   ifelse(preTime * ZOE_chargeflow > ZOE_battery, ZOE_battery, preTime * ZOE_chargeflow)),
    consumption = km * ZOE_consumption,
    SOC_E = SOC_S - consumption
  )
ZOE_P <- ZOE %>% # Trips with possible problems
  filter(SOC_S <= 0 | SOC_E <0)

The result:

A tibble: 6 x 12

Groups: car [1]

  place   car          start_trip            end_trip    km seq_id   preTime  useTime  postTime SOC_S consumption
 <fctr> <int>              <dttm>              <dttm> <int>  <int>    <time>   <time>    <time> <dbl>       <dbl>
1 681990401   171 2014-04-30 20:31:00 2014-05-01 12:08:00    43      1   NA secs 937 secs 1350 secs    22      10.019
2 681990401   171 2014-05-02 10:38:00 2014-05-02 14:03:00    32      2 1350 secs 205 secs 1512 secs    22       7.456
3 681990401   171 2014-05-03 15:15:00 2014-05-03 22:49:00    25      3 1512 secs 454 secs  791 secs    22       5.825
4 681990401   171 2014-05-04 12:00:00 2014-05-04 17:07:00    71      4  791 secs 307 secs  879 secs    22      16.543
5 681990401   171 2014-05-05 07:46:00 2014-05-05 13:38:00    71      5  879 secs 352 secs 1418 secs    22      16.543
6 681990401   171 2014-05-06 13:16:00 2014-05-06 19:20:00    52      6 1418 secs 364 secs   19 secs    22      12.116

Now i know, that that only 1.5% of all trips would have had problems, because the state of charge at start was to low for the intended trip.

于 2017-09-30T08:24:16.007 回答