diff --git a/src/build_sequences.jl b/src/build_sequences.jl index 84b62f58e1de081e3593544fd9e76db583fe1e05..8392f064ec322defd3a53ce0d6659ae12ae5bde0 100644 --- a/src/build_sequences.jl +++ b/src/build_sequences.jl @@ -1,5 +1,5 @@ module BuildSequences -import JuMP: Model, optimizer_with_attributes +import JuMP: Model, optimizer_with_attributes, optimize! import Ipopt import Juniper diff --git a/src/building_blocks.jl b/src/building_blocks.jl index ef275c54d8c8820d22998ddcc4d76bd7970472cc..476fa7a93917f5ee44f7f21559f6cd36184e33f9 100644 --- a/src/building_blocks.jl +++ b/src/building_blocks.jl @@ -32,6 +32,14 @@ The [`BuildingBlock`](@ref) is defined by one or more indices as defined below. 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) diff --git a/src/containers/sequences.jl b/src/containers/sequences.jl index 8c91cf0476d05acc384bafc7f360f9d65cd8b335..c5a6f37102709e67ea1758303780a5a1c6bc71f3 100644 --- a/src/containers/sequences.jl +++ b/src/containers/sequences.jl @@ -2,7 +2,7 @@ module Sequences import JuMP: Model import ...BuildSequences: @global_model_constructor import ...Variables: variables, start_time, duration, VariableType -import ...BuildingBlocks: BuildingBlock +import ...BuildingBlocks: BuildingBlock, to_block """ Sequence(building_blocks...) @@ -17,7 +17,7 @@ end @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.getindex(seq::Sequence, index) = seq[index] diff --git a/src/readouts/instant_readouts.jl b/src/readouts/instant_readouts.jl index 6f3bf4cd5da847b7935aea7a6e0301d4f7a0300b..56727f5c0eff2ad2ae2f890c292339b5bbb6b6a0 100644 --- a/src/readouts/instant_readouts.jl +++ b/src/readouts/instant_readouts.jl @@ -1,5 +1,5 @@ module InstantReadouts -import ...BuildingBlocks: BuildingBlock +import ...BuildingBlocks: BuildingBlock, to_block import ...ConcreteBlocks: AbstractConcreteBlock, to_concrete_block import ...Variables: variables @@ -15,4 +15,5 @@ end variables(::Type{<:InstantReadout}) = [] to_concrete_block(::InstantReadout) = InstantReadout() +to_block(::Type{<:InstantReadout}) = InstantReadout() end \ No newline at end of file diff --git a/src/wait.jl b/src/wait.jl index 678b7ff2bd694ed2842ad4882afe8005a7263c96..039098e0063ce139e93e4cba424d59652444b948 100644 --- a/src/wait.jl +++ b/src/wait.jl @@ -1,7 +1,7 @@ module Wait import JuMP: Model, @constraint, @variable, VariableRef, owner_model, value import ..Variables: VariableType, variables, duration, get_free_variable -import ..BuildingBlocks: BuildingBlock +import ..BuildingBlocks: BuildingBlock, to_block import ..ConcreteBlocks: to_concrete_block, ConcreteBlock import ..BuildSequences: @global_model_constructor import ...Scanners: Scanner @@ -34,6 +34,15 @@ function WaitBlock(model::Model, duration=nothing) return res 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)