UNPKG

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

26 lines (25 loc) 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mutationFunction = void 0; const utils_1 = require("./utils"); const mutationFunction = (props) => (phenotype) => { const { totalDuration, mutationRate } = props; const timeAdjustment = (low, mid, high) => { return (0, utils_1.random)(0.1 * (low - mid), 0.1 * (high - mid)); }; return { periods: phenotype.periods.map((gene, node) => { const g = { ...gene }; if (Math.random() < mutationRate) { // Mutate action g.activity = (0, utils_1.generateRandomActivity)(gene.activity); } if (gene.start > 0 && Math.random() < mutationRate) { g.start += timeAdjustment(node.previous.data.start + 1, gene.start, node.next ? node.next.data.start : totalDuration); } return g; }), excessPvEnergyUse: phenotype.excessPvEnergyUse, }; }; exports.mutationFunction = mutationFunction;