Re: Ideas on how to proceed
| From: | php3 at developersdesk dot com | Date: | Thu, 26 Oct 2000 03:34:50 +0000 |
| Subject: | Re: Ideas on how to proceed | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-3916@lists.php.net to get a copy of this message | ||
Addressed to: Christopher King <chris@create4u.com>
<php-db@lists.php.net>
** Reply to note from Christopher King <chris@create4u.com> Tue, 24 Oct 2000 10:37:36 +0000
> The function I am trying to enable now is the ability to roll over orders
> to the next day when they reach their weight limit. So that if the
> foreman enters an order for Wednesday and it exceeds the weight limit it
> will automatically split the order and roll part of it over to Thursday
> and if by doing that Thursday hits it's weight limit it will roll over
> and so on... This would do the same thing if an order is modified or
> deleted.
>
Sincd it is possible that the order will roll over more than one day I
would use a recursive function like this:
# Maximum amounts a machine can do in a day
$MaxDaily = array( 1 => 300, # Machine 1 can do 300/day
2 => 120, # Machine 2 can do 120/day
3 => 225 ); # Machine 3 can do 225/day
function ScheduleMachine( $MachineID, $Day, $Weight, $Item ) {
global $MaxDaily;
if( $Weight > $MaxDaily ) {
ScheduleMachine( $MachineID, $Day + 1, $Weight - $MaxDaily, $Item );
$Weight = $MaxDaily[ $MachineID ];
}
mysql_query( "INSERT INTO MachineSchedule SET " .
" MachineID = $MachineID, " .
" Day = $Day, " .
" Weight = $Weight, " .
" Item = '$Item' " );
}
This code has a side effect, the entries are posted to the database
starting with the last day of production, but you are not supposed to
depend on the order of entries in a database snyway.
To schedule 260 lbs of widgets on machine 2 for day 47:
ScheduleMachine( 2, 47, 260, 'widgets' );
The first time thru $Weight (260) is larger than Maximum so the function
calls itself with a Weight value of 140, (260-120) and a the Day + 1.
The second time through Weight (140) is still larger than Maximum so
the function calls itself with a Weight of 20, and Day + 1 (total=2)
The third time through 20 is less than the capacity of the machine
so the if fails, and the function posts the reservation to the db
with a weight 0f 20 and Day + 2. The third invocation returns to
the second.
The second invocation continues by setting $Weight to the daily
maximum for the machine, (120) and posting the reservation to the db
with Day + 1. It then returns to the first invocation.
The first invocation continues by setting $Weight to MaxDaily, and posting
the reservation for Day + 0. The function then returns to the caller.
This example ignores the possibility of scheduling the same machine twice,
that more than one item can be produced during one day, and uses an integer
for day number which does not account for weekends or holidays.
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com