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?

Here is an example of how a network bandwidth task looks like.

If you have any ideas on php or modules, please advise.

  • The classical problem of maximum flow. Take any described algorithm and implement it. - Fine

1 answer 1

<?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] ; ?> 
  • Parse error: syntax error, unexpected '[' in Z: \ home \ localhost \ www \ saipis \ do_work.php on line 5 - OverLoader