Faced a very interesting task. It is necessary to calculate the maximum network bandwidth using php. Someone faced perhaps with similar tasks. How did you implement and through what?
If you have any ideas on php or modules, please advise.
Faced a very interesting task. It is necessary to calculate the maximum network bandwidth using php. Someone faced perhaps with similar tasks. How did you implement and through what?
If you have any ideas on php or modules, please advise.
<?php class getMaximumFromPath { static $points = [ '1' => ['3' => 8.4, '2' => 7.1, '4' => 5.3], '2' => ['5' => 9.1], '3' => ['6' => 8.2, '5' => 4.2], '4' => ['6' => 7.3], '5' => ['6' => 6.3], ]; public static $startPointId = 1; public static $endPointId = 6; static function getSum($summ, $parentPointId, $pathPointId) { $summResult = []; foreach(self::$points[$parentPointId] as $key => $value) { if ($parentPointId == self::$startPointId) { $summ = 0; $pathPointId = self::$startPointId; } $summ = $summ + $value; $pointId = $key; $pathPointId = $pathPointId . "," . $pointId; if ($pointId != self::$endPointId) { $summResult = array_merge( $summResult, self::getSum($summ, $pointId, $pathPointId)); } else { $summResult[] = [$summ, $pathPointId]; $summ = $summ - $value; $pathPointId = explode(',', $pathPointId); unset($pathPointId[count($pathPointId) - 1]); $pathPointId = implode(',', $pathPointId); } } return $summResult; } } function usersort($a, $b) { if ($a[0] == $b[0]) { return 0; } return ($a[0] > $b[0]) ? -1 : 1; } $getMax = getMaximumFromPath::getSum(0, getMaximumFromPath::$startPointId, getMaximumFromPath::$startPointId); usort($getMax, 'usersort'); var_dump($getMax); echo "Maximum path it is = " . $getMax[0][1] . " with score: " . $getMax[0][0] ; ?> Source: https://ru.stackoverflow.com/questions/525193/
All Articles