1
パッケージをr
と一緒に使用していますが、私のニーズに合わせて目的関数を変更する方法がわかりません。最初のモデルは走っていますが、目的は実際に私が必要としているものではありません。ompr objective:rowsumsの分散を最小限にする
library(ompr)
library(magrittr)
library(ROI.plugin.glpk)
library(ompr.roi)
anz_schulen <- 50
anz_sfkz <- 10
# This model works
model <- MIPModel() %>%
add_variable(x[i, j], i = 1:anz_schulen, j = 1:anz_sfkz, type = "binary") %>%
set_objective(sum_expr(x[i, j], i = 1:anz_schulen, j = 1:anz_sfkz), sense="max") %>%
add_constraint(sum_expr(x[i, j], i = 1:anz_schulen) <= 7, j = 1:anz_sfkz) %>%
add_constraint(sum_expr(x[i, j], i = 1:anz_schulen) >= 1, j = 1:anz_sfkz) %>%
add_constraint(sum_expr(x[i, j], j = 1:anz_sfkz) <= 10, i = 1:anz_schulen) %>%
add_constraint(sum_expr(x[i, j], j = 1:anz_sfkz) >= 1, i = 1:anz_schulen)
erg <- solve_model(model, solver=with_ROI(solver = "glpk"))
xの最小化された行数の分散が必要です。誰かがそれをする方法を知っている?
model <- MIPModel() %>%
add_variable(x[i, j], i = 1:anz_schulen, j = 1:anz_sfkz, type = "binary") %>%
# I NEED SOMETHING LIKE: substitute(var(rowSums(x[i,j])) ... THIS IS NOT WORKING
set_objective(substitute(var(rowSums(x[i,j]))), sense="min") %>%
add_constraint(sum_expr(x[i, j], i = 1:anz_schulen) <= 7, j = 1:anz_sfkz) %>%
add_constraint(sum_expr(x[i, j], i = 1:anz_schulen) >= 1, j = 1:anz_sfkz) %>%
add_constraint(sum_expr(x[i, j], j = 1:anz_sfkz) <= 10, i = 1:anz_schulen) %>%
add_constraint(sum_expr(x[i, j], j = 1:anz_sfkz) >= 1, i = 1:anz_schulen)
ありがとうございます!