hashbangcode/webolution
Composer 安装命令:
composer require hashbangcode/webolution
包简介
Webolution, an evolution engine.
关键字:
README 文档
README
An experimental set of classes that attempts to put together an application that will evolve a webpage. This is intended to be a test application that allows me to learn the techniques involved in genetic algorithms as well as how to to put together a modern PHP application with composer. As a result things might change significantly without warning.
I'm interested in finding out if anyone has looked at this code or has any suggestions for improvement. Please get in touch via the issue queue and let me know.
Requirements
- PHP (preferably 7.2+).
- Composer.
Structure
The application is structured into different types of objects in order to ensure separate concerns.
Types
The types classes take care of the data types at the core of the evolution process. At it's core a Type class only cares about the data that it contains. Type classes do not have functionliaty to perform mutations or calculate fitness metrics, this is the domain of Individual classes.
Individuals
Individual classes provide mutation and fitness functionality for Type classes. Instead of extending the types they wrap them as a parameter. Individual classes can be regarded as decorators of the Type classes. Each Type class maps to an Individual class.
Populations
The Population class provides a collection of Individuals.
Evolution
An Evolution class is used to control the process of evolution. This ties together the Population, Individual and Type classes and controls each generation of Population objects. An EvolutionStorage class has been created to allow larger number of Individuals to be evolved at once using a database as a storage engine.
Types Detail
The following details each of the types and any interactions they have with other types.
Number
Defines a class that contains a number. The NumberType class can add or subtract from this number. It was created as a very simple initial type in order to test the functionality of the evolution process.
Text
Defines a class that contains a string. The class has functions to get or set the string.
Color
Defines a class that contains information about a color. This is stored internally by the RGB value of the color.
Image
This defines a 2 dimensional array that renders out into an image. The array consists of either “on” or “off” values, which are then used to create a grid of boxes in an image.
Element
This represents a HTML element. The core property is the element type (div, p, strong etc) and one or more attributes. The attributes can be used to give the elements a class or id, although any attribute is allowed. An Element object can also contain one or more child Element objects, which creates a hierarchical structure of Elements.
Unit
The Unit is an object that holds information about a measurement in CSS. This is represented by a number and a unit of measurement. So values like 10px, 10em, 10% can exist. A special value of ‘auto’ can also be represented.
Style
This defines an object that contains information about a CSS rule set against a single element. The class contains a selector property and an attributes property that combine together to form a CSS block.
Page
A Page brings together the Style and Element classes into a page structure. The use of the Page class allows the basic HTML structure of a page to be static whilst the elements and styles within it can change.
The Evolution Process
The following describes how the process of evolution works for each generation.
Culling
To start the evolution process a certain amount of the population is removed. The chances of an individual being removed are dependent of the fitness of the individual. Individuals with a high fitness are less likely to be removed.
Replicate
The existing individuals in the population are then replicated to bring the population number back to a designated minimum. This means that the current population will contain the fittest individuals.
Mutate
The population is then randomly mutated. How the population is mutated is dependent on the type of object being used. After the population has been through the mutation cycle the population can then go through a crossover cycle. This is where individuals are mixed together and their attributes are swapped.
Generate Statistics
Any statistics for the population are then calculated.
Storage
This action clones the population into an array to that it can be retrieved later. This is important when looking through the history of the population.
Next steps
Some things that need to happen.
- Have a look at performance. Lots of objects being created can use up a lot of memory maybe look at only storing the top (or bottom) individuals in a population instead of everything.
- The way in which the TextIndividual works out it's fitness is based on an external factor. As such it would be better to abstract that functionality out so that it's not just this class that has this functionality.
Future plans
- Add a dependency injection container to streamline the use of the application in other applications.
- Generate a family tree of individuals.
- Performance testing and improvements.
hashbangcode/webolution 适用场景与选型建议
hashbangcode/webolution 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「webolution」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hashbangcode/webolution 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hashbangcode/webolution 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-29