-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmip_benchmark.jl
More file actions
92 lines (74 loc) · 2.61 KB
/
mip_benchmark.jl
File metadata and controls
92 lines (74 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using HiGHS
using UnitCommitment
using Dates
using JSON
using JuMP
# Create directory for solutions
solutions_dir = "case118_contingency_solutions"
if !isdir(solutions_dir)
mkdir(solutions_dir)
end
# Get all available dates from the case118_data directory
data_dir = "data/contingency_cases/case118_data"
json_files = filter(f -> endswith(f, ".json"), readdir(data_dir))
dates = sort([replace(f, ".json" => "") for f in json_files])
# Start from index
START_INDEX = 330*5
dates = dates[START_INDEX:end]
println("Found $(length(dates)) benchmark cases to solve (starting from index $START_INDEX)")
println("Starting optimization runs...")
println("=" ^ 80)
# Track statistics
success_count = 0
failure_count = 0
failed_cases = []
# Process each date
for (idx, date_str) in enumerate(dates)
global success_count, failure_count, failed_cases
try
println("\n[$(idx + START_INDEX - 1)/$(length(dates) + START_INDEX - 1)] Processing: $date_str")
# Read the file
instance = UnitCommitment.read(joinpath(data_dir, "$date_str.json"))
# Build and solve the model
model = UnitCommitment.build_model(
instance = instance,
optimizer = HiGHS.Optimizer
)
# Optimize
UnitCommitment.optimize!(model, UnitCommitment.XavQiuWanThi2019.Method(time_limit = 300.0))
# Get solution
solution = UnitCommitment.solution(model)
# Save solution to file
output_file = joinpath(solutions_dir, "$(date_str)_solution.json")
UnitCommitment.write(output_file, solution)
println(" ✓ Solution saved to: $output_file")
success_count += 1
catch e
println(" ✗ ERROR: Failed to solve $date_str")
println(" ✗ Error message: $e")
failure_count += 1
push!(failed_cases, date_str)
end
# Print progress every 50 cases
if idx % 50 == 0
println("\n" * "=" ^ 80)
println("Progress: $(idx + START_INDEX - 1)/$(length(dates) + START_INDEX - 1) completed")
println("Success: $success_count | Failures: $failure_count")
println("=" ^ 80)
end
end
# Final summary
println("\n" * "=" ^ 80)
println("FINAL SUMMARY")
println("=" ^ 80)
println("Total cases processed: $(length(dates)) (started from index $START_INDEX)")
println("Successful: $success_count")
println("Failed: $failure_count")
println("Solutions saved to: $solutions_dir/")
if !isempty(failed_cases)
println("\nFailed cases:")
for case in failed_cases
println(" - $case")
end
end
println("\nAll done! ✓")