mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Fix code style
This commit is contained in:
parent
d4aa5b1bc5
commit
5433e64d8e
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Ai\NeuralNetwork;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Neuron
|
||||
final class Neuron
|
||||
{
|
||||
/**
|
||||
* Neuron inputs
|
||||
|
|
|
|||
|
|
@ -26,54 +26,116 @@ use phpOMS\Utils\NumericUtils;
|
|||
*/
|
||||
final class Kernel
|
||||
{
|
||||
/**
|
||||
* Kernel matrix for ridge
|
||||
*
|
||||
* @var array<int, int[]>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const KERNEL_RIDGE_1 = [
|
||||
[0, -1, 0],
|
||||
[-1, 4, -1],
|
||||
[0, -1, 0],
|
||||
];
|
||||
|
||||
/**
|
||||
* Kernel matrix for ridge
|
||||
*
|
||||
* @var array<int, int[]>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const KERNEL_RIDGE_2 = [
|
||||
[-1, -1, -1],
|
||||
[-1, 8, -1],
|
||||
[-1, -1, -1],
|
||||
];
|
||||
|
||||
/**
|
||||
* Kernel matrix for sharpening
|
||||
*
|
||||
* @var array<int, int[]>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const KERNEL_SHARPEN = [
|
||||
[0, -1, 0],
|
||||
[-1, 5, -1],
|
||||
[0, -1, 0],
|
||||
];
|
||||
|
||||
/**
|
||||
* Kernel matrix for blurring
|
||||
*
|
||||
* @var array<int, int[]>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const KERNEL_BOX_BLUR = [
|
||||
[1 / 9, 1 / 9, 1 / 9],
|
||||
[1 / 9, 1 / 9, 1 / 9],
|
||||
[1 / 9, 1 / 9, 1 / 9],
|
||||
];
|
||||
|
||||
/**
|
||||
* Kernel matrix for gaussian blurring
|
||||
*
|
||||
* @var array<int, int[]>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const KERNEL_GAUSSUAN_BLUR_3 = [
|
||||
[1 / 16, 2 / 16, 1 / 16],
|
||||
[2 / 16, 4 / 16, 2 / 16],
|
||||
[1 / 16, 2 / 16, 1 / 16],
|
||||
];
|
||||
|
||||
/**
|
||||
* Kernel matrix for embossing
|
||||
*
|
||||
* @var array<int, int[]>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const KERNEL_EMBOSS = [
|
||||
[-2, -1, 0],
|
||||
[-1, 1, 1],
|
||||
[0, 1, 2],
|
||||
];
|
||||
|
||||
/**
|
||||
* Kernel matrix for unsharpening
|
||||
*
|
||||
* @var array<int, int[]>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const KERNEL_UNSHARP_MASKING = [
|
||||
[-1 / 256, -4 / 256, -6 / 256, -4 / 256, -1 / 256],
|
||||
[-4 / 256, -16 / 256, -24 / 256, -16 / 256, -4 / 256],
|
||||
[-6 / 256, -24 / 256, 476 / 256, -24 / 256, -6 / 256],
|
||||
[-4 / 256, -16 / 256, -24 / 256, -16 / 256, -4 / 256],
|
||||
[-1 / 256, -4 / 256, -6 / 256, -4 / 256, -1 / 256],
|
||||
[-1 / 256, -4 / 256, -6 / 256, -4 / 256, -1 / 256],
|
||||
[-4 / 256, -16 / 256, -24 / 256, -16 / 256, -4 / 256],
|
||||
[-6 / 256, -24 / 256, 476 / 256, -24 / 256, -6 / 256],
|
||||
[-4 / 256, -16 / 256, -24 / 256, -16 / 256, -4 / 256],
|
||||
[-1 / 256, -4 / 256, -6 / 256, -4 / 256, -1 / 256],
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply kernel matrix
|
||||
*
|
||||
* @param string $inParth Image file path
|
||||
* @param string $outPath Image output path
|
||||
* @param array $kernel Kernel matrix
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Kernel_(image_processing)
|
||||
* @see https://towardsdatascience.com/image-processing-with-python-blurring-and-sharpening-for-beginners-3bcebec0583a
|
||||
* @see https://web.eecs.umich.edu/~jjcorso/t/598F14/files/lecture_0924_filtering.pdf
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function convolve(string $inPath, string $outPath, array $kernel) : void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Image;
|
|||
*/
|
||||
final class Skew
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically rotate image based on projection profile
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,6 +26,16 @@ use phpOMS\Utils\ImageUtils;
|
|||
*/
|
||||
final class Thresholding
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform integral thresholding
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,6 +26,16 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException;
|
|||
*/
|
||||
final class Algebra
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the product of two arrays
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D2;
|
|||
*/
|
||||
final class Circle implements D2ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Area
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D2;
|
|||
*/
|
||||
final class Ellipse implements D2ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Area
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D2;
|
|||
*/
|
||||
final class Quadrilateral implements D2ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the surface area from the length of all sides and the angle between a and b
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D2;
|
|||
*/
|
||||
final class Rectangle implements D2ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Area
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D2;
|
|||
*/
|
||||
final class Trapezoid implements D2ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Area
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D2;
|
|||
*/
|
||||
final class Triangle implements D2ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Area
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D3;
|
|||
*/
|
||||
final class Cone implements D3ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Volume
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D3;
|
|||
*/
|
||||
final class Cuboid implements D3ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Volume
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D3;
|
|||
*/
|
||||
final class Cylinder implements D3ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Volume
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,6 +26,16 @@ use phpOMS\Math\Geometry\Shape\D2\Polygon;
|
|||
*/
|
||||
final class Prism implements D3ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get volume of regular polygon prism by side length
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D3;
|
|||
*/
|
||||
final class RectangularPyramid implements D3ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Volume
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Geometry\Shape\D3;
|
|||
*/
|
||||
final class Tetrahedron implements D3ShapeInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Volume
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Numerics;
|
|||
*/
|
||||
final class Integration
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Integrate function by using rectangles from the left side
|
||||
*
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ final class LagrangeInterpolation implements InterpolationInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(array $points) {
|
||||
public function __construct(array $points)
|
||||
{
|
||||
$this->points = $points;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ final class LinearInterpolation implements InterpolationInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(array $points) {
|
||||
public function __construct(array $points)
|
||||
{
|
||||
$this->points = $points;
|
||||
|
||||
$n = \count($this->points);
|
||||
|
|
|
|||
|
|
@ -17,31 +17,113 @@ namespace phpOMS\Math\Optimization;
|
|||
/**
|
||||
* Simplex class.
|
||||
*
|
||||
* The Simplex algorithm aims to solve a linear program - optimising a linear function subject
|
||||
* to linear constraints. As such it is useful for a very wide range of applications.
|
||||
*
|
||||
* N.B. The linear program has to be given in *slack form*, which is as follows:
|
||||
* maximise
|
||||
* c_1 * x_1 + c_2 * x_2 + ... + c_n * x_n + v
|
||||
* subj. to
|
||||
* a_11 * x_1 + a_12 * x_2 + ... + a_1n * x_n + b_1 = s_1
|
||||
* a_21 * x_1 + a_22 * x_2 + ... + a_2n * x_n + b_2 = s_2
|
||||
* ...
|
||||
* a_m1 * x_1 + a_m2 * x_2 + ... + a_mn * x_n + b_m = s_m
|
||||
* and
|
||||
* x_1, x_2, ..., x_n, s_1, s_2, ..., s_m >= 0
|
||||
*
|
||||
* Every linear program can be translated into slack form; the parameters to specify are:
|
||||
* - the number of variables, n, and the number of constraints, m;
|
||||
* - the matrix A = [[A_11, A_12, ..., A_1n], ..., [A_m1, A_m2, ..., A_mn]];
|
||||
* - the vector b = [b_1, b_2, ..., b_m];
|
||||
* - the vector c = [c_1, c_2, ..., c_n] and the constant v.
|
||||
*
|
||||
* Complexity: O(m^(n/2)) worst case
|
||||
* O(n + m) average case (common)
|
||||
*
|
||||
* @package phpOMS\Math\Optimization
|
||||
* @license Copyright (c) 2015 Petar Veličković
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @link https://github.com/PetarV-/Algorithms/blob/master/Mathematical%20Algorithms/Simplex%20Algorithm.cpp
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Simplex
|
||||
final class Simplex
|
||||
{
|
||||
/**
|
||||
* Bounding equations
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $m = 0;
|
||||
|
||||
/**
|
||||
* Bounding variables
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $n = 0;
|
||||
|
||||
/**
|
||||
* Bounding equations
|
||||
*
|
||||
* @var array<int, array<int|float>>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $A = [];
|
||||
|
||||
/**
|
||||
* Bounds for bounding equations
|
||||
*
|
||||
* @var array<int|float>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $b = [];
|
||||
|
||||
/**
|
||||
* Maximize vector
|
||||
*
|
||||
* @var array<int|float>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $c = [];
|
||||
|
||||
/**
|
||||
* Maximized value
|
||||
*
|
||||
* @var float
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private float $v = 0.0;
|
||||
|
||||
private array $Basic = [];
|
||||
/**
|
||||
* Basic solutions
|
||||
*
|
||||
* @var array<int|float>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $basic = [];
|
||||
|
||||
private array $Nonbasic = [];
|
||||
/**
|
||||
* Non-basic solutions
|
||||
*
|
||||
* @var array<int|float>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $nonbasic = [];
|
||||
|
||||
private function pivot (int $x, int $y) : void
|
||||
/**
|
||||
* Pivot yth variable around xth constraint
|
||||
*
|
||||
* @param int $x Constraint index
|
||||
* @param int $y Variable index
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function pivot(int $x, int $y) : void
|
||||
{
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($j !== $y) {
|
||||
|
|
@ -74,11 +156,18 @@ 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];
|
||||
$this->Nonbasic[$y] = $temp;
|
||||
$temp = $this->basic[$x];
|
||||
$this->basic[$x] = $this->nonbasic[$y];
|
||||
$this->nonbasic[$y] = $temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform simplex iteration step
|
||||
*
|
||||
* @return int 0 = OK, 1 = stop, -1 = unbound
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function iterate() : int
|
||||
{
|
||||
$ind = -1;
|
||||
|
|
@ -86,9 +175,9 @@ class Simplex
|
|||
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($this->c[$j] > 0
|
||||
&& ($best === -1 || $this->Nonbasic[$j] < $ind)
|
||||
&& ($best === -1 || $this->nonbasic[$j] < $ind)
|
||||
) {
|
||||
$ind = $this->Nonbasic[$j];
|
||||
$ind = $this->nonbasic[$j];
|
||||
$best = $j;
|
||||
}
|
||||
}
|
||||
|
|
@ -119,6 +208,16 @@ class Simplex
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize simplex algorithm
|
||||
*
|
||||
* 1. possibly converts LP to slack form
|
||||
* 2. find feasible basic solution
|
||||
*
|
||||
* @return int 0 = OK, 1 = stop, -1 = unbound
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function initialize() : int
|
||||
{
|
||||
$k = -1;
|
||||
|
|
@ -133,11 +232,11 @@ class Simplex
|
|||
|
||||
if ($this->b[$k] >= 0) {
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
$this->Nonbasic[$j] = $j;
|
||||
$this->nonbasic[$j] = $j;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
$this->Basic[$i] = $this->n + $i;
|
||||
$this->basic[$i] = $this->n + $i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -145,11 +244,11 @@ class Simplex
|
|||
|
||||
++$this->n;
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
$this->Nonbasic[$j] = $j;
|
||||
$this->nonbasic[$j] = $j;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
$this->Basic[$i] = $this->n + $i;
|
||||
$this->basic[$i] = $this->n + $i;
|
||||
}
|
||||
|
||||
$oldC = [];
|
||||
|
|
@ -180,7 +279,7 @@ class Simplex
|
|||
|
||||
$basicZ = -1;
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
if ($this->Basic[$i] === $this->n - 1) {
|
||||
if ($this->basic[$i] === $this->n - 1) {
|
||||
$basicZ = $i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -192,7 +291,7 @@ class Simplex
|
|||
|
||||
$nonbasicZ = -1;
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($this->Nonbasic[$j] === $this->n - 1) {
|
||||
if ($this->nonbasic[$j] === $this->n - 1) {
|
||||
$nonbasicZ = $j;
|
||||
break;
|
||||
}
|
||||
|
|
@ -202,20 +301,20 @@ class Simplex
|
|||
$this->A[$i][$nonbasicZ] = $this->A[$i][$this->n - 1];
|
||||
}
|
||||
|
||||
$temp = $this->Nonbasic[$nonbasicZ];
|
||||
$this->Nonbasic[$nonbasicZ] = $this->Nonbasic[$this->n - 1];
|
||||
$this->Nonbasic[$this->n - 1] = $temp;
|
||||
$temp = $this->nonbasic[$nonbasicZ];
|
||||
$this->nonbasic[$nonbasicZ] = $this->nonbasic[$this->n - 1];
|
||||
$this->nonbasic[$this->n - 1] = $temp;
|
||||
|
||||
--$this->n;
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($this->Nonbasic[$j] > $this->n) {
|
||||
--$this->Nonbasic[$j];
|
||||
if ($this->nonbasic[$j] > $this->n) {
|
||||
--$this->nonbasic[$j];
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
if ($this->Basic[$i] > $this->n) {
|
||||
--$this->Basic[$i];
|
||||
if ($this->basic[$i] > $this->n) {
|
||||
--$this->basic[$i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -228,7 +327,7 @@ class Simplex
|
|||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
$ok = false;
|
||||
for ($k = 0; $k < $this->n; ++$k) {
|
||||
if ($j === $this->Nonbasic[$k]) {
|
||||
if ($j === $this->nonbasic[$k]) {
|
||||
$this->c[$k] += $oldC[$j];
|
||||
$ok = true;
|
||||
break;
|
||||
|
|
@ -240,7 +339,7 @@ class Simplex
|
|||
}
|
||||
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
if ($j === $this->Basic[$i]) {
|
||||
if ($j === $this->basic[$i]) {
|
||||
for ($k = 0; $k < $this->n; ++$k) {
|
||||
$this->c[$k] = $oldC[$j] * $this->A[$i][$k];
|
||||
}
|
||||
|
|
@ -254,13 +353,25 @@ class Simplex
|
|||
return 0;
|
||||
}
|
||||
|
||||
public function solve(array $A, array $b, array $c)
|
||||
/**
|
||||
* Solve simplex problem
|
||||
*
|
||||
* @param array<int, array<int|float>> $A Bounding equations
|
||||
* @param int[]|float[] $b Boundings for equations
|
||||
* @param int[]|float[] $c Equation to maximize
|
||||
*
|
||||
* @return array{0:array<int|float>, 1:float}
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function solve(array $A, array $b, array $c) : array
|
||||
{
|
||||
$this->A = $A;
|
||||
$this->b = $b;
|
||||
$this->c = $c;
|
||||
|
||||
// @todo: createSlackForm() required?
|
||||
// @todo: create minimize
|
||||
|
||||
$this->m = \count($A);
|
||||
$this->n = \count(\reset($A));
|
||||
|
|
@ -278,11 +389,11 @@ class Simplex
|
|||
|
||||
$result = [];
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
$result[$this->Nonbasic[$j]] = 0;
|
||||
$result[$this->nonbasic[$j]] = 0;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
$result[$this->Basic[$i]] = $this->b[$i];
|
||||
$result[$this->basic[$i]] = $this->b[$i];
|
||||
}
|
||||
|
||||
return [$result, $this->v];
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Math\Parser;
|
|||
*/
|
||||
final class Evaluator
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate function.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,6 +32,16 @@ final class Bisection
|
|||
*/
|
||||
public const EPSILON = 1e-6;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform bisection to find the root of a function
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,6 +32,16 @@ final class Illinois
|
|||
*/
|
||||
public const EPSILON = 1e-6;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform bisection to find the root of a function
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,6 +32,16 @@ final class RegulaFalsi
|
|||
*/
|
||||
public const EPSILON = 1e-6;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform bisection to find the root of a function
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use phpOMS\Utils\IO\IODatabaseMapper;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CsvDatabaseMapper implements IODatabaseMapper
|
||||
final class CsvDatabaseMapper implements IODatabaseMapper
|
||||
{
|
||||
/**
|
||||
* Database connection
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Utils\IO\Json;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class InvalidJsonException extends \UnexpectedValueException
|
||||
final class InvalidJsonException extends \UnexpectedValueException
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use phpOMS\Utils\StringUtils;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||
final class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||
{
|
||||
/**
|
||||
* Database connection
|
||||
|
|
|
|||
|
|
@ -24,8 +24,18 @@ namespace phpOMS\Utils\IO\Zip;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Gz implements ArchiveInterface
|
||||
final class Gz implements ArchiveInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -31,8 +31,18 @@ use phpOMS\System\File\Local\Directory;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Tar implements ArchiveInterface
|
||||
final class Tar implements ArchiveInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -26,8 +26,18 @@ use phpOMS\System\File\Local\File;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class TarGz implements ArchiveInterface
|
||||
final class TarGz implements ArchiveInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -27,8 +27,18 @@ use phpOMS\System\File\Local\Directory;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Zip implements ArchiveInterface
|
||||
final class Zip implements ArchiveInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -22,8 +22,18 @@ namespace phpOMS\Utils\Parser\Calendar;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ICalParser
|
||||
final class ICalParser
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse iCal data
|
||||
*
|
||||
|
|
|
|||
|
|
@ -25,8 +25,18 @@ use PhpOffice\PhpWord\Writer\HTML;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class DocumentParser
|
||||
final class DocumentParser
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Document to string
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use phpOMS\Utils\StringUtils;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PdfParser
|
||||
final class PdfParser
|
||||
{
|
||||
/**
|
||||
* PDFToText path.
|
||||
|
|
@ -44,6 +44,16 @@ class PdfParser
|
|||
*/
|
||||
public static string $pdftoppm = '/usr/bin/pdftoppm';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Pdf to text
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,8 +26,18 @@ use phpOMS\Contract\SerializableInterface;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ArrayParser
|
||||
final class ArrayParser
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializing array (recursively).
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,8 +24,18 @@ use PhpOffice\PhpPresentation\IOFactory;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PresentationParser
|
||||
final class PresentationParser
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Presentation to string
|
||||
*
|
||||
|
|
|
|||
|
|
@ -25,8 +25,18 @@ use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SpreadsheetParser
|
||||
final class SpreadsheetParser
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Spreadsheet to string
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,8 +22,18 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ArrayRandomize
|
||||
final class ArrayRandomize
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Yates array shuffler.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,8 +22,18 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class DateTime
|
||||
final class DateTime
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random \DateTime.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,8 +22,18 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Email
|
||||
final class Email
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random email.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class File
|
||||
final class File
|
||||
{
|
||||
/**
|
||||
* Extensions.
|
||||
|
|
@ -44,6 +44,16 @@ class File
|
|||
['flv'], ['fla'], ['deb'], ['py'], ['pl'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random file extension.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class LinearCongruentialGenerator
|
||||
final class LinearCongruentialGenerator
|
||||
{
|
||||
/**
|
||||
* BSD seed value.
|
||||
|
|
@ -40,6 +40,16 @@ class LinearCongruentialGenerator
|
|||
*/
|
||||
private static $msvcrtSeed = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* BSD random number
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Name
|
||||
final class Name
|
||||
{
|
||||
private static array $names = [
|
||||
'western' => [
|
||||
|
|
@ -481,6 +481,16 @@ class Name
|
|||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random string.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,8 +22,18 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Phone
|
||||
final class Phone
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random phone number.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,8 +22,18 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class StringUtils
|
||||
final class StringUtils
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random string.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Utils\RnG;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Text
|
||||
final class Text
|
||||
{
|
||||
/**
|
||||
* Vocabulary.
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Utils\RnG;
|
|||
*/
|
||||
final class UUID
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default random UUID
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user