0

I am creating a headcount model for a contact center. I would like to apply erlang c to a new column of my forecasted data (forecast pulled in via RODBC con)

When I apply my erlang c formula, I get multiple warnings, mostly repeating themselves. The formula does run, but only the 1st line is accurate.

Warning messages:

1: In 1:agents : numerical expression has 96 elements: only the first used

2: In while (gos < gos_target * (gos_target > 1)/100) { : the condition has length > 1 and only the first element will be used

3: In 1:agents : numerical expression has 96 elements: only the first used

4: In while (gos < gos_target * (gos_target > 1)/100) { : the condition has length > 1 and only the first element will be used

The problem is that I need some of the input for the function to pull from the data frame

I need the function to take the call volume and AHT from that current row in the data frame and work out a headcount requirement

The data is a basic table that consist of date, day, month AHT & Calls Columns

I have tried different methods of applying it:

  1. I have used Lapply

  2. I have tried adding it by creating new column

  3. I have tried using rep function

  4. I have tried using for loop

#
  Interval <- 15
  Calls <- Should pull from Data
  Duration <- Should pull from Data
  Wait_time <- 20
  gos_target <- 90
  Shrinkage <- 21
  Rate <- Calls *(60/Interval)

  intensity <- function(rate, duration, interval = 60) {
    (rate / (60 * interval)) * duration
  }

  erlang_c <- function(agents, rate, duration, interval = 60) {
    int <- intensity(rate, duration, interval)
    erlang_b_inv <- 1
    for (i in 1:agents) {
      erlang_b_inv <- 1 + erlang_b_inv * i / int
    }
    erlang_b <- 1 / erlang_b_inv
    agents * erlang_b / (agents - int * (1 - erlang_b))
  }

  service_level <- function(agents, rate, duration, target, interval = 60) {
    pw <- erlang_c(agents, rate, duration, interval)
    int <- intensity(rate, duration, interval)
    1 - (pw * exp(-(agents - int) * (target / duration)))
  }

  resource <- function(rate, duration, target, gos_target, interval = 60) {
    agents <-round(intensity(rate, duration, interval) + 1)
    gos <- service_level(agents, rate, duration, target, interval)
    while (gos < gos_target * (gos_target > 1) / 100) {
      agents <- agents + 1
      gos <- service_level(agents, rate, duration, target, interval)
    }
    return(c(ceiling(agents/(1-(Shrinkage/100)))))
  }

  resource(Calls, Duration, Wait_time, gos_target, 15)
#

I need each column to give me the accurate headcount required. when i run it for one, line of data, any line, the answer is always accurate. as soon as i have more than one row of data i my headcount results calculates, however is always inaccurate, by 5 to 15 agents

2
  • Welcome to SO. Could you please try to reduce your problem to a lighter problem. So it would be easier for us to understand and you might find your solution on the way. But, the warning seems pretty explicit: gos is more than one dimensional. It shouldn't be the case. You should try to see where / why you have length(gos)>1 Commented Feb 5, 2019 at 13:55
  • That code isn't erlang, so why does your question have an erlang tag? Commented Feb 5, 2019 at 20:17

1 Answer 1

1

If I understand correctly, the Calls and Duration arguments are potentially vectors, whereas the other arguments are parameters to the model. One simple solution would be to vectorize the function itself:

vresource <- Vectorize(resource)

Vectorize does the work of converting a function to one which accepts both vectors and constant v values and applying across those which are vectors in parallel. This would produced the following result with the following data frame:

R> df <- data.frame(Calls=c(1,5,3,7), Duration=c(30,50,45,10))
R> with(df, vresource(Calls, Duration, Wait_time, gos_target, 15))
[1] 2 3 3 2

This could then be easily added to the data frame by assigning it to a new column, e.g., df$resource <- with(df, vresource(Calls, Duration, Wait_time, gos_target, 15)).

Sign up to request clarification or add additional context in comments.

1 Comment

It Worked, Thanks so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.