예제 #1
0
 /**
  * check if balance is okay and throw exception otherwise
  *
  * @throws UnexpectedValueException
  * @return AlgorithmMCF             $this (chainable)
  */
 protected function checkBalance()
 {
     $alg = new AlgorithmFlow($this->graph);
     $balance = $alg->getBalance();
     $tolerance = 1.0E-6;
     if ($balance >= $tolerance || $balance <= -$tolerance) {
         throw new UnexpectedValueException('The given graph is not balanced value is: ' . $balance);
     }
     return $this;
 }
예제 #2
0
 public function testGraphBalance()
 {
     // source(+100) -> sink(-10)
     $graph = new Graph();
     $graph->createVertex('source')->setBalance(100);
     $graph->createVertex('sink')->setBalance(-10);
     $alg = new AlgorithmFlow($graph);
     $this->assertEquals(90, $alg->getBalance());
     $this->assertFalse($alg->isBalancedFlow());
 }