node-red-contrib-genetic-charging-strategy
Version:
A module for Node-RED that adds a battery charging strategy to node-red-contrib-power-saver. It uses genetic algorithms to find the best schedule
30 lines (29 loc) • 988 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.crossoverFunction = void 0;
const schedule_1 = require("./schedule");
const utils_1 = require("./utils");
const crossoverFunction = (props) => (phenotypeA, phenotypeB) => {
const { totalDuration } = props;
const midpoint = (0, utils_1.random)(0, totalDuration);
const childGenes = new schedule_1.DoublyLinkedList();
phenotypeA.periods.reduce((acc, data) => {
if (data.start <= midpoint) {
acc.insertBack(data);
}
return acc;
}, childGenes);
phenotypeB.periods.reduce((acc, data) => {
if (data.start > midpoint) {
acc.insertBack(data);
}
return acc;
}, childGenes);
return [
{
periods: childGenes,
excessPvEnergyUse: Math.random() < 0.5 ? phenotypeA.excessPvEnergyUse : phenotypeB.excessPvEnergyUse,
},
];
};
exports.crossoverFunction = crossoverFunction;