Reputation: 355
I need help in the way for doing this, not the code (tha's my work i think ;) )
I need to distribute the visits that a vendor must do during a month in the working days. I havve 100 people to visit this month, with different periodical parameters.
25 people to visit once a month. 25 people to visit twice a month 25 people to visit once a week 25 people to visit every day
I need to distribute all those visits every first day of the month, throught all the working days of the month and i really don't have any idea of how can i doit.
I get some of the data i think i need with the next code :
$days_this_month = date("d",mktime(0,0,0,$month+1,0,$year));
function weeks_this_month($year, $month, $start = 0) {
$unix = strtotime ( "$year-$month-01" );
$numDays = date ( 't', $unix );
if ($start === 0) {
$dayOne = date ( 'w', $unix ); // Based on 0-6
} else {
$dayOne = date ( 'N', $unix ); //based on 1-7
$dayOne --; //convert for 0 based weeks
}
//if day one is not the start of the week then advance to start
$numWeeks = floor ( ($numDays - (6 - $dayOne)) / 7 );
return $numWeeks;
}
$weeks_this_month = weeks_this_month($year, $month);
I also get the days per week with:
$weekArray = array();
// set current date1
$date = date("m/d/Y"); //'05/09/2011';
$date = "05/11/2011"; //'05/09/2011';
// parse about any English textual datetime description into a Unix timestamp
$ts = strtotime( $date );
// calculate the number of days since Monday
$dow = date('w', $ts);
$offset = $dow - 1;
if ($offset < 0) $offset = 6;
// calculate timestamp for the Monday
$ts = $ts - $offset*86400;
// loop from Monday till Sunday
for ($i=0; $i<7; $i++, $ts+=86400){
$temp_date = date("Y-m-d", $ts); // here I set it to the same format as my database
array_push( $weekArray, $temp_date );
}
print_r ($weekArray);
With the current result:
[0] => 2011-05-09
[1] => 2011-05-10
[2] => 2011-05-11
[3] => 2011-05-12
[4] => 2011-05-13
[5] => 2011-05-14
[6] => 2011-05-15
And my last check is a function to know if the resultants days are working days, not Sat or Sun.
The problem is that i am really lost.
I don't know the way to mix all this info to distribute the vendor visits.
Anyone could give me an idea please?
Really thnx.
Upvotes: 2
Views: 782
Reputation: 3102
This is only a partial answer, but if I rephrase the question:
So some of the things which you need to know as inputs to the problem:
Assuming you know which month you are calculating, your logic above provides a way to get the dates in a specific month. The working days are also calculated. You need to know (or get) the number of visits which can fit into a single day; without this constraint you will not be able to "schedule" the visits. Here's the logic I would follow (loosely):
Get Available Days
So far so good - we've got a discrete list of "available days"; now we look at a possible labor distribution algorithm.
Get needed visits
Hopefully #5 and #6 will be obvious, but I'll explain #7 a bit... If you want to allocate visits, and assuming all visits are of equal priority, then one approach would be to start with the highest frequency and then work backwards to the lowest. If you have daily visits, then spread them out first, then the weekly, then the bi-weekly, then the monthly. Each periodicity has a different set of constraints, so it probably makes sense to isolate the logic. The rough idea is:
Daily
Weekly
Bi Monthly
Monthly
...
There are some problems still left to be solved, depending on your purposes...
Just a few thoughts. Hope this helps.
Upvotes: 1