Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在r(一台机器n个作业)中分配数字_R - Fatal编程技术网

如何在r(一台机器n个作业)中分配数字

如何在r(一台机器n个作业)中分配数字,r,R,我正在研究R中的赋值问题。我在R中有以下数据帧 cycle_time TAT ready_for_next ITV_no 2 10 12 0 4 12 16 0 6 13 19 0 8 11 19

我正在研究R中的赋值问题。我在R中有以下数据帧

  cycle_time   TAT  ready_for_next  ITV_no    
        2      10        12          0           
        4      12        16          0           
        6      13        19          0           
        8      11        19          0           
       10      15        25          0           
       12      17        29          0           
       14      13        27          0           
       16      13        29          0           
       18      12        30          0             
       20      16        36          0
       22      13        35          0
       24      12        36          0
       26      15        41          0
       28      14        42          0
       30      17        47          0
我想要的数据帧是

  cycle_time   TAT  ready_for_next  ITV_no     wait_time
        2      10        12          1            0
        4      12        16          2            0
        6      13        19          3            0
        8      11        19          4            0
       10      15        25          5            0
       12      17        29          1            0 
       14      13        27          6            0
       16      13        29          2            0
       18      12        30          3            1
       20      16        36          4            1
       22      13        35          5            3
       24      12        36          6            3
       26      15        41          2            3 
       28      14        42          3            2 
       30      17        47          5            5

 cycle_time = crane cycle time
 TAT(in mins) = turn around time of truck
 ready_for_next(in mins) = ready to take next container
 ITV_no = ITV no to be assigned for that job

 ***There are only 6 unique trucks available***
这里的想法是分配卡车,使等待时间最短。 在前五次观察中,分配了所有5辆卡车

对于下一个集装箱,即第6行(第12分钟),ITV_1号将从其工作中返回,以便分配给该工作。 第7次观察(即第14分钟)没有可用的卡车,因此我们必须分配新卡车(即ITV_6号) 第8次观察(16分钟)ITV_2号正在从其工作中返回,因此将分配给该工作,以此类推

如果没有可用的卡车,则必须等到最近的卡车下班回来

如何在R中实现这一点

我已经建立了一些逻辑

cycle_time <- c(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)
ITV_no <- c(1,2,3,4,5,6,7)
temp <- c()
TAT <- c(10,12,13,11,15,17,13,13,12,16,13,12,15,14,17)
ready_for_next <- cycle_time + TAT

assignment <- data.frame(cycle_time,TAT,ready_for_next)
assignment$ITV_no <- 0

for(i in 1:nrow(assignment)) {

   for(j in 1:length(ITV_no)){
       assignment$ITV_no[i] <- ifelse(assignment$cycle_time <= assignment$ready_for_next,ITV_no[j],
            ifelse())

 ## I am not able to update the count of trucks which are already assigned
 # and which are free to be assigned
 }
 }

Logic
1. first row increment ITV_no by 1. directly assign truck to that job
2. check if cycle_time <= previous all ready_for_next(i.e 12), if yes then increment ITV_no by 1,if no then assign previous ITV_no for that job(i.e 1)

e.g 
for row 6, cycle time will get compared to all previous ready_for_next column values (25,19,19,16,12) it finds the match at first row then that ITV_no(i.e 2) is assigned to 6th row
for row 7, cycle time will get compared to all previous ready_for_next column values (25,19,19,16) **12 should be removed from comparison because the truck is already assigned to the job** match at first row then that ITV_no(i.e 2) is assigned to 6th row. No match,so new truck is assigned to that job

cycle\u time我想出了一些解决方案。。。
它正在处理样本数据

rm(list=ls())
df <- data.frame(qc_time =   seq(2,40,2),itv_tat=c(10,15,12,18,25,19,18,16,14,10,12,15,17,19,13,12,8,15,9,14))
itv_number_vec <- vector()
itv_number_vec <- 0

itvno_time <- list()

for (i in 1:nrow(df))
{

  ####  Initialisation ####
    if (i==1)
    {
      df$itv_available_time[i] <- sum(df$qc_time[i] + df$itv_tat[i])
      itvno_time[[i]] <- df$itv_available_time[i]
      df$delay[i] <- 0
      df$itv_number[i] <- 1
      itv_number_vec <- 1
   }
    if(i!=1)
   {
    if (df$qc_time[i] >= min(unlist(itvno_time)))
  {
    for (j in 1:length(itvno_time))
    {

      if (itvno_time[[j]] <= df$qc_time[i])
      {
        df$itv_number[i] <- j
        df$itv_available_time[i] <- sum(df$qc_time[i] + df$itv_tat[i])
        itvno_time[[j]] <- df$itv_available_time[i]
        break
      }
    }
  }else{

          if (max(itv_number_vec)<7)
          {
            df$itv_number[i] <- max(itv_number_vec) + 1
            itv_number_vec <- c(itv_number_vec,(max(itv_number_vec) + 1))
            df$delay[i] <- 0
            df$itv_available_time[i] <- sum(df$qc_time[i] + df$itv_tat[i])
            itvno_time[[max(itv_number_vec)]] <- df$itv_available_time[i]
          }else{
                  df$delay[i] <- (min(unlist(itvno_time)) - df$qc_time[i])
                  df$itv_number[i] <- which.min(itvno_time)
                  df$itv_available_time[i] <- sum(df$qc_time[i], df$itv_tat[i] ,df$delay[i])
                  itvno_time[[which.min(itvno_time)]] <- df$itv_available_time[i] 
                }
        }

  }
}
rm(list=ls())

df请列出完整的算法,以及您如何尝试实现它,以及您在哪里遇到了困难。此外,请共享可复制的数据(例如,与
dput
df可复制的数据已在代码中共享。它的工作完全符合我的预期。我非常感谢您的时间和努力。非常感谢。