mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-04-02 11:58:40 +00:00
Documentation
This commit is contained in:
parent
d53cb93b79
commit
c23d515173
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Account;
|
||||
|
||||
/**
|
||||
* Account group class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Group
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ namespace phpOMS\DataStorage\Database\Query;
|
|||
class Column
|
||||
{
|
||||
|
||||
/**
|
||||
* Column name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $column = '';
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +51,14 @@ class Column
|
|||
$this->column = $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column string.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getColumn() : \string
|
||||
{
|
||||
return $this->column;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Regression class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Regression
|
||||
{
|
||||
public static function linearRegression(array $x, array $y)
|
||||
/**
|
||||
* Calculate linear regression.
|
||||
*
|
||||
* Example: ([1, 4, 6, 8, 9], [5, 3, 8, 6, 2])
|
||||
*
|
||||
* @param array $x X coordinates
|
||||
* @param array $y Y coordinates
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function linearRegression(array $x, array $y) : array
|
||||
{
|
||||
$count = count($x);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Differential;
|
||||
|
||||
/**
|
||||
* Chi square distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class FiniteDifference
|
||||
{
|
||||
/**
|
||||
* Epsilon.
|
||||
*
|
||||
* @var float
|
||||
* @since 1.0.0
|
||||
*/
|
||||
const EPSILON = 0.00001;
|
||||
|
||||
public static function getNewtonDifferenceQuotient(\string $formula, array $variables, \int $derivative = 1) : \float
|
||||
/**
|
||||
* Differentiate by using the Newton difference quotient.
|
||||
*
|
||||
* Example: ('2*x^3-4x', ['x' => 99])
|
||||
*
|
||||
* @param string $formula Formula to differentiate
|
||||
* @param array $variable Variable to differentiate (name value assiziation)
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getNewtonDifferenceQuotient(\string $formula, array $variable) : \float
|
||||
{
|
||||
return (Evaluator::evaluate($formula, ['x' => $variables['x'] + self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variables['x']])) / self::EPSILON;
|
||||
return (Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x']])) / self::EPSILON;
|
||||
}
|
||||
|
||||
public static function getSymmetricDifferenceQuotient(\string $formula, array $variables, \int $derivative = 1) : \float
|
||||
/**
|
||||
* Differentiate by using the symmetric difference quotient.
|
||||
*
|
||||
* Example: ('2*x^3-4x', ['x' => 99])
|
||||
*
|
||||
* @param string $formula Formula to differentiate
|
||||
* @param array $variable Variable to differentiate (name value assiziation)
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSymmetricDifferenceQuotient(\string $formula, array $variable) : \float
|
||||
{
|
||||
return (Evaluator::evaluate($formula, ['x' => $variables['x'] + self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variables['x'] - self::EPSILON])) / (2 * self::EPSILON);
|
||||
return (Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON])) / (2 * self::EPSILON);
|
||||
}
|
||||
|
||||
public static function getFivePointStencil(\string $formula, array $variables, \int $derivative = 1) : \float
|
||||
/**
|
||||
* Differentiate by using the five point stencil.
|
||||
*
|
||||
* Example: ('2*x^3-4x', ['x' => 99], 3)
|
||||
*
|
||||
* @param string $formula Formula to differentiate
|
||||
* @param array $variable Variable to differentiate (name value assiziation)
|
||||
* @param int $derivative Derivative (4th = highest)
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getFivePointStencil(\string $formula, array $variable, \int $derivative = 1) : \float
|
||||
{
|
||||
if ($derivative === 1) {
|
||||
return (-Evaluator::evaluate($formula, ['x' => $variables['x'] + 2 * self::EPSILON]) + 8 * Evaluator::evaluate($formula, ['x' => $variables['x'] + self::EPSILON]) - 8 * Evaluator::evaluate($formula, ['x' => $variables['x'] - self::EPSILON]) + Evaluator::evaluate($formula, ['x' => $variables['x'] - 2 * self::EPSILON])) / (12 * self::EPSILON);
|
||||
return (-Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) + 8 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - 8 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) + Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (12 * self::EPSILON);
|
||||
} elseif ($derivative === 2) {
|
||||
return (-Evaluator::evaluate($formula, ['x' => $variables['x'] + 2 * self::EPSILON]) + 16 * Evaluator::evaluate($formula, ['x' => $variables['x'] + self::EPSILON]) - 30 * Evaluator::evaluate($formula, ['x' => $variables['x']]) + 16 * Evaluator::evaluate($formula, ['x' => $variables['x'] - self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variables['x'] - 2 * self::EPSILON])) / (12 * self::EPSILON ** 2);
|
||||
return (-Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) + 16 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - 30 * Evaluator::evaluate($formula, ['x' => $variable['x']]) + 16 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (12 * self::EPSILON ** 2);
|
||||
} elseif ($derivative === 3) {
|
||||
return (Evaluator::evaluate($formula, ['x' => $variables['x'] + 2 * self::EPSILON]) - 2 * Evaluator::evaluate($formula, ['x' => $variables['x'] + self::EPSILON]) + 2 * Evaluator::evaluate($formula, ['x' => $variables['x'] - self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variables['x'] - 2 * self::EPSILON])) / (2 * self::EPSILON ** 3);
|
||||
return (Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) - 2 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) + 2 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (2 * self::EPSILON ** 3);
|
||||
} elseif ($derivative === 4) {
|
||||
return (Evaluator::evaluate($formula, ['x' => $variables['x'] + 2 * self::EPSILON]) - 4 * Evaluator::evaluate($formula, ['x' => $variables['x'] + self::EPSILON]) + 6 * Evaluator::evaluate($formula, ['x' => $variables['x']]) - 4 * Evaluator::evaluate($formula, ['x' => $variables['x'] - self::EPSILON]) + Evaluator::evaluate($formula, ['x' => $variables['x'] - 2 * self::EPSILON])) / (self::EPSILON ** 4);
|
||||
return (Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) - 4 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) + 6 * Evaluator::evaluate($formula, ['x' => $variable['x']]) - 4 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) + Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (self::EPSILON ** 4);
|
||||
}
|
||||
|
||||
throw new \Exception('Derivative too high');
|
||||
|
|
|
|||
|
|
@ -1,21 +1,118 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math;
|
||||
|
||||
/**
|
||||
* Well known functions class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Functions
|
||||
{
|
||||
public static function getGammaInteger(\int $k)
|
||||
/**
|
||||
* Calculate gammar function value.
|
||||
*
|
||||
* Example: (7)
|
||||
*
|
||||
* @param int $k Variable
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getGammaInteger(\int $k) : \int
|
||||
{
|
||||
return self::fact($k-1);
|
||||
return self::fact($k - 1);
|
||||
}
|
||||
|
||||
public static function fact(\int $n, \int $start = 1)
|
||||
/**
|
||||
* Calculate gammar function value.
|
||||
*
|
||||
* Example: (7, 2)
|
||||
*
|
||||
* @param int $n Factorial upper bound
|
||||
* @param int $start Factorial starting value
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function fact(\int $n, \int $start = 1) : \int
|
||||
{
|
||||
$fact = 1;
|
||||
|
||||
for($i = $start; $i < $n; $i++) {
|
||||
for ($i = $start; $i < $n + 1; $i++) {
|
||||
$fact *= $i;
|
||||
}
|
||||
|
||||
return $fact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate binomial coefficient
|
||||
*
|
||||
* Algorithm optimized for large factorials without the use of big int or string manipulation.
|
||||
*
|
||||
* Example: (7, 2)
|
||||
*
|
||||
* @param int $n
|
||||
* @param int $k
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function binomialCoefficient(\int $n, \int $k) : \int
|
||||
{
|
||||
$max = max([$k, $n - $k]);
|
||||
$min = min([$k, $n - $k]);
|
||||
|
||||
$fact = 1;
|
||||
$range = array_reverse(range(1, $min));
|
||||
|
||||
for ($i = $max + 1; $i < $n + 1; $i++) {
|
||||
$div = 1;
|
||||
foreach ($range as $key => $d) {
|
||||
if ($i % $d === 0) {
|
||||
$div = $d;
|
||||
|
||||
unset($range[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$fact *= $i / $div;
|
||||
}
|
||||
|
||||
$fact2 = 1;
|
||||
|
||||
foreach ($range as $d) {
|
||||
$fact2 *= $d;
|
||||
}
|
||||
|
||||
return $fact / $fact2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Optimization\TSP;
|
||||
|
||||
/**
|
||||
* TSP solution with brute force.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BruteForce
|
||||
{
|
||||
/**
|
||||
* City limit (for factorial calculation).
|
||||
*
|
||||
* @var float
|
||||
* @since 1.0.0
|
||||
*/
|
||||
const LIMIT = 22;
|
||||
|
||||
/**
|
||||
* City pool.
|
||||
*
|
||||
* @var CityPool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $cityPool = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CityPool $pool City pool
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(CityPool $pool)
|
||||
{
|
||||
$this->cityPool = $pool;
|
||||
|
|
@ -17,6 +64,16 @@ class BruteForce
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate best routes.
|
||||
*
|
||||
* @param int $limit Amount of best routes
|
||||
*
|
||||
* @return Population
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getSolution(\int $limit = 1) : Population
|
||||
{
|
||||
$population = new Population($this->cityPool, $limit, true);
|
||||
|
|
@ -27,6 +84,18 @@ class BruteForce
|
|||
return $population;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bruteforce best solutions.
|
||||
*
|
||||
* @param array $cities Cities
|
||||
* @param Tour $tour Current (potential) optimal tour
|
||||
* @param Population $population Population of tours
|
||||
*
|
||||
* @return Population
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function bruteForce(array $cities, Tour $tour, Population $population)
|
||||
{
|
||||
if (count($cities) === 0) {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Math\Optimization\TSP;
|
||||
|
||||
use phpOMS\Math\Shape\D3\Sphere;
|
||||
|
||||
/**
|
||||
* City class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class City
|
||||
{
|
||||
/**
|
||||
* City name
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $name = '';
|
||||
private $long = 0.0;
|
||||
private $lat = 0.0;
|
||||
|
||||
/**
|
||||
* City longitude
|
||||
*
|
||||
* @var float
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $long = 0.0;
|
||||
|
||||
/**
|
||||
* City latitude
|
||||
*
|
||||
* @var float
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $lat = 0.0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param float $lat Latitude
|
||||
* @param float $long Longitude
|
||||
* @param string $name City name
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(\float $lat, \float $long, \string $name)
|
||||
{
|
||||
$this->long = $long;
|
||||
|
|
@ -17,26 +71,70 @@ class City
|
|||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get longitude.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getLongitude() : \float
|
||||
{
|
||||
return $this->long;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latitude.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getLatitude() : \float
|
||||
{
|
||||
return $this->lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getName() : \string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is equals to.
|
||||
*
|
||||
* @param City $city City
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function equals(City $city) : \bool
|
||||
{
|
||||
return $this->name === $city->getName() && $this->lat === $city->getLatitude() && $this->long === $city->getLatitude();
|
||||
}
|
||||
|
||||
/**
|
||||
* Distance to city
|
||||
*
|
||||
* @param City $city City
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getDistanceTo(City $city) : \float
|
||||
{
|
||||
return Sphere::distance2PointsOnSphere($this->lat, $this->long, $city->getLatitude(), $city->getLongitude());
|
||||
|
|
|
|||
|
|
@ -1,31 +1,106 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Optimization\TSP;
|
||||
|
||||
/**
|
||||
* City pool.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CityPool implements \Countable
|
||||
{
|
||||
/**
|
||||
* Cities
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $cities = [];
|
||||
|
||||
public function __construct($cities = [])
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param City[] $cities Cities
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(array $cities = [])
|
||||
{
|
||||
$this->cities = $cities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add city.
|
||||
*
|
||||
* @param City $city City
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function addCity(City $city)
|
||||
{
|
||||
$this->cities[$city->getName() . $city->getLatitude() . $city->getLongitude()] = $city;
|
||||
}
|
||||
|
||||
public function getCity($index) : City
|
||||
/**
|
||||
* Get city.
|
||||
*
|
||||
* @param int $index City index
|
||||
*
|
||||
* @return City
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getCity(\int $index) : City
|
||||
{
|
||||
return array_values($this->cities)[$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cities.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getCities() : array
|
||||
{
|
||||
return $this->cities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has city.
|
||||
*
|
||||
* @param City $city City
|
||||
*
|
||||
* @return \bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function hasCity(City $city) : \bool
|
||||
{
|
||||
foreach ($this->cities as $c) {
|
||||
|
|
@ -37,6 +112,14 @@ class CityPool implements \Countable
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count cities
|
||||
*
|
||||
* @return \int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function count() : \int
|
||||
{
|
||||
return count($this->cities);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Optimization\TSP;
|
||||
|
||||
/**
|
||||
* TSP solution by genetic algorithm.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GA
|
||||
{
|
||||
const MUTATION = 15; /* 1000 = 100% */
|
||||
const TOURNAMENT = 5;
|
||||
const ELITISM = true;
|
||||
/**
|
||||
* Mutation percentage
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
const MUTATION = 15; /* 1000 = 100% */
|
||||
|
||||
/**
|
||||
* Tournaments
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
const TOURNAMENT = 5;
|
||||
|
||||
/**
|
||||
* Elitism
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
const ELITISM = true;
|
||||
|
||||
/**
|
||||
* City pool
|
||||
*
|
||||
* @var CityPool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $cityPool = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CityPool $pool City pool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(CityPool $pool)
|
||||
{
|
||||
$this->cityPool = $pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evolve population.
|
||||
*
|
||||
* @param Population $population Population to eveolve
|
||||
*
|
||||
* @return Population
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function evolvePopulation(Population $population) : Population
|
||||
{
|
||||
$shift = self::ELITISM ? 1 : 0;
|
||||
|
|
@ -39,6 +108,17 @@ class GA
|
|||
return $newPopulation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crossover tours
|
||||
*
|
||||
* @param Tour $tour1 Tour 1
|
||||
* @param Tour $tour2 Tour 2
|
||||
*
|
||||
* @return Tour
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function crossover(Tour $tour1, Tour $tour2) : Tour
|
||||
{
|
||||
$child = new Tour($this->cityPool, false);
|
||||
|
|
@ -72,6 +152,16 @@ class GA
|
|||
return $child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutate tour
|
||||
*
|
||||
* @param Tour $tour Tour to mutate
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function mutate(Tour $tour)
|
||||
{
|
||||
$count = $tour->count();
|
||||
|
|
@ -91,6 +181,16 @@ class GA
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find fittest
|
||||
*
|
||||
* @param Population $population Population to evaluate
|
||||
*
|
||||
* @return Tour
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function tournamentSelection(Population $population) : Tour
|
||||
{
|
||||
$tournament = new Population($this->cityPool, self::TOURNAMENT, false);
|
||||
|
|
|
|||
|
|
@ -1,41 +1,126 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Optimization\TSP;
|
||||
|
||||
/**
|
||||
* Population class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Population implements \Countable
|
||||
{
|
||||
/**
|
||||
* Tours
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $tours = [];
|
||||
|
||||
public function __construct(CityPool $pool, \int $size, \bool $initialise = false)
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CityPool $pool City pool
|
||||
* @param int $size Population size
|
||||
* @param bool $initialize Initialize with random tours
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(CityPool $pool, \int $size, \bool $initialize = false)
|
||||
{
|
||||
if ($initialise) {
|
||||
if ($initialize) {
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$this->tours[] = new Tour($pool, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert Tour at position.
|
||||
*
|
||||
* @param int $index Position to insert at
|
||||
* @param Tour $tour Tour to insert
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function insertTourAt(\int $index, Tour $tour)
|
||||
{
|
||||
$this->tours = array_slice($this->tours, 0, $index) + [$tour] + array_slice($this->tours, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set tour at position
|
||||
*
|
||||
* @param int $index Position to set/replace
|
||||
* @param Tour $tour Tour to set
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setTour(\int $index, Tour $tour)
|
||||
{
|
||||
$this->tours[$index] = $tour;
|
||||
asort($this->tours);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tour
|
||||
*
|
||||
* @param Tour $tour Tour to add
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function addTour(Tour $tour)
|
||||
{
|
||||
$this->tours[] = $tour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tour
|
||||
*
|
||||
* @param int $index Index of tour
|
||||
*
|
||||
* @return null|Tour
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getTour(\int $index)
|
||||
{
|
||||
return $this->tours[$index] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fittest tour
|
||||
*
|
||||
* @return Tour
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getFittest() : Tour
|
||||
{
|
||||
$fittest = $this->tours[0];
|
||||
|
|
@ -50,6 +135,14 @@ class Population implements \Countable
|
|||
return $fittest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unfittest tour
|
||||
*
|
||||
* @return Tour
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getUnfittest() : Tour
|
||||
{
|
||||
$unfittest = $this->tours[0];
|
||||
|
|
@ -64,6 +157,14 @@ class Population implements \Countable
|
|||
return $unfittest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tour count
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function count() : \int
|
||||
{
|
||||
return count($this->tours);
|
||||
|
|
|
|||
|
|
@ -1,30 +1,108 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Optimization\TSP;
|
||||
|
||||
/**
|
||||
* Tour class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Tour implements \Countable
|
||||
{
|
||||
private $cities = [];
|
||||
private $fitness = 0.0;
|
||||
/**
|
||||
* Cities
|
||||
*
|
||||
* @var City[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $cities = [];
|
||||
|
||||
/**
|
||||
* Tour fitness
|
||||
*
|
||||
* @var City[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $fitness = 0.0;
|
||||
|
||||
/**
|
||||
* Tour distance
|
||||
*
|
||||
* @var City[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $distance = 0.0;
|
||||
|
||||
/**
|
||||
* City pool
|
||||
*
|
||||
* @var CityPool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $cityPool = null;
|
||||
|
||||
public function __construct(CityPool $pool, \bool $initialise = false)
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CityPool $pool City pool
|
||||
* @param bool $initialize Initialize with random tours
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(CityPool $pool, \bool $initialize = false)
|
||||
{
|
||||
$this->cityPool = $pool;
|
||||
|
||||
if ($initialise) {
|
||||
if ($initialize) {
|
||||
$this->cities = $this->cityPool->getCities();
|
||||
shuffle($this->cities);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get city.
|
||||
*
|
||||
* @param int $index Index
|
||||
*
|
||||
* @return null|City
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getCity($index)
|
||||
{
|
||||
return array_values($this->cities)[$index] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fitness.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getFitness() : \float
|
||||
{
|
||||
if ($this->fitness === 0.0 && ($distance = $this->getDistance()) !== 0.0) {
|
||||
|
|
@ -34,6 +112,14 @@ class Tour implements \Countable
|
|||
return $this->fitness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add city to tour.
|
||||
*
|
||||
* @param City $city City
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function addCity(City $city)
|
||||
{
|
||||
$this->cities[] = $city;
|
||||
|
|
@ -42,6 +128,15 @@ class Tour implements \Countable
|
|||
$this->distance = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set city
|
||||
*
|
||||
* @param int $index Index to set/replace
|
||||
* @param City $city City
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setCity(\int $index, City $city)
|
||||
{
|
||||
$this->cities[$index] = $city;
|
||||
|
|
@ -51,6 +146,14 @@ class Tour implements \Countable
|
|||
$this->distance = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tour distance
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getDistance() : \float
|
||||
{
|
||||
if ($this->distance === 0.0) {
|
||||
|
|
@ -70,6 +173,16 @@ class Tour implements \Countable
|
|||
return $this->distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has city.
|
||||
*
|
||||
* @param City $city City
|
||||
*
|
||||
* @return \bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function hasCity(City $city) : \bool
|
||||
{
|
||||
foreach ($this->cities as $c) {
|
||||
|
|
@ -81,6 +194,14 @@ class Tour implements \Countable
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get city count
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function count() : \int
|
||||
{
|
||||
return count($this->cities);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Circle shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Circle
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Ellipse shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Ellipse
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Rectangle shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Rectangle
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,18 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
class Rectangle
|
||||
/**
|
||||
* Trapezoid shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Trapezoid
|
||||
{
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Triangle shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Triangle
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Cone shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Cone
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Cuboid shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Cuboid
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Cylinder shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Cylinder
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Rectangular pyramid shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class RectangularPyramid
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Shape\D3;
|
||||
|
||||
/**
|
||||
* Sphere shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Sphere
|
||||
{
|
||||
|
||||
|
|
@ -25,7 +36,7 @@ class Sphere
|
|||
* @param float $longStart Longitude of start point in deg
|
||||
* @param float $latEnd Latitude of target point in deg
|
||||
* @param float $longEnd Longitude of target point in deg
|
||||
* @param float $radius Sphere radius
|
||||
* @param float $radius Sphere radius (6371000 = earth)
|
||||
*
|
||||
* @return float Distance between points in meter
|
||||
*
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
namespace phpOMS\Math\Algebra;
|
||||
|
||||
/**
|
||||
* Tetraedron shape.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Tetrahedron
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Uniform (discrete) distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class UniformDistributionDiscrete
|
||||
{
|
||||
|
||||
/**
|
||||
* Get probability mass function.
|
||||
*
|
||||
* @param \float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPmf(\float $a, \float $b) : \float
|
||||
{
|
||||
return 1 / ($b - $a + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param float $k
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\float $k, \float $a, \float $b) : \float
|
||||
{
|
||||
if ($k > $b || $k < $a) {
|
||||
throw new \Exception('Out of bounds');
|
||||
}
|
||||
|
||||
return (floor($k) - $a + 1) / ($b - $a + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param int $t
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\int $t, \float $a, \float $b) : \float
|
||||
{
|
||||
return (exp($a * $t) - exp(($b + 1) * $t)) / (($b - $a + 1) * (1 - exp($t)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness() : \float
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis(\float $a, \float $b) : \float
|
||||
{
|
||||
$n = ($b - $a + 1);
|
||||
|
||||
return -6 / 5 * ($n ** 2 + 1) / ($n ** 2 - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $a, \float $b) : \float
|
||||
{
|
||||
return ($a + $b) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $a, \float $b) : \float
|
||||
{
|
||||
return ($a + $b) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $a, \float $b) : \float
|
||||
{
|
||||
return (($b - $a + 1) ** 2 - 1) / 12;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -15,11 +15,8 @@
|
|||
*/
|
||||
namespace phpOMS\Uri;
|
||||
|
||||
|
||||
/**
|
||||
* Uri interface.
|
||||
*
|
||||
* Used in order to create and evaluate a uri
|
||||
* Uri exception.
|
||||
*
|
||||
* @category Uri
|
||||
* @package Framework
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user