mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 00:08:52 -06:00
Implement UnitCommitment.write
This commit is contained in:
@@ -52,11 +52,11 @@ model = UnitCommitment.build_model(
|
|||||||
# Solve model
|
# Solve model
|
||||||
UnitCommitment.optimize!(model)
|
UnitCommitment.optimize!(model)
|
||||||
|
|
||||||
# Extract solution and write it to a file
|
# Extract solution
|
||||||
solution = UnitCommitment.solution(model)
|
solution = UnitCommitment.solution(model)
|
||||||
open("/path/to/output.json", "w") do file
|
|
||||||
JSON.print(file, solution, 2)
|
# Write solution to a file
|
||||||
end
|
UnitCommitment.write("/path/to/output.json", solution)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Solving benchmark instances
|
### Solving benchmark instances
|
||||||
|
|||||||
11
src/model.jl
11
src/model.jl
@@ -578,7 +578,14 @@ function solution(model::JuMP.Model)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function fix!(model::JuMP.Model, solution)::Nothing
|
function write(filename::AbstractString, solution::AbstractDict)::Nothing
|
||||||
|
open(filename, "w") do file
|
||||||
|
JSON.print(file, solution, 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function fix!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
||||||
instance, T = model[:instance], model[:instance].time
|
instance, T = model[:instance], model[:instance].time
|
||||||
is_on = model[:is_on]
|
is_on = model[:is_on]
|
||||||
prod_above = model[:prod_above]
|
prod_above = model[:prod_above]
|
||||||
@@ -600,7 +607,7 @@ function fix!(model::JuMP.Model, solution)::Nothing
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function set_warm_start!(model::JuMP.Model, solution)::Nothing
|
function set_warm_start!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
||||||
instance, T = model[:instance], model[:instance].time
|
instance, T = model[:instance], model[:instance].time
|
||||||
is_on = model[:is_on]
|
is_on = model[:is_on]
|
||||||
prod_above = model[:prod_above]
|
prod_above = model[:prod_above]
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ using UnitCommitment, LinearAlgebra, Cbc, JuMP
|
|||||||
optimizer=optimizer,
|
optimizer=optimizer,
|
||||||
variable_names=true,
|
variable_names=true,
|
||||||
)
|
)
|
||||||
|
|
||||||
@test name(model[:is_on]["g1", 1]) == "is_on[g1,1]"
|
@test name(model[:is_on]["g1", 1]) == "is_on[g1,1]"
|
||||||
|
|
||||||
JuMP.write_to_file(model, "test.mps")
|
|
||||||
|
|
||||||
# Optimize and retrieve solution
|
# Optimize and retrieve solution
|
||||||
UnitCommitment.optimize!(model)
|
UnitCommitment.optimize!(model)
|
||||||
solution = UnitCommitment.solution(model)
|
solution = UnitCommitment.solution(model)
|
||||||
|
|
||||||
|
# Write solution to a file
|
||||||
|
filename = tempname()
|
||||||
|
UnitCommitment.write(filename, solution)
|
||||||
|
loaded = JSON.parsefile(filename)
|
||||||
|
@test length(loaded["Is on"]) == 6
|
||||||
|
|
||||||
# Verify solution
|
# Verify solution
|
||||||
@test UnitCommitment.validate(instance, solution)
|
@test UnitCommitment.validate(instance, solution)
|
||||||
|
|||||||
Reference in New Issue
Block a user