3

このアプリケーションの目的は、可能な限り最も効率的な方法で工場内の多数の機械をスケジュールすることです。このプロセスは再帰的で、スケジュールを組み立て、効率を測定します。これは機能しますが、実行には文字通り数日かかります。以下のコード ブロックは、かなりの時間を浪費します。

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 は、連想配列のキーによって連想配列の配列をソートする関数であることに注意してください。

どんな助けでも大歓迎です!

4

2 に答える 2