Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug for createDSR() in API mode #131

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ NEW FEATURES :
BUGFIXES :

* Fix `filter_synthesis` and `filter_year_by_year` parameters of `editLink()` in API mode
* Fix `createDSR()` in API mode : daily binding constraint takes 366 rows


# antaresEditObject 0.6.1
Expand Down
7 changes: 4 additions & 3 deletions R/createDSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ createDSR <- function(areasAndDSRParam = NULL,

#coef binding
coefficientsDSR <- .getCoefDsr(areaName, nameDsr)

# A binding constraint at a daily timestep expects 366 rows
createBindingConstraint(
nameBindDSR,
values = matrix(data = c(rep(installedCapacityLink * as.double(numberHour), 365), rep(0, 365 * 2)), ncol = 3),
values = matrix(data = c(rep(installedCapacityLink * as.double(numberHour), 366), rep(0, 366 * 2)), ncol = 3),
enabled = TRUE,
timeStep = "daily",
operator = c("less"),
Expand Down Expand Up @@ -440,9 +440,10 @@ editDSR <- function(area = NULL,
#coef binding
coefficientsDSR <- .getCoefDsr(area, previousNameDsr)

# A binding constraint at a daily timestep expects 366 rows
createBindingConstraint(
previousNameDsr,
values = matrix(data = c(rep(newCapacityLink * as.double(previousNumberHour), 365), rep(0, 365 * 2)), ncol = 3),
values = matrix(data = c(rep(newCapacityLink * as.double(previousNumberHour), 366), rep(0, 366 * 2)), ncol = 3),
enabled = TRUE,
timeStep = "daily",
operator = c("less"),
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-createDSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ sapply(studies, function(study) {
expect_equal(bindingList$a_dsr_3h$operator, "less")
expect_equal(as.double(bindingList$a_dsr_3h$coefs["a%a_dsr_3h"]), -1)
expect_equal(as.double(bindingList$b_dsr_7h$coefs["b%b_dsr_7h"]), -1)

expect_equal(nrow(bindingList$a_dsr_3h$values), 366)
expect_equal(nrow(bindingList$b_dsr_7h$values), 366)

expect_equal(unique(bindingList$a_dsr_3h$values$less)[1], dsrData[dsrData$area=="a",]$unit*dsrData[dsrData$area=="a",]$nominalCapacity*dsrData[dsrData$area=="a",]$hour)
expect_equal(unique(bindingList$b_dsr_7h$values$less)[1], dsrData[dsrData$area=="b",]$unit*dsrData[dsrData$area=="b",]$nominalCapacity*dsrData[dsrData$area=="b",]$hour)

Expand Down Expand Up @@ -136,4 +138,3 @@ sapply(studies, function(study) {
unlink(x = file.path(pathstd, "test_case"), recursive = TRUE)

})

Loading