if (FALSE) {
# < v8.7.0 :
# Create constraints with multi coeffs (only weight)
createBindingConstraint(
name = "myconstraint",
values = matrix(data = rep(0, 8760 * 3), ncol = 3),
enabled = FALSE,
timeStep = "hourly",
operator = "both",
coefficients = list("area1%area2" = 1,
"area1%area3" = 2)
)
# Create constraints with multi coeffs + offset
createBindingConstraint(
name = "myconstraint",
values = matrix(data = rep(0, 8760 * 3), ncol = 3),
enabled = FALSE,
timeStep = "hourly",
operator = "both",
coefficients = list("area1%area2" = "1%1",
"area1%area3" = "2%3")
)
# Create multiple constraints
# Prepare data for constraints
bindings_constraints <- lapply(
X = seq_len(100),
FUN = function(i) {
# use arguments of createBindingConstraint()
# all arguments must be provided !
list(
name = paste0("constraints", i),
id = paste0("constraints", i),
values = matrix(data = rep(0, 8760 * 3), ncol = 3),
enabled = FALSE,
timeStep = "hourly",
operator = "both",
coefficients = list("area1%area2" = 1),
overwrite = TRUE
)
}
)
# create all constraints
createBindingConstraintBulk(bindings_constraints)
# >= v8.7.0 :
# values are now named list containing `data.frame` according to
# `operator` parameter (for "less", build a list with at least "lt" floor in list)
# data values (hourly)
df <- matrix(data = rep(0, 8760 * 3), ncol = 3)
values_data <- list(lt=df)
# create bc with minimum value
createBindingConstraint(name = "bc_example",
operator = "less",
values = values_data,
overwrite = TRUE)
# or you can provide list data with all value
values_data <- list(lt=df,
gt= df,
eq= df)
createBindingConstraint(name = "bc_example",
operator = "less",
values = values_data,
overwrite = TRUE)
# create multiple constraints
bindings_constraints <- lapply(
X = seq_len(10),
FUN = function(i) {
# use arguments of createBindingConstraint()
# all arguments must be provided !
list(
name = paste0("constraints_bulk", i),
id = paste0("constraints_bulk", i),
values = values_data,
enabled = FALSE,
timeStep = "hourly",
operator = "both",
coefficients = list("at%fr" = 1),
group= "group_bulk",
overwrite = TRUE
)
}
)
createBindingConstraintBulk(bindings_constraints)
}
Run the code above in your browser using DataLab