此应用程序的目的是以最有效的方式安排车间中的大量机器。该过程是递归的,组装时间表和测量效率。这可行,但实际上需要几天才能运行。一个重要的时间消耗是下面的代码块:
foreach($machines AS $machine) {
# To begin, we analyze the schedule thus far to get this machine's existing schedule.
$machSched = array();
foreach($schedule AS $booking) {
if($booking['mach']==$machine && strtotime($booking['end']) > date('U')) {
$machSched[] = $booking;
}
}
# We seek the next time the machine can be booked. We begin by sorting its current bookings.
aasort($machSched, 'start');
# Now we construct the list of available times
$lastEnd = date('U');
$freeTimes=array();
foreach($machSched AS $booking) {
if(strtotime($booking['start']) > $lastEnd) $freeTimes[] = array('start' => $lastEnd, 'end' => strtotime($booking['start']));
$lastEnd = strtotime($booking['end']);
}
$freeTimes[] = array('start' => $lastEnd, 'end' => strtotime('2030-12-31'));
# Now we go through each available timeslot to see what we can book.
foreach($freeTimes AS $slot) {
// Scheduling stuff here...
}
}
此块迭代每台机器的现有计划时间,对其进行排序,并创建一个“空闲槽”数组(现有计划项目之间的时间。我已经优化和优化了这个程序,但我似乎无法提出有一个更好的方法来做这件小事。注意 aasort 是一个通过关联数组中的键对关联数组进行排序的函数。
任何帮助,将不胜感激!