【问题标题】:Distributing appointments over a date range在日期范围内分配约会
【发布时间】:2010-02-11 12:59:54
【问题描述】:

我正在尝试生成一些测试数据。

假设我需要在一个日期范围内分配 1000 个约会。

现在我需要分配这些约会,使月底每天的约会数量是月初的两倍。约会的增加需要以一致的速度增加。

因此,例如,如果每月 1 日有 5 个约会,那么到月底,我们每天将获得 10 个约会。

约会只能在工作日进行。

有没有合适的算法可以帮助我以这种方式分发这些日期?

编辑

这是迄今为止我得到的最好的,受 Henriks 解决方案的启发:

    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;
    }

它返回在给定日期的特定日期分配的天数。 它负责分离每个月的分配并处理舍入溢出,但它不是很完美,在最后一天分配的天数已经用完了,但现在已经足够好了,我已经没有时间来完善它了。 .

【问题讨论】:

  • "如果一个月的第一天有 5 次预约,到月底我们将获得每月 10 次预约" --- 这是每月还是每天,因为你在你的问题的不同地方有不同的说法。谢谢
  • 对不起.. 明显的错字!我的意思是每天10个。已编辑。感谢您发现 ;)

标签: algorithm date test-data


【解决方案1】:

第一天预约 x 次,最后一天预约 2 次,因此平均 1.5 倍。 当有 y 个工作日时,x 为 1000 / (1.5y)。 所以第一天是 667/y,最后一天是 1333/y,对中间的日子进行插值

【讨论】:

  • 我想你忘记了一个要求:“约会的增加需要以一致的速度增加(不是线性的)。”这是 f''(x) = c。你的是 f(x) = cx, f'(x) = c, f''(x) = 0。
  • @Thomas:也许你是对的。我误读了“增加增加”。
  • @Thomas:但是根据这种解释,问题是不确定的,我的解决方案仍然是正确的,因为 f'' = 0 = const. :)
  • 这种增加的增加真的很不错。我只是想了解数学并实施您的解决方案(太多年的数据库编程对我的数学大脑造成了严重破坏!)
猜你喜欢
  • 2014-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-15
相关资源
最近更新 更多