alphazygma/combinatorics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alphazygma/combinatorics

Composer 安装命令:

composer require alphazygma/combinatorics

包简介

Math libraries for Combinatorics (Combinations, Permutations, ...).

README 文档

README

Latest Stable Version Build Status Coverage Status Total Downloads Latest Unstable Version License

COMBINATORICS

Wikipedia : Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures. Aspects of combinatorics include counting the structures of a given kind and size (enumerative combinatorics), deciding when certain criteria can be met, and constructing and analyzing objects meeting the criteria (as in combinatorial designs and matroid theory), finding "largest", "smallest", or "optimal" objects (extremal combinatorics and combinatorial optimization), and studying combinatorial structures arising in an algebraic context, or applying algebraic techniques to combinatorial problems (algebraic combinatorics).

Requirements

PHP 5.4+ is required. (The [] short array syntax was introduced on 5.4)

Disclosure

The Combination and Permutation implementation is based on the work of David Sanders (shangxiao@php.net).

Source Link
PEAR https://pear.php.net/package/Math_Combinatorics
Pckagist https://packagist.org/packages/pear/math_combinatorics
Github https://github.com/pear/Math_Combinatorics

Changelog

  • 1.0 Added Permutations code (with unit tests)
  • 0.2 Unit Tests added to Combinations library.
  • 0.1 Port of the Combinations library (manual tests done, but unit tests, need to be added).

Classes

Combinations

This version is similar to David's with the difference that the base method will return all possible combinations based on the supplied set.

It also provides with a Static method to access the class as a utility, so if you need this functionality very often, use the Instance approach for you'll get better performance, but if you use it here and there, the static access may prove more readable.

Additionally, it detaches the Pointers functionality into it's own class, providing a bit more clarity into the Combinations code as well as making it better thread-safe as the pointers are no longer an attribute of the class shared across the methods, it is an object created for each run and thus allowing to run multiple combinations in parallel from the same class instance without having them interfere with each other.

Note: As with David's implementation, the returned combinations preserve the keys supplied. (However fixes a minor bug where the single element combinations would not preserve its keys)

Permutations

As in Combinations, this code is similar to David's with the difference that both pieces are not mixed in the same class, Permutations is a class of its own and has an internal reference to the Combinations class.

It as well, provides with a Static method to access the class as a utility.

Usage

This usage considers that you have an autoloader running. (see Install for more reference)

The result of the functionality is an Array of Arrays in which the Outer Array is a list of combinations and each Inner Array is the combination itself.

Retrieving all combinations for a source data set.
$sourceDataSet = ['a' => 5, 'b' => 6, 'c' => 8, 'd' => 10];

// Retrieve all combinations as Utility
$combinationsList = \Math\Combinatorics\Combination::get($sourceDataSet);

// Retrieve all combinations as instance class
$combination      = new \Math\Combinatorics\Combination();
$combinationsList = $combination->getCombinations($sourceDataSet);

Here is a detailed version of the expanded array

size 1:  [`a` => 5]  [`b` => 6]  [`c` => 8]  [`d` => 10] 
size 2:  [`a` => 5,`b` => 6]     [`a` => 5,`c` => 8]
         [`a` => 5,`d` => 10]    [`b` => 6,`c` => 8]
         [`b` => 6,`d` => 10]    [`c` => 8,`d` => 10] 
size 3:  [`a` => 5,`b` => 6,`c` => 8]
         [`a` => 5,`b` => 6,`d` => 10]
         [`a` => 5,`c` => 8,`d` => 10]
         [`b` => 6,`c` => 8,`d` => 10] 
size 4:  [`a` => 5,`b` => 6,`c` => 8,`d` => 10]
Retrieving combinations of a given length for a source data set.
$sourceDataSet = ['a' => 5, 'b' => 6, 'c' => 8, 'd' => 10];

// Retrieve all combinations as Utility
$combinationsList = \Math\Combinatorics\Combination::get($sourceDataSet, 3);

// Retrieve all combinations as instance class
$combination      = new \Math\Combinatorics\Combination();
$combinationsList = $combination->getCombinations($sourceDataSet, 3);

Here is a detailed version of the expanded array

size 3:  [`a` => 5,`b` => 6,`c` => 8]
         [`a` => 5,`b` => 6,`d` => 10]
         [`a` => 5,`c` => 8,`d` => 10]
         [`b` => 6,`c` => 8,`d` => 10]
Retrieving all permutations for a source data set.
$sourceDataSet = ['z' => 10, 'a' => 50, 'x' => 77];

// Retrieve all combinations as Utility
$permtuationList = \Math\Combinatorics\Permutation::get($sourceDataSet);

// Retrieve all combinations as instance class
$permutation      = new \Math\Combinatorics\Permutation();
$permutationsList = $permutation->getPermutations($sourceDataSet);

Here is a detailed version of the expanded array

size 1:  ['z' => 10]
         ['a' => 50]
         ['x' => 77]
size 2:  ['z' => 10, 'a' => 50]
         ['a' => 50, 'z' => 10]
         ['z' => 10, 'x' => 77]
         ['x' => 77, 'z' => 10]
         ['a' => 50, 'x' => 77]
         ['x' => 77, 'a' => 50]
size 3:  ['z' => 10, 'a' => 50, 'x' => 77]
         ['z' => 10, 'x' => 77, 'a' => 50]
         ['a' => 50, 'x' => 77, 'z' => 10]
         ['a' => 50, 'z' => 10, 'x' => 77]
         ['x' => 77, 'z' => 10, 'a' => 50]
         ['x' => 77, 'a' => 50, 'z' => 10]
Retrieving permutations of a given length for a source data set.
$sourceDataSet = ['z' => 10, 'a' => 50, 'x' => 77];

// Retrieve all combinations as Utility
$permtuationList = \Math\Combinatorics\Permutation::get($sourceDataSet, 2);

// Retrieve all combinations as instance class
$permutation      = new \Math\Combinatorics\Permutation();
$permutationsList = $permutation->getPermutations($sourceDataSet, 2);

Here is a detailed version of the expanded array

size 2:  ['z' => 10, 'a' => 50]
         ['a' => 50, 'z' => 10]
         ['z' => 10, 'x' => 77]
         ['x' => 77, 'z' => 10]
         ['a' => 50, 'x' => 77]
         ['x' => 77, 'a' => 50]

Install

The easiest way to install is through composer.

Just create a composer.json file for your project:

{
    "require": {
        "alphazygma/combinatorics": "~1.0"
    }
}

Then you can run these two commands to install it:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

or simply run composer install if you have have already installed the composer globally.

Then you can include the autoloader, and you will have access to the library classes:

<?php
require 'vendor/autoload.php';

alphazygma/combinatorics 适用场景与选型建议

alphazygma/combinatorics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 199.57k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2016 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「math」 「combinatorics」 「combination」 「permutation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alphazygma/combinatorics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alphazygma/combinatorics 我们能提供哪些服务?
定制开发 / 二次开发

基于 alphazygma/combinatorics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 199.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2016-03-21