24小时正态分布,中午高峰?
Distribute load via normal distribution over 24 hours with the peak at noon?
我正在尝试在一天中的每个小时内不均匀地分配负载,并在有更多人可用时在中午左右进行峰值处理。基本上,我想要一个 "Normal Distribution" 的任务而不是一个简单的 n / 24 = hourly load
。
目标是大部分工作需要在中午进行,清晨和深夜的工作较少。
这是我目前为止制作的曲线。
// Number per day
const numberPerDay = 600;
const numberPerHour = numberPerDay / 24;
let total = 0;
for (let hour = 1; hour < 24; hour++) {
// Normal Distribution should be higher at 12pm / noon
// This Inverse bell-curve is higher at 1am and 11pm
const max = Math.min(24 - hour, hour);
const min = Math.max(hour, 24 - hour);
const penalty = Math.max(1, Math.abs(max - min));
const percentage = Math.floor(100 * ((penalty - 1) / (24 - 1)));
const number = Math.floor(numberPerHour - (numberPerHour * percentage / 100));
console.log(`hour: ${hour}, penalty: ${penalty}, number: ${number}`);
total += number;
}
console.log('Expected for today:', numberPerDay);
console.log('Actual for today:', total);
直播jsfiddle.
产生这样的东西:
你需要实现一个高斯函数。以下 link 可能会有所帮助:
https://math.stackexchange.com/questions/1236727/the-x-y-coordinates-for-points-on-a-bell-curve-normal-distribution
您需要选择均值和标准差 (sigma)。这是我找到的一个片段:
//taken from Jason Davies science library
// https://github.com/jasondavies/science.js/
function gaussian(x) {
var gaussianConstant = 1 / Math.sqrt(2 * Math.PI),
mean = 0,
sigma = 1;
x = (x - mean) / sigma;
return gaussianConstant * Math.exp(-.5 * x * x) / sigma;
};
https://gist.github.com/phil-pedruco/88cb8a51cdce45f13c7e
要使其达到 0-24,请将均值设置为 12 并调整 sigma 以根据需要尽可能多地展开曲线。您还需要稍微缩放 "y" 值。
更新
我已经为您创建了一个 JS Fiddle 来绘制我认为您需要的内容。
https://jsfiddle.net/arwmxc69/2/
var data = [];
var scaleFactor = 600
mean = 12,
sigma = 4;
function gaussian(x) {
var gaussianConstant = 1 / Math.sqrt(2 * Math.PI);
x = (x - mean) / sigma;
return gaussianConstant * Math.exp(-.5 * x * x) / sigma;
};
for(x=0;x<24;x+=1) {
var y = gaussian(x)
data.push({x:x,y:y*scaleFactor});
}
我想你可以接受近似值。在那种情况下,类似 y=sin(pi*x)^4 的东西可能是一个相对较好(且简单)的解决方案。然后可以通过将 y 提高到接近 1 的某个幂来使该分布更宽或更窄。
此外,它是循环的,因此可以通过执行类似
的操作来帮助实施
y = (sin(pi*hour/24))^4
并扩展以适应 600 个职位。
我正在尝试在一天中的每个小时内不均匀地分配负载,并在有更多人可用时在中午左右进行峰值处理。基本上,我想要一个 "Normal Distribution" 的任务而不是一个简单的 n / 24 = hourly load
。
目标是大部分工作需要在中午进行,清晨和深夜的工作较少。
这是我目前为止制作的曲线。
// Number per day
const numberPerDay = 600;
const numberPerHour = numberPerDay / 24;
let total = 0;
for (let hour = 1; hour < 24; hour++) {
// Normal Distribution should be higher at 12pm / noon
// This Inverse bell-curve is higher at 1am and 11pm
const max = Math.min(24 - hour, hour);
const min = Math.max(hour, 24 - hour);
const penalty = Math.max(1, Math.abs(max - min));
const percentage = Math.floor(100 * ((penalty - 1) / (24 - 1)));
const number = Math.floor(numberPerHour - (numberPerHour * percentage / 100));
console.log(`hour: ${hour}, penalty: ${penalty}, number: ${number}`);
total += number;
}
console.log('Expected for today:', numberPerDay);
console.log('Actual for today:', total);
直播jsfiddle.
产生这样的东西:
你需要实现一个高斯函数。以下 link 可能会有所帮助: https://math.stackexchange.com/questions/1236727/the-x-y-coordinates-for-points-on-a-bell-curve-normal-distribution
您需要选择均值和标准差 (sigma)。这是我找到的一个片段:
//taken from Jason Davies science library
// https://github.com/jasondavies/science.js/
function gaussian(x) {
var gaussianConstant = 1 / Math.sqrt(2 * Math.PI),
mean = 0,
sigma = 1;
x = (x - mean) / sigma;
return gaussianConstant * Math.exp(-.5 * x * x) / sigma;
};
https://gist.github.com/phil-pedruco/88cb8a51cdce45f13c7e
要使其达到 0-24,请将均值设置为 12 并调整 sigma 以根据需要尽可能多地展开曲线。您还需要稍微缩放 "y" 值。
更新
我已经为您创建了一个 JS Fiddle 来绘制我认为您需要的内容。 https://jsfiddle.net/arwmxc69/2/
var data = [];
var scaleFactor = 600
mean = 12,
sigma = 4;
function gaussian(x) {
var gaussianConstant = 1 / Math.sqrt(2 * Math.PI);
x = (x - mean) / sigma;
return gaussianConstant * Math.exp(-.5 * x * x) / sigma;
};
for(x=0;x<24;x+=1) {
var y = gaussian(x)
data.push({x:x,y:y*scaleFactor});
}
我想你可以接受近似值。在那种情况下,类似 y=sin(pi*x)^4 的东西可能是一个相对较好(且简单)的解决方案。然后可以通过将 y 提高到接近 1 的某个幂来使该分布更宽或更窄。
此外,它是循环的,因此可以通过执行类似
的操作来帮助实施y = (sin(pi*hour/24))^4
并扩展以适应 600 个职位。