PHPackages                             sedatsevgili/charlie - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sedatsevgili/charlie

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sedatsevgili/charlie
====================

A simple genetic algorithm library

v1.0.0(2y ago)32MITPHPPHP ^8.1

Since Feb 6Pushed 2y ago2 watchersCompare

[ Source](https://github.com/sedatsevgili/Charlie)[ Packagist](https://packagist.org/packages/sedatsevgili/charlie)[ RSS](/packages/sedatsevgili-charlie/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (10)Used By (0)

Charlie Project
===============

[](#charlie-project)

Description
-----------

[](#description)

This project is a simple library that allows PHP developers to easily build their own applications by using Genetic Algorithms.

Installation
------------

[](#installation)

To install this library, you can use composer:

```
composer require sedatsevgili/charlie

```

Usage
-----

[](#usage)

To use this library for your own purposes as a PHP developer, you need to:

1. Define your own Gene class that will implement the `Charlie\Gene\GeneInterface` interface.
2. Define your own FitnessFunction class that will implement the `Charlie\Fitness\CalculatorInterface` interface.
3. Define your own Selection class that will implement the `Charlie\Actions\Selection\SelectorInterface` interface.
4. Build your populations by implementing the `Charlie\Population\PopulationBuilderInterface` interface.
5. Define your problem by using the `Charlie\Problem\Problem` class.
6. Run the `solve` method of the `Charlie\Problem\Problem` class.

Example
-------

[](#example)

Let's say we want to find the best possible solution for the following knapsack problem:

> We have a list of 10 items. Each item has a weight and a value. We want to find the best combination of items that will maximize the total value of the items, but the total weight of the items must not exceed 15.

First, we need to define our Gene class. In our example, a Gene will be an item from the list. Therefore, we need to create a class that will represent an item from the list. Let's call it `Item`. The `Item` class needs to implement the `Charlie\Gene\GeneInterface` interface. Here is how the `Item` class will look like:

```
