mod context;
mod enrich;
mod hvdc_q;
mod issues;
mod network;
mod policy;
mod reserves;
pub mod types;
mod voltage;
pub use context::{
AcLineInitialState, BranchRef, DcLineInitialState, DcLineReactiveBounds,
DcLineReactiveSupportResources, GoC3Context, GoC3DeviceKind, TransformerInitialState,
};
pub use enrich::enrich_network;
pub use hvdc_q::apply_hvdc_reactive_terminals;
pub use issues::{GoC3Issue, GoC3IssueSeverity};
pub use network::{to_network, to_network_with_policy};
pub use policy::{
GoC3AcReconcileMode, GoC3CommitmentMode, GoC3ConsumerMode, GoC3Formulation, GoC3Policy,
GoC3ScucLossTreatment, GoC3SecurityCutStrategy, GoC3SlackInferenceMode,
};
pub use reserves::apply_reserves;
pub use types::*;
pub use voltage::apply_voltage_regulation;
use std::io::BufReader;
use std::path::Path;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON parse error: {0}")]
Json(#[from] serde_json::Error),
#[error("GO C3 conversion error: {0}")]
Conversion(String),
}
pub fn load_problem(path: impl AsRef<Path>) -> Result<GoC3Problem, Error> {
let path = path.as_ref();
let file = std::fs::File::open(path)?;
let reader = BufReader::new(file);
let problem: GoC3Problem = serde_json::from_reader(reader)?;
Ok(problem)
}
pub fn load_problem_str(content: &str) -> Result<GoC3Problem, Error> {
let problem: GoC3Problem = serde_json::from_str(content)?;
Ok(problem)
}
pub fn load_network(
path: impl AsRef<Path>,
) -> Result<(surge_network::Network, GoC3Context), Error> {
let problem = load_problem(path)?;
to_network(&problem)
}
pub fn load_enriched_network(
path: impl AsRef<Path>,
policy: &GoC3Policy,
) -> Result<(surge_network::Network, GoC3Context), Error> {
let problem = load_problem(path)?;
let (mut network, mut context) = to_network_with_policy(&problem, policy)?;
enrich_network(&mut network, &mut context, &problem, policy)?;
apply_reserves(&mut network, &mut context, &problem)?;
apply_hvdc_reactive_terminals(&mut network, &mut context, &problem, policy)?;
apply_voltage_regulation(&mut network, &mut context, &problem, policy)?;
Ok((network, context))
}
pub fn save_solution(solution: &GoC3Solution, path: impl AsRef<Path>) -> Result<(), Error> {
let file = std::fs::File::create(path.as_ref())?;
serde_json::to_writer_pretty(file, solution)?;
Ok(())
}
pub fn dumps_solution(solution: &GoC3Solution) -> Result<String, Error> {
let json = serde_json::to_string_pretty(solution)?;
Ok(json)
}