How PHP allocates traffic for each time period based on a specified number of IP

problem description

for example, a total of 100IP needs to be allocated, and the proportion of traffic for each hour has been set. Divide the IP into a time period (one-dimensional array, one for each segment, and 0 if it is not assigned to the IP). After the allocation, the sum of the numbers in the array must be equal to the total assigned traffic. No more, no less.

the following array is the proportion of traffic per hour:

          $hour = array(
                0 => 0.01,
                1 => 0.01,
                2 => 0,
                3 => 0,
                4 => 0,
                5 => 0.01,
                6 => 0.02,
                7 => 0.02,
                8 => 0.03,
                9 => 0.05,
                10 => 0.07,
                11 => 0.08,
                12 => 0.05,
                13 => 0.07,
                14 => 0.09,
                15 => 0.10,
                16 => 0.06,
                17 => 0.05,
                18 => 0.04,
                19 => 0.07,
                20 => 0.06,
                21 => 0.06,
                22 => 0.04,
                23 => 0.02,
            );
            

10 IP,24 hours, according to the results of the assigned traffic graph (handwritten in this array):
$time = array.

the environmental background of the problems and what methods you have tried

tried to calculate traffic cyclically, but there will be more or less traffic after allocation. In addition, when the total traffic is less than 24, it should be allocated in several time periods with the highest proportion as far as possible (for example, if the total traffic is 16 IP, it can be allocated in proportion to 8 time periods)

what result do you expect?

how can distribution be equal to the total traffic that needs to be allocated, and be as close as possible to the proportion of traffic distribution

Jul.28,2021
Menu