tryingtolearn Posted October 26, 2014 Share Posted October 26, 2014 I am trying to wrap my head around the best approach to accomplish this. I am trying to come up with a random schedule for a full 24 hour day with random time periods ranges including breaks. The only constants will be the minimum time and maximum time of the events and the minimum and maximum time of the breaks between each event. for example There are three teams Team A Team B Team C Each event will last either a minimum of 7 minutes to a maximum of 38 minutes The breaks will last a minimum of 30 seconds to a maximum of 5 minutes. so the events need to be generated randomly with a break period following each event and the timelines are different for each team with the current event time left going to a timer on the page I think I have the part to generate the random blocks figured out by using <!DOCTYPE html> <html> <body> <?php function eventRange($min, $max, $blocks) { $events = range($min, $max); shuffle($events); return array_slice($events, 0, $blocks); } function breakRange($min, $max, $blocks) { $breaks = range($min, $max, 0.1); shuffle($breaks); return array_slice($breaks, 0, $blocks); } echo"<pre>"; print_r( eventRange(7,38,32) ); echo"</pre>"; echo"<pre>"; print_r( breakRange(.5,5,32) ); echo"</pre>"; ?> </body> </html> bur is there a way to make it fill a full 24 hour period and then a way to determine which block to display based on the current time when either team is viewing the page. Sounds totally confusing to me as I try to explain it so I hope what Im asking makes sense. Thanks for any guidance.. Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/ Share on other sites More sharing options...
Barand Posted October 26, 2014 Share Posted October 26, 2014 Does each event involve a single team or two of the teams? Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494788 Share on other sites More sharing options...
tryingtolearn Posted October 26, 2014 Author Share Posted October 26, 2014 Each event involves a single team but each team will eventually do each event if that makes sense Along the lines of a relay race sort of... Each team starts at a different station (event) has to complete it in that time-frame and has the break period until going on to the next station (event). Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494792 Share on other sites More sharing options...
Barand Posted October 26, 2014 Share Posted October 26, 2014 So for a particular event, team 1 could have 7 minutes but team 2 could have 38 minutes? Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494793 Share on other sites More sharing options...
tryingtolearn Posted October 26, 2014 Author Share Posted October 26, 2014 No Guess I should have explained that better for instance Event 1 = 7 minutes / break after Event 1 = 2 minutes 30 seconds Event 2 = 24 minutes / break after Event 2 = 3 minutes 24 seconds Event 3 = 9 minutes 14 seconds / break after Event 3 = 1 minute and so on until the times (Events + Breaks) fill a 24 hour period The number of events and number of breaks do not matter, it is determined from the minimum and maximum set for the ranges of both events and breaks but has to fill a 24 hour period Then each team will complete each event just in different orders So Team 1 might do Event 3 then go to Event 1 then to Event 2 Team 2 might do Event 2 then go to Event 3 then to Event 1 Team 3 might do Event 3 then go to Event 2 then to Event 1 and so on -------- All the events run simultaneous from 12:00a.m. to 11:59p.m. but each team will do them in different orders some overlap is ok but I cant have all teams doing each event at the same time/order. Hopefully that makes more sense. Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494795 Share on other sites More sharing options...
Barand Posted October 26, 2014 Share Posted October 26, 2014 That's a lot clearer. From the times produced by your code you will have around 57 events $e = eventRange(7,38,32); $b = breakRange(.5,5,32); $ae = array_sum ($e) / count($e); $ab = array_sum($b) / count($b); $k = floor((24*60)/($ae+$ab)); echo"<pre>"; print_r($e); print_r($b ); printf ("Ave event: %5.2f\nAve break: %5.2f\nNum events in 24hrs: %d", $ae, $ab, $k); echo"</pre>"; Giving: Ave event: 22.50 Ave break: 2.76 Num events in 24hrs: 57 Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494797 Share on other sites More sharing options...
tryingtolearn Posted October 26, 2014 Author Share Posted October 26, 2014 Thanks for that The part I cannot figure out is how to generate the 57 events because it stops generating at 31 (Due to the range) Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494801 Share on other sites More sharing options...
Barand Posted October 26, 2014 Share Posted October 26, 2014 You have set a restriction that all events must be of different durations (and the same for the breaks). Does that need to be the case? Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494802 Share on other sites More sharing options...
tryingtolearn Posted October 26, 2014 Author Share Posted October 26, 2014 if possible it would be good but isnt necessary Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494803 Share on other sites More sharing options...
Barand Posted October 26, 2014 Share Posted October 26, 2014 I would generate random times for the events and breaks and maintain a running total of the time until 24 hours were filled $events = array(); $cumval = 0; $finished = 0; $k = 0; // // GENERATE RANDOM EVENT AND BREAK TIMES // UNTIL THE 24HRS HAVE BEEN FILLED // while (!$finished) { $remain = 24*60*60 - $cumval; if ($remain < 7*60 + 30) break; // cannot fit another event/break if ($remain < 39*60) { $eTime = floor($remain/60) - 1; $bTime = $remain - $eTime*60; $finished = 1; } else { $eTime = mt_rand(7, 38); // mins $bTime = mt_rand(3, 30) * 10; // 10 sec increments } $events[++$k] = array ( 'event' => $eTime, //mins 'break' => $bTime //secs ); $cumval += $eTime*60 + $bTime; } // // GET THE SCHEDULE FOR EACH OF THE 3 TEAMS // $schedule = array(); $keys = array_keys($events); $k = count($keys); for ($team = 1; $team <= 3; $team++) { shuffle($keys); $schedule[$team] = $keys; } Once you have the event and break durations in the $events array you can generate a timetable for each time using their schedule of events Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494841 Share on other sites More sharing options...
tryingtolearn Posted October 26, 2014 Author Share Posted October 26, 2014 Thanks for that Barand!! I was working on this a good part of today and came up with a method The downfall to mine is I have to adjust the last element of the array to get it to the 1440 (Minutes of the day) so I didnt like that. //events $events = range(7, 38, 0.01); shuffle($events); //breaks $breaks = range(0.5, 5.5, 0.01); shuffle($breaks); $ae = array_sum ($events) / count($events); $ab = array_sum($breaks) / count($breaks); $k = floor((24*60)/($ae+$ab)); $theDay = array(); $c=0; while ($c <= $k) { $c++; $theDay[]=$events[$c]; $theDay[]=$breaks[$c]; } if(array_sum($theDay) != 1440){ if(array_sum($theDay) < 1440){ $diff = (1440-array_sum($theDay)); $theDay[]=$diff; } if(array_sum($theDay) > 1440){ while (array_sum($theDay) > 1440) { $num=count($theDay); $num=$num-1; unset($theDay[$num]); } $diff = (1440-array_sum($theDay)); $theDay[]=$diff; } } I tested yours and it smooth but on some teams it falls shy of the 1440 so I have to see how that pans out when I try and figure out how to deploy these results to a timer. I appreciate you taking the time and thanks for the first post because it got me thinking and trying different things. My attempt seems alot less efficient than yours but I was trying hahaha Thanks again! Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494848 Share on other sites More sharing options...
tryingtolearn Posted October 27, 2014 Author Share Posted October 27, 2014 That works out perfect Barand Much appreciated! Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494887 Share on other sites More sharing options...
Barand Posted October 27, 2014 Share Posted October 27, 2014 Another thing that you might want to consider (and which would probably be appreciated by team member) is to keep the task time random but make the following break proportional to the task time so they they get a longer break after a long task. $eTime = mt_rand(7, 38); // mins $bTime = calcBreak(30,300,7,38,$eTime); function calcBreak($min,$max,$minet,$maxet,$et) { return floor(($max-$min) * ($et-$minet) / ($maxet-$minet)) + $min; } Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494893 Share on other sites More sharing options...
tryingtolearn Posted October 27, 2014 Author Share Posted October 27, 2014 I might be able to work that in as a comparison of sorts at the end. The actual "randomness" is the key. The goal of the exercise is for a team to review the schedule and dedicate their teams resources accordingly. Measuring that ability is what I am after. The events are made up of various logic and physical activities so they need to be able to assign the right people at the right times taking those breaks into consideration. Mainly Im measuring the ability to put together the right team for the given task actually completing the tasks is secondary if that makes sense. Link to comment https://forums.phpfreaks.com/topic/292067-best-way-to-approach-random-time-blocks-with-break-periods-in-a-day/#findComment-1494897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.