Ejemplo n.º 1
0
 /**
  * Обработка узла: разделение на подмножества, переход к следующему узлу,
  * формирование ответа.
  */
 function handleNode()
 {
     $this->callId = CallId::getID();
     self::$messages->open($this->callId);
     self::$messages->add([], "Нули на предыдущих этапах:" . $this->history());
     if ($this->branchnBound->solved) {
         $lastBranch = new BranchAndBound([], $this->branchnBound->minBorder);
         $lastBranch->rowRam = key($this->branchnBound->table);
         $lastBranch->columnRam = key(current($this->branchnBound->table));
         $lastBranch->includeVet = true;
         $lastBranch2 = new BranchAndBound([], INF);
         $lastBranch2->rowRam = key($this->branchnBound->table);
         $lastBranch2->columnRam = key(current($this->branchnBound->table));
         $this->childrens[] = new Node($lastBranch2, $this);
         $this->childrens[] = new Node($lastBranch, $this);
         $this->makeAnswer();
         return;
     }
     $devideResult = $this->branchnBound->devide();
     self::$messages->close();
     if (is_array($devideResult)) {
         $this->addNewNodes($devideResult);
     } else {
         $this->removeMyselfFromMins();
         $this->addMyselfToMins();
         $this->chooseForWorkFromMins();
     }
 }
Ejemplo n.º 2
0
 /**
  * Возвращает объект в случае успешной обработки таблицы с ребром
  * @param \TheSaturn\BranchAndBound\Coords $coord
  * @return \TheSaturn\BranchAndBound\BranchAndBound|boolean
  */
 protected function withCoordsHandle(Coords $coord)
 {
     $table2 = $this->table;
     $table2 = $this->unsetRowColumn($table2, $coord->row, $coord->column);
     isset($table2[$coord->column][$coord->row]) && ($table2[$coord->column][$coord->row] = INF);
     $table2 = $this->preventCycle($table2);
     $branchnBound2 = new BranchAndBound($table2, $this->minBorder, $this->path);
     $branchnBound2->path[$coord->row] = $coord->column;
     $branchnBound2->fullPath[$coord->row] = $coord->column;
     $branchnBound2->includeVet = true;
     $branchnBound2->rowRam = $coord->row;
     $branchnBound2->columnRam = $coord->column;
     self::addMess($table2, "Страт обработки множества включающего в себя ребро ({$coord->row},{$coord->column})");
     try {
         $branchnBound2->doOperations();
     } catch (Exception $e) {
         $branchnBound2->solvable = false;
     }
     return $branchnBound2;
 }
Ejemplo n.º 3
0
<?php

namespace TheSaturn\BranchAndBound;

spl_autoload_register(function ($class) {
    $class = substr($class, strrpos($class, "\\") + 1);
    include 'lib/' . $class . '.php';
});
$messages = new Messages();
BranchAndBound::$messages = $messages;
Node::$messages = $messages;
$t1 = microtime(true);
$tableBranchAndBound = new TableBranchAndBound();
$root = new Node($tableBranchAndBound->table);
$t2 = microtime(true);
$googleRows = new RowsGoogleCharts($root);
?>
<!DOCTYPE html>
<html lang="ru">
<head>
    <base href="http://<?php 
echo $_SERVER['HTTP_HOST'];
?>
"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Метод ветвей и границ</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="user.css" rel="stylesheet">
    <!-- Yandex.Metrika counter -->
<script type="text/javascript">