Skip to content
Snippets Groups Projects
Verified Commit 90f75bd0 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Standardise way to get children blocks of containers

parent e80b81cf
No related branches found
No related tags found
No related merge requests found
...@@ -28,10 +28,21 @@ abstract type GradientBlock <: BuildingBlock end ...@@ -28,10 +28,21 @@ abstract type GradientBlock <: BuildingBlock end
""" """
Parent type for all types combining one or more pulses/gradients. Parent type for all types combining one or more pulses/gradients.
Required methods:
- [`get_children_blocks`](@ref): return all the [`BuildingBlock`](@ref) objects includes in this container with their indices.
""" """
abstract type ContainerBlock <: BuildingBlock end abstract type ContainerBlock <: BuildingBlock end
"""
get_children_blocks(container)
Return all the [`BuildingBlock`](@ref) objects includes in this container with their indices.
"""
function get_children_blocks end
""" """
start_time(container, args...) start_time(container, args...)
...@@ -72,6 +83,11 @@ function scanner_constraints!(model::Model, building_block::BuildingBlock, scann ...@@ -72,6 +83,11 @@ function scanner_constraints!(model::Model, building_block::BuildingBlock, scann
@constraint model func(building_block) <= func(scanner) @constraint model func(building_block) <= func(scanner)
end end
end end
if building_block isa ContainerBlock
for (_, child_block) in get_children_blocks(building_block)
scanner_constraints!(model, child_block, scanner)
end
end
end end
""" """
......
...@@ -2,7 +2,7 @@ module Sequences ...@@ -2,7 +2,7 @@ module Sequences
import JuMP: Model, @constraint import JuMP: Model, @constraint
import ...BuildSequences: @global_model_constructor import ...BuildSequences: @global_model_constructor
import ...Variables: variables, start_time, duration, VariableType, get_free_variable, TR import ...Variables: variables, start_time, duration, VariableType, get_free_variable, TR
import ...BuildingBlocks: BuildingBlock, ContainerBlock, to_block, add_scanner_constraints! import ...BuildingBlocks: BuildingBlock, ContainerBlock, to_block, get_children_blocks
""" """
Sequence(building_blocks...) Sequence(building_blocks...)
...@@ -14,7 +14,7 @@ struct Sequence <: ContainerBlock ...@@ -14,7 +14,7 @@ struct Sequence <: ContainerBlock
model :: Model model :: Model
blocks :: Vector{<:BuildingBlock} blocks :: Vector{<:BuildingBlock}
TR :: VariableType TR :: VariableType
function Sequence(model::Model, blocks::Vector; TR=nothing) function Sequence(model::Model, blocks::AbstractVector; TR=nothing)
seq = new( seq = new(
model, model,
to_block.(blocks), to_block.(blocks),
...@@ -31,6 +31,7 @@ Sequence(model::Model, blocks...; TR=nothing) = Sequence(model, [blocks...]; TR= ...@@ -31,6 +31,7 @@ Sequence(model::Model, blocks...; TR=nothing) = Sequence(model, [blocks...]; TR=
Base.length(seq::Sequence) = length(seq.blocks) Base.length(seq::Sequence) = length(seq.blocks)
Base.getindex(seq::Sequence, index) = seq.blocks[index] Base.getindex(seq::Sequence, index) = seq.blocks[index]
get_children_blocks(seq::Sequence) = enumerate(seq.blocks)
""" """
start_time(sequence::Sequence, index::Integer, args...) start_time(sequence::Sequence, index::Integer, args...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment