optimizationjulianomethoderror

No method matching error in Optimization Model


I am trying to create a linear optimization model in Julia, but when I add "/Sb" (scalar = 250) to the following constraint.

@constraint(planing, cons_freq[i=1:nGen, j=1:nBloques], pg[i,j] <= Delta_f*(sum(H[k]*pCap[k])/Sb for k in 1:nGen if k != i))

i get the this error:

ERROR: MethodError: no method matching *(::Float64, ::Base.Generator{Base.Iterators.Filter{var"#559#562"{Int64}, UnitRange{Int64}}, var"#558#561"})

Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:578
  *(::T, ::T) where T<:Union{Float16, Float32, Float64}
   @ Base float.jl:410
  *(::Union{Float16, Float32, Float64}, ::BigFloat)
   @ Base mpfr.jl:423
  ...

Stacktrace:
  [1] operate(::typeof(*), ::Float64, ::Base.Generator{Base.Iterators.Filter{var"#559#562"{Int64}, UnitRange{Int64}}, var"#558#561"})
    @ MutableArithmetics C:\Users\Gosha\.julia\packages\MutableArithmetics\cnvbo\src\interface.jl:206
  [2] macro expansion
    @ C:\Users\Gosha\.julia\packages\MutableArithmetics\cnvbo\src\rewrite.jl:321 [inlined]
  [3] macro expansion
    @ C:\Users\Gosha\.julia\packages\JuMP\OUdu2\src\macros.jl:710 [inlined]
  [4] (::var"#557#560"{Model})(i::Int64, j::Int64)
    @ Main C:\Users\Gosha\.julia\packages\JuMP\OUdu2\src\Containers\macro.jl:301
  [5] #84
    @ C:\Users\Gosha\.julia\packages\JuMP\OUdu2\src\Containers\container.jl:85 [inlined]
  [6] iterate
    @ .\generator.jl:47 [inlined]
  [7] collect(itr::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, JuMP.Containers.var"#84#85"{var"#557#560"{Model}}})
    @ Base .\array.jl:782
  [8] map(f::Function, A::JuMP.Containers.VectorizedProductIterator{Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}})
    @ Base .\abstractarray.jl:3291
  [9] container
    @ C:\Users\Gosha\.julia\packages\JuMP\OUdu2\src\Containers\container.jl:85 [inlined]
 [10] container
    @ C:\Users\Gosha\.julia\packages\JuMP\OUdu2\src\Containers\container.jl:71 [inlined]
 [11] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, #unused#::Type{JuMP.Containers.AutoContainerType}, names::Vector{Any})
    @ JuMP.Containers C:\Users\Gosha\.julia\packages\JuMP\OUdu2\src\Containers\container.jl:75
 [12] macro expansion
    @ C:\Users\Gosha\.julia\packages\JuMP\OUdu2\src\macros.jl:1211 [inlined]
 [13] top-level scope

pCap is a @variable and H a 3x1 matrix. Values of H are 2, 3 and 4 and Delta_f = 0.0008714285714285706. pg[i,j] is generation of generator i in demand j. If you need any information to be able to help me in this I am willing.

I tried multiplying the inside of the summation by a scalar, and that's the only way the script worked, but it's not what I'm looking for.

I am new to Julia, so I would like to receive guidance on how I can solve this problem. Thanks


Solution

  • The same error can be replicated in this code:

    1.0 * (x for x in 1:2)
    

    Most likely for the RHS you want to have:

    Delta_f*sum((sum(H[k]*pCap[k])/Sb  for k in 1:nGen if k != i))
    

    That is you cannot multiple scalar by a generator and you are most likely needing a summation operator (other option would be to vectorize).