Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 在日期范围内分配约会_Algorithm_Date_Test Data - Fatal编程技术网

Algorithm 在日期范围内分配约会

Algorithm 在日期范围内分配约会,algorithm,date,test-data,Algorithm,Date,Test Data,我正在尝试生成一些测试数据 假设我有1000个约会需要在某个日期范围内分配 现在我需要分配这些预约,以便在月底每天有两倍于月初的预约。任命的增加需要以一致的速度增加 例如,如果一个月的第一天有5个约会,那么到月底,我们每天将有10个约会 约会只能在工作日进行 有没有合适的算法可以帮助我以这种方式分配这些日期 编辑 这是迄今为止我从Henriks解决方案中获得的最好的解决方案: private int GetNumForCurrentDate (DateTime date) {

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

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

现在我需要分配这些预约,以便在月底每天有两倍于月初的预约。任命的增加需要以一致的速度增加


例如,如果一个月的第一天有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;
    }
它返回给定日期的特定日期要分配的天数。
它处理的是将分配给每个月,并处理四舍五入溢出,但它并不十分完美,它在最后一天分配的天数已经用完,但现在已经足够好了,我没有时间来完善它。

x第一天的约会,2倍于最后一天,因此平均1.5倍。 当有y个工作日时,x为1000/(1.5y)。
因此,第一天667/y,最后一天1333/y,在这两天之间插入“如果一个月的第一天有5个约会,那么到月底我们将每月有10个约会”——这是每月还是每天,因为您在问题的不同地方有不同的表述。谢谢你。。明目张胆的打字错误!我是说每天10个。编辑过。感谢您的关注;)我想你忘记了一个要求:“约会的增加需要以一致的速度(不是线性的)增加。”。你的是f(x)=cx,f'(x)=c,f''(x)=0。@Thomas:也许你是对的。我误读了“增加中的增加”。@Thomas:但根据这种解释,问题被低估了。我的解决方案仍然是正确的,因为f'=0=const.)这种增长是一种非常好的增长。我只是想了解一下数学知识并实现你的解决方案(太多年的数据库编程已经严重破坏了我的数学头脑!)