Download the PHP package sedatsevgili/charlie without Composer
On this page you can find all versions of the php package sedatsevgili/charlie. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sedatsevgili/charlie
More information about sedatsevgili/charlie
Files in sedatsevgili/charlie
Package charlie
Short Description A simple genetic algorithm library
License MIT
Informations about the package charlie
Charlie Project
Description
This project is a simple library that allows PHP developers to easily build their own applications by using Genetic Algorithms.
Installation
To install this library, you can use composer:
Usage
To use this library for your own purposes as a PHP developer, you need to:
- Define your own Gene class that will implement the
Charlie\Gene\GeneInterfaceinterface. - Define your own FitnessFunction class that will implement the
Charlie\Fitness\CalculatorInterfaceinterface. - Define your own Selection class that will implement the
Charlie\Actions\Selection\SelectorInterfaceinterface. - Build your populations by implementing the
Charlie\Population\PopulationBuilderInterfaceinterface. - Define your problem by using the
Charlie\Problem\Problemclass. - Run the
solvemethod of theCharlie\Problem\Problemclass.
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:
Next, we need to define our FitnessFunction class. In our example, the FitnessFunction will calculate the total value of a combination of items. Therefore, we need to create a class that will calculate the total value of a combination of items. Let's call it KnapsackFitnessFunction. The KnapsackFitnessFunction class needs to implement the Charlie\Fitness\CalculatorInterface interface. Here is how the KnapsackFitnessFunction class will look like:
Now, we can solve our problem. In our example, we will run the Problem class. Here is how we run it:
License
This library is licensed under the MIT License - see the LICENSE.md file for details.