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

Add JuMP helper methods for BuildingBlocks

parent cdff9357
No related branches found
No related tags found
No related merge requests found
module BuildingBlocks module BuildingBlocks
import JuMP: has_values, GenericVariableRef, value, Model, @constraint, @objective, owner_model, objective_function import JuMP: has_values, GenericVariableRef, value, Model, @constraint, @objective, owner_model, objective_function, optimize!, AbstractJuMPScalar
import Printf: @sprintf import Printf: @sprintf
import ..Scanners: Scanner import ..Scanners: Scanner
import ..Variables: variables, start_time, duration, end_time, gradient_strength, slew_rate import ..Variables: variables, start_time, duration, end_time, gradient_strength, slew_rate
...@@ -138,4 +138,20 @@ function match_blocks!(block1::BuildingBlock, block2::BuildingBlock) ...@@ -138,4 +138,20 @@ function match_blocks!(block1::BuildingBlock, block2::BuildingBlock)
match_blocks!(block1, block2, property_list) match_blocks!(block1, block2, property_list)
end end
optimize!(bb::BuildingBlock) = optimize!(owner_model(bb))
function owner_model(bb::BuildingBlock)
if hasproperty(bb, :model)
return bb.model
else
for name in propertynames(bb)
value = getproperty(bb, name)
if value isa AbstractJuMPScalar
return owner_model(value)
end
end
end
error("Cannot find owner model of $bb")
end
end end
\ No newline at end of file
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