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

Convert every part of Sequence to BuildingBlocks

parent e0787782
No related branches found
No related tags found
No related merge requests found
module BuildSequences module BuildSequences
import JuMP: Model, optimizer_with_attributes import JuMP: Model, optimizer_with_attributes, optimize!
import Ipopt import Ipopt
import Juniper import Juniper
......
...@@ -32,6 +32,14 @@ The [`BuildingBlock`](@ref) is defined by one or more indices as defined below. ...@@ -32,6 +32,14 @@ The [`BuildingBlock`](@ref) is defined by one or more indices as defined below.
end_time(bb) = duration(bb) end_time(bb) = duration(bb)
"""
to_block(object)
Function used internally to convert a wide variety of objects into [`BuildingBlock`](@ref) objects.
"""
function to_block end
""" """
scanner_constraints!([model, ]building_block, scanner) scanner_constraints!([model, ]building_block, scanner)
......
...@@ -2,7 +2,7 @@ module Sequences ...@@ -2,7 +2,7 @@ module Sequences
import JuMP: Model import JuMP: Model
import ...BuildSequences: @global_model_constructor import ...BuildSequences: @global_model_constructor
import ...Variables: variables, start_time, duration, VariableType import ...Variables: variables, start_time, duration, VariableType
import ...BuildingBlocks: BuildingBlock import ...BuildingBlocks: BuildingBlock, to_block
""" """
Sequence(building_blocks...) Sequence(building_blocks...)
...@@ -17,7 +17,7 @@ end ...@@ -17,7 +17,7 @@ end
@global_model_constructor Sequence @global_model_constructor Sequence
Sequence(model::Model, blocks...) = Sequence(model, blocks) Sequence(model::Model, blocks::BuildingBlock...) = Sequence(model, to_block.(blocks))
Base.length(seq::Sequence) = length(seq) Base.length(seq::Sequence) = length(seq)
Base.getindex(seq::Sequence, index) = seq[index] Base.getindex(seq::Sequence, index) = seq[index]
......
module InstantReadouts module InstantReadouts
import ...BuildingBlocks: BuildingBlock import ...BuildingBlocks: BuildingBlock, to_block
import ...ConcreteBlocks: AbstractConcreteBlock, to_concrete_block import ...ConcreteBlocks: AbstractConcreteBlock, to_concrete_block
import ...Variables: variables import ...Variables: variables
...@@ -15,4 +15,5 @@ end ...@@ -15,4 +15,5 @@ end
variables(::Type{<:InstantReadout}) = [] variables(::Type{<:InstantReadout}) = []
to_concrete_block(::InstantReadout) = InstantReadout() to_concrete_block(::InstantReadout) = InstantReadout()
to_block(::Type{<:InstantReadout}) = InstantReadout()
end end
\ No newline at end of file
module Wait module Wait
import JuMP: Model, @constraint, @variable, VariableRef, owner_model, value import JuMP: Model, @constraint, @variable, VariableRef, owner_model, value
import ..Variables: VariableType, variables, duration, get_free_variable import ..Variables: VariableType, variables, duration, get_free_variable
import ..BuildingBlocks: BuildingBlock import ..BuildingBlocks: BuildingBlock, to_block
import ..ConcreteBlocks: to_concrete_block, ConcreteBlock import ..ConcreteBlocks: to_concrete_block, ConcreteBlock
import ..BuildSequences: @global_model_constructor import ..BuildSequences: @global_model_constructor
import ...Scanners: Scanner import ...Scanners: Scanner
...@@ -34,6 +34,15 @@ function WaitBlock(model::Model, duration=nothing) ...@@ -34,6 +34,15 @@ function WaitBlock(model::Model, duration=nothing)
return res return res
end end
"""
to_block(JuMP variable/:min or :max/nothing/number)
Converts object into a [`WaitBlock`](@ref).
- if a Number or a JuMP variable the wait time will match that value.
- if `:min`, the wait time will be minimised in the final sequence (limited by any external constraints).
- if `:max`, the wait time will be maximised in the final sequence (limited by any external constraints).
- if `nothing`, the wait time is only constrained by external factors.
"""
to_block(time::Union{VariableType, Symbol, Nothing, Val{:min}, Val{:max}}) = WaitBlock(time) to_block(time::Union{VariableType, Symbol, Nothing, Val{:min}, Val{:max}}) = WaitBlock(time)
......
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