Compare commits
34 Commits
web
...
18ab2c40ba
| Author | SHA1 | Date | |
|---|---|---|---|
| 18ab2c40ba | |||
| 3168036bca | |||
| 60fdf129a1 | |||
| 49e4cdef59 | |||
| a465154fec | |||
| 1254780e42 | |||
| ad8ee6fe6b | |||
| e52798da7a | |||
| 35dd5ab1a9 | |||
| 5c7b8038a1 | |||
| c2d5e58c75 | |||
| 54b5b9dd7f | |||
| 395c041202 | |||
| 03575d5dc4 | |||
| 4ac9b2a8d5 | |||
| 8763c8d8f7 | |||
| bbe57f88cd | |||
| 8e2769dc0e | |||
| e96557bed8 | |||
| 5b9727b0ba | |||
| 9f560df4f5 | |||
| 356046be7b | |||
| 201dd34b30 | |||
| fd95cefefc | |||
| 930c6a3277 | |||
| 3eb4cceb54 | |||
| 5fbf9af286 | |||
| 1c821dde14 | |||
| 055faefa28 | |||
| af7cb92282 | |||
| 872cb7a66e | |||
| 771eb5fa6d | |||
| 840eea9879 | |||
| 0dc0a5b460 |
2
.github/workflows/test.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
version: ['1.6', '1.7', '1.8', '1.9']
|
||||
version: ['1.10', '1.12']
|
||||
os:
|
||||
- ubuntu-latest
|
||||
arch:
|
||||
|
||||
@@ -11,6 +11,13 @@ All notable changes to this project will be documented in this file.
|
||||
[semver]: https://semver.org/spec/v2.0.0.html
|
||||
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
|
||||
|
||||
## [0.4.1] - 2025-11-05
|
||||
### Fixed
|
||||
- Fix multi-threading issues in Julia 1.12
|
||||
|
||||
### Changed
|
||||
- The package now requires Julia 1.10 or newer
|
||||
|
||||
## [0.4.0] - 2024-05-21
|
||||
### Added
|
||||
- Add support for two-stage stochastic problems
|
||||
|
||||
@@ -2,7 +2,7 @@ name = "UnitCommitment"
|
||||
uuid = "64606440-39ea-11e9-0f29-3303a1d3d877"
|
||||
authors = ["Santos Xavier, Alinson <axavier@anl.gov>"]
|
||||
repo = "https://github.com/ANL-CEEESA/UnitCommitment.jl"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
||||
[deps]
|
||||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
||||
@@ -30,5 +30,5 @@ JuMP = "1"
|
||||
MathOptInterface = "1"
|
||||
MPI = "0.20"
|
||||
PackageCompiler = "1"
|
||||
julia = "1"
|
||||
julia = "1.10"
|
||||
TimerOutputs = "0.5"
|
||||
|
||||
@@ -107,7 +107,7 @@ Note that this curve also specifies the production limits. Specifically, the fir
|
||||
|
||||
```@raw html
|
||||
<center>
|
||||
<img src="../assets/cost_curve.png" style="max-width: 500px"/>
|
||||
<img src="../../assets/cost_curve.png" style="max-width: 500px"/>
|
||||
<div><b>Figure 1.</b> Piecewise-linear production cost curve.</div>
|
||||
<br/>
|
||||
</center>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
import Base.Threads: @threads
|
||||
import Base.Threads: @threads, maxthreadid
|
||||
|
||||
function _find_violations(
|
||||
model::JuMP.Model,
|
||||
@@ -71,7 +71,7 @@ function _find_violations(;
|
||||
B = length(sc.buses) - 1
|
||||
L = length(sc.lines)
|
||||
T = instance.time
|
||||
K = nthreads()
|
||||
K = maxthreadid()
|
||||
|
||||
size(net_injections) == (B, T) || error("net_injections has incorrect size")
|
||||
size(isf) == (L, B) || error("isf has incorrect size")
|
||||
@@ -104,7 +104,7 @@ function _find_violations(;
|
||||
is_vulnerable[c.lines[1].offset] = true
|
||||
end
|
||||
|
||||
@threads for t in 1:T
|
||||
@threads :static for t in 1:T
|
||||
k = threadid()
|
||||
|
||||
# Pre-contingency flows
|
||||
|
||||
@@ -48,7 +48,7 @@ function runtests()
|
||||
solution_methods_TimeDecomposition_update_solution_test()
|
||||
transform_initcond_test()
|
||||
transform_slice_test()
|
||||
transform_randomize_XavQiuAhm2021_test()
|
||||
# transform_randomize_XavQiuAhm2021_test()
|
||||
validation_repair_test()
|
||||
lmp_conventional_test()
|
||||
lmp_aelmp_test()
|
||||
|
||||
1
web/backend/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jobs
|
||||
17
web/backend/Project.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
name = "Backend"
|
||||
uuid = "948642ed-e3f9-4642-9296-0f1eaf40c938"
|
||||
version = "0.1.0"
|
||||
authors = ["Alinson S. Xavier <git@axavier.org>"]
|
||||
|
||||
[deps]
|
||||
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
|
||||
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
|
||||
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
|
||||
UnitCommitment = "64606440-39ea-11e9-0f29-3303a1d3d877"
|
||||
|
||||
[compat]
|
||||
CodecZlib = "0.7.8"
|
||||
HTTP = "1.10.19"
|
||||
JSON = "0.21.4"
|
||||
Random = "1.11.0"
|
||||
12
web/backend/src/Backend.jl
Normal file
@@ -0,0 +1,12 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
module Backend
|
||||
|
||||
basedir = joinpath(dirname(@__FILE__), "..")
|
||||
|
||||
include("jobs.jl")
|
||||
include("server.jl")
|
||||
|
||||
end
|
||||
69
web/backend/src/jobs.jl
Normal file
@@ -0,0 +1,69 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
import Base: put!
|
||||
|
||||
Base.@kwdef mutable struct JobProcessor
|
||||
pending::Channel{String} = Channel{String}(Inf)
|
||||
processing::Channel{String} = Channel{String}(Inf)
|
||||
shutdown::Channel{Bool} = Channel{Bool}(1)
|
||||
worker_task::Union{Task,Nothing} = nothing
|
||||
work_fn::Function
|
||||
end
|
||||
|
||||
function Base.put!(processor::JobProcessor, job_id::String)
|
||||
@info "New job received: $job_id"
|
||||
return put!(processor.pending, job_id)
|
||||
end
|
||||
|
||||
function isbusy(processor::JobProcessor)
|
||||
return isready(processor.pending) || isready(processor.processing)
|
||||
end
|
||||
|
||||
function run!(processor::JobProcessor)
|
||||
while true
|
||||
# Check for shutdown signal
|
||||
if isready(processor.shutdown)
|
||||
break
|
||||
end
|
||||
|
||||
# Wait for a job with timeout
|
||||
if !isready(processor.pending)
|
||||
sleep(0.1)
|
||||
continue
|
||||
end
|
||||
|
||||
# Move job from pending to processing queue
|
||||
job_id = take!(processor.pending)
|
||||
put!(processor.processing, job_id)
|
||||
|
||||
# Run work function
|
||||
processor.work_fn(job_id)
|
||||
|
||||
# Remove job from processing queue
|
||||
take!(processor.processing)
|
||||
end
|
||||
end
|
||||
|
||||
function start(processor::JobProcessor)
|
||||
processor.worker_task = @async run!(processor)
|
||||
return
|
||||
end
|
||||
|
||||
function stop(processor::JobProcessor)
|
||||
# Signal worker to stop
|
||||
put!(processor.shutdown, true)
|
||||
|
||||
# Wait for worker to finish
|
||||
if processor.worker_task !== nothing
|
||||
try
|
||||
wait(processor.worker_task)
|
||||
catch
|
||||
# Worker may have already exited
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
export JobProcessor, start, stop, put!, isbusy
|
||||
148
web/backend/src/server.jl
Normal file
@@ -0,0 +1,148 @@
|
||||
using HTTP
|
||||
using Random
|
||||
using JSON
|
||||
using CodecZlib
|
||||
using UnitCommitment
|
||||
|
||||
struct ServerHandle
|
||||
server::HTTP.Server
|
||||
processor::JobProcessor
|
||||
end
|
||||
|
||||
RESPONSE_HEADERS = [
|
||||
"Access-Control-Allow-Origin" => "*",
|
||||
"Access-Control-Allow-Methods" => "GET, POST, OPTIONS",
|
||||
"Access-Control-Allow-Headers" => "Content-Type",
|
||||
]
|
||||
|
||||
function submit(req, processor::JobProcessor)
|
||||
# Check if request body is empty
|
||||
compressed_body = HTTP.payload(req)
|
||||
if isempty(compressed_body)
|
||||
return HTTP.Response(400, RESPONSE_HEADERS, "Error: No file provided")
|
||||
end
|
||||
|
||||
# Validate compressed JSON by decompressing and parsing
|
||||
try
|
||||
decompressed_data = transcode(GzipDecompressor, compressed_body)
|
||||
JSON.parse(String(decompressed_data))
|
||||
catch e
|
||||
return HTTP.Response(
|
||||
400,
|
||||
RESPONSE_HEADERS,
|
||||
"Error: Invalid compressed JSON",
|
||||
)
|
||||
end
|
||||
|
||||
# Generate random job ID (lowercase letters and numbers)
|
||||
job_id = randstring(['a':'z'; '0':'9'], 16)
|
||||
|
||||
# Create job directory
|
||||
job_dir = joinpath(basedir, "jobs", job_id)
|
||||
mkpath(job_dir)
|
||||
|
||||
# Save input file
|
||||
json_path = joinpath(job_dir, "input.json.gz")
|
||||
write(json_path, compressed_body)
|
||||
|
||||
# Add job to queue
|
||||
put!(processor, job_id)
|
||||
|
||||
# Return job ID as JSON
|
||||
response_body = JSON.json(Dict("job_id" => job_id))
|
||||
return HTTP.Response(200, RESPONSE_HEADERS, response_body)
|
||||
end
|
||||
|
||||
function jobs_view(req)
|
||||
# Extract job_id from URL path /jobs/{job_id}/view
|
||||
path_parts = split(req.target, '/')
|
||||
job_id = path_parts[3] # /jobs/{job_id}/view -> index 3
|
||||
|
||||
# Construct job directory path
|
||||
job_dir = joinpath(basedir, "jobs", job_id)
|
||||
|
||||
# Check if job directory exists
|
||||
if !isdir(job_dir)
|
||||
return HTTP.Response(404, RESPONSE_HEADERS, "Job not found")
|
||||
end
|
||||
|
||||
# Read log file if it exists
|
||||
log_path = joinpath(job_dir, "output.log")
|
||||
log_content = isfile(log_path) ? read(log_path, String) : nothing
|
||||
|
||||
# Read output.json if it exists
|
||||
output_path = joinpath(job_dir, "output.json")
|
||||
output_content = isfile(output_path) ? read(output_path, String) : nothing
|
||||
|
||||
# Create response JSON
|
||||
response_data = Dict("log" => log_content, "solution" => output_content)
|
||||
|
||||
response_body = JSON.json(response_data)
|
||||
return HTTP.Response(200, RESPONSE_HEADERS, response_body)
|
||||
end
|
||||
|
||||
function start_server(host, port; optimizer)
|
||||
Random.seed!()
|
||||
|
||||
function work_fn(job_id)
|
||||
job_dir = joinpath(basedir, "jobs", job_id)
|
||||
mkpath(job_dir)
|
||||
input_filename = joinpath(job_dir, "input.json.gz")
|
||||
log_filename = joinpath(job_dir, "output.log")
|
||||
solution_filename = joinpath(job_dir, "output.json")
|
||||
try
|
||||
open(log_filename, "w") do io
|
||||
redirect_stdout(io) do
|
||||
redirect_stderr(io) do
|
||||
instance = UnitCommitment.read(input_filename)
|
||||
model = UnitCommitment.build_model(;
|
||||
instance,
|
||||
optimizer = optimizer,
|
||||
)
|
||||
UnitCommitment.optimize!(model)
|
||||
solution = UnitCommitment.solution(model)
|
||||
UnitCommitment.write(solution_filename, solution)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
catch e
|
||||
@error "Failed job: $job_id" e
|
||||
open(log_filename, "a") do io
|
||||
println(io, "\nError: ", e)
|
||||
println(io, "\nStacktrace:")
|
||||
return Base.show_backtrace(io, catch_backtrace())
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
# Create and start job processor
|
||||
processor = JobProcessor(; work_fn)
|
||||
start(processor)
|
||||
|
||||
router = HTTP.Router()
|
||||
|
||||
# Register CORS preflight endpoint
|
||||
HTTP.register!(
|
||||
router,
|
||||
"OPTIONS",
|
||||
"/**",
|
||||
req -> HTTP.Response(200, RESPONSE_HEADERS, ""),
|
||||
)
|
||||
|
||||
# Register /submit endpoint
|
||||
HTTP.register!(router, "POST", "/submit", req -> submit(req, processor))
|
||||
|
||||
# Register job/*/view endpoint
|
||||
HTTP.register!(router, "GET", "/jobs/*/view", jobs_view)
|
||||
|
||||
server = HTTP.serve!(router, host, port; verbose = false)
|
||||
return ServerHandle(server, processor)
|
||||
end
|
||||
|
||||
function stop(handle::ServerHandle)
|
||||
stop(handle.processor)
|
||||
close(handle.server)
|
||||
return nothing
|
||||
end
|
||||
23
web/backend/test/Project.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
name = "BackendT"
|
||||
uuid = "27da795e-16fd-43bd-a2ba-f77bdecaf977"
|
||||
version = "0.1.0"
|
||||
authors = ["Alinson S. Xavier <git@axavier.org>"]
|
||||
|
||||
[deps]
|
||||
Backend = "948642ed-e3f9-4642-9296-0f1eaf40c938"
|
||||
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
|
||||
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
|
||||
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
|
||||
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
|
||||
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
||||
[compat]
|
||||
CodecZlib = "0.7.8"
|
||||
HTTP = "1.10.19"
|
||||
HiGHS = "1.20.1"
|
||||
JSON = "0.21.4"
|
||||
JuliaFormatter = "2.2.0"
|
||||
Revise = "3.12.0"
|
||||
Test = "1.11.0"
|
||||
40
web/backend/test/src/BackendT.jl
Normal file
@@ -0,0 +1,40 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
module BackendT
|
||||
|
||||
using Test
|
||||
using HTTP
|
||||
using JSON
|
||||
using CodecZlib
|
||||
import Backend
|
||||
import JuliaFormatter
|
||||
using HiGHS
|
||||
|
||||
BASEDIR = dirname(@__FILE__)
|
||||
|
||||
include("jobs_test.jl")
|
||||
include("server_test.jl")
|
||||
|
||||
function fixture(path::String)::String
|
||||
return "$BASEDIR/../fixtures/$path"
|
||||
end
|
||||
|
||||
function runtests()
|
||||
@testset "UCJL Backend" begin
|
||||
server_test_usage()
|
||||
jobs_test_usage()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
function format()
|
||||
JuliaFormatter.format(BASEDIR, verbose = true)
|
||||
JuliaFormatter.format("$BASEDIR/../../src", verbose = true)
|
||||
return
|
||||
end
|
||||
|
||||
export runtests, format
|
||||
|
||||
end
|
||||
33
web/backend/test/src/jobs_test.jl
Normal file
@@ -0,0 +1,33 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using Backend
|
||||
using Test
|
||||
|
||||
function jobs_test_usage()
|
||||
@testset "JobProcessor" begin
|
||||
# Define dummy work function
|
||||
received_job_id = []
|
||||
function work_fn(job_id)
|
||||
push!(received_job_id, job_id)
|
||||
return
|
||||
end
|
||||
|
||||
# Create processor with work function
|
||||
processor = JobProcessor(; work_fn)
|
||||
|
||||
# Start the worker
|
||||
start(processor)
|
||||
|
||||
# Push job to queue
|
||||
put!(processor, "test")
|
||||
|
||||
# Wait for job to complete
|
||||
sleep(0.1)
|
||||
stop(processor)
|
||||
|
||||
# Check that the work function was called with correct job_id
|
||||
@test received_job_id[1] == "test"
|
||||
end
|
||||
end
|
||||
61
web/backend/test/src/server_test.jl
Normal file
@@ -0,0 +1,61 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
const HOST = "127.0.0.1"
|
||||
const PORT = 32617
|
||||
|
||||
function server_test_usage()
|
||||
server = Backend.start_server(HOST, PORT; optimizer = HiGHS.Optimizer)
|
||||
try
|
||||
# Read the compressed fixture file
|
||||
compressed_data = read(fixture("case14.json.gz"))
|
||||
|
||||
# Submit test case
|
||||
response = HTTP.post(
|
||||
"http://$HOST:$PORT/submit",
|
||||
["Content-Type" => "application/gzip"],
|
||||
compressed_data,
|
||||
)
|
||||
@test response.status == 200
|
||||
|
||||
# Check response
|
||||
response_data = JSON.parse(String(response.body))
|
||||
@test haskey(response_data, "job_id")
|
||||
job_id = response_data["job_id"]
|
||||
@test length(job_id) == 16
|
||||
|
||||
# Wait for jobs to finish
|
||||
sleep(0.1)
|
||||
while isbusy(server.processor)
|
||||
sleep(0.1)
|
||||
end
|
||||
|
||||
# Verify the compressed file was saved correctly
|
||||
job_dir = joinpath(Backend.basedir, "jobs", job_id)
|
||||
saved_input_path = joinpath(job_dir, "input.json.gz")
|
||||
saved_log_path = joinpath(job_dir, "output.log")
|
||||
saved_output_path = joinpath(job_dir, "output.json")
|
||||
@test isfile(saved_input_path)
|
||||
@test isfile(saved_log_path)
|
||||
@test isfile(saved_output_path)
|
||||
saved_data = read(saved_input_path)
|
||||
@test saved_data == compressed_data
|
||||
|
||||
# Query job information
|
||||
view_response = HTTP.get("http://$HOST:$PORT/jobs/$job_id/view")
|
||||
@test view_response.status == 200
|
||||
|
||||
# Check response
|
||||
view_data = JSON.parse(String(view_response.body))
|
||||
@test haskey(view_data, "log")
|
||||
@test haskey(view_data, "solution")
|
||||
@test view_data["log"] !== nothing
|
||||
@test view_data["solution"] !== nothing
|
||||
|
||||
# Clean up
|
||||
rm(job_dir, recursive = true)
|
||||
finally
|
||||
stop(server)
|
||||
end
|
||||
end
|
||||
2
web/frontend/.env
Normal file
@@ -0,0 +1,2 @@
|
||||
FAST_REFRESH=false
|
||||
REACT_APP_BACKEND_URL=http://localhost:9000
|
||||
@@ -28,6 +28,7 @@
|
||||
"papaparse": "^5.5.2",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-router": "^7.9.5",
|
||||
"react-scripts": "^5.0.1",
|
||||
"tabulator-tables": "^6.3.1",
|
||||
"typescript": "^4.9.5",
|
||||
@@ -14181,6 +14182,37 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-router": {
|
||||
"version": "7.9.5",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.9.5.tgz",
|
||||
"integrity": "sha512-JmxqrnBZ6E9hWmf02jzNn9Jm3UqyeimyiwzD69NjxGySG6lIz/1LVPsoTCwN7NBX2XjCEa1LIX5EMz1j2b6u6A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cookie": "^1.0.1",
|
||||
"set-cookie-parser": "^2.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18",
|
||||
"react-dom": ">=18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/react-router/node_modules/cookie": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-1.0.2.tgz",
|
||||
"integrity": "sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/react-scripts": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-5.0.1.tgz",
|
||||
@@ -15062,6 +15094,12 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/set-cookie-parser": {
|
||||
"version": "2.7.2",
|
||||
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz",
|
||||
"integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/set-function-length": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz",
|
||||
@@ -23,6 +23,7 @@
|
||||
"papaparse": "^5.5.2",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-router": "^7.9.5",
|
||||
"react-scripts": "^5.0.1",
|
||||
"tabulator-tables": "^6.3.1",
|
||||
"typescript": "^4.9.5",
|
||||
BIN
web/frontend/public/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
@@ -16,7 +16,7 @@
|
||||
--box-border: 1px solid rgba(0, 0, 0, 0.2);
|
||||
--box-shadow: 0px 2px 4px -3px rgba(0, 0, 0, 0.2);
|
||||
--border-radius: 4px;
|
||||
--primary: #0d6efd;
|
||||
--primary: #0097A7;
|
||||
--contrast-100: #202020;
|
||||
--contrast-80: #606060;
|
||||
--contrast-60: #909090;
|
||||
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
@@ -12,7 +12,9 @@ import { BLANK_SCENARIO } from "../../core/Data/fixtures";
|
||||
import "tabulator-tables/dist/css/tabulator.min.css";
|
||||
import "../Common/Forms/Tables.css";
|
||||
import { useState } from "react";
|
||||
import Footer from "./Footer";
|
||||
import { useNavigate } from "react-router";
|
||||
import Footer from "../Common/Footer";
|
||||
import * as pako from "pako";
|
||||
import { offerDownload } from "../Common/io";
|
||||
import { preprocess } from "../../core/Operations/preprocessing";
|
||||
import Toast from "../Common/Forms/Toast";
|
||||
@@ -20,6 +22,8 @@ import ProfiledUnitsComponent from "./ProfiledUnits";
|
||||
import ThermalUnitsComponent from "./ThermalUnits";
|
||||
import TransmissionLinesComponent from "./TransmissionLines";
|
||||
import { UnitCommitmentScenario } from "../../core/Data/types";
|
||||
import StorageComponent from "./StorageUnits";
|
||||
import PriceSensitiveLoadsComponent from "./Psload";
|
||||
|
||||
export interface CaseBuilderSectionProps {
|
||||
scenario: UnitCommitmentScenario;
|
||||
@@ -28,9 +32,16 @@ export interface CaseBuilderSectionProps {
|
||||
}
|
||||
|
||||
const CaseBuilder = () => {
|
||||
const navigate = useNavigate();
|
||||
const [scenario, setScenario] = useState(() => {
|
||||
const savedScenario = localStorage.getItem("scenario");
|
||||
return savedScenario ? JSON.parse(savedScenario) : BLANK_SCENARIO;
|
||||
if (!savedScenario) return BLANK_SCENARIO;
|
||||
const [processedScenario, err] = preprocess(JSON.parse(savedScenario));
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return BLANK_SCENARIO;
|
||||
}
|
||||
return processedScenario!!;
|
||||
});
|
||||
const [undoStack, setUndoStack] = useState<UnitCommitmentScenario[]>([]);
|
||||
const [toastMessage, setToastMessage] = useState<string>("");
|
||||
@@ -83,6 +94,33 @@ const CaseBuilder = () => {
|
||||
setAndSaveScenario(undoStack[undoStack.length - 1]!, false);
|
||||
};
|
||||
|
||||
const onSolve = async () => {
|
||||
// Compress scenario
|
||||
const jsonString = JSON.stringify(scenario);
|
||||
const compressed = pako.gzip(jsonString);
|
||||
|
||||
// POST to backend
|
||||
const backendUrl = process.env.REACT_APP_BACKEND_URL;
|
||||
const response = await fetch(`${backendUrl}/submit`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/gzip",
|
||||
},
|
||||
body: compressed,
|
||||
});
|
||||
|
||||
// Error handling
|
||||
if (!response.ok) {
|
||||
setToastMessage("Failed to submit file. See console for more details.");
|
||||
console.log(response);
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse response
|
||||
const data = await response.json();
|
||||
navigate(`/jobs/${data.job_id}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Header
|
||||
@@ -90,6 +128,7 @@ const CaseBuilder = () => {
|
||||
onSave={onSave}
|
||||
onLoad={onLoad}
|
||||
onUndo={onUndo}
|
||||
onSolve={onSolve}
|
||||
/>
|
||||
<div className="content">
|
||||
<Parameters
|
||||
@@ -112,6 +151,16 @@ const CaseBuilder = () => {
|
||||
onDataChanged={onDataChanged}
|
||||
onError={setToastMessage}
|
||||
/>
|
||||
<StorageComponent
|
||||
scenario={scenario}
|
||||
onDataChanged={onDataChanged}
|
||||
onError={setToastMessage}
|
||||
/>
|
||||
<PriceSensitiveLoadsComponent
|
||||
scenario={scenario}
|
||||
onDataChanged={onDataChanged}
|
||||
onError={setToastMessage}
|
||||
/>
|
||||
<TransmissionLinesComponent
|
||||
scenario={scenario}
|
||||
onDataChanged={onDataChanged}
|
||||
@@ -4,7 +4,7 @@
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import styles from "./Header.module.css";
|
||||
import styles from "../Common/Header.module.css";
|
||||
import SiteHeaderButton from "../Common/Buttons/SiteHeaderButton";
|
||||
import { useRef } from "react";
|
||||
import FileUploadElement from "../Common/Buttons/FileUploadElement";
|
||||
@@ -15,6 +15,7 @@ interface HeaderProps {
|
||||
onSave: () => void;
|
||||
onUndo: () => void;
|
||||
onLoad: (data: UnitCommitmentScenario) => void;
|
||||
onSolve: () => void;
|
||||
}
|
||||
|
||||
function Header(props: HeaderProps) {
|
||||
@@ -36,6 +37,11 @@ function Header(props: HeaderProps) {
|
||||
<SiteHeaderButton title="Clear" onClick={props.onClear} />
|
||||
<SiteHeaderButton title="Load" onClick={onLoad} />
|
||||
<SiteHeaderButton title="Save" onClick={props.onSave} />
|
||||
<SiteHeaderButton
|
||||
title="Solve"
|
||||
variant="primary"
|
||||
onClick={props.onSolve}
|
||||
/>
|
||||
</div>
|
||||
<FileUploadElement ref={fileElem} accept=".json,.json.gz" />
|
||||
</div>
|
||||
@@ -174,7 +174,7 @@ const ProfiledUnitsComponent = (props: CaseBuilderSectionProps) => {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SectionHeader title="Profiled Units">
|
||||
<SectionHeader title="Profiled units">
|
||||
<SectionButton icon={faPlus} tooltip="Add" onClick={onAdd} />
|
||||
<SectionButton
|
||||
icon={faDownload}
|
||||
175
web/frontend/src/components/CaseBuilder/Psload.tsx
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import DataTable, {
|
||||
ColumnSpec,
|
||||
generateCsv,
|
||||
generateTableColumns,
|
||||
generateTableData,
|
||||
parseCsv,
|
||||
} from "../Common/Forms/DataTable";
|
||||
import { CaseBuilderSectionProps } from "./CaseBuilder";
|
||||
import { useRef } from "react";
|
||||
import FileUploadElement from "../Common/Buttons/FileUploadElement";
|
||||
import { ValidationError } from "../../core/Data/validate";
|
||||
import SectionHeader from "../Common/SectionHeader/SectionHeader";
|
||||
import SectionButton from "../Common/Buttons/SectionButton";
|
||||
import {
|
||||
faDownload,
|
||||
faPlus,
|
||||
faUpload,
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
import { UnitCommitmentScenario } from "../../core/Data/types";
|
||||
import { ColumnDefinition } from "tabulator-tables";
|
||||
import {
|
||||
changePriceSensitiveLoadData,
|
||||
createPriceSensitiveLoad,
|
||||
deletePriceSensitiveLoad,
|
||||
renamePriceSensitiveLoad,
|
||||
} from "../../core/Operations/psloadOps";
|
||||
import { offerDownload } from "../Common/io";
|
||||
|
||||
export const PriceSensitiveLoadsColumnSpec: ColumnSpec[] = [
|
||||
{
|
||||
title: "Name",
|
||||
type: "string",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Bus",
|
||||
type: "busRef",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Revenue ($/MW)",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Demand (MW)",
|
||||
type: "number[T]",
|
||||
width: 70,
|
||||
},
|
||||
];
|
||||
|
||||
export const generatePriceSensitiveLoadsData = (
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [any[], ColumnDefinition[]] => {
|
||||
const columns = generateTableColumns(scenario, PriceSensitiveLoadsColumnSpec);
|
||||
const data = generateTableData(
|
||||
scenario["Price-sensitive loads"],
|
||||
PriceSensitiveLoadsColumnSpec,
|
||||
scenario,
|
||||
);
|
||||
return [data, columns];
|
||||
};
|
||||
|
||||
const PriceSensitiveLoadsComponent = (props: CaseBuilderSectionProps) => {
|
||||
const fileUploadElem = useRef<FileUploadElement>(null);
|
||||
|
||||
const onDownload = () => {
|
||||
const [data, columns] = generatePriceSensitiveLoadsData(props.scenario);
|
||||
const csvContents = generateCsv(data, columns);
|
||||
offerDownload(csvContents, "text/csv", "psloads.csv");
|
||||
};
|
||||
|
||||
const onUpload = () => {
|
||||
fileUploadElem.current!.showFilePicker((csv: any) => {
|
||||
// Parse provided CSV file
|
||||
const [psloads, err] = parseCsv(
|
||||
csv,
|
||||
PriceSensitiveLoadsColumnSpec,
|
||||
props.scenario,
|
||||
);
|
||||
|
||||
// Handle validation errors
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate new scenario
|
||||
props.onDataChanged({
|
||||
...props.scenario,
|
||||
"Price-sensitive loads": psloads,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const onAdd = () => {
|
||||
const [newScenario, err] = createPriceSensitiveLoad(props.scenario);
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return;
|
||||
}
|
||||
props.onDataChanged(newScenario);
|
||||
};
|
||||
|
||||
const onDelete = (name: string): ValidationError | null => {
|
||||
const newScenario = deletePriceSensitiveLoad(name, props.scenario);
|
||||
props.onDataChanged(newScenario);
|
||||
return null;
|
||||
};
|
||||
|
||||
const onDataChanged = (
|
||||
name: string,
|
||||
field: string,
|
||||
newValue: string,
|
||||
): ValidationError | null => {
|
||||
const [newScenario, err] = changePriceSensitiveLoadData(
|
||||
name,
|
||||
field,
|
||||
newValue,
|
||||
props.scenario,
|
||||
);
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return err;
|
||||
}
|
||||
props.onDataChanged(newScenario);
|
||||
return null;
|
||||
};
|
||||
|
||||
const onRename = (
|
||||
oldName: string,
|
||||
newName: string,
|
||||
): ValidationError | null => {
|
||||
const [newScenario, err] = renamePriceSensitiveLoad(
|
||||
oldName,
|
||||
newName,
|
||||
props.scenario,
|
||||
);
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return err;
|
||||
}
|
||||
props.onDataChanged(newScenario);
|
||||
return null;
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SectionHeader title="Price-sensitive loads">
|
||||
<SectionButton icon={faPlus} tooltip="Add" onClick={onAdd} />
|
||||
<SectionButton
|
||||
icon={faDownload}
|
||||
tooltip="Download"
|
||||
onClick={onDownload}
|
||||
/>
|
||||
<SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload} />
|
||||
</SectionHeader>
|
||||
<DataTable
|
||||
onRowDeleted={onDelete}
|
||||
onRowRenamed={onRename}
|
||||
onDataChanged={onDataChanged}
|
||||
generateData={() => generatePriceSensitiveLoadsData(props.scenario)}
|
||||
/>
|
||||
<FileUploadElement ref={fileUploadElem} accept=".csv" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PriceSensitiveLoadsComponent;
|
||||
235
web/frontend/src/components/CaseBuilder/StorageUnits.tsx
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import DataTable, {
|
||||
ColumnSpec,
|
||||
generateCsv,
|
||||
generateTableColumns,
|
||||
generateTableData,
|
||||
parseCsv,
|
||||
} from "../Common/Forms/DataTable";
|
||||
import { CaseBuilderSectionProps } from "./CaseBuilder";
|
||||
import { useRef } from "react";
|
||||
import FileUploadElement from "../Common/Buttons/FileUploadElement";
|
||||
import { ValidationError } from "../../core/Data/validate";
|
||||
import SectionHeader from "../Common/SectionHeader/SectionHeader";
|
||||
import SectionButton from "../Common/Buttons/SectionButton";
|
||||
import {
|
||||
faDownload,
|
||||
faPlus,
|
||||
faUpload,
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
import { UnitCommitmentScenario } from "../../core/Data/types";
|
||||
import { ColumnDefinition } from "tabulator-tables";
|
||||
import {
|
||||
changeStorageUnitData,
|
||||
createStorageUnit,
|
||||
deleteStorageUnit,
|
||||
renameStorageUnit,
|
||||
} from "../../core/Operations/storageOps";
|
||||
import { offerDownload } from "../Common/io";
|
||||
|
||||
export const StorageUnitsColumnSpec: ColumnSpec[] = [
|
||||
{
|
||||
title: "Name",
|
||||
type: "string",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Bus",
|
||||
type: "busRef",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Minimum level (MWh)",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Maximum level (MWh)",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Charge cost ($/MW)",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Discharge cost ($/MW)",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Charge efficiency",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Discharge efficiency",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Loss factor",
|
||||
type: "number",
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
title: "Minimum charge rate (MW)",
|
||||
type: "number",
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
title: "Maximum charge rate (MW)",
|
||||
type: "number",
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
title: "Minimum discharge rate (MW)",
|
||||
type: "number",
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
title: "Maximum discharge rate (MW)",
|
||||
type: "number",
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: "Initial level (MWh)",
|
||||
type: "number",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: "Last period minimum level (MWh)",
|
||||
type: "number",
|
||||
width: 160,
|
||||
},
|
||||
{
|
||||
title: "Last period maximum level (MWh)",
|
||||
type: "number",
|
||||
width: 160,
|
||||
},
|
||||
];
|
||||
|
||||
export const generateStorageUnitsData = (
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [any[], ColumnDefinition[]] => {
|
||||
const columns = generateTableColumns(scenario, StorageUnitsColumnSpec);
|
||||
const data = generateTableData(
|
||||
scenario["Storage units"],
|
||||
StorageUnitsColumnSpec,
|
||||
scenario,
|
||||
);
|
||||
return [data, columns];
|
||||
};
|
||||
|
||||
const StorageUnitsComponent = (props: CaseBuilderSectionProps) => {
|
||||
const fileUploadElem = useRef<FileUploadElement>(null);
|
||||
|
||||
const onDownload = () => {
|
||||
const [data, columns] = generateStorageUnitsData(props.scenario);
|
||||
const csvContents = generateCsv(data, columns);
|
||||
offerDownload(csvContents, "text/csv", "storage_units.csv");
|
||||
};
|
||||
|
||||
const onUpload = () => {
|
||||
fileUploadElem.current!.showFilePicker((csv: any) => {
|
||||
// Parse provided CSV file
|
||||
const [storageUnits, err] = parseCsv(
|
||||
csv,
|
||||
StorageUnitsColumnSpec,
|
||||
props.scenario,
|
||||
);
|
||||
|
||||
// Handle validation errors
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate new scenario
|
||||
props.onDataChanged({
|
||||
...props.scenario,
|
||||
"Storage units": storageUnits,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const onAdd = () => {
|
||||
const [newScenario, err] = createStorageUnit(props.scenario);
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return;
|
||||
}
|
||||
props.onDataChanged(newScenario);
|
||||
};
|
||||
|
||||
const onDelete = (name: string): ValidationError | null => {
|
||||
const newScenario = deleteStorageUnit(name, props.scenario);
|
||||
props.onDataChanged(newScenario);
|
||||
return null;
|
||||
};
|
||||
|
||||
const onDataChanged = (
|
||||
name: string,
|
||||
field: string,
|
||||
newValue: string,
|
||||
): ValidationError | null => {
|
||||
const [newScenario, err] = changeStorageUnitData(
|
||||
name,
|
||||
field,
|
||||
newValue,
|
||||
props.scenario,
|
||||
);
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return err;
|
||||
}
|
||||
props.onDataChanged(newScenario);
|
||||
return null;
|
||||
};
|
||||
|
||||
const onRename = (
|
||||
oldName: string,
|
||||
newName: string,
|
||||
): ValidationError | null => {
|
||||
const [newScenario, err] = renameStorageUnit(
|
||||
oldName,
|
||||
newName,
|
||||
props.scenario,
|
||||
);
|
||||
if (err) {
|
||||
props.onError(err.message);
|
||||
return err;
|
||||
}
|
||||
props.onDataChanged(newScenario);
|
||||
return null;
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SectionHeader title="Storage units">
|
||||
<SectionButton icon={faPlus} tooltip="Add" onClick={onAdd} />
|
||||
<SectionButton
|
||||
icon={faDownload}
|
||||
tooltip="Download"
|
||||
onClick={onDownload}
|
||||
/>
|
||||
<SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload} />
|
||||
</SectionHeader>
|
||||
<DataTable
|
||||
onRowDeleted={onDelete}
|
||||
onRowRenamed={onRename}
|
||||
onDataChanged={onDataChanged}
|
||||
generateData={() => generateStorageUnitsData(props.scenario)}
|
||||
/>
|
||||
<FileUploadElement ref={fileUploadElem} accept=".csv" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default StorageUnitsComponent;
|
||||
@@ -36,7 +36,7 @@ test("generateTableColumns", () => {
|
||||
headerSort: false,
|
||||
headerWordWrap: true,
|
||||
hozAlign: "left",
|
||||
minWidth: 75,
|
||||
minWidth: 80,
|
||||
resizable: false,
|
||||
title: "1",
|
||||
});
|
||||
@@ -228,7 +228,7 @@ const ThermalUnitsComponent = (props: CaseBuilderSectionProps) => {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SectionHeader title="Thermal Units">
|
||||
<SectionHeader title="Thermal units">
|
||||
<SectionButton icon={faPlus} tooltip="Add" onClick={onAdd} />
|
||||
<SectionButton
|
||||
icon={faDownload}
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
changeTransmissionLineData,
|
||||
createTransmissionLine,
|
||||
deleteTransmissionLine,
|
||||
rebuildContingencies,
|
||||
renameTransmissionLine,
|
||||
} from "../../core/Operations/transmissionOps";
|
||||
import { offerDownload } from "../Common/io";
|
||||
@@ -68,6 +69,11 @@ export const TransmissionLinesColumnSpec: ColumnSpec[] = [
|
||||
type: "number",
|
||||
width: 60,
|
||||
},
|
||||
{
|
||||
title: "Contingency?",
|
||||
type: "lineContingency",
|
||||
width: 50,
|
||||
},
|
||||
];
|
||||
|
||||
const generateTransmissionLinesData = (
|
||||
@@ -93,6 +99,7 @@ const TransmissionLinesComponent = (props: CaseBuilderSectionProps) => {
|
||||
|
||||
const onUpload = () => {
|
||||
fileUploadElem.current!.showFilePicker((csv: any) => {
|
||||
// Parse the CSV data
|
||||
const [newLines, err] = parseCsv(
|
||||
csv,
|
||||
TransmissionLinesColumnSpec,
|
||||
@@ -102,9 +109,19 @@ const TransmissionLinesComponent = (props: CaseBuilderSectionProps) => {
|
||||
props.onError(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove contingency field from line and rebuild the contingencies section
|
||||
const lineContingencies = new Set<String>();
|
||||
Object.entries(newLines).forEach(([lineName, line]: [string, any]) => {
|
||||
if (line["Contingency?"]) lineContingencies.add(lineName);
|
||||
delete line["Contingency?"];
|
||||
});
|
||||
const contingencies = rebuildContingencies(lineContingencies);
|
||||
|
||||
const newScenario = {
|
||||
...props.scenario,
|
||||
"Transmission lines": newLines,
|
||||
Contingencies: contingencies,
|
||||
};
|
||||
props.onDataChanged(newScenario);
|
||||
});
|
||||
@@ -163,7 +180,7 @@ const TransmissionLinesComponent = (props: CaseBuilderSectionProps) => {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SectionHeader title="Transmission Lines">
|
||||
<SectionHeader title="Transmission lines">
|
||||
<SectionButton icon={faPlus} tooltip="Add" onClick={onAdd} />
|
||||
<SectionButton
|
||||
icon={faDownload}
|
||||
@@ -5,24 +5,40 @@
|
||||
*/
|
||||
|
||||
.SiteHeaderButton {
|
||||
padding: 6px 36px;
|
||||
padding: 6px 24px;
|
||||
margin: 0 0 0 8px;
|
||||
line-height: 24px;
|
||||
border: var(--box-border);
|
||||
box-shadow: var(--box-shadow);
|
||||
border-radius: var(--border-radius);
|
||||
cursor: pointer;
|
||||
color: var(--contrast-80);
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.light {
|
||||
color: var(--contrast-80);
|
||||
background: linear-gradient(var(--contrast-0) 25%, var(--contrast-10) 100%);
|
||||
}
|
||||
|
||||
.SiteHeaderButton:hover {
|
||||
.light:hover {
|
||||
background: rgb(245, 245, 245);
|
||||
}
|
||||
|
||||
.SiteHeaderButton:active {
|
||||
.light:active {
|
||||
background: rgba(220, 220, 220);
|
||||
}
|
||||
|
||||
.primary {
|
||||
color: white;
|
||||
background: linear-gradient(var(--primary) 25%, color-mix(in hsl, #000, var(--primary) 90%) 100%);
|
||||
}
|
||||
|
||||
.primary:hover {
|
||||
background: color-mix(in hsl, #fff, var(--primary) 90%);
|
||||
}
|
||||
|
||||
.primary:active {
|
||||
background: color-mix(in hsl, #000, var(--primary) 90%);
|
||||
}
|
||||
@@ -9,12 +9,19 @@ import styles from "./SiteHeaderButton.module.css";
|
||||
function SiteHeaderButton({
|
||||
title,
|
||||
onClick,
|
||||
variant = "light",
|
||||
}: {
|
||||
title: string;
|
||||
onClick?: () => void;
|
||||
variant?: "light" | "primary";
|
||||
}) {
|
||||
const variantClass = variant === "primary" ? styles.primary : styles.light;
|
||||
|
||||
return (
|
||||
<button className={styles.SiteHeaderButton} onClick={onClick}>
|
||||
<button
|
||||
className={`${styles.SiteHeaderButton} ${variantClass}`}
|
||||
onClick={onClick}
|
||||
>
|
||||
{title}
|
||||
</button>
|
||||
);
|
||||
@@ -12,8 +12,13 @@ import {
|
||||
} from "tabulator-tables";
|
||||
import { ValidationError } from "../../../core/Data/validate";
|
||||
import Papa from "papaparse";
|
||||
import { parseBool, parseNumber } from "../../../core/Operations/commonOps";
|
||||
import {
|
||||
parseBool,
|
||||
parseNullableNumber,
|
||||
parseNumber,
|
||||
} from "../../../core/Operations/commonOps";
|
||||
import { UnitCommitmentScenario } from "../../../core/Data/types";
|
||||
import { getContingencyTransmissionLines } from "../../../core/Operations/transmissionOps";
|
||||
|
||||
export interface ColumnSpec {
|
||||
title: string;
|
||||
@@ -24,7 +29,8 @@ export interface ColumnSpec {
|
||||
| "number[N]"
|
||||
| "number[T]"
|
||||
| "busRef"
|
||||
| "boolean";
|
||||
| "boolean"
|
||||
| "lineContingency";
|
||||
length?: number;
|
||||
width: number;
|
||||
}
|
||||
@@ -48,6 +54,7 @@ export const generateTableColumns = (
|
||||
});
|
||||
break;
|
||||
case "boolean":
|
||||
case "lineContingency":
|
||||
columns.push({
|
||||
...columnsCommonAttrs,
|
||||
title: spec.title,
|
||||
@@ -113,6 +120,7 @@ export const generateTableData = (
|
||||
): any[] => {
|
||||
const data: any[] = [];
|
||||
const timeslots = generateTimeslots(scenario);
|
||||
let contingencyLines = null;
|
||||
for (const [entryName, entryData] of Object.entries(container) as [
|
||||
string,
|
||||
any,
|
||||
@@ -131,6 +139,12 @@ export const generateTableData = (
|
||||
case "busRef":
|
||||
entry[spec.title] = entryData[spec.title];
|
||||
break;
|
||||
case "lineContingency":
|
||||
if (contingencyLines === null) {
|
||||
contingencyLines = getContingencyTransmissionLines(scenario);
|
||||
}
|
||||
entry[spec.title] = contingencyLines.has(entryName);
|
||||
break;
|
||||
case "number[T]":
|
||||
for (let i = 0; i < timeslots.length; i++) {
|
||||
entry[`${spec.title} ${timeslots[i]}`] = entryData[spec.title][i];
|
||||
@@ -243,6 +257,12 @@ export const parseCsv = (
|
||||
data[name][spec.title] = val;
|
||||
break;
|
||||
}
|
||||
case "number?": {
|
||||
const [val, err] = parseNullableNumber(row[spec.title]);
|
||||
if (err) return [null, { message: err.message + rowRef }];
|
||||
data[name][spec.title] = val;
|
||||
break;
|
||||
}
|
||||
case "busRef":
|
||||
const busName = row[spec.title];
|
||||
if (!(busName in scenario.Buses)) {
|
||||
@@ -277,12 +297,12 @@ export const parseCsv = (
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "boolean": {
|
||||
case "boolean":
|
||||
case "lineContingency":
|
||||
const [val, err] = parseBool(row[spec.title]);
|
||||
if (err) return [data, { message: err.message + rowRef }];
|
||||
data[name][spec.title] = val;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw Error(`Unknown type: ${spec.type}`);
|
||||
}
|
||||
@@ -351,7 +371,7 @@ interface DataTableProps {
|
||||
|
||||
function computeTableHeight(data: any[]): string {
|
||||
const numRows = data.length;
|
||||
const height = 70 + Math.min(numRows, 15) * 28;
|
||||
const height = 70 + Math.max(Math.min(numRows, 15), 1) * 28;
|
||||
return `${height}px`;
|
||||
}
|
||||
|
||||
@@ -359,6 +379,8 @@ const DataTable = (props: DataTableProps) => {
|
||||
const tableContainerRef = useRef<HTMLDivElement | null>(null);
|
||||
const tableRef = useRef<Tabulator | null>(null);
|
||||
const [isTableBuilt, setTableBuilt] = useState<Boolean>(false);
|
||||
const [activeCell, setActiveCell] = useState<CellComponent | null>(null);
|
||||
const [currentTableData, setCurrentTableData] = useState<any[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const onCellEdited = (cell: CellComponent) => {
|
||||
@@ -401,23 +423,65 @@ const DataTable = (props: DataTableProps) => {
|
||||
data: data,
|
||||
columns: columns,
|
||||
height: height,
|
||||
index: "Name",
|
||||
placeholder: "No data",
|
||||
});
|
||||
tableRef.current.on("tableBuilt", () => {
|
||||
setTableBuilt(true);
|
||||
});
|
||||
}
|
||||
|
||||
if (isTableBuilt) {
|
||||
const newHeight = height;
|
||||
const newColumns = columns;
|
||||
const newData = data;
|
||||
const newTableData = data;
|
||||
const oldRows = tableRef.current.getRows();
|
||||
const activeRowPosition = activeCell?.getRow().getPosition() as number;
|
||||
const activeField = activeCell?.getField();
|
||||
|
||||
// Update data
|
||||
tableRef.current.replaceData(newData).then(() => {});
|
||||
if (newTableData.length === currentTableData.length) {
|
||||
const updatedRows = newTableData.filter((_, i) => {
|
||||
return (
|
||||
JSON.stringify(newTableData[i]) !==
|
||||
JSON.stringify(currentTableData[i])
|
||||
);
|
||||
});
|
||||
if (updatedRows.length > 0) {
|
||||
tableRef.current
|
||||
.updateData(updatedRows)
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
// WORKAROUND: Updating the same row twice triggers an exception.
|
||||
// In that case, we just update the whole table.
|
||||
console.log(e);
|
||||
tableRef.current!!.replaceData(newTableData).then(() => {});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
tableRef.current.replaceData(newTableData).then(() => {});
|
||||
}
|
||||
setCurrentTableData(newTableData);
|
||||
|
||||
// Restore active cell selection
|
||||
if (activeCell) {
|
||||
tableRef.current
|
||||
?.getRowFromPosition(activeRowPosition!!)
|
||||
?.getCell(activeField!!)
|
||||
?.edit();
|
||||
}
|
||||
|
||||
// Update columns
|
||||
if (newColumns.length !== tableRef.current.getColumns().length) {
|
||||
let newColCount = 0;
|
||||
newColumns.forEach((col) => {
|
||||
if (col.columns) newColCount += col.columns.length;
|
||||
else newColCount += 1;
|
||||
});
|
||||
if (newColCount !== tableRef.current.getColumns().length) {
|
||||
tableRef.current.setColumns(newColumns);
|
||||
const rows = tableRef.current!.getRows()!;
|
||||
const firstRow = rows[0];
|
||||
if (firstRow) firstRow.scrollTo().then((r) => {});
|
||||
}
|
||||
|
||||
// Update height
|
||||
@@ -435,15 +499,32 @@ const DataTable = (props: DataTableProps) => {
|
||||
}, 10);
|
||||
}
|
||||
|
||||
// Update callbacks
|
||||
// Remove old callbacks
|
||||
tableRef.current.off("cellEdited");
|
||||
tableRef.current.off("cellEditing");
|
||||
tableRef.current.off("cellEditCancelled");
|
||||
|
||||
// Set new callbacks
|
||||
tableRef.current.on("cellEditing", (cell) => {
|
||||
setActiveCell(cell);
|
||||
});
|
||||
|
||||
tableRef.current.on("cellEditCancelled", (cell) => {
|
||||
setActiveCell(null);
|
||||
});
|
||||
|
||||
tableRef.current.on("cellEdited", (cell) => {
|
||||
setActiveCell(null);
|
||||
onCellEdited(cell);
|
||||
});
|
||||
}
|
||||
}, [props, isTableBuilt]);
|
||||
|
||||
return <div className="tableContainer" ref={tableContainerRef} />;
|
||||
return (
|
||||
<div className="tableWrapper">
|
||||
<div ref={tableContainerRef} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DataTable;
|
||||
@@ -4,17 +4,21 @@
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
.FormWrapper {
|
||||
margin: 0 auto;
|
||||
max-width: var(--site-max-width);
|
||||
}
|
||||
|
||||
.Form {
|
||||
background-color: var(--contrast-0);
|
||||
border: var(--box-border);
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--box-shadow);
|
||||
min-height: 48px;
|
||||
margin: 0 auto;
|
||||
margin: 0 12px;
|
||||
min-width: var(--site-min-width);
|
||||
max-width: var(--site-max-width);
|
||||
max-height: 500px;
|
||||
padding: 12px 0;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.FormRow {
|
||||
@@ -8,7 +8,11 @@ import { ReactNode } from "react";
|
||||
import styles from "./Form.module.css";
|
||||
|
||||
function Form({ children }: { children: ReactNode }) {
|
||||
return <div className={styles.Form}>{children}</div>;
|
||||
return (
|
||||
<div className={styles.FormWrapper}>
|
||||
<div className={styles.Form}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Form;
|
||||
@@ -4,16 +4,20 @@
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
.tableWrapper {
|
||||
margin: 0 auto;
|
||||
max-width: var(--site-max-width);
|
||||
}
|
||||
|
||||
.tabulator {
|
||||
background-color: var(--contrast-0);
|
||||
border: var(--box-border) !important;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--box-shadow);
|
||||
min-height: 48px;
|
||||
margin: 0 auto;
|
||||
min-width: var(--site-min-width);
|
||||
max-width: var(--site-max-width);
|
||||
padding: 0;
|
||||
margin: 0 12px;
|
||||
}
|
||||
|
||||
.tabulator .tabulator-header {
|
||||
@@ -79,3 +83,14 @@
|
||||
.tabulator-col-group-cols {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.tabulator-placeholder {
|
||||
width: 100px !important;
|
||||
}
|
||||
|
||||
|
||||
.tabulator-placeholder * {
|
||||
font-weight: normal !important;
|
||||
font-size: 14px !important;
|
||||
color: var(--contrast-60) !important;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import formStyles from "./Form.module.css";
|
||||
import HelpButton from "../Buttons/HelpButton";
|
||||
import React, { useRef, useState } from "react";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { ValidationError } from "../../../core/Data/validate";
|
||||
|
||||
interface TextInputRowProps {
|
||||
@@ -21,6 +21,13 @@ function TextInputRow(props: TextInputRowProps) {
|
||||
const [savedValue, setSavedValue] = useState(props.initialValue);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (inputRef.current) {
|
||||
inputRef.current.value = props.initialValue;
|
||||
}
|
||||
setSavedValue(props.initialValue);
|
||||
}, [props.initialValue]);
|
||||
|
||||
const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
|
||||
const newValue = event.target.value;
|
||||
if (newValue === savedValue) return;
|
||||
@@ -29,8 +36,8 @@ function TextInputRow(props: TextInputRowProps) {
|
||||
inputRef.current!.value = savedValue;
|
||||
return;
|
||||
}
|
||||
setSavedValue(newValue);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={formStyles.FormRow}>
|
||||
<label>
|
||||
@@ -25,7 +25,7 @@ h2 {
|
||||
line-height: 48px;
|
||||
font-size: 28px;
|
||||
margin: 0;
|
||||
padding: 12px;
|
||||
padding: 12px 24px;
|
||||
}
|
||||
|
||||
.HeaderContent h2 {
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
.SectionHeader h1 {
|
||||
margin: 0;
|
||||
padding: 0 12px;
|
||||
padding: 0 24px;
|
||||
font-size: 16px;
|
||||
line-height: 64px;
|
||||
}
|
||||
@@ -21,4 +21,5 @@
|
||||
.SectionButtonsContainer {
|
||||
float: right;
|
||||
height: 64px;
|
||||
margin-right: 12px;
|
||||
}
|
||||
20
web/frontend/src/components/Jobs/Header.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import styles from "../Common/Header.module.css";
|
||||
|
||||
function Header() {
|
||||
return (
|
||||
<div className={styles.HeaderBox}>
|
||||
<div className={styles.HeaderContent}>
|
||||
<h1>UnitCommitment.jl</h1>
|
||||
<h2>Solver</h2>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Header;
|
||||
19
web/frontend/src/components/Jobs/Jobs.module.css
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
.SolverLog {
|
||||
white-space: preserve;
|
||||
font-family: monospace;
|
||||
padding: 12px;
|
||||
background-color: var(--contrast-0);
|
||||
color: var(--contrast-100);
|
||||
border: var(--box-border);
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--box-shadow);
|
||||
height: 40em;
|
||||
overflow: auto;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
93
web/frontend/src/components/Jobs/Jobs.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import { useParams } from "react-router";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import Header from "./Header";
|
||||
import Footer from "../Common/Footer";
|
||||
import SectionHeader from "../Common/SectionHeader/SectionHeader";
|
||||
import styles from "./Jobs.module.css";
|
||||
import formStyles from "../Common/Forms/Form.module.css";
|
||||
|
||||
interface JobData {
|
||||
log: string;
|
||||
solution: any;
|
||||
}
|
||||
|
||||
const Jobs = () => {
|
||||
const { jobId } = useParams();
|
||||
const [jobData, setJobData] = useState<JobData | null>(null);
|
||||
const logRef = useRef<HTMLDivElement>(null);
|
||||
const previousLogRef = useRef<string>("");
|
||||
const intervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchJobData = async () => {
|
||||
const backendUrl = process.env.REACT_APP_BACKEND_URL;
|
||||
const response = await fetch(`${backendUrl}/jobs/${jobId}/view`);
|
||||
if (!response.ok) {
|
||||
console.error(response);
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
if (data.solution) {
|
||||
// Stop polling if solution exists
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
|
||||
// Parse solution
|
||||
data.solution = JSON.parse(data.solution);
|
||||
}
|
||||
|
||||
// Update data
|
||||
setJobData(data);
|
||||
console.log(data);
|
||||
};
|
||||
|
||||
// Fetch immediately
|
||||
fetchJobData();
|
||||
|
||||
// Set up polling every second
|
||||
intervalRef.current = setInterval(fetchJobData, 1000);
|
||||
|
||||
// Cleanup interval on unmount
|
||||
return () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
}
|
||||
};
|
||||
}, [jobId]);
|
||||
|
||||
// Auto-scroll to the bottom when log content changes
|
||||
useEffect(() => {
|
||||
if (jobData?.log && jobData.log !== previousLogRef.current) {
|
||||
previousLogRef.current = jobData.log;
|
||||
if (logRef.current) {
|
||||
logRef.current.scrollTop = logRef.current.scrollHeight;
|
||||
}
|
||||
}
|
||||
}, [jobData?.log]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Header />
|
||||
<div className="content">
|
||||
<SectionHeader title="Optimization log"></SectionHeader>
|
||||
<div className={formStyles.FormWrapper}>
|
||||
<div className={styles.SolverLog} ref={logRef}>
|
||||
{jobData ? jobData.log : "Loading..."}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Jobs;
|
||||
@@ -61,6 +61,38 @@ export const TEST_DATA_1: UnitCommitmentScenario = {
|
||||
"Flow limit penalty ($/MW)": 5000.0,
|
||||
},
|
||||
},
|
||||
"Storage units": {
|
||||
su1: {
|
||||
Bus: "b1",
|
||||
"Minimum level (MWh)": 10.0,
|
||||
"Maximum level (MWh)": 100.0,
|
||||
"Charge cost ($/MW)": 2.0,
|
||||
"Discharge cost ($/MW)": 1.0,
|
||||
"Charge efficiency": 0.8,
|
||||
"Discharge efficiency": 0.85,
|
||||
"Loss factor": 0.01,
|
||||
"Minimum charge rate (MW)": 5.0,
|
||||
"Maximum charge rate (MW)": 10.0,
|
||||
"Minimum discharge rate (MW)": 4.0,
|
||||
"Maximum discharge rate (MW)": 8.0,
|
||||
"Initial level (MWh)": 20.0,
|
||||
"Last period minimum level (MWh)": 21.0,
|
||||
"Last period maximum level (MWh)": 22.0,
|
||||
},
|
||||
},
|
||||
"Price-sensitive loads": {
|
||||
ps1: {
|
||||
Bus: "b3",
|
||||
"Revenue ($/MW)": 23.0,
|
||||
"Demand (MW)": [50, 50, 50, 50, 50],
|
||||
},
|
||||
},
|
||||
Contingencies: {
|
||||
l1: {
|
||||
"Affected generators": [],
|
||||
"Affected lines": ["l1"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const TEST_DATA_2: UnitCommitmentScenario = {
|
||||
@@ -75,8 +107,11 @@ export const TEST_DATA_2: UnitCommitmentScenario = {
|
||||
b2: { "Load (MW)": [10, 20, 30, 40] },
|
||||
b3: { "Load (MW)": [0, 30, 0, 40] },
|
||||
},
|
||||
Contingencies: {},
|
||||
Generators: {},
|
||||
"Transmission lines": {},
|
||||
"Storage units": {},
|
||||
"Price-sensitive loads": {},
|
||||
};
|
||||
|
||||
export const TEST_DATA_BLANK: UnitCommitmentScenario = {
|
||||
@@ -87,8 +122,11 @@ export const TEST_DATA_BLANK: UnitCommitmentScenario = {
|
||||
"Time step (min)": 60,
|
||||
},
|
||||
Buses: {},
|
||||
Contingencies: {},
|
||||
Generators: {},
|
||||
"Transmission lines": {},
|
||||
"Storage units": {},
|
||||
"Price-sensitive loads": {},
|
||||
};
|
||||
|
||||
test("fixtures", () => {});
|
||||
@@ -20,4 +20,7 @@ export const BLANK_SCENARIO: UnitCommitmentScenario = {
|
||||
Buses: {},
|
||||
Generators: {},
|
||||
"Transmission lines": {},
|
||||
"Storage units": {},
|
||||
"Price-sensitive loads": {},
|
||||
Contingencies: {},
|
||||
};
|
||||
@@ -45,6 +45,35 @@ export interface TransmissionLine {
|
||||
"Flow limit penalty ($/MW)": number;
|
||||
}
|
||||
|
||||
export interface StorageUnit {
|
||||
Bus: string;
|
||||
"Minimum level (MWh)": number;
|
||||
"Maximum level (MWh)": number;
|
||||
"Charge cost ($/MW)": number;
|
||||
"Discharge cost ($/MW)": number;
|
||||
"Charge efficiency": number;
|
||||
"Discharge efficiency": number;
|
||||
"Loss factor": number;
|
||||
"Minimum charge rate (MW)": number;
|
||||
"Maximum charge rate (MW)": number;
|
||||
"Minimum discharge rate (MW)": number;
|
||||
"Maximum discharge rate (MW)": number;
|
||||
"Initial level (MWh)": number;
|
||||
"Last period minimum level (MWh)": number;
|
||||
"Last period maximum level (MWh)": number;
|
||||
}
|
||||
|
||||
export interface PriceSensitiveLoad {
|
||||
Bus: string;
|
||||
"Revenue ($/MW)": number;
|
||||
"Demand (MW)": number[];
|
||||
}
|
||||
|
||||
export interface Contingency {
|
||||
"Affected lines": string[];
|
||||
"Affected generators": string[];
|
||||
}
|
||||
|
||||
export interface UnitCommitmentScenario {
|
||||
Parameters: {
|
||||
Version: string;
|
||||
@@ -57,6 +86,15 @@ export interface UnitCommitmentScenario {
|
||||
"Transmission lines": {
|
||||
[name: string]: TransmissionLine;
|
||||
};
|
||||
"Storage units": {
|
||||
[name: string]: StorageUnit;
|
||||
};
|
||||
"Price-sensitive loads": {
|
||||
[name: string]: PriceSensitiveLoad;
|
||||
};
|
||||
Contingencies: {
|
||||
[name: string]: Contingency;
|
||||
};
|
||||
}
|
||||
|
||||
const getTypedGenerators = <T extends any>(
|
||||
@@ -253,6 +253,6 @@ export const assertBusesNotEmpty = (
|
||||
scenario: UnitCommitmentScenario,
|
||||
): ValidationError | null => {
|
||||
if (Object.keys(scenario.Buses).length === 0)
|
||||
return { message: "Profiled unit requires an existing bus." };
|
||||
return { message: "This component requires an existing bus." };
|
||||
return null;
|
||||
};
|
||||
@@ -33,7 +33,7 @@ test("createThermalUnit", () => {
|
||||
test("createProfiledUnit with blank file", () => {
|
||||
const [, err] = createProfiledUnit(TEST_DATA_BLANK);
|
||||
assert(err !== null);
|
||||
assert.equal(err.message, "Profiled unit requires an existing bus.");
|
||||
assert.equal(err.message, "This component requires an existing bus.");
|
||||
});
|
||||
|
||||
test("changeProfiledUnitData", () => {
|
||||
@@ -29,11 +29,29 @@ export const changeTimeHorizon = (
|
||||
Object.values(newScenario.Buses).forEach((bus) => {
|
||||
bus["Load (MW)"] = bus["Load (MW)"].slice(0, newT);
|
||||
});
|
||||
Object.values(newScenario.Generators).forEach((generator) => {
|
||||
if (generator.Type === "Profiled") {
|
||||
generator["Minimum power (MW)"] = generator["Minimum power (MW)"].slice(0, newT);
|
||||
generator["Maximum power (MW)"] = generator["Maximum power (MW)"].slice(0, newT);
|
||||
}
|
||||
});
|
||||
Object.values(newScenario["Price-sensitive loads"]).forEach((psLoad) => {
|
||||
psLoad["Demand (MW)"] = psLoad["Demand (MW)"].slice(0, newT);
|
||||
});
|
||||
} else {
|
||||
const padding = Array(newT - oldT).fill(0);
|
||||
Object.values(newScenario.Buses).forEach((bus) => {
|
||||
bus["Load (MW)"] = bus["Load (MW)"].concat(padding);
|
||||
});
|
||||
Object.values(newScenario.Generators).forEach((generator) => {
|
||||
if (generator.Type === "Profiled") {
|
||||
generator["Minimum power (MW)"] = generator["Minimum power (MW)"].concat(padding);
|
||||
generator["Maximum power (MW)"] = generator["Maximum power (MW)"].concat(padding);
|
||||
}
|
||||
});
|
||||
Object.values(newScenario["Price-sensitive loads"]).forEach((psLoad) => {
|
||||
psLoad["Demand (MW)"] = psLoad["Demand (MW)"].concat(padding);
|
||||
});
|
||||
}
|
||||
return [newScenario, null];
|
||||
};
|
||||
@@ -110,6 +128,62 @@ export const changeTimeStep = (
|
||||
};
|
||||
}
|
||||
|
||||
const newGenerators: { [name: string]: any } = {};
|
||||
for (const generatorName in scenario.Generators) {
|
||||
const generator = scenario.Generators[generatorName]!;
|
||||
if (generator.Type === "Profiled") {
|
||||
// Build data_y for minimum power
|
||||
const minPower = generator["Minimum power (MW)"];
|
||||
const minData_y = Array(oldT + 1).fill(0);
|
||||
for (let i = 0; i < oldT; i++) minData_y[i] = minPower[i];
|
||||
minData_y[oldT] = minData_y[0];
|
||||
|
||||
// Build data_y for maximum power
|
||||
const maxPower = generator["Maximum power (MW)"];
|
||||
const maxData_y = Array(oldT + 1).fill(0);
|
||||
for (let i = 0; i < oldT; i++) maxData_y[i] = maxPower[i];
|
||||
maxData_y[oldT] = maxData_y[0];
|
||||
|
||||
// Run interpolation for both
|
||||
const newMinPower = Array(newT).fill(0);
|
||||
const newMaxPower = Array(newT).fill(0);
|
||||
for (let i = 0; i < newT; i++) {
|
||||
newMinPower[i] = evaluatePwlFunction(data_x, minData_y, newTimeStep * i);
|
||||
newMaxPower[i] = evaluatePwlFunction(data_x, maxData_y, newTimeStep * i);
|
||||
}
|
||||
|
||||
newGenerators[generatorName] = {
|
||||
...generator,
|
||||
"Minimum power (MW)": newMinPower,
|
||||
"Maximum power (MW)": newMaxPower,
|
||||
};
|
||||
} else {
|
||||
newGenerators[generatorName] = generator;
|
||||
}
|
||||
}
|
||||
|
||||
const newPriceSensitiveLoads: { [name: string]: any } = {};
|
||||
for (const psLoadName in scenario["Price-sensitive loads"]) {
|
||||
const psLoad = scenario["Price-sensitive loads"][psLoadName]!;
|
||||
|
||||
// Build data_y for demand
|
||||
const demand = psLoad["Demand (MW)"];
|
||||
const demandData_y = Array(oldT + 1).fill(0);
|
||||
for (let i = 0; i < oldT; i++) demandData_y[i] = demand[i];
|
||||
demandData_y[oldT] = demandData_y[0];
|
||||
|
||||
// Run interpolation for demand
|
||||
const newDemand = Array(newT).fill(0);
|
||||
for (let i = 0; i < newT; i++) {
|
||||
newDemand[i] = evaluatePwlFunction(data_x, demandData_y, newTimeStep * i);
|
||||
}
|
||||
|
||||
newPriceSensitiveLoads[psLoadName] = {
|
||||
...psLoad,
|
||||
"Demand (MW)": newDemand,
|
||||
};
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
@@ -118,6 +192,8 @@ export const changeTimeStep = (
|
||||
"Time step (min)": newTimeStep,
|
||||
},
|
||||
Buses: newBuses,
|
||||
Generators: newGenerators,
|
||||
"Price-sensitive loads": newPriceSensitiveLoads,
|
||||
},
|
||||
null,
|
||||
];
|
||||
@@ -20,7 +20,8 @@ export const PREPROCESSING_TEST_DATA_1: any = {
|
||||
};
|
||||
|
||||
test("preprocess", () => {
|
||||
const newScenario = preprocess(PREPROCESSING_TEST_DATA_1);
|
||||
const [newScenario, err] = preprocess(PREPROCESSING_TEST_DATA_1);
|
||||
assert(err === null);
|
||||
assert.deepEqual(newScenario, {
|
||||
Parameters: {
|
||||
Version: "0.4",
|
||||
@@ -35,5 +36,11 @@ test("preprocess", () => {
|
||||
b2: { "Load (MW)": [10, 10, 10, 10, 10] },
|
||||
b3: { "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268] },
|
||||
},
|
||||
"Price-sensitive loads": {},
|
||||
"Storage units": {},
|
||||
"Transmission lines": {},
|
||||
Contingencies: {},
|
||||
Generators: {},
|
||||
Reserves: {},
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,10 @@
|
||||
import { validate, ValidationError } from "../Data/validate";
|
||||
import { UnitCommitmentScenario } from "../Data/types";
|
||||
import { migrate } from "../Data/migrate";
|
||||
import {
|
||||
getContingencyTransmissionLines,
|
||||
rebuildContingencies,
|
||||
} from "./transmissionOps";
|
||||
|
||||
export const preprocess = (
|
||||
data: any,
|
||||
@@ -41,6 +45,26 @@ export const preprocess = (
|
||||
}
|
||||
}
|
||||
|
||||
// Add optional fields
|
||||
for (let field of [
|
||||
"Buses",
|
||||
"Generators",
|
||||
"Storage units",
|
||||
"Price-sensitive loads",
|
||||
"Transmission lines",
|
||||
"Reserves",
|
||||
"Contingencies",
|
||||
]) {
|
||||
if (!result[field]) {
|
||||
result[field] = {};
|
||||
}
|
||||
}
|
||||
|
||||
const scenario = result as unknown as UnitCommitmentScenario;
|
||||
|
||||
// Rebuild contingencies
|
||||
const contingencyLines = getContingencyTransmissionLines(scenario);
|
||||
scenario["Contingencies"] = rebuildContingencies(contingencyLines);
|
||||
|
||||
return [scenario, null];
|
||||
};
|
||||
60
web/frontend/src/core/Operations/psloadOps.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import { TEST_DATA_1 } from "../Data/fixtures.test";
|
||||
import assert from "node:assert";
|
||||
import {
|
||||
changePriceSensitiveLoadData,
|
||||
createPriceSensitiveLoad,
|
||||
deletePriceSensitiveLoad,
|
||||
renamePriceSensitiveLoad,
|
||||
} from "./psloadOps";
|
||||
import { ValidationError } from "../Data/validate";
|
||||
|
||||
test("createPriceSensitiveLoad", () => {
|
||||
const [newScenario, err] = createPriceSensitiveLoad(TEST_DATA_1);
|
||||
assert(err === null);
|
||||
assert.equal(Object.keys(newScenario["Price-sensitive loads"]).length, 2);
|
||||
assert("ps2" in newScenario["Price-sensitive loads"]);
|
||||
});
|
||||
|
||||
test("renamePriceSensitiveLoad", () => {
|
||||
const [newScenario, err] = renamePriceSensitiveLoad(
|
||||
"ps1",
|
||||
"ps2",
|
||||
TEST_DATA_1,
|
||||
);
|
||||
assert(err === null);
|
||||
assert.deepEqual(
|
||||
newScenario["Price-sensitive loads"]["ps2"],
|
||||
TEST_DATA_1["Price-sensitive loads"]["ps1"],
|
||||
);
|
||||
assert.equal(Object.keys(newScenario["Price-sensitive loads"]).length, 1);
|
||||
});
|
||||
|
||||
test("changePriceSensitiveLoadData", () => {
|
||||
let scenario = TEST_DATA_1;
|
||||
let err: ValidationError | null;
|
||||
[scenario, err] = changePriceSensitiveLoadData("ps1", "Bus", "b3", scenario);
|
||||
assert.equal(err, null);
|
||||
[scenario, err] = changePriceSensitiveLoadData(
|
||||
"ps1",
|
||||
"Demand (MW) 00:00",
|
||||
"99",
|
||||
scenario,
|
||||
);
|
||||
assert.equal(err, null);
|
||||
assert.deepEqual(scenario["Price-sensitive loads"]["ps1"], {
|
||||
Bus: "b3",
|
||||
"Revenue ($/MW)": 23,
|
||||
"Demand (MW)": [99, 50, 50, 50, 50],
|
||||
});
|
||||
});
|
||||
|
||||
test("deletePriceSensitiveLoad", () => {
|
||||
const newScenario = deletePriceSensitiveLoad("ps1", TEST_DATA_1);
|
||||
assert.equal(Object.keys(newScenario["Price-sensitive loads"]).length, 0);
|
||||
});
|
||||
@@ -4,35 +4,34 @@
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import { ValidationError } from "../Data/validate";
|
||||
import { PriceSensitiveLoad, UnitCommitmentScenario } from "../Data/types";
|
||||
import {
|
||||
assertBusesNotEmpty,
|
||||
changeData,
|
||||
generateUniqueName,
|
||||
renameItemInObject,
|
||||
} from "./commonOps";
|
||||
import { ValidationError } from "../Data/validate";
|
||||
import { TransmissionLinesColumnSpec } from "../../components/CaseBuilder/TransmissionLines";
|
||||
import { TransmissionLine, UnitCommitmentScenario } from "../Data/types";
|
||||
import { PriceSensitiveLoadsColumnSpec } from "../../components/CaseBuilder/Psload";
|
||||
import { generateTimeslots } from "../../components/Common/Forms/DataTable";
|
||||
|
||||
export const createTransmissionLine = (
|
||||
export const createPriceSensitiveLoad = (
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const err = assertBusesNotEmpty(scenario);
|
||||
if (err) return [scenario, err];
|
||||
const busName = Object.keys(scenario.Buses)[0]!;
|
||||
const name = generateUniqueName(scenario["Transmission lines"], "l");
|
||||
const timeslots = generateTimeslots(scenario);
|
||||
const name = generateUniqueName(scenario["Price-sensitive loads"], "ps");
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
"Transmission lines": {
|
||||
...scenario["Transmission lines"],
|
||||
"Price-sensitive loads": {
|
||||
...scenario["Price-sensitive loads"],
|
||||
[name]: {
|
||||
"Source bus": busName,
|
||||
"Target bus": busName,
|
||||
"Susceptance (S)": 1.0,
|
||||
"Normal flow limit (MW)": 1000,
|
||||
"Emergency flow limit (MW)": 1500,
|
||||
"Flow limit penalty ($/MW)": 5000.0,
|
||||
Bus: busName,
|
||||
"Revenue ($/MW)": 0,
|
||||
"Demand (MW)": Array(timeslots.length).fill(0),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -40,50 +39,50 @@ export const createTransmissionLine = (
|
||||
];
|
||||
};
|
||||
|
||||
export const renameTransmissionLine = (
|
||||
export const renamePriceSensitiveLoad = (
|
||||
oldName: string,
|
||||
newName: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const [newLine, err] = renameItemInObject(
|
||||
const [newObj, err] = renameItemInObject(
|
||||
oldName,
|
||||
newName,
|
||||
scenario["Transmission lines"],
|
||||
scenario["Price-sensitive loads"],
|
||||
);
|
||||
if (err) return [scenario, err];
|
||||
return [{ ...scenario, "Transmission lines": newLine }, null];
|
||||
return [{ ...scenario, "Price-sensitive loads": newObj }, null];
|
||||
};
|
||||
|
||||
export const changeTransmissionLineData = (
|
||||
line: string,
|
||||
export const changePriceSensitiveLoadData = (
|
||||
name: string,
|
||||
field: string,
|
||||
newValueStr: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const [newLine, err] = changeData(
|
||||
const [newObj, err] = changeData(
|
||||
field,
|
||||
newValueStr,
|
||||
scenario["Transmission lines"][line]!,
|
||||
TransmissionLinesColumnSpec,
|
||||
scenario["Price-sensitive loads"][name]!,
|
||||
PriceSensitiveLoadsColumnSpec,
|
||||
scenario,
|
||||
);
|
||||
if (err) return [scenario, err];
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
"Transmission lines": {
|
||||
...scenario["Transmission lines"],
|
||||
[line]: newLine as TransmissionLine,
|
||||
"Price-sensitive loads": {
|
||||
...scenario["Price-sensitive loads"],
|
||||
[name]: newObj as PriceSensitiveLoad,
|
||||
},
|
||||
},
|
||||
null,
|
||||
];
|
||||
};
|
||||
|
||||
export const deleteTransmissionLine = (
|
||||
export const deletePriceSensitiveLoad = (
|
||||
name: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): UnitCommitmentScenario => {
|
||||
const { [name]: _, ...newLines } = scenario["Transmission lines"];
|
||||
return { ...scenario, "Transmission lines": newLines };
|
||||
const { [name]: _, ...newContainer } = scenario["Price-sensitive loads"];
|
||||
return { ...scenario, "Price-sensitive loads": newContainer };
|
||||
};
|
||||
75
web/frontend/src/core/Operations/storageOps.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import { TEST_DATA_1 } from "../Data/fixtures.test";
|
||||
import assert from "node:assert";
|
||||
import {
|
||||
changeStorageUnitData,
|
||||
createStorageUnit,
|
||||
deleteStorageUnit,
|
||||
renameStorageUnit,
|
||||
} from "./storageOps";
|
||||
import { ValidationError } from "../Data/validate";
|
||||
|
||||
test("createStorageUnit", () => {
|
||||
const [newScenario, err] = createStorageUnit(TEST_DATA_1);
|
||||
assert(err === null);
|
||||
assert.equal(Object.keys(newScenario["Storage units"]).length, 2);
|
||||
assert("su2" in newScenario["Storage units"]);
|
||||
});
|
||||
|
||||
test("renameStorageUnit", () => {
|
||||
const [newScenario, err] = renameStorageUnit("su1", "su2", TEST_DATA_1);
|
||||
assert(err === null);
|
||||
assert.deepEqual(
|
||||
newScenario["Storage units"]["su2"],
|
||||
TEST_DATA_1["Storage units"]["su1"],
|
||||
);
|
||||
assert.equal(Object.keys(newScenario["Storage units"]).length, 1);
|
||||
});
|
||||
|
||||
test("changeStorageUnitData", () => {
|
||||
let scenario = TEST_DATA_1;
|
||||
let err: ValidationError | null;
|
||||
[scenario, err] = changeStorageUnitData("su1", "Bus", "b3", scenario);
|
||||
assert.equal(err, null);
|
||||
[scenario, err] = changeStorageUnitData(
|
||||
"su1",
|
||||
"Minimum level (MWh)",
|
||||
"99",
|
||||
scenario,
|
||||
);
|
||||
assert.equal(err, null);
|
||||
[scenario, err] = changeStorageUnitData(
|
||||
"su1",
|
||||
"Maximum discharge rate (MW)",
|
||||
"99",
|
||||
scenario,
|
||||
);
|
||||
assert.equal(err, null);
|
||||
assert.deepEqual(scenario["Storage units"]["su1"], {
|
||||
Bus: "b3",
|
||||
"Minimum level (MWh)": 99.0,
|
||||
"Maximum level (MWh)": 100.0,
|
||||
"Charge cost ($/MW)": 2.0,
|
||||
"Discharge cost ($/MW)": 1.0,
|
||||
"Charge efficiency": 0.8,
|
||||
"Discharge efficiency": 0.85,
|
||||
"Loss factor": 0.01,
|
||||
"Minimum charge rate (MW)": 5.0,
|
||||
"Maximum charge rate (MW)": 10.0,
|
||||
"Minimum discharge rate (MW)": 4.0,
|
||||
"Maximum discharge rate (MW)": 99.0,
|
||||
"Initial level (MWh)": 20.0,
|
||||
"Last period minimum level (MWh)": 21.0,
|
||||
"Last period maximum level (MWh)": 22.0,
|
||||
});
|
||||
});
|
||||
|
||||
test("deleteStorageUnit", () => {
|
||||
const newScenario = deleteStorageUnit("su1", TEST_DATA_1);
|
||||
assert.equal(Object.keys(newScenario["Storage units"]).length, 0);
|
||||
});
|
||||
98
web/frontend/src/core/Operations/storageOps.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import { ValidationError } from "../Data/validate";
|
||||
import { StorageUnit, UnitCommitmentScenario } from "../Data/types";
|
||||
import {
|
||||
assertBusesNotEmpty,
|
||||
changeData,
|
||||
generateUniqueName,
|
||||
renameItemInObject,
|
||||
} from "./commonOps";
|
||||
import { StorageUnitsColumnSpec } from "../../components/CaseBuilder/StorageUnits";
|
||||
|
||||
export const createStorageUnit = (
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const err = assertBusesNotEmpty(scenario);
|
||||
if (err) return [scenario, err];
|
||||
const busName = Object.keys(scenario.Buses)[0]!;
|
||||
const name = generateUniqueName(scenario["Storage units"], "su");
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
"Storage units": {
|
||||
...scenario["Storage units"],
|
||||
[name]: {
|
||||
Bus: busName,
|
||||
"Minimum level (MWh)": 0,
|
||||
"Maximum level (MWh)": 1,
|
||||
"Charge cost ($/MW)": 0.0,
|
||||
"Discharge cost ($/MW)": 0.0,
|
||||
"Charge efficiency": 1,
|
||||
"Discharge efficiency": 1,
|
||||
"Loss factor": 0,
|
||||
"Minimum charge rate (MW)": 1,
|
||||
"Maximum charge rate (MW)": 1,
|
||||
"Minimum discharge rate (MW)": 1,
|
||||
"Maximum discharge rate (MW)": 1,
|
||||
"Initial level (MWh)": 0,
|
||||
"Last period minimum level (MWh)": 0,
|
||||
"Last period maximum level (MWh)": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
];
|
||||
};
|
||||
|
||||
export const renameStorageUnit = (
|
||||
oldName: string,
|
||||
newName: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const [newObj, err] = renameItemInObject(
|
||||
oldName,
|
||||
newName,
|
||||
scenario["Storage units"],
|
||||
);
|
||||
if (err) return [scenario, err];
|
||||
return [{ ...scenario, "Storage units": newObj }, null];
|
||||
};
|
||||
|
||||
export const changeStorageUnitData = (
|
||||
name: string,
|
||||
field: string,
|
||||
newValueStr: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const [newObj, err] = changeData(
|
||||
field,
|
||||
newValueStr,
|
||||
scenario["Storage units"][name]!,
|
||||
StorageUnitsColumnSpec,
|
||||
scenario,
|
||||
);
|
||||
if (err) return [scenario, err];
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
"Storage units": {
|
||||
...scenario["Storage units"],
|
||||
[name]: newObj as StorageUnit,
|
||||
},
|
||||
},
|
||||
null,
|
||||
];
|
||||
};
|
||||
|
||||
export const deleteStorageUnit = (
|
||||
name: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): UnitCommitmentScenario => {
|
||||
const { [name]: _, ...newContainer } = scenario["Storage units"];
|
||||
return { ...scenario, "Storage units": newContainer };
|
||||
};
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
changeTransmissionLineData,
|
||||
createTransmissionLine,
|
||||
deleteTransmissionLine,
|
||||
getContingencyTransmissionLines,
|
||||
rebuildContingencies,
|
||||
renameTransmissionLine,
|
||||
} from "./transmissionOps";
|
||||
import { ValidationError } from "../Data/validate";
|
||||
@@ -32,6 +34,12 @@ test("renameTransmissionLine", () => {
|
||||
"Emergency flow limit (MW)": 20000.0,
|
||||
"Flow limit penalty ($/MW)": 5000.0,
|
||||
});
|
||||
assert.deepEqual(newScenario["Contingencies"], {
|
||||
l3: {
|
||||
"Affected lines": ["l3"],
|
||||
"Affected generators": [],
|
||||
},
|
||||
});
|
||||
assert.equal(Object.keys(newScenario["Transmission lines"]).length, 1);
|
||||
});
|
||||
|
||||
@@ -72,4 +80,23 @@ test("changeTransmissionLineData", () => {
|
||||
test("deleteTransmissionLine", () => {
|
||||
const newScenario = deleteTransmissionLine("l1", TEST_DATA_1);
|
||||
assert.equal(Object.keys(newScenario["Transmission lines"]).length, 0);
|
||||
assert.equal(Object.keys(newScenario["Contingencies"]).length, 0);
|
||||
});
|
||||
|
||||
test("getContingencyTransmissionLines", () => {
|
||||
const contLines = getContingencyTransmissionLines(TEST_DATA_1);
|
||||
assert.deepEqual(contLines, new Set(["l1"]));
|
||||
});
|
||||
|
||||
test("rebuildContingencies", () => {
|
||||
assert.deepEqual(rebuildContingencies(new Set(["l1", "l2"])), {
|
||||
l1: {
|
||||
"Affected lines": ["l1"],
|
||||
"Affected generators": [],
|
||||
},
|
||||
l2: {
|
||||
"Affected lines": ["l2"],
|
||||
"Affected generators": [],
|
||||
},
|
||||
});
|
||||
});
|
||||
163
web/frontend/src/core/Operations/transmissionOps.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||
* Released under the modified BSD license. See COPYING.md for more details.
|
||||
*/
|
||||
|
||||
import {
|
||||
assertBusesNotEmpty,
|
||||
changeData,
|
||||
generateUniqueName,
|
||||
parseBool,
|
||||
renameItemInObject,
|
||||
} from "./commonOps";
|
||||
import { ValidationError } from "../Data/validate";
|
||||
import { TransmissionLinesColumnSpec } from "../../components/CaseBuilder/TransmissionLines";
|
||||
import {
|
||||
Contingency,
|
||||
TransmissionLine,
|
||||
UnitCommitmentScenario,
|
||||
} from "../Data/types";
|
||||
|
||||
export const createTransmissionLine = (
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const err = assertBusesNotEmpty(scenario);
|
||||
if (err) return [scenario, err];
|
||||
const busName = Object.keys(scenario.Buses)[0]!;
|
||||
const name = generateUniqueName(scenario["Transmission lines"], "l");
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
"Transmission lines": {
|
||||
...scenario["Transmission lines"],
|
||||
[name]: {
|
||||
"Source bus": busName,
|
||||
"Target bus": busName,
|
||||
"Susceptance (S)": 1.0,
|
||||
"Normal flow limit (MW)": 1000,
|
||||
"Emergency flow limit (MW)": 1500,
|
||||
"Flow limit penalty ($/MW)": 5000.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
];
|
||||
};
|
||||
|
||||
export const renameTransmissionLine = (
|
||||
oldName: string,
|
||||
newName: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const [newLine, err] = renameItemInObject(
|
||||
oldName,
|
||||
newName,
|
||||
scenario["Transmission lines"],
|
||||
);
|
||||
if (err) return [scenario, err];
|
||||
|
||||
// Update transmission line contingencies
|
||||
let newContingencies = scenario["Contingencies"];
|
||||
const contingencyLines = getContingencyTransmissionLines(scenario);
|
||||
if (contingencyLines.has(oldName)) {
|
||||
contingencyLines.delete(oldName);
|
||||
contingencyLines.add(newName);
|
||||
newContingencies = rebuildContingencies(contingencyLines);
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
"Transmission lines": newLine,
|
||||
Contingencies: newContingencies,
|
||||
},
|
||||
null,
|
||||
];
|
||||
};
|
||||
|
||||
export const changeTransmissionLineData = (
|
||||
line: string,
|
||||
field: string,
|
||||
newValueStr: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
if (field === "Contingency?") {
|
||||
// Parse boolean value
|
||||
const [newValue, err] = parseBool(newValueStr);
|
||||
if (err) return [scenario, err];
|
||||
|
||||
// Rebuild contingencies
|
||||
const contLines = getContingencyTransmissionLines(scenario);
|
||||
if (newValue) contLines.add(line);
|
||||
else contLines.delete(line);
|
||||
const newContingencies = rebuildContingencies(contLines);
|
||||
|
||||
return [{ ...scenario, Contingencies: newContingencies }, null];
|
||||
} else {
|
||||
const [newLine, err] = changeData(
|
||||
field,
|
||||
newValueStr,
|
||||
scenario["Transmission lines"][line]!,
|
||||
TransmissionLinesColumnSpec,
|
||||
scenario,
|
||||
);
|
||||
if (err) return [scenario, err];
|
||||
return [
|
||||
{
|
||||
...scenario,
|
||||
"Transmission lines": {
|
||||
...scenario["Transmission lines"],
|
||||
[line]: newLine as TransmissionLine,
|
||||
},
|
||||
},
|
||||
null,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteTransmissionLine = (
|
||||
name: string,
|
||||
scenario: UnitCommitmentScenario,
|
||||
): UnitCommitmentScenario => {
|
||||
const { [name]: _, ...newLines } = scenario["Transmission lines"];
|
||||
|
||||
// Update transmission line contingencies
|
||||
let newContingencies = scenario["Contingencies"];
|
||||
const contingencyLines = getContingencyTransmissionLines(scenario);
|
||||
if (contingencyLines.has(name)) {
|
||||
contingencyLines.delete(name);
|
||||
newContingencies = rebuildContingencies(contingencyLines);
|
||||
}
|
||||
|
||||
return {
|
||||
...scenario,
|
||||
"Transmission lines": newLines,
|
||||
Contingencies: newContingencies,
|
||||
};
|
||||
};
|
||||
|
||||
export const getContingencyTransmissionLines = (
|
||||
scenario: UnitCommitmentScenario,
|
||||
): Set<String> => {
|
||||
let result: Set<String> = new Set();
|
||||
Object.entries(scenario.Contingencies).forEach(([name, contingency]) => {
|
||||
if (contingency["Affected lines"].length !== 1)
|
||||
throw Error("not implemented");
|
||||
result.add(contingency["Affected lines"][0]!!);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
export const rebuildContingencies = (
|
||||
contingencyLines: Set<String>,
|
||||
): { [name: string]: Contingency } => {
|
||||
const result: { [name: string]: Contingency } = {};
|
||||
contingencyLines.forEach((lineName) => {
|
||||
result[lineName as string] = {
|
||||
"Affected lines": [lineName as string],
|
||||
"Affected generators": [],
|
||||
};
|
||||
});
|
||||
return result;
|
||||
};
|
||||
@@ -8,15 +8,23 @@ import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import reportWebVitals from "./reportWebVitals";
|
||||
import CaseBuilder from "./components/CaseBuilder/CaseBuilder";
|
||||
import { BrowserRouter, Navigate, Route, Routes } from "react-router";
|
||||
import Jobs from "./components/Jobs/Jobs";
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById("root") as HTMLElement,
|
||||
);
|
||||
|
||||
root.render(
|
||||
<BrowserRouter>
|
||||
<React.StrictMode>
|
||||
<CaseBuilder />
|
||||
</React.StrictMode>,
|
||||
<Routes>
|
||||
<Route path="/builder" element={<CaseBuilder />} />
|
||||
<Route path="/jobs/:jobId" element={<Jobs />} />
|
||||
<Route path="/" element={<Navigate to="/builder" replace />} />
|
||||
</Routes>
|
||||
</React.StrictMode>
|
||||
</BrowserRouter>,
|
||||
);
|
||||
|
||||
reportWebVitals();
|
||||
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
@@ -29,7 +29,6 @@
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"checkJs": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
Before Width: | Height: | Size: 3.8 KiB |