0

我有一个控制医疗办公室议程的系统。如果医生取消当天的预约,我需要使用回溯算法。该算法必须根据患者日程安排(工作日和小时)的偏好,在另一个日期和时间重新安排取消的预约。如果所有取消的约会都被重新安排,它必须返回 true。如果一个或多个失败,它必须重试,直到没有解决方案。谁能解释我应该如何使用算法来解决这个问题?或者给我一些有用的链接?我正在尝试在谷歌和这里搜索它,但没有成功。

谢谢!

4

1 回答 1

2

也许这个伪代码会有所帮助:

boolean schedule (array-of-appointments-to-reschedule, calendar-with-available-times) {
    for each possible TIME where array-of-appointments[FIRST] can fit into
          calendar-with-available-times {
        if (array-of-appointments has only 1 element)
            return true;  // we've succeeded
        success = schedule (array-of-appointments-WITHOUT-the-first-one,
                            calendar-with-available-time with TIME blocked out);
            // this is the backtracking part, we call schedule recursively on the
            // _remaining_ appointments, and if we can't fit the rest of the           
            // appointments, then backtrack and try the next TIME
        if (success) return true;
    }
    return false;
}

这并不能完全解决所有问题,因为它实际上并没有跟踪成功的结果,但希望它能让你开始。

于 2013-09-16T23:19:47.540 回答