@@ -42,7 +42,7 @@ utils::globalVariables(c('V2', 'dim_study', 'dim_input', 'name_group'))
4242# '
4343# ' @name createBindingConstraint
4444# '
45- # ' @importFrom antaresRead getLinks readClusterDesc setSimulationPath readIniFile simOptions
45+ # ' @importFrom antaresRead getLinks setSimulationPath readIniFile simOptions
4646# ' @importFrom utils write.table
4747# ' @importFrom assertthat assert_that
4848# '
@@ -212,7 +212,7 @@ createBindingConstraint <- function(name,
212212 group ,
213213 overwrite ,
214214 links = getLinks(opts = opts , namesOnly = TRUE ),
215- clusters = readClusterDesc (opts = opts ),
215+ clusters = .list_clusters_for_binding_constraints (opts = opts ),
216216 output_operator = values_operator ,
217217 opts = opts
218218 )
@@ -668,7 +668,7 @@ group_values_meta_check <- function(group_value,
668668# ' @template opts
669669# ' @family binding constraints functions
670670# '
671- # ' @importFrom antaresRead getLinks setSimulationPath readIniFile readClusterDesc
671+ # ' @importFrom antaresRead getLinks setSimulationPath readIniFile
672672# '
673673# ' @details
674674# ' According to Antares version, usage may vary :
@@ -754,7 +754,7 @@ createBindingConstraintBulk <- function(constraints,
754754 bindingConstraints <- readIniFile(pathIni , stringsAsFactors = FALSE )
755755
756756 all_links <- getLinks(opts = opts , namesOnly = TRUE )
757- all_clusters <- readClusterDesc (opts = opts )
757+ all_clusters <- .list_clusters_for_binding_constraints (opts = opts )
758758
759759 for (i in seq_along(constraints )) {
760760 values_operator <- switch_to_list_name_operator_870(operator = constraints [[i ]][[" operator" ]])
@@ -893,12 +893,43 @@ switch_to_list_name_operator_870 <- function(operator) {
893893 }
894894
895895 coefficientsToControl <- coefficients [grep(type_elements [[type ]][[" pattern" ]], names(coefficients ))]
896+ coefs_names <- tolower(names(coefficientsToControl ))
896897
897- if (length(coefficientsToControl ) > 0 ) {
898- if (! all(names( coefficientsToControl ) %in% reference )) {
899- badcoef <- names( coefficientsToControl )[ ! names( coefficientsToControl ) %in% reference ]
898+ if (length(coefs_names ) > 0 ) {
899+ if (! all(coefs_names %in% reference )) {
900+ badcoef <- coefs_names [ ! coefs_names %in% reference ]
900901 badcoef <- paste(shQuote(badcoef ), collapse = " , " )
901902 stop(paste0(badcoef , " : is or are not valid " , type_elements [[type ]][[" stop_msg" ]]))
902903 }
903904 }
904905}
906+
907+
908+ # ' @importFrom antaresRead readIniFile
909+ .list_clusters_for_binding_constraints <- function (opts ) {
910+
911+ path <- file.path(opts [[" inputPath" ]], " thermal" , " clusters" )
912+ areas <- data.frame (" area" = list.files(path ))
913+ areas $ path <- file.path(path , areas $ area , " list.ini" )
914+ areas $ file_size <- sapply(areas $ path , file.size )
915+ areas_fi <- areas [areas $ file_size > 0 ,]
916+
917+ all_clusters <- data.frame (" area" = c(), " cluster" = c())
918+ if (nrow(areas_fi ) > 0 ) {
919+ clusters_by_area <- apply(areas_fi [,c(" area" ," path" )],
920+ MARGIN = 1 ,
921+ FUN = function (row ) {
922+ iniFile <- readIniFile(file = as.character(row [2 ]))
923+ cl_names <- sapply(X = iniFile , " [[" , " name" )
924+ cl_names <- unname(cl_names )
925+ df_cl_names <- data.frame (" area" = rep(as.character(row [1 ]), length(cl_names )), " cluster" = cl_names )
926+ return (df_cl_names )
927+ }
928+ )
929+ all_clusters <- do.call(" rbind" , clusters_by_area )
930+ all_clusters $ area <- tolower(all_clusters $ area )
931+ all_clusters $ cluster <- tolower(all_clusters $ cluster )
932+ }
933+
934+ return (all_clusters )
935+ }
0 commit comments