Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colon Case for Arrays #832

Open
lrennels opened this issue Jun 4, 2021 · 1 comment
Open

Colon Case for Arrays #832

lrennels opened this issue Jun 4, 2021 · 1 comment
Milestone

Comments

@lrennels
Copy link
Collaborator

lrennels commented Jun 4, 2021

Add methods to support colons between Timesteps ie.
using Mimi

## Failing Case
@defcomp A begin
    p = Parameter(index = [time, pools])
    v1 = Variable(index = [time, pools])
    v2 = Variable(index = [time])

    function run_timestep(p, v, d, t)
        v.v1[t,:] = p.p[t,:]
        if is_first(t)
            v.v2[t] = 0
        else
            v.v2[t] = sum(v.v1[(t-1):t,:])
        end
    end
end

m = Model()
set_dimension!(m, :time, 1:10)
set_dimension!(m, :pools, 1:3)
add_comp!(m, A)

set_param!(m, :A, :p, fill(1,10,3))

run(m)
## Smaller Case
@efcomp A begin
    p = Parameter(index = [time])
    v = Variable(index = [time])

    function run_timestep(p, v, d, t)
        if is_first(t)
            v.v[t] = p.p[t]
        else
            v.v[t] = sum(p.p[t:t])
            # or v.v[t] = sum(p, p[t-1:t])
        end
    end
end

m = Model()
set_dimension!(m, :time, 1:10)
add_comp!(m, A)

set_param!(m, :A, :p, 1:10)

run(m)
@lrennels
Copy link
Collaborator Author

lrennels commented Jun 4, 2021

or even smaller ...

julia> Mimi.FixedTimestep:Mimi.FixedTimestep
ERROR: MethodError: no method matching -(::Type{Mimi.FixedTimestep}, ::Type{Mimi.FixedTimestep})
Closest candidates are:
  -(::Array{DoubleFloats.DoubleFloat{T}, 2}, ::T) where T at /Users/lisarennels/.julia/packages/DoubleFloats/KXG5r/src/extras/misc.jl:62
  -(::Array{DoubleFloats.DoubleFloat{T}, 1}, ::T) where T at /Users/lisarennels/.julia/packages/DoubleFloats/KXG5r/src/extras/misc.jl:56
  -(::Intervals.Interval, ::Any) at /Users/lisarennels/.julia/packages/Intervals/ua9cq/src/interval.jl:297
  ...
Stacktrace:
 [1] (::Colon)(start::Type{Mimi.FixedTimestep}, stop::Type{Mimi.FixedTimestep})
   @ Base ./range.jl:7
 [2] top-level scope
   @ REPL[147]:1

@davidanthoff davidanthoff added this to the Backlog milestone Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants