Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MRIBuilder.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
MRIBuilder.jl
Commits
185b857a
Verified
Commit
185b857a
authored
1 year ago
by
Michiel Cottaar
Browse files
Options
Downloads
Patches
Plain Diff
Adjust iteration to go across multiple repeats
parent
2b07d523
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/all_sequences/base_sequences.jl
+39
-8
39 additions, 8 deletions
src/all_sequences/base_sequences.jl
src/all_sequences/sequences.jl
+4
-2
4 additions, 2 deletions
src/all_sequences/sequences.jl
with
43 additions
and
10 deletions
src/all_sequences/base_sequences.jl
+
39
−
8
View file @
185b857a
module
BaseSequences
module
BaseSequences
import
...
ContainerBlocks
:
ContainerBlock
import
...
ContainerBlocks
:
ContainerBlock
import
...
AllBuildingBlocks
:
BaseBuildingBlock
import
...
AllBuildingBlocks
:
BaseBuildingBlock
import
...
Variables
:
TR
,
duration
import
...
Variables
:
TR
,
duration
,
start_time
"""
"""
Super-type of any sequence of non-overlapping building blocks that should be played after each other.
Super-type of any sequence of non-overlapping building blocks that should be played after each other.
...
@@ -11,27 +11,58 @@ It contains `N` [`ContainerBlock`](@ref) objects (e.g., building blocks or other
...
@@ -11,27 +11,58 @@ It contains `N` [`ContainerBlock`](@ref) objects (e.g., building blocks or other
Main interface:
Main interface:
- Acts as an iterable containing the blocks and sequences.
- Acts as an iterable containing the blocks and sequences.
- Indiviual blocks/sequences can be obtained using indexing.
- Indiviual blocks/sequences can be obtained using indexing.
- If there is a finite number of repeats, the iteration will continue over all repeats.
Sub-types need to implement:
Sub-types need to implement:
- `Base.getindex`: returns the actual component for each integer index in 1:N.
- `get_index_single_TR`: return the index assuming it is between 1 and N
- [`nrepeat`](@ref): how often the sequence should repeat (if not implemented, this will be 1).
- [`TR`](@ref): time scale on which to repeat (if not implemented, this will be the sum of the individual block durations).
"""
"""
abstract type
BaseSequence
{
N
}
<:
ContainerBlock
end
abstract type
BaseSequence
{
N
}
<:
ContainerBlock
end
function
Base.getindex
(
bs
::
BaseSequence
{
N
},
index
::
Integer
)
where
{
N
}
if
index
<
1
||
index
>
length
(
bs
)
throw
(
BoundsError
(
bs
,
index
))
end
base_index
=
((
index
-
1
)
%
N
)
+
1
return
get_index_single_TR
(
bs
,
base_index
)
end
Base
.
iterate
(
bs
::
BaseSequence
)
=
Base
.
iterate
(
bs
,
1
)
Base
.
iterate
(
bs
::
BaseSequence
)
=
Base
.
iterate
(
bs
,
1
)
Base
.
iterate
(
bs
::
BaseSequence
{
N
},
index
::
Integer
)
where
{
N
}
=
index
>
N
?
nothing
:
(
bs
[
index
],
index
+
1
)
Base
.
iterate
(
bs
::
BaseSequence
{
N
},
index
::
Integer
)
where
{
N
}
=
index
>
length
(
bs
)
?
nothing
:
(
bs
[
index
],
index
+
1
)
Base
.
length
(
::
BaseSequence
{
N
})
where
{
N
}
=
N
Base
.
length
(
bs
::
BaseSequence
{
N
})
where
{
N
}
=
nrepeat
(
bs
)
*
N
Base
.
eltype
(
::
Type
{
<:
BaseSequence
})
=
ContainerBlock
Base
.
eltype
(
::
Type
{
<:
BaseSequence
})
=
ContainerBlock
function
start_time
(
bs
::
BaseSequence
{
N
},
index
::
Integer
)
where
{
N
}
nTR
=
div
(
index
-
1
,
N
,
RoundDown
)
if
0
<
nrepeat
(
bs
)
<=
nTR
throw
(
BoundsError
(
bs
,
index
))
end
base_index
=
((
index
-
1
)
%
N
)
+
1
base_time
=
sum
(
i
->
duration
(
bs
[
i
]),
1
:
base_index
)
if
iszero
(
nTR
)
return
base_time
else
return
nTR
*
TR
(
bs
)
+
base_time
end
end
"""
get_index_single_TR(sequence, index)
Used internally by any [`BaseSequence`](@ref) to get a specific block.
The `index` should be between 1 and N.
It should be implemented for any sub-classes of [`BaseSequence`](@ref).
"""
function
get_index_single_TR
end
"""
"""
nrepeat(sequence)
nrepeat(sequence)
How often sequence should be repeated.
How often sequence should be repeated.
Set to 0 to repeat indefinetely (default value if not overriden for a particular sequence type).
"""
"""
nrepeat
(
bs
::
BaseSequence
)
=
0
nrepeat
(
bs
::
BaseSequence
)
=
1
"""
"""
TR(sequence)
TR(sequence)
...
...
This diff is collapsed.
Click to expand it.
src/all_sequences/sequences.jl
+
4
−
2
View file @
185b857a
...
@@ -5,7 +5,7 @@ import ...Variables: get_free_variable, TR, VariableType
...
@@ -5,7 +5,7 @@ import ...Variables: get_free_variable, TR, VariableType
import
...
AllBuildingBlocks
:
Wait
,
BuildingBlock
import
...
AllBuildingBlocks
:
Wait
,
BuildingBlock
import
...
BuildSequences
:
global_model
import
...
BuildSequences
:
global_model
import
...
Components
:
EventComponent
import
...
Components
:
EventComponent
import
..
BaseSequences
:
ContainerBlock
,
BaseSequence
,
nrepeat
import
..
BaseSequences
:
ContainerBlock
,
BaseSequence
,
nrepeat
,
get_index_single_TR
"""
"""
Sequence(blocks; TR=:min, nrepeat=0)
Sequence(blocks; TR=:min, nrepeat=0)
...
@@ -35,7 +35,9 @@ end
...
@@ -35,7 +35,9 @@ end
Sequence
(
blocks
...
;
kwargs
...
)
=
Sequence
([
blocks
...
];
kwargs
...
)
Sequence
(
blocks
...
;
kwargs
...
)
=
Sequence
([
blocks
...
];
kwargs
...
)
Base
.
getindex
(
s
::
Sequence
,
i
::
Integer
)
=
s
.
blocks
[
i
]
get_index_single_TR
(
s
::
Sequence
,
i
::
Integer
)
=
s
.
blocks
[
i
]
Base
.
IteratorSize
(
::
Type
{
<:
Sequence
})
=
Base
.
IsInfinite
()
nrepeat
(
::
Sequence
)
=
Inf
"""
"""
to_block(block_like)
to_block(block_like)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment