@@ -30,17 +30,18 @@ The three-argument version of [`parameter_values`](@ref) is implemented for this
30
30
[`parameter_timeseries`](@ref) is implemented for this type. This type does not implement
31
31
any traits.
32
32
"""
33
- struct ParameterTimeseriesCollection{T}
33
+ struct ParameterTimeseriesCollection{T, P }
34
34
collection:: T
35
+ paramcache:: P
35
36
36
- function ParameterTimeseriesCollection (collection:: T ) where {T}
37
+ function ParameterTimeseriesCollection (collection:: T , paramcache :: P ) where {T, P }
37
38
if any (x -> is_timeseries (x) == NotTimeseries (), collection)
38
39
throw (ArgumentError ("""
39
- All objects passed to `ParameterTimeseriesCollection` must be timeseries \
40
- objects.
40
+ All objects in the collection `ParameterTimeseriesCollection` must be \
41
+ timeseries objects.
41
42
""" ))
42
43
end
43
- new {T} (collection)
44
+ new {T, P } (collection, paramcache )
44
45
end
45
46
end
46
47
@@ -73,6 +74,111 @@ function parameter_values(
73
74
ptc:: ParameterTimeseriesCollection , idx:: ParameterTimeseriesIndex , subidx)
74
75
return ptc[idx, subidx]
75
76
end
77
+ function parameter_values (prob, i:: ParameterTimeseriesIndex , j)
78
+ parameter_values (get_parameter_timeseries_collection (prob), i, j)
79
+ end
76
80
function parameter_timeseries (ptc:: ParameterTimeseriesCollection , idx)
77
81
return current_time (ptc[idx])
78
82
end
83
+
84
+ function _timeseries_value (ptc:: ParameterTimeseriesCollection , ts_idx, t)
85
+ ts_obj = ptc[ts_idx]
86
+ time_idx = searchsortedlast (current_time (ts_obj), t)
87
+ value = state_values (ts_obj, time_idx)
88
+ return value
89
+ end
90
+
91
+ """
92
+ parameter_values_at_time(valp, t)
93
+
94
+ Return an indexable collection containing the value of all parameters in `valp` at time
95
+ `t`. Note that `t` here is a floating-point time, and not an index into a timeseries.
96
+
97
+ This has a default implementation relying on [`get_parameter_timeseries_collection`](@ref)
98
+ and [`with_updated_parameter_timeseries_values`](@ref).
99
+ """
100
+ function parameter_values_at_time (valp, t)
101
+ ptc = get_parameter_timeseries_collection (valp)
102
+ with_updated_parameter_timeseries_values (ptc. paramcache,
103
+ (ts_idx => _timeseries_value (ptc, ts_idx, t) for ts_idx in eachindex (ptc)). .. )
104
+ end
105
+
106
+ """
107
+ parameter_values_at_state_time(valp, i)
108
+ parameter_values_at_state_time(valp)
109
+
110
+ Return an indexable collection containing the value of all parameters in `valp` at time
111
+ index `i` in the state timeseries.
112
+
113
+ By default, this function relies on [`parameter_values_at_time`](@ref) and
114
+ [`current_time`](@ref) for a default implementation.
115
+
116
+ The single-argument version of this function is a shorthand to return parameter values
117
+ at each point in the state timeseries. This also has a default implementation relying on
118
+ [`parameter_values_at_time`](@ref) and [`current_time`](@ref).
119
+ """
120
+ function parameter_values_at_state_time end
121
+
122
+ function parameter_values_at_state_time (p, i)
123
+ state_time = current_time (p, i)
124
+ return parameter_values_at_time (p, state_time)
125
+ end
126
+ function parameter_values_at_state_time (p)
127
+ return (parameter_values_at_time (p, t) for t in current_time (p))
128
+ end
129
+
130
+ """
131
+ parameter_timeseries(valp, i)
132
+
133
+ Return a vector of the time steps at which the parameter values in the parameter
134
+ timeseries at index `i` are saved. This is only required for objects where
135
+ `is_parameter_timeseries(valp) === Timeseries()`. It will not be called otherwise. It is
136
+ assumed that the timeseries is sorted in increasing order.
137
+
138
+ See also: [`is_parameter_timeseries`](@ref).
139
+ """
140
+ function parameter_timeseries end
141
+
142
+ function parameter_timeseries (valp, i)
143
+ return parameter_timeseries (get_parameter_timeseries_collection (valp), i)
144
+ end
145
+
146
+ """
147
+ parameter_timeseries_at_state_time(valp, i, j)
148
+ parameter_timeseries_at_state_time(valp, i)
149
+
150
+ Return the index of the timestep in the parameter timeseries at timeseries index `i` which
151
+ occurs just before or at the same time as the state timestep with index `j`. The two-
152
+ argument version of this function returns an iterable of indexes, one for each timestep in
153
+ the state timeseries. If `j` is an object that refers to multiple values in the state
154
+ timeseries (e.g. `Colon`), return an iterable of the indexes in the parameter timeseries
155
+ at the appropriate points.
156
+
157
+ Both versions of this function have default implementations relying on
158
+ [`current_time`](@ref) and [`parameter_timeseries`](@ref), for the cases where `j` is one
159
+ of: `Int`, `CartesianIndex`, `AbstractArray{Bool}`, `Colon` or an iterable of the
160
+ aforementioned.
161
+ """
162
+ function parameter_timeseries_at_state_time end
163
+
164
+ function parameter_timeseries_at_state_time (valp, i, j:: Union{Int, CartesianIndex} )
165
+ state_time = current_time (valp, j)
166
+ timeseries = parameter_timeseries (valp, i)
167
+ searchsortedlast (timeseries, state_time)
168
+ end
169
+
170
+ function parameter_timeseries_at_state_time (valp, i, :: Colon )
171
+ parameter_timeseries_at_state_time (valp, i)
172
+ end
173
+
174
+ function parameter_timeseries_at_state_time (valp, i, j:: AbstractArray{Bool} )
175
+ parameter_timeseries_at_state_time (valp, i, only (to_indices (current_time (valp), (j,))))
176
+ end
177
+
178
+ function parameter_timeseries_at_state_time (valp, i, j)
179
+ (parameter_timeseries_at_state_time (valp, i, jj) for jj in j)
180
+ end
181
+
182
+ function parameter_timeseries_at_state_time (valp, i)
183
+ parameter_timeseries_at_state_time (valp, i, eachindex (current_time (valp)))
184
+ end
0 commit comments