Hi,
Here is a MWE of my problem that is returning the same error. I cannot seem to understand why.
using DataStructures
using JuMP
using TaylorSeries
S = ["s1","s2","s3","s4"]
N = [1:10]
price = OrderedDict(
"s1" => 0,
"s2" => 0,
"s3" => 0,
"s4" => 5
)
m = Model()
@variables m begin
d[s in S, n in N] >= 0
end
g(d)= sum((price[s]*d[s,n]) for n in N for s in keys(price))
∫⬩dn(N::Taylor1) = integrate(p)
function Taylor(f, p0)
p = copy(p0)
pnew = p0 + ∫⬩dn(f(N))
while (pnew - p) != 0
p = pnew
pnew = p0 + ∫⬩dn(f(N))
end
return p
end
degree = 3
p0 = Taylor1([1], degree)
SurrogateApproximation = Taylor(g, p0)
When the equation is on its own, it does not return that error but returns it when called into the function Taylor
sum((price[s]*d[s,n]) for n in N for s in keys(price))
Here is the full details of the error
ArgumentError: invalid index: “s1” of type String
Stacktrace:
[1] to_index(::String) at .\indices.jl:297
[2] to_index(::Array{UnitRange{Int64},1}, ::String) at .\indices.jl:274
[3] to_indices at .\indices.jl:325 [inlined]
[4] to_indices at .\indices.jl:321 [inlined]
[5] getindex at .\abstractarray.jl:1060 [inlined]
[6] (::var"#393#396"{UnitRange{Int64},Array{UnitRange{Int64},1}})(::String) at .\none:0
[7] MappingRF at .\reduce.jl:93 [inlined]
[8] _foldl_impl(::Base.MappingRF{var"#393#396"{UnitRange{Int64},Array{UnitRange{Int64},1}},Base.BottomRF{typeof(Base.add_sum)}}, ::Base._InitialValue, ::Base.KeySet{String,OrderedDict{String,Int64}}) at .\reduce.jl:58
[9] FlatteningRF at .\reduce.jl:119 [inlined]
[10] MappingRF at .\reduce.jl:93 [inlined]
[11] _foldl_impl(::Base.MappingRF{var"#394#395"{Array{UnitRange{Int64},1}},Base.FlatteningRF{Base.BottomRF{typeof(Base.add_sum)}}}, ::Base._InitialValue, ::Array{UnitRange{Int64},1}) at .\reduce.jl:58
[12] foldl_impl at .\reduce.jl:48 [inlined]
[13] mapfoldl_impl at .\reduce.jl:44 [inlined]
[14] #mapfoldl#204 at .\reduce.jl:160 [inlined]
[15] mapfoldl at .\reduce.jl:160 [inlined]
[16] #mapreduce#208 at .\reduce.jl:287 [inlined]
[17] mapreduce at .\reduce.jl:287 [inlined]
[18] sum at .\reduce.jl:494 [inlined]
[19] sum(::Base.Iterators.Flatten{Base.Generator{Array{UnitRange{Int64},1},var"#394#395"{Array{UnitRange{Int64},1}}}}) at .\reduce.jl:511
[20] h(::Array{UnitRange{Int64},1}) at .\In[29]:1
[21] Taylor(::typeof(h), ::Taylor1{Int64}) at .\In[21]:4
[22] top-level scope at In[31]:5
[23] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091