diff --git a/Account/Group.php b/Account/Group.php index bc927f905..7f5e7b459 100644 --- a/Account/Group.php +++ b/Account/Group.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Account; +/** + * Account group class. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Group { diff --git a/DataStorage/Database/Query/Column.php b/DataStorage/Database/Query/Column.php index 91ca433e4..67ecb3431 100644 --- a/DataStorage/Database/Query/Column.php +++ b/DataStorage/Database/Query/Column.php @@ -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 + */ public function getColumn() : \string { return $this->column; diff --git a/Math/Algebra/Regression.php b/Math/Algebra/Regression.php index f85023fdf..107b67918 100644 --- a/Math/Algebra/Regression.php +++ b/Math/Algebra/Regression.php @@ -1,9 +1,50 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + public static function linearRegression(array $x, array $y) : array { $count = count($x); diff --git a/Math/Differential/FiniteDifference.php b/Math/Differential/FiniteDifference.php index 75ec8090a..cb4b7bd02 100644 --- a/Math/Differential/FiniteDifference.php +++ b/Math/Differential/FiniteDifference.php @@ -1,29 +1,104 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + 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 + */ + 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 + */ + 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'); diff --git a/Math/Functions.php b/Math/Functions.php index 19ad5f64f..a8a2f0613 100644 --- a/Math/Functions.php +++ b/Math/Functions.php @@ -1,21 +1,118 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + 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 + */ + 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 + */ + 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; + } } diff --git a/Math/Optimization/TSP/BruteForce.php b/Math/Optimization/TSP/BruteForce.php index 046692ba4..8fec7c267 100644 --- a/Math/Optimization/TSP/BruteForce.php +++ b/Math/Optimization/TSP/BruteForce.php @@ -1,13 +1,60 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ 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 + */ 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 + */ private function bruteForce(array $cities, Tour $tour, Population $population) { if (count($cities) === 0) { diff --git a/Math/Optimization/TSP/City.php b/Math/Optimization/TSP/City.php index 312d28438..cece23c4b 100644 --- a/Math/Optimization/TSP/City.php +++ b/Math/Optimization/TSP/City.php @@ -1,15 +1,69 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ 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 + */ public function getLongitude() : \float { return $this->long; } + /** + * Get latitude. + * + * @return float + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getLatitude() : \float { return $this->lat; } + /** + * Get name. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getName() : \string { return $this->name; } + /** + * Is equals to. + * + * @param City $city City + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ 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 + */ public function getDistanceTo(City $city) : \float { return Sphere::distance2PointsOnSphere($this->lat, $this->long, $city->getLatitude(), $city->getLongitude()); diff --git a/Math/Optimization/TSP/CityPool.php b/Math/Optimization/TSP/CityPool.php index 02b82612a..18a72cd88 100644 --- a/Math/Optimization/TSP/CityPool.php +++ b/Math/Optimization/TSP/CityPool.php @@ -1,31 +1,106 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + public function __construct(array $cities = []) { $this->cities = $cities; } + /** + * Add city. + * + * @param City $city City + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ 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 + */ + public function getCity(\int $index) : City { return array_values($this->cities)[$index]; } + /** + * Get cities. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getCities() : array { return $this->cities; } + /** + * Has city. + * + * @param City $city City + * + * @return \bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ 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 + */ public function count() : \int { return count($this->cities); diff --git a/Math/Optimization/TSP/GA.php b/Math/Optimization/TSP/GA.php index a3c860ad9..e225df767 100644 --- a/Math/Optimization/TSP/GA.php +++ b/Math/Optimization/TSP/GA.php @@ -1,20 +1,89 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ 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 + */ 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 + */ 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 + */ 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 + */ private function tournamentSelection(Population $population) : Tour { $tournament = new Population($this->cityPool, self::TOURNAMENT, false); diff --git a/Math/Optimization/TSP/Population.php b/Math/Optimization/TSP/Population.php index 24f031f55..d1866b6a1 100644 --- a/Math/Optimization/TSP/Population.php +++ b/Math/Optimization/TSP/Population.php @@ -1,41 +1,126 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + 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 + */ 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 + */ 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 + */ 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 + */ public function getTour(\int $index) { return $this->tours[$index] ?? null; } + /** + * Get fittest tour + * + * @return Tour + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ 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 + */ 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 + */ public function count() : \int { return count($this->tours); diff --git a/Math/Optimization/TSP/Tour.php b/Math/Optimization/TSP/Tour.php index 579900c39..10baf8a8e 100644 --- a/Math/Optimization/TSP/Tour.php +++ b/Math/Optimization/TSP/Tour.php @@ -1,30 +1,108 @@ + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + 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 + */ public function getCity($index) { return array_values($this->cities)[$index] ?? null; } + /** + * Get fitness. + * + * @return float + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ 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 + */ 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 + */ 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 + */ 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 + */ 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 + */ public function count() : \int { return count($this->cities); diff --git a/Math/Shape/D2/Circle.php b/Math/Shape/D2/Circle.php index abd933b3f..fac109eb8 100644 --- a/Math/Shape/D2/Circle.php +++ b/Math/Shape/D2/Circle.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Circle shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Circle { diff --git a/Math/Shape/D2/Ellipse.php b/Math/Shape/D2/Ellipse.php index 8810b4387..2b5f32c22 100644 --- a/Math/Shape/D2/Ellipse.php +++ b/Math/Shape/D2/Ellipse.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Ellipse shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Ellipse { diff --git a/Math/Shape/D2/Rectangle.php b/Math/Shape/D2/Rectangle.php index 684b42707..3cbc1c1e3 100644 --- a/Math/Shape/D2/Rectangle.php +++ b/Math/Shape/D2/Rectangle.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Rectangle shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Rectangle { diff --git a/Math/Shape/D2/Trapezoid.php b/Math/Shape/D2/Trapezoid.php index f1ff06005..56a864023 100644 --- a/Math/Shape/D2/Trapezoid.php +++ b/Math/Shape/D2/Trapezoid.php @@ -15,7 +15,18 @@ */ namespace phpOMS\Math\Algebra; -class Rectangle +/** + * Trapezoid shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Trapezoid { /** diff --git a/Math/Shape/D2/Triangle.php b/Math/Shape/D2/Triangle.php index 351bf5596..3a8ed435a 100644 --- a/Math/Shape/D2/Triangle.php +++ b/Math/Shape/D2/Triangle.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Triangle shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Triangle { diff --git a/Math/Shape/D3/Cone.php b/Math/Shape/D3/Cone.php index f6f155db1..5e3baa7b2 100644 --- a/Math/Shape/D3/Cone.php +++ b/Math/Shape/D3/Cone.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Cone shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Cone { diff --git a/Math/Shape/D3/Cuboid.php b/Math/Shape/D3/Cuboid.php index 518c4c025..f54216b6c 100644 --- a/Math/Shape/D3/Cuboid.php +++ b/Math/Shape/D3/Cuboid.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Cuboid shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Cuboid { diff --git a/Math/Shape/D3/Cylinder.php b/Math/Shape/D3/Cylinder.php index 2101bf04d..8ece0463d 100644 --- a/Math/Shape/D3/Cylinder.php +++ b/Math/Shape/D3/Cylinder.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Cylinder shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Cylinder { diff --git a/Math/Shape/D3/RectangularPyramid.php b/Math/Shape/D3/RectangularPyramid.php index 6788d4a0a..4d0d19be1 100644 --- a/Math/Shape/D3/RectangularPyramid.php +++ b/Math/Shape/D3/RectangularPyramid.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Rectangular pyramid shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class RectangularPyramid { diff --git a/Math/Shape/D3/Sphere.php b/Math/Shape/D3/Sphere.php index cfa5602e9..020335e52 100644 --- a/Math/Shape/D3/Sphere.php +++ b/Math/Shape/D3/Sphere.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Shape\D3; +/** + * Sphere shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @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 * diff --git a/Math/Shape/D3/Tetrahedron.php b/Math/Shape/D3/Tetrahedron.php index 7ebd50d96..2db2df22d 100644 --- a/Math/Shape/D3/Tetrahedron.php +++ b/Math/Shape/D3/Tetrahedron.php @@ -15,6 +15,17 @@ */ namespace phpOMS\Math\Algebra; +/** + * Tetraedron shape. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Tetrahedron { diff --git a/Math/Stochastic/Distribution/UniformDistributionDiscrete.php b/Math/Stochastic/Distribution/UniformDistributionDiscrete.php index e69de29bb..3b6fb1ae2 100644 --- a/Math/Stochastic/Distribution/UniformDistributionDiscrete.php +++ b/Math/Stochastic/Distribution/UniformDistributionDiscrete.php @@ -0,0 +1,172 @@ + + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + public static function getVariance(\float $a, \float $b) : \float + { + return (($b - $a + 1) ** 2 - 1) / 12; + } + + public static function getRandom() + { + + } +} diff --git a/Uri/InvalidUriException.php b/Uri/InvalidUriException.php index 46a828b01..cd2d9ea0b 100644 --- a/Uri/InvalidUriException.php +++ b/Uri/InvalidUriException.php @@ -15,11 +15,8 @@ */ namespace phpOMS\Uri; - /** - * Uri interface. - * - * Used in order to create and evaluate a uri + * Uri exception. * * @category Uri * @package Framework