Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ end

Add a case to a ConstraintItem with specified region and parameters.
"""
function case!(item::ConstraintItem, region; value=nothing, time_function=nothing, comment=nothing)
function case!(item::ConstraintItem, region; value=nothing, time_function=nothing, condition=nothing, comment=nothing)
case_dict = Dict{String, Any}("Region" => region)
if value !== nothing
case_dict["Value"] = value
end
if time_function !== nothing
case_dict["TimeFunction"] = time_function
end
if condition !== nothing
case_dict["Condition"] = condition
end
if comment !== nothing
case_dict["Comment"] = comment
end
Expand Down Expand Up @@ -176,7 +179,16 @@ function code(constraint::Constraint)
line *= "; TimeFunction $(case["TimeFunction"])"
end
line *= "; }"
push!(code_lines, line)

# Check for condition and wrap with If statement
if haskey(case, "Condition")
condition = case["Condition"]
push!(code_lines, " If ($(condition))")
push!(code_lines, " " * line)
push!(code_lines, " EndIf")
else
push!(code_lines, line)
end
end
push!(code_lines, " EndFor")
end
Expand All @@ -191,4 +203,4 @@ function code(constraint::Constraint)
else
return join(code_lines, "\n")
end
end
end
Loading