Skip to content

Commit

Permalink
ignore undeclared indexes (#203)
Browse files Browse the repository at this point in the history
* ignore undeclared indexes

With this change, the model will only give a warning when indexes that do not exist with a given variable are used in a constraint

* changing the test
  • Loading branch information
hugolarzabal authored and dirkschumacher committed Jun 23, 2018
1 parent c758222 commit c69377d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion R/linearopt-variables.R
Expand Up @@ -538,7 +538,8 @@ setMethod("[", signature("LinearVariableCollection", i = "ANY", j = "ANY", drop
}
cols <- merge(new_indexes, index_mapping, by = join_cols)
if (nrow(cols) != nrow(new_indexes)) {
stop("You used the variable '", var_name, "' with at least one index that does not exists.", call. = FALSE)
warning("You used the variable '", var_name, "' with ", nrow(new_indexes),
" indexes but only ", nrow(cols), " indexes will be used", call. = FALSE)
}
new_vars <- data.table::data.table(
variable = var_name,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-model-milp.R
Expand Up @@ -283,8 +283,8 @@ test_that("numeric - varaible sum", {
expect_equal(constr$rhs, 3)
})

test_that("nice error message if sum_expr selected non existent variable", {
expect_error(
test_that("nice warning message if sum_expr selected non existent variable", {
expect_warning(
MILPModel() %>%
add_variable(x[i], i = 1:3, i != 2) %>%
set_objective(sum_expr(x[i], i = 1:3, i != 1)),
Expand Down

0 comments on commit c69377d

Please sign in to comment.