|
457 | 457 | estimate_delays(::SimModel) = 0 |
458 | 458 |
|
459 | 459 |
|
460 | | -"Get move blocking vector `nb` and actual `Hc` value from provided `Hc_arg` argument" |
461 | | -move_blocking(Hc_arg::AbstractVector{Int}) = (Hc_arg, length(nb)) |
462 | | -move_blocking(Hc_arg::Int) = (fill(1, length(Hc_arg)), Hc_arg) |
| 460 | +""" |
| 461 | + move_blocking(Hp::Int, Hc::AbstractVector{Int}) -> nb, Hc |
| 462 | +
|
| 463 | +Get move blocking vector `nb` and actual control horizon from `Hp` and `Hc` arguments. |
| 464 | +
|
| 465 | +The argument `Hc` is in fact the move blocking vector `nb` provided by the user. The `nb` |
| 466 | +vector is modified in these two cases: |
| 467 | +
|
| 468 | +- If `sum(nb) < Hp`, a new element is added to `nb` with the value `Hp - sum(nb)`. |
| 469 | +- If `sum(nb) > Hp`, the intervals are truncated until the sum is `Hp`. For example, if |
| 470 | + `Hp = 10` and `nb = [1, 2, 3, 6, 7]`, then `nb` is truncated to `[1, 2, 3, 4]`. |
| 471 | +""" |
| 472 | +function move_blocking(Hp_arg::Int, Hc_arg::AbstractVector{Int}) |
| 473 | + Hp = Hp_arg |
| 474 | + nb = Hc_arg |
| 475 | + if sum(nb) < Hp |
| 476 | + newblock = [Hp - sum(nb)] |
| 477 | + nb = [nb; newblock] |
| 478 | + elseif sum(nb) > Hp |
| 479 | + #For example, if Hp = 10 and nb = [1, 2, 3, 6, 7], than nb is truncated to [1, 2, 3, 4] |
| 480 | + nb = nb[begin:findfirst(≥(Hp), cumsum(nb))] |
| 481 | + if sum(nb) > Hp |
| 482 | + # if the last block is too large, it is truncated to fit Hp: |
| 483 | + nb[end] = Hp - @views sum(nb[begin:end-1]) |
| 484 | + end |
| 485 | + end |
| 486 | + Hc = length(nb) |
| 487 | + return nb, Hc |
| 488 | +end |
| 489 | + |
| 490 | +""" |
| 491 | + move_blocking(Hp::Int, Hc::Int) -> nb, Hc |
| 492 | +
|
| 493 | +Construct a move blocking vector `nb` to fit the provides `Hp` and `Hc` horizons. |
| 494 | +
|
| 495 | +The vector is filled with `1`s for the first `Hc` blocks. If `Hc < Hp`, the last block in |
| 496 | +`nb` is set to `Hp - Hc` to ensure the total sum is `Hp`. |
| 497 | +""" |
| 498 | +function move_blocking(Hp_arg::Int, Hc_arg::Int) |
| 499 | + Hp, Hc = Hp_arg, Hc_arg |
| 500 | + nb = fill(1, Hc_arg) |
| 501 | + if Hc < Hp |
| 502 | + newblock = Hp - Hc |
| 503 | + nb = [nb; newblock] |
| 504 | + end |
| 505 | + return nb, Hc |
| 506 | +end |
463 | 507 |
|
464 | 508 |
|
465 | 509 | """ |
|
0 commit comments