code fixes

This commit is contained in:
Dennis Eichhorn 2023-10-15 17:41:45 +00:00
parent 513fa7bf8b
commit 0b5d51f9b8
6 changed files with 23 additions and 22 deletions

View File

@ -137,7 +137,7 @@ final class MarkovChain
$cProb += $p;
if ($prob <= $cProb) {
$new = $val;
$new = $val;
break;
}
@ -177,7 +177,7 @@ final class MarkovChain
$prob = 1.0;
for ($i = $this->order; $i < $length; ++$i) {
$prob *= $this->data[\implode($key)][$path[$i]] ?? 0.0;
$prob *= $this->data[\implode(' ', $key)][$path[$i]] ?? 0.0;
$key[] = $path[$i];
\array_shift($key);

View File

@ -433,7 +433,7 @@ final class ReadMapper extends DataMapperAbstract
$query = $this->getQuery(
null,
[
'COUNT(' . (empty($this->columns) ? '*' : \implode($this->columns)) . ')' => 'count'
'COUNT(' . (empty($this->columns) ? '*' : \implode(',', $this->columns)) . ')' => 'count',
]
);
@ -452,7 +452,7 @@ final class ReadMapper extends DataMapperAbstract
$query = $this->getQuery(
null,
[
'SUM(' . (empty($this->columns) ? '*' : \implode($this->columns)) . ')' => 'sum'
'SUM(' . (empty($this->columns) ? '*' : \implode(',', $this->columns)) . ')' => 'sum',
]
);

View File

@ -70,7 +70,7 @@ final class GrahamScan
$subpoints = \array_slice($points, 2, $count);
\usort($subpoints, function (array $a, array $b) use ($c) : int {
// @todo: Might be wrong order of comparison
return \atan2($a['y'] - $c['y'], $a['x'] - $c['x']) <=> \atan2( $b['y'] - $c['y'], $b['x'] - $c['x']);
return \atan2($a['y'] - $c['y'], $a['x'] - $c['x']) <=> \atan2($b['y'] - $c['y'], $b['x'] - $c['x']);
});
/** @var array<int, array{x:int|float, y:int|float}> $points */
@ -106,9 +106,9 @@ final class GrahamScan
/**
* Counterclockwise rotation
*
* @param array<x:int|float, y:int|float> $a Vector
* @param array<x:int|float, y:int|float> $b Vector
* @param array<x:int|float, y:int|float> $c Vector
* @param array{x:int|float, y:int|float} $a Vector
* @param array{x:int|float, y:int|float} $b Vector
* @param array{x:int|float, y:int|float} $c Vector
*
* @return int|float
*

View File

@ -26,6 +26,7 @@ namespace phpOMS\Math\Optimization;
class Simplex
{
private int $m = 0;
private int $n = 0;
private array $A = [];
@ -40,7 +41,7 @@ class Simplex
private array $Nonbasic = [];
private function pivot (int $x, int $y)
private function pivot (int $x, int $y) : void
{
for ($j = 0; $j < $this->n; ++$j) {
if ($j !== $y) {
@ -73,20 +74,20 @@ class Simplex
$this->v += $this->c[$y] * $this->b[$x];
$this->c[$y] *= $this->A[$x][$y];
$temp = $this->Basic[$x];
$this->Basic[$x] = $this->Nonbasic[$y];
$temp = $this->Basic[$x];
$this->Basic[$x] = $this->Nonbasic[$y];
$this->Nonbasic[$y] = $temp;
}
private function iterate() : int
{
$ind = -1;
$ind = -1;
$best = -1;
for ($j = 0; $j < $this->n; ++$j) {
if ($this->c[$j] > 0) {
if ($best === -1 || $this->Nonbasic[$j] < $ind) {
$ind = $this->Nonbasic[$j];
$ind = $this->Nonbasic[$j];
$best = $j;
}
}
@ -96,14 +97,14 @@ class Simplex
return 1;
}
$maxConstraint = \INF;
$maxConstraint = \INF;
$bestConstraint = -1;
for ($i = 0; $i < $this->m; ++$i) {
if ($this->A[$i][$best] < 0) {
$currentConstraint = -$this->b[$i] / $this->A[$i][$best];
if ($currentConstraint < $maxConstraint) {
$maxConstraint = $currentConstraint;
$maxConstraint = $currentConstraint;
$bestConstraint = $i;
}
}
@ -120,12 +121,12 @@ class Simplex
private function initialize() : int
{
$k = -1;
$k = -1;
$minB = -1;
for ($i = 0; $i < $this->m; ++$i) {
if ($k === -1 || $this->b[$i] < $minB) {
$k = $i;
$k = $i;
$minB = $this->b[$i];
}
}
@ -201,8 +202,8 @@ class Simplex
$this->A[$i][$nonbasicZ] = $this->A[$i][$this->n - 1];
}
$temp = $this->Nonbasic[$nonbasicZ];
$this->Nonbasic[$nonbasicZ] = $this->Nonbasic[$this->n - 1];
$temp = $this->Nonbasic[$nonbasicZ];
$this->Nonbasic[$nonbasicZ] = $this->Nonbasic[$this->n - 1];
$this->Nonbasic[$this->n - 1] = $temp;
--$this->n;

View File

@ -185,7 +185,7 @@ class BinarySearchTree
if ($comparison < 0) {
if ($current->left === null) {
$BST = new BinarySearchTree();
$BST = new self();
$new = new Node($node->key, $node->data);
$new->parent = $current;
$new->tree = $BST;
@ -197,7 +197,7 @@ class BinarySearchTree
}
} elseif ($comparison > 0) {
if ($current->right === null) {
$BST = new BinarySearchTree();
$BST = new self();
$new = new Node($node->key, $node->data);
$new->parent = $current;
$new->tree = $BST;

View File

@ -14,9 +14,9 @@ declare(strict_types=1);
namespace phpOMS\tests\Utils\IO\Spreadsheet;
use phpOMS\tests\Autoloader;
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\tests\Autoloader;
use phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper;
use phpOMS\Utils\StringUtils;