我正在尝试生成一些测试数据。
假设我有1000个约会需要安排在一段日期范围内。
现在我需要安排这些约会,使得月底每天的约会数量是月初的两倍。预约的增加速度需要保持一致。
举个例子,如果某月的第一天有5个约会,到月底时我们每天将会收到10个约会。
预约只能在工作日进行。
有没有一个合适的算法可以帮助我以这种方式分配这些日期?
编辑
这是我迄今为止在亨利克斯解决方案的激励下最出色的:
private int GetNumForCurrentDate (DateTime date)
{
int daysInMonth = DateTime.DaysInMonth ( date.Year, date.Month );
// x is the number of appointments on the first day
double firstDay = this._NumPerMonth / ( ( ( ratio + 1 ) / 2 ) * daysInMonth );
// x * ratio is the number of appointments on the last day.
double lastDay = firstDay * ratio;
// Interpolate a value between the first and last days
double exactNumOnThisDay = firstDay + ( lastDay - firstDay ) * ( (double)date.Day / (double)daysInMonth );
int numOnThisDay = Convert.ToInt32 ( Math.Truncate ( exactNumOnThisDay ) );
// Accumulate any overflow
this._Overflow += exactNumOnThisDay - numOnThisDay;
if ( this._Overflow > 1 )
{
// Shove the overflow into our number when it gets into whole number teritory
numOnThisDay++;
this._Overflow--;
}
return numOnThisDay;
}
It returns the number of days to allocate on a particular day given the date. It deals with separating out the allocations to each month and handles rounding overflow, but its not quite perfect, it runs out of days to allocate on the last day, but it is good enough for now and Ive run out of time to perfect it..