Skip to content

Commit

Permalink
add unique key to simulation name + bugfix on benders_check
Browse files Browse the repository at this point in the history
  • Loading branch information
baptsegu committed May 24, 2017
1 parent 2a37f95 commit 9cf3d58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions R/benders.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ benders <- function(path_solver, display = TRUE, report = TRUE, opts = antaresRe
set_antares_options(exp_options, opts)

# check that the study is appropriately set for the expansion problem
assertthat::assert_that(benders_check(exp_options, opts))
assertthat::assert_that(benders_check(opts))

# initiate text files to communicate with master problem
# and copy AMPL file into the temporary file
Expand All @@ -59,6 +59,7 @@ benders <- function(path_solver, display = TRUE, report = TRUE, opts = antaresRe
best_solution <- NA # best solution identifier
tmp_folder <- paste(opts$studyPath,"/user/expansion/temp",sep="") # temporary folder
relax_integrality <- exp_options$master %in% c("relaxed", "integer")
unique_key <- paste(sample(c(0:9, letters), size = 3, replace = TRUE),collapse = "")

# create output structure
x <- list()
Expand Down Expand Up @@ -157,7 +158,7 @@ benders <- function(path_solver, display = TRUE, report = TRUE, opts = antaresRe
# run the ANTARES simulation, load the path related to this
# simulation and read the outputs

simulation_name <- paste0("benders-", current_it$id)
simulation_name <- paste0("benders-", unique_key, "-", current_it$id)
if(display){ cat(" ANTARES simulation running ... ", sep="")}
run_simulation(simulation_name, mode = "economy", path_solver, wait = TRUE, show_output_on_console = FALSE, opts)
if(display){ cat("[done] \n", sep="")}
Expand Down
22 changes: 11 additions & 11 deletions R/check.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@

#' Check that the ANTARES study is ready for benders decomposition
#'
#'
#' @param benders_options
#' list of benders decomposition options, as returned by
#' \code{\link{read_options}}.

#' @param opts
#' list of simulation parameters returned by the function
#' \code{antaresRead::setSimulationPath}
#'
#' @return boolean, indicating whether or not the test are fullfilled
#'
#' @importFrom antaresRead simOptions readClusterDesc
#' @importFrom dplyr filter
#'
#'
benders_check <- function(benders_options, opts = antaresRead::simOptions())
benders_check <- function(opts = antaresRead::simOptions())
{

checked <- TRUE

#1. for all the clusters of the study, the market bid should be equal to the marginal cost
cluster <- antaresRead::readClusterDesc(opts = opts)

if (nrow(cluster[marginal.cost != market.bid.cost]) > 0)
if (nrow(cluster) > 0)
{
checked <- FALSE
stop("for all thermal clusters, market bid must be equal to marginal cost (e.g. see cluster ",
cluster[marginal.cost != market.bid.cost][1, area] , " - ",
cluster[marginal.cost != market.bid.cost][1, cluster], ")")
if (nrow(dplyr::filter(cluster, marginal.cost != market.bid.cost)) > 0)
{
checked <- FALSE
stop("for all thermal clusters, market bid must be equal to marginal cost (e.g. see cluster ",
dplyr::filter(cluster, marginal.cost != market.bid.cost)[1, "area"] , " - ",
dplyr::filter(cluster, marginal.cost != market.bid.cost)[1, "cluster"], ")")
}
}


return(checked)

}

0 comments on commit 9cf3d58

Please sign in to comment.