A simulation tool for modeling a simplified electrical grid with various types of power plants and consumers. The tool uses a linear programming solver to optimize costs for all connected entities.
The simulation supports the following entities:
- Grid: Manages excess energy by producing or consuming as needed.
- Producer: Generates energy with defined capacity and efficiency constraints.
- Consumer: Requires energy to be supplied at specific timesteps.
- Storage: Stores surplus energy for later use, with configurable charging and discharging rules.
The grid is defined by the following parameters:
name(string): Grid identifiercost_prod(array): Production costs per timesteppower_prod(array): Production capacities per timestepcost_cons(array): Consumption costs per timesteppower_cons(array): Consumption capacities per timestepentity_type(string): Must be "Grid"
name(string): Consumer identifierpower_cons(array): Consumption demands per timestepeff_cons(array): Consumption efficiencies per timestepcost_cons(array): Consumption costs per timestepentity_type(string): Must be "Consumer"
name(string): Producer identifiercan_be_disabled(boolean): Indicates whether the producer can be disabledpower_prod(array): Production capacities per timestepeff_prod(array): Production efficiencies per timestepcost_prod(array): Production costs per timestepentity_type(string): Must be "Producer"
name(string): Storage identifierpower_prod(array): Production capacities per timestepeff_prod(array): Production efficiencies per timestepcost_prod(array): Production costs per timesteppower_cons(array): Consumption capacities per timestepeff_cons(array): Consumption efficiencies per timestepcost_cons(array): Consumption costs per timestepstorage_capacity(float): Maximum energy storage capacitystart_capacity(float): Initial stored energyend_capacity(float, optional): Final stored energystorage_to_grid_allowed(boolean): Whether storage can supply energy to the grid (default:false)grid_to_storage_allowed(boolean): Whether the grid can charge the storage (default:false)entity_type(string): Must be "Storage"
All numerical parameters must be provided as arrays. The value for a given timestep is determined using the following approach:
let index = timestep % array.len();
let value = array[index];
return value;- Single-value array (
length = 1): Applies a constant value across all timesteps. - Hourly values (
length = 24): Specifies a unique value for each hour of the day. - Custom periodicities: Arrays of varying lengths can be used to define specific repeating patterns.
This flexibility allows for realistic modeling of energy consumption and production patterns.
Compile the project using Cargo:
cargo build --releaseRun the test suite with:
cargo testTo use the solver, create a JSON file containing all the entities. The file structure is as follows:
{
"entities": [
{
"name": "Grid",
"cost_prod": [1.0],
"power_prod": [10.0],
"cost_cons": [-1.0],
"power_cons": [10.0],
"entity_type": "Grid"
},
...
],
"timesteps": 24
}Then, run the solver with:
./target/release/solver < path_to_json > path_to_outputThis project depends on good_lp for formulating and solving linear programs.