|
132 | 132 | #' # remember to prefix in the list |
133 | 133 | #' |
134 | 134 | #' name_no_prefix <- "add_constraints" |
135 | | -#' clust_name <- paste(area_test_clust, |
136 | | -#' name_no_prefix, |
137 | | -#' sep = "_") |
138 | 135 | #' |
139 | 136 | #' constraints_properties <- list( |
140 | 137 | #' "withdrawal-1"=list( |
141 | | -#' cluster = clust_name, |
142 | 138 | #' variable = "withdrawal", |
143 | 139 | #' operator = "equal", |
144 | 140 | #' hours = c("[1,3,5]", |
145 | 141 | #' "[120,121,122,123,124,125,126,127,128]") |
146 | 142 | #' ), |
147 | 143 | #' "netting-1"=list( |
148 | | -#' cluster = clust_name, |
149 | 144 | #' variable = "netting", |
150 | 145 | #' operator = "less", |
151 | 146 | #' hours = c("[1, 168]") |
|
157 | 152 | #' constraints_properties = constraints_properties) |
158 | 153 | #' |
159 | 154 | #' # Add optional constraints properties + TS |
| 155 | +#' |
| 156 | +#' constraints_properties <- list( |
| 157 | +#' "withdrawal-2"=list( |
| 158 | +#' variable = "withdrawal", |
| 159 | +#' operator = "equal", |
| 160 | +#' hours = c("[1,3,5]", |
| 161 | +#' "[120,121,122,123,124,125,126,127,128]") |
| 162 | +#' ), |
| 163 | +#' "netting-2"=list( |
| 164 | +#' variable = "netting", |
| 165 | +#' operator = "less", |
| 166 | +#' hours = c("[1, 168]") |
| 167 | +#' )) |
| 168 | +#' |
160 | 169 | #' good_ts <- matrix(0.7, 8760) |
161 | 170 | #' constraints_ts <- list( |
162 | 171 | #' "withdrawal-2"=good_ts, |
@@ -237,6 +246,7 @@ createClusterST <- function(area, |
237 | 246 | params_cluster <- hyphenize_names(storage_parameters) |
238 | 247 |
|
239 | 248 | ## Standardize cluster name + prefix ---- |
| 249 | + cluster_name_ori <- cluster_name |
240 | 250 | cluster_name <- generate_cluster_name(area = area, |
241 | 251 | cluster_name = cluster_name, |
242 | 252 | add_prefix = add_prefix) |
@@ -411,7 +421,7 @@ createClusterST <- function(area, |
411 | 421 | ## add constraint(s) ---- |
412 | 422 | if(!is.null(constraints_properties)) |
413 | 423 | .add_storage_constraint(area = area, |
414 | | - cluster_name = cluster_name, |
| 424 | + cluster_name = cluster_name_ori, |
415 | 425 | constraints_properties = constraints_properties, |
416 | 426 | constraints_ts = constraints_ts, |
417 | 427 | overwrite = overwrite, |
@@ -578,13 +588,14 @@ storage_values_default <- function(opts = simOptions()) { |
578 | 588 | constraints_ts, |
579 | 589 | overwrite, |
580 | 590 | opts){ |
581 | | - # constraints/<area id>/additional-constraints.ini |
| 591 | + # constraints/<area id>/cluster/additional-constraints.ini |
582 | 592 |
|
583 | 593 | # create dir |
584 | 594 | dir_path <- file.path(opts$inputPath, |
585 | 595 | "st-storage", |
586 | 596 | "constraints", |
587 | | - area) |
| 597 | + area, |
| 598 | + cluster_name) |
588 | 599 | dir.create(dir_path, recursive = TRUE, showWarnings = FALSE) |
589 | 600 |
|
590 | 601 | ## write properties ---- |
@@ -633,25 +644,27 @@ storage_values_default <- function(opts = simOptions()) { |
633 | 644 |
|
634 | 645 | ## write ts values ---- |
635 | 646 | # check if ts already exist |
636 | | - ts_name <- paste0("rhs_", names(constraints_ts), ".txt") |
637 | | - path_ts_files <- file.path(dir_path, |
638 | | - ts_name) |
639 | | - |
640 | | - if(any(file.exists(path_ts_files))){ |
641 | | - if(!overwrite) |
642 | | - stop(paste(constraints_names, " already exist "), |
643 | | - call. = FALSE) |
644 | | - } |
645 | | - lapply(names(constraints_ts), |
646 | | - function(x){ |
647 | | - fwrite( |
648 | | - x = constraints_ts[[x]], |
649 | | - row.names = FALSE, |
650 | | - col.names = FALSE, |
651 | | - sep = "\t", |
652 | | - file = file.path(dir_path, |
653 | | - paste0("rhs_", x, ".txt"))) |
| 647 | + if(!is.null(constraints_ts)){ |
| 648 | + ts_name <- paste0("rhs_", names(constraints_ts), ".txt") |
| 649 | + path_ts_files <- file.path(dir_path, |
| 650 | + ts_name) |
| 651 | + |
| 652 | + if(any(file.exists(path_ts_files))){ |
| 653 | + if(!overwrite) |
| 654 | + stop(paste(constraints_names, " already exist "), |
| 655 | + call. = FALSE) |
| 656 | + } |
| 657 | + lapply(names(constraints_ts), |
| 658 | + function(x){ |
| 659 | + fwrite( |
| 660 | + x = constraints_ts[[x]], |
| 661 | + row.names = FALSE, |
| 662 | + col.names = FALSE, |
| 663 | + sep = "\t", |
| 664 | + file = file.path(dir_path, |
| 665 | + paste0("rhs_", x, ".txt"))) |
654 | 666 | }) |
| 667 | + } |
655 | 668 | } |
656 | 669 |
|
657 | 670 |
|
|
0 commit comments