parent
8397571c11
commit
86aababf33
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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";
|
||||
|
||||
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;
|
||||
};
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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,
|
||||
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("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,36 +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 { 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.");
|
||||
});
|
Loading…
Reference in new issue