我正在和 Julia 一起练习,但在试图做出限制时遇到了困难。
# Server Costs
> df_custos = DataFrame(C1=[2,4,3],C2=[1,2,1],C3=[3,3,2],C4=[6,2,3],)
# City num
> num_cidades=ncol(df_custos)
# Server num
> num_servidores = nrow(df_custos)
# Server demand
> df_demanda = [100, 120, 80, 200]
# Model -----------------------------------------------
> model_s = Model(Cbc.Optimizer)
# X[i,j] where i = Server and j=City
> @variable(model_s,
> x[i=1:num_servidores,j=1:num_cidades],Int,lower_bound=0)
# Objetive as costs[i.j]*x[i,j]
> @objective(model_s, Min, sum(df_custos[i,j]*x[i,j] for
> i=1:num_servidores,j=1:num_cidades))
# Sum(x[i,j])==df_demanda
> @constraint(model_s,[j=1:num_cidades], sum(x[i,j] for
> i=1:num_servidores) .>= df_demanda
)
> print(model_s)
问题是当我打印模型时,我得到了这个:
当我期望只有 4 个按需限制时,每个城市一个,例如:
x11+x21+x31 == 100
x12+x22+x32 == 120
x13+x23+x33 == 80
x14+x24+x34 == 200
如何编辑约束以使其正确?