Skip to content

Commit

Permalink
update print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mcosovic committed Oct 15, 2024
1 parent e173347 commit 6302e42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/src/manual/acOptimalPowerFlow.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ nothing # hide
---

##### Add Variables
The user has the ability to easily add new variables to the defined AC optimal power flow model by using the [`@variable`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.@variable) macro from the JuMP package. Here is an example:
The user has the ability to easily add new variables to the defined AC optimal power flow model by using the [`@variable`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.@variable) macro from the JuMP package:
```@example ACOptimalPowerFlow
JuMP.@variable(analysis.method.jump, newVariable)
nothing # hide
Expand Down
16 changes: 14 additions & 2 deletions src/backend/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,17 @@ function print(
)
for (key, idx) in label
if haskey(obj, idx) && is_valid(owner_model(obj[idx]), obj[idx])
println(io::IO, key, ": ", obj[idx])
expr = constraint_string(MIME("text/plain"), obj[idx])
println(io::IO, key, ": ", simplifyExpression(expr))
end
end
end

function print(io::IO, obj::Dict{Int64, ConstraintRef})
for key in sort(collect(keys(obj)))
if is_valid(owner_model(obj[key]), obj[key])
println(io::IO, obj[key])
expr = constraint_string(MIME("text/plain"), obj[key])
println(io::IO, simplifyExpression(expr))
end
end
end
Expand Down Expand Up @@ -419,6 +421,16 @@ function print(io::IO, obj::Dict{Int64, Vector{ConstraintRef}})
end
end

function simplifyExpression(expr::String)
expr = replace(expr, r"[-]?0\.0\s*\*\s*(cos|sin)\(\s*[^()]*\s*\)" => "0")
expr = replace(expr, r"\(\s*[-]?0[.0]?\s*\)" => "")
expr = replace(expr, r"\(\s*[+]\s*\(" => "((")
expr = replace(expr, r"^\((.*)\)" => s"\1")

return expr
end


##### Error Messages #####
function errorVoltage(voltage::Vector{Float64})
if isempty(voltage)
Expand Down

0 comments on commit 6302e42

Please sign in to comment.