本質的にHMMですね。
si_1 <- c(250, 260, 250) si_2 <- c(220, 240, 230) ka_1 <- c(240, 260, 230) ka_2 <- c(250, 270, 260) si <- c(240, 250, 230) ka <- c(230, 260, 250) target_cost <- function(x, y) { abs(x[1] - y[1]) + 2 * abs(x[2] - y[2]) + abs(x[3] - y[3]) } connection_cost <- function(x, y) { abs(x[3] - y[1]) } # ターゲットコスト target_cost(si, si_1) target_cost(si, si_2) target_cost(ka, ka_1) target_cost(ka, ka_2) # 接続コスト connection_cost(si_1, ka_1) connection_cost(si_1, ka_2) connection_cost(si_2, ka_1) connection_cost(si_2, ka_2)