Compare commits

..

No commits in common. '1b37af82e394a75f8cf998e8b543311bf5bbaf0d' and '8397571c111f00cbbf5925f702a7f624e9ee899f' have entirely different histories.

@ -30,7 +30,7 @@ import {
createBus, createBus,
deleteBus, deleteBus,
renameBus, renameBus,
} from "../../../core/Operations/busOps"; } from "../../../core/Operations/busOperations";
export const BusesColumnSpec: ColumnSpec[] = [ export const BusesColumnSpec: ColumnSpec[] = [
{ {

@ -12,7 +12,7 @@ import {
changeParameter, changeParameter,
changeTimeHorizon, changeTimeHorizon,
changeTimeStep, changeTimeStep,
} from "../../../core/Operations/parameterOps"; } from "../../../core/Operations/parameterOperations";
interface ParametersProps { interface ParametersProps {
scenario: UnitCommitmentScenario; scenario: UnitCommitmentScenario;

@ -23,13 +23,7 @@ import { ColumnDefinition } from "tabulator-tables";
import { offerDownload } from "../../Common/io"; import { offerDownload } from "../../Common/io";
import FileUploadElement from "../../Common/Buttons/FileUploadElement"; import FileUploadElement from "../../Common/Buttons/FileUploadElement";
import { useRef } from "react"; import { useRef } from "react";
import { import { createProfiledUnit } from "../../../core/Operations/profiledUnitOps";
changeProfiledUnitData,
createProfiledUnit,
deleteGenerator,
renameGenerator,
} from "../../../core/Operations/generatorOps";
import { ValidationError } from "../../../core/Validation/validate";
interface ProfiledUnitsProps { interface ProfiledUnitsProps {
scenario: UnitCommitmentScenario; scenario: UnitCommitmentScenario;
@ -37,7 +31,7 @@ interface ProfiledUnitsProps {
onError: (msg: string) => void; onError: (msg: string) => void;
} }
export const ProfiledUnitsColumnSpec: ColumnSpec[] = [ const ProfiledUnitsColumnSpec: ColumnSpec[] = [
{ {
title: "Name", title: "Name",
type: "string", type: "string",
@ -45,7 +39,7 @@ export const ProfiledUnitsColumnSpec: ColumnSpec[] = [
}, },
{ {
title: "Bus", title: "Bus",
type: "busRef", type: "string",
width: 150, width: 150,
}, },
{ {
@ -114,48 +108,6 @@ const ProfiledUnitsComponent = (props: ProfiledUnitsProps) => {
props.onDataChanged(newScenario); props.onDataChanged(newScenario);
}; };
const onDelete = (name: string): ValidationError | null => {
const newScenario = deleteGenerator(name, props.scenario);
props.onDataChanged(newScenario);
return null;
};
const onDataChanged = (
name: string,
field: string,
newValue: string,
): ValidationError | null => {
const [newScenario, err] = changeProfiledUnitData(
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] = renameGenerator(
oldName,
newName,
props.scenario,
);
if (err) {
props.onError(err.message);
return err;
}
props.onDataChanged(newScenario);
return null;
};
return ( return (
<div> <div>
<SectionHeader title="Profiled Units"> <SectionHeader title="Profiled Units">
@ -168,9 +120,15 @@ const ProfiledUnitsComponent = (props: ProfiledUnitsProps) => {
<SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload} /> <SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload} />
</SectionHeader> </SectionHeader>
<DataTable <DataTable
onRowDeleted={onDelete} onRowDeleted={() => {
onRowRenamed={onRename} return null;
onDataChanged={onDataChanged} }}
onRowRenamed={() => {
return null;
}}
onDataChanged={() => {
return null;
}}
generateData={() => generateProfiledUnitsData(props.scenario)} generateData={() => generateProfiledUnitsData(props.scenario)}
/> />
<FileUploadElement ref={fileUploadElem} accept=".csv" /> <FileUploadElement ref={fileUploadElem} accept=".csv" />

@ -16,7 +16,7 @@ import Papa from "papaparse";
export interface ColumnSpec { export interface ColumnSpec {
title: string; title: string;
type: "string" | "number" | "number[]" | "busRef"; type: "string" | "number" | "number[]";
width: number; width: number;
} }
@ -29,7 +29,6 @@ export const generateTableColumns = (
colSpecs.forEach((spec) => { colSpecs.forEach((spec) => {
switch (spec.type) { switch (spec.type) {
case "string": case "string":
case "busRef":
columns.push({ columns.push({
...columnsCommonAttrs, ...columnsCommonAttrs,
title: spec.title, title: spec.title,
@ -63,7 +62,7 @@ export const generateTableColumns = (
}); });
break; break;
default: default:
throw Error(`Unknown type: ${spec.type}`); console.error(`Unknown type: ${spec.type}`);
} }
}); });
return columns; return columns;
@ -89,7 +88,6 @@ export const generateTableData = (
switch (spec.type) { switch (spec.type) {
case "string": case "string":
case "number": case "number":
case "busRef":
entry[spec.title] = entryData[spec.title]; entry[spec.title] = entryData[spec.title];
break; break;
case "number[]": case "number[]":

@ -4,7 +4,12 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import { changeBusData, createBus, deleteBus, renameBus } from "./busOps"; import {
changeBusData,
createBus,
deleteBus,
renameBus,
} from "./busOperations";
import assert from "node:assert"; import assert from "node:assert";
import { TEST_DATA_1 } from "../fixtures.test"; import { TEST_DATA_1 } from "../fixtures.test";
@ -35,7 +40,7 @@ test("changeBusData", () => {
test("changeBusData with invalid numbers", () => { test("changeBusData with invalid numbers", () => {
let [, err] = changeBusData("b1", "Load (MW) 00:00", "xx", TEST_DATA_1); let [, err] = changeBusData("b1", "Load (MW) 00:00", "xx", TEST_DATA_1);
assert(err !== null); assert(err !== null);
assert.equal(err.message, '"xx" is not a valid number'); assert.equal(err.message, "Invalid value: xx");
}); });
test("deleteBus", () => { test("deleteBus", () => {
@ -60,5 +65,5 @@ test("renameBus", () => {
test("renameBus with duplicated name", () => { test("renameBus with duplicated name", () => {
let [, err] = renameBus("b3", "b1", TEST_DATA_1); let [, err] = renameBus("b3", "b1", TEST_DATA_1);
assert(err != null); assert(err != null);
assert.equal(err.message, `b1 already exists`); assert.equal(err.message, `Bus b1 already exists`);
}); });

@ -0,0 +1,104 @@
/*
* 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 { Buses, UnitCommitmentScenario } from "../fixtures";
import { ValidationError } from "../Validation/validate";
import { generateTimeslots } from "../../components/Common/Forms/DataTable";
export const generateUniqueName = (container: any, prefix: string): string => {
let counter = 1;
let name = `${prefix}${counter}`;
while (name in container) {
counter++;
name = `${prefix}${counter}`;
}
return name;
};
export const createBus = (scenario: UnitCommitmentScenario) => {
const name = generateUniqueName(scenario.Buses, "b");
const timeslots = generateTimeslots(scenario);
return {
...scenario,
Buses: {
...scenario.Buses,
[name]: {
"Load (MW)": Array(timeslots.length).fill(0),
},
},
};
};
export const changeBusData = (
bus: string,
field: string,
newValueStr: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
// Load (MW)
const match = field.match(/Load \(MW\) (\d+):(\d+)/);
if (match) {
const newValueFloat = parseFloat(newValueStr);
if (isNaN(newValueFloat)) {
return [scenario, { message: `Invalid value: ${newValueStr}` }];
}
// Convert HH:MM to offset
const hours = parseInt(match[1]!, 10);
const min = parseInt(match[2]!, 10);
const idx = (hours * 60 + min) / scenario.Parameters["Time step (min)"];
const newLoad = [...scenario.Buses[bus]!["Load (MW)"]];
newLoad[idx] = newValueFloat;
return [
{
...scenario,
Buses: {
...scenario.Buses,
[bus]: {
"Load (MW)": newLoad,
},
},
},
null,
];
}
throw Error(`Unknown field: ${field}`);
};
export const deleteBus = (bus: string, scenario: UnitCommitmentScenario) => {
const { [bus]: _, ...newBuses } = scenario.Buses;
return {
...scenario,
Buses: newBuses,
};
};
export const renameBus = (
oldName: string,
newName: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
if (newName in scenario.Buses) {
return [scenario, { message: `Bus ${newName} already exists` }];
}
const newBuses: Buses = Object.keys(scenario.Buses).reduce((acc, val) => {
if (val === oldName) {
acc[newName] = scenario.Buses[val]!;
} else {
acc[val] = scenario.Buses[val]!;
}
return acc;
}, {} as Buses);
return [
{
...scenario,
Buses: newBuses,
},
null,
];
};

@ -1,70 +0,0 @@
/*
* 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 { Buses, UnitCommitmentScenario } from "../fixtures";
import { ValidationError } from "../Validation/validate";
import { generateTimeslots } from "../../components/Common/Forms/DataTable";
import {
changeData,
generateUniqueName,
renameItemInObject,
} from "./commonOps";
import { BusesColumnSpec } from "../../components/CaseBuilder/Buses/Buses";
export const createBus = (scenario: UnitCommitmentScenario) => {
const name = generateUniqueName(scenario.Buses, "b");
const timeslots = generateTimeslots(scenario);
return {
...scenario,
Buses: {
...scenario.Buses,
[name]: {
"Load (MW)": Array(timeslots.length).fill(0),
},
},
};
};
export const changeBusData = (
bus: string,
field: string,
newValueStr: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
const [newBus, err] = changeData(
field,
newValueStr,
scenario.Buses[bus]!,
BusesColumnSpec,
scenario,
);
if (err) return [scenario, err];
return [
{
...scenario,
Buses: {
...scenario.Buses,
[bus]: newBus,
} as Buses,
},
null,
];
};
export const deleteBus = (bus: string, scenario: UnitCommitmentScenario) => {
const { [bus]: _, ...newBuses } = scenario.Buses;
return { ...scenario, Buses: newBuses };
};
export const renameBus = (
oldName: string,
newName: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
const [newBuses, err] = renameItemInObject(oldName, newName, scenario.Buses);
if (err) return [scenario, err];
return [{ ...scenario, Buses: newBuses }, null];
};

@ -1,157 +0,0 @@
/*
* 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 "../Validation/validate";
import { UnitCommitmentScenario } from "../fixtures";
import { ColumnSpec } from "../../components/Common/Forms/DataTable";
export const renameItemInObject = <T>(
oldName: string,
newName: string,
container: { [key: string]: T },
): [{ [key: string]: T }, ValidationError | null] => {
if (newName in container) {
return [container, { message: `${newName} already exists` }];
}
const newContainer = Object.keys(container).reduce(
(acc, val) => {
if (val === oldName) {
acc[newName] = container[val]!;
} else {
acc[val] = container[val]!;
}
return acc;
},
{} as { [key: string]: T },
);
return [newContainer, null];
};
export const generateUniqueName = (container: any, prefix: string): string => {
let counter = 1;
let name = `${prefix}${counter}`;
while (name in container) {
counter++;
name = `${prefix}${counter}`;
}
return name;
};
const parseNumber = (valueStr: string): [number, ValidationError | null] => {
const valueFloat = parseFloat(valueStr);
if (isNaN(valueFloat)) {
return [0, { message: `"${valueStr}" is not a valid number` }];
} else {
return [valueFloat, null];
}
};
export const changeStringData = (
field: string,
newValue: string,
container: { [key: string]: any },
): [{ [key: string]: any }, ValidationError | null] => {
return [
{
...container,
[field]: newValue,
},
null,
];
};
export const changeBusRefData = (
field: string,
newValue: string,
container: { [key: string]: any },
scenario: UnitCommitmentScenario,
): [{ [key: string]: any }, ValidationError | null] => {
if (!(newValue in scenario.Buses)) {
return [scenario, { message: `Bus "${newValue}" does not exist` }];
}
return changeStringData(field, newValue, container);
};
export const changeNumberData = (
field: string,
newValueStr: string,
container: { [key: string]: any },
): [{ [key: string]: any }, ValidationError | null] => {
// Parse value
const [newValueFloat, err] = parseNumber(newValueStr);
if (err) return [container, err];
// Build the new object
return [
{
...container,
[field]: newValueFloat,
},
null,
];
};
export const changeNumberVecData = (
field: string,
time: string,
newValueStr: string,
container: { [key: string]: any },
scenario: UnitCommitmentScenario,
): [{ [key: string]: any }, ValidationError | null] => {
// Parse value
const [newValueFloat, err] = parseNumber(newValueStr);
if (err) return [container, err];
// Convert HH:MM to offset
const hours = parseInt(time.split(":")[0]!, 10);
const min = parseInt(time.split(":")[1]!, 10);
const idx = (hours * 60 + min) / scenario.Parameters["Time step (min)"];
// Build the new vector
const newVec = [...container[field]];
newVec[idx] = newValueFloat;
return [
{
...container,
[field]: newVec,
},
null,
];
};
export const changeData = (
field: string,
newValueStr: string,
container: { [key: string]: any },
colSpecs: ColumnSpec[],
scenario: UnitCommitmentScenario,
): [{ [key: string]: any }, ValidationError | null] => {
const match = field.match(/^([^0-9]+)(\d+:\d+)?$/);
const fieldName = match![1]!.trim();
const fieldTime = match![2];
for (const spec of colSpecs) {
if (spec.title !== fieldName) continue;
switch (spec.type) {
case "string":
return changeStringData(fieldName, newValueStr, container);
case "busRef":
return changeBusRefData(fieldName, newValueStr, container, scenario);
case "number":
return changeNumberData(fieldName, newValueStr, container);
case "number[]":
return changeNumberVecData(
fieldName,
fieldTime!,
newValueStr,
container,
scenario,
);
default:
throw Error(`Unknown type: ${spec.type}`);
}
}
throw Error(`Unknown field: ${fieldName}`);
};

@ -1,127 +0,0 @@
/*
* 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, TEST_DATA_BLANK } from "../fixtures.test";
import assert from "node:assert";
import {
changeProfiledUnitData,
createProfiledUnit,
deleteGenerator,
renameGenerator,
} from "./generatorOps";
test("createProfiledUnit", () => {
const [newScenario, err] = createProfiledUnit(TEST_DATA_1);
assert(err === null);
assert.deepEqual(newScenario.Generators, {
pu1: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 12.5,
"Maximum power (MW)": [10, 12, 13, 15, 20],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
pu2: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 120,
"Maximum power (MW)": [50, 50, 50, 50, 50],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
pu3: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 0,
"Maximum power (MW)": [0, 0, 0, 0, 0],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
});
});
test("createProfiledUnit with blank file", () => {
const [, err] = createProfiledUnit(TEST_DATA_BLANK);
assert(err !== null);
assert.equal(err.message, "Profiled unit requires an existing bus.");
});
test("changeProfiledUnitData", () => {
let scenario = TEST_DATA_1;
let err = null;
[scenario, err] = changeProfiledUnitData(
"pu1",
"Cost ($/MW)",
"99",
scenario,
);
assert.equal(err, null);
[scenario, err] = changeProfiledUnitData(
"pu1",
"Maximum power (MW) 03:00",
"99",
scenario,
);
assert.equal(err, null);
[scenario, err] = changeProfiledUnitData("pu2", "Bus", "b3", scenario);
assert.equal(err, null);
assert.deepEqual(scenario.Generators, {
pu1: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 99,
"Maximum power (MW)": [10, 12, 13, 99, 20],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
pu2: {
Bus: "b3",
Type: "Profiled",
"Cost ($/MW)": 120,
"Maximum power (MW)": [50, 50, 50, 50, 50],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
});
});
test("changeProfiledUnitData with invalid bus", () => {
let scenario = TEST_DATA_1;
let err = null;
[scenario, err] = changeProfiledUnitData("pu1", "Bus", "b99", scenario);
assert(err !== null);
assert.equal(err.message, 'Bus "b99" does not exist');
});
test("deleteGenerator", () => {
const newScenario = deleteGenerator("pu1", TEST_DATA_1);
assert.deepEqual(newScenario.Generators, {
pu2: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 120,
"Maximum power (MW)": [50, 50, 50, 50, 50],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
});
});
test("renameGenerator", () => {
const [newScenario, err] = renameGenerator("pu1", "pu5", TEST_DATA_1);
assert(err === null);
assert.deepEqual(newScenario.Generators, {
pu5: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 12.5,
"Maximum power (MW)": [10, 12, 13, 15, 20],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
pu2: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 120,
"Maximum power (MW)": [50, 50, 50, 50, 50],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
});
});

@ -1,90 +0,0 @@
/*
* 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 { Generators, UnitCommitmentScenario } from "../fixtures";
import { generateTimeslots } from "../../components/Common/Forms/DataTable";
import { ValidationError } from "../Validation/validate";
import {
changeData,
generateUniqueName,
renameItemInObject,
} from "./commonOps";
import { ProfiledUnitsColumnSpec } from "../../components/CaseBuilder/ProfiledUnits/ProfiledUnits";
export const createProfiledUnit = (
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
const busNames = Object.keys(scenario.Buses);
if (busNames.length === 0) {
return [scenario, { message: "Profiled unit requires an existing bus." }];
}
const timeslots = generateTimeslots(scenario);
const name = generateUniqueName(scenario.Generators, "pu");
return [
{
...scenario,
Generators: {
...scenario.Generators,
[name]: {
Bus: busNames[0]!,
Type: "Profiled",
"Cost ($/MW)": 0,
"Minimum power (MW)": Array(timeslots.length).fill(0),
"Maximum power (MW)": Array(timeslots.length).fill(0),
},
},
},
null,
];
};
export const changeProfiledUnitData = (
generator: string,
field: string,
newValueStr: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
const [newGen, err] = changeData(
field,
newValueStr,
scenario.Generators[generator]!,
ProfiledUnitsColumnSpec,
scenario,
);
if (err) return [scenario, err];
return [
{
...scenario,
Generators: {
...scenario.Generators,
[generator]: newGen,
} as Generators,
},
null,
];
};
export const deleteGenerator = (
name: string,
scenario: UnitCommitmentScenario,
): UnitCommitmentScenario => {
const { [name]: _, ...newGenerators } = scenario.Generators;
return { ...scenario, Generators: newGenerators };
};
export const renameGenerator = (
oldName: string,
newName: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
const [newGen, err] = renameItemInObject(
oldName,
newName,
scenario.Generators,
);
if (err) return [scenario, err];
return [{ ...scenario, Generators: newGen }, null];
};

@ -8,7 +8,7 @@ import {
changeTimeHorizon, changeTimeHorizon,
changeTimeStep, changeTimeStep,
evaluatePwlFunction, evaluatePwlFunction,
} from "./parameterOps"; } from "./parameterOperations";
import assert from "node:assert"; import assert from "node:assert";
import { TEST_DATA_1, TEST_DATA_2 } from "../fixtures.test"; import { TEST_DATA_1, TEST_DATA_2 } from "../fixtures.test";
@ -31,16 +31,18 @@ test("changeTimeHorizon: Shrink 1", () => {
test("changeTimeHorizon: Shrink 2", () => { test("changeTimeHorizon: Shrink 2", () => {
const [newScenario, err] = changeTimeHorizon(TEST_DATA_2, "1"); const [newScenario, err] = changeTimeHorizon(TEST_DATA_2, "1");
assert(err === null); assert(err === null);
assert.deepEqual(newScenario.Parameters, { assert.deepEqual(newScenario, {
Version: "0.4", Parameters: {
"Power balance penalty ($/MW)": 1000.0, Version: "0.4",
"Time horizon (h)": 1, "Power balance penalty ($/MW)": 1000.0,
"Time step (min)": 30, "Time horizon (h)": 1,
}); "Time step (min)": 30,
assert.deepEqual(newScenario.Buses, { },
b1: { "Load (MW)": [30, 30] }, Buses: {
b2: { "Load (MW)": [10, 20] }, b1: { "Load (MW)": [30, 30] },
b3: { "Load (MW)": [0, 30] }, b2: { "Load (MW)": [10, 20] },
b3: { "Load (MW)": [0, 30] },
},
}); });
}); });
@ -89,30 +91,34 @@ test("evaluatePwlFunction", () => {
test("changeTimeStep", () => { test("changeTimeStep", () => {
let [scenario, err] = changeTimeStep(TEST_DATA_2, "15"); let [scenario, err] = changeTimeStep(TEST_DATA_2, "15");
assert(err === null); assert(err === null);
assert.deepEqual(scenario.Parameters, { assert.deepEqual(scenario, {
Version: "0.4", Parameters: {
"Power balance penalty ($/MW)": 1000.0, Version: "0.4",
"Time horizon (h)": 2, "Power balance penalty ($/MW)": 1000.0,
"Time step (min)": 15, "Time horizon (h)": 2,
}); "Time step (min)": 15,
assert.deepEqual(scenario.Buses, { },
b1: { "Load (MW)": [30, 30, 30, 30, 30, 30, 30, 30] }, Buses: {
b2: { "Load (MW)": [10, 15, 20, 25, 30, 35, 40, 25] }, b1: { "Load (MW)": [30, 30, 30, 30, 30, 30, 30, 30] },
b3: { "Load (MW)": [0, 15, 30, 15, 0, 20, 40, 20] }, b2: { "Load (MW)": [10, 15, 20, 25, 30, 35, 40, 25] },
b3: { "Load (MW)": [0, 15, 30, 15, 0, 20, 40, 20] },
},
}); });
[scenario, err] = changeTimeStep(TEST_DATA_2, "60"); [scenario, err] = changeTimeStep(TEST_DATA_2, "60");
assert(err === null); assert(err === null);
assert.deepEqual(scenario.Parameters, { assert.deepEqual(scenario, {
Version: "0.4", Parameters: {
"Power balance penalty ($/MW)": 1000.0, Version: "0.4",
"Time horizon (h)": 2, "Power balance penalty ($/MW)": 1000.0,
"Time step (min)": 60, "Time horizon (h)": 2,
}); "Time step (min)": 60,
assert.deepEqual(scenario.Buses, { },
b1: { "Load (MW)": [30, 30] }, Buses: {
b2: { "Load (MW)": [10, 30] }, b1: { "Load (MW)": [30, 30] },
b3: { "Load (MW)": [0, 0] }, b2: { "Load (MW)": [10, 30] },
b3: { "Load (MW)": [0, 0] },
},
}); });
}); });

@ -0,0 +1,36 @@
/*
* 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, TEST_DATA_BLANK } from "../fixtures.test";
import assert from "node:assert";
import { createProfiledUnit } from "./profiledUnitOps";
test("createUnit", () => {
const [newScenario, err] = createProfiledUnit(TEST_DATA_1);
assert(err === null);
assert.deepEqual(newScenario.Generators, {
pu1: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 12.5,
"Maximum power (MW)": [10, 12, 13, 15, 20],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
pu2: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 0,
"Maximum power (MW)": [0, 0, 0, 0, 0],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
});
});
test("createUnit with blank file", () => {
const [newScenario, err] = createProfiledUnit(TEST_DATA_BLANK);
assert(err !== null);
assert.equal(err.message, "Profiled unit requires an existing bus.");
});

@ -0,0 +1,37 @@
/*
* 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 { UnitCommitmentScenario } from "../fixtures";
import { generateTimeslots } from "../../components/Common/Forms/DataTable";
import { generateUniqueName } from "./busOperations";
import { ValidationError } from "../Validation/validate";
export const createProfiledUnit = (
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
const busNames = Object.keys(scenario.Buses);
if (busNames.length === 0) {
return [scenario, { message: "Profiled unit requires an existing bus." }];
}
const timeslots = generateTimeslots(scenario);
const name = generateUniqueName(scenario.Generators, "pu");
return [
{
...scenario,
Generators: {
...scenario.Generators,
[name]: {
Bus: busNames[0]!,
Type: "Profiled",
"Cost ($/MW)": 0,
"Minimum power (MW)": Array(timeslots.length).fill(0),
"Maximum power (MW)": Array(timeslots.length).fill(0),
},
},
},
null,
];
};

@ -20,13 +20,6 @@ export const TEST_DATA_1: UnitCommitmentScenario = {
"Maximum power (MW)": [10, 12, 13, 15, 20], "Maximum power (MW)": [10, 12, 13, 15, 20],
"Minimum power (MW)": [0, 0, 0, 0, 0], "Minimum power (MW)": [0, 0, 0, 0, 0],
}, },
pu2: {
Bus: "b1",
Type: "Profiled",
"Cost ($/MW)": 120,
"Maximum power (MW)": [50, 50, 50, 50, 50],
"Minimum power (MW)": [0, 0, 0, 0, 0],
},
}, },
}; };
@ -42,7 +35,6 @@ export const TEST_DATA_2: UnitCommitmentScenario = {
b2: { "Load (MW)": [10, 20, 30, 40] }, b2: { "Load (MW)": [10, 20, 30, 40] },
b3: { "Load (MW)": [0, 30, 0, 40] }, b3: { "Load (MW)": [0, 30, 0, 40] },
}, },
Generators: {},
}; };
export const TEST_DATA_BLANK: UnitCommitmentScenario = { export const TEST_DATA_BLANK: UnitCommitmentScenario = {

@ -28,7 +28,7 @@ export interface UnitCommitmentScenario {
"Time step (min)": number; "Time step (min)": number;
}; };
Buses: Buses; Buses: Buses;
Generators: Generators; Generators?: Generators;
} }
export const BLANK_SCENARIO: UnitCommitmentScenario = { export const BLANK_SCENARIO: UnitCommitmentScenario = {

Loading…
Cancel
Save