Latest 0.1.0
Homepage https://github.com/natmark/Evolver
License MIT
Platforms osx 10.9
Authors

Evolver-Header


Build Status


Pods Version


Platforms


Swift


Carthage Compatible

Evolver is a Genetic Algorithm library for Swift🐧.

Usage

The main units of Evolver are Generable protocol and Evolver class.

  1. Create Model conformed to Generable
    struct Player: Generable {
    var direction = Array(
        repeating: Gene.template(Direction.self, geneSize: Counter(Direction.self).count),
        count: 20
    )
    var action = Array(
        repeating: Gene.template(Action.self, geneSize: Counter(Action.self).count),
        count: 10
    )
    }
  2. Prepare Enumeration conformed to Int & GeneBase
    enum Direction: Int, GeneBase {
    case left
    case right
    case up
    case down
    }
  3. Implement Evaluate function
    func evaluate(model: Player) -> Int {
    ・・・
    }
  4. Simulate Genetic Algorithm
    
    let result = Evolver.run(template: Player.self,
                        generations: 20,
                        individuals: 10,
                        completion: {  model, generation, individual in
    // Implement Evaluate model function    
    let score = self.evaluate(model: model)
    return score
    })

switch result {
case .success(let model):
for direction in model.direction {
print(direction.value) // You can get enum case
}
case .failure(let error):
print(error)
}


## Tips
`Evolver` is simulating on main thread default.
Use `DispatchQueue` if you want to running on sub thread.

```Swift
DispatchQueue.global(qos: .userInitiated).async {
    let result = Evolver.run(template: Player.self,
                            generations: 20,
                            individuals: 10,
                            completion: { model, generation, individual in
        let score = self.evaluate(model: model)
        return score
    })
    DispatchQueue.main.async {
        switch result {
        case .success(let model):
            print(model)
        case .failure(let error):
            print(error)
        }
    }
}

Instration

CocoaPods

Add the following to your Podfile:

  pod "Evolver"

Carthage

Add the following to your Cartfile:

  github "natmark/Evolver"

License

Evolver is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Evolver",
    "version": "0.1.0",
    "summary": "Genetic Algorithm library for Swift.",
    "description": "Evolver is a Genetic Algorithm library for Swift.",
    "homepage": "https://github.com/natmark/Evolver",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Atsuya Sato": "[email protected]"
    },
    "platforms": {
        "osx": "10.9"
    },
    "source": {
        "git": "https://github.com/natmark/Evolver.git",
        "tag": "0.1.0"
    },
    "source_files": "Evolver/**/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This