Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better async wrapper and small tweaks / additions.
- Loading branch information
Showing
12 changed files
with
170 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// DiscreteChoiceGene.swift | ||
// SwiftGenetics | ||
// | ||
// Created by Santiago Gonzalez on 7/25/19. | ||
// Copyright © 2019 Santiago Gonzalez. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol DiscreteChoice: CaseIterable, Hashable { } | ||
|
||
struct DiscreteChoiceGene<C: DiscreteChoice, E: GeneticEnvironment>: Gene { | ||
typealias Environment = E | ||
|
||
var choice: C | ||
|
||
mutating func mutate(rate: Double, environment: DiscreteChoiceGene<C, E>.Environment) { | ||
guard Double.random(in: 0..<1) < rate else { return } | ||
|
||
// Select a new choice randomly. | ||
choice = C.allCases.filter { $0 != choice }.randomElement()! | ||
} | ||
} | ||
|
||
extension DiscreteChoiceGene: RawRepresentable { | ||
typealias RawValue = C | ||
var rawValue: RawValue { return choice } | ||
init?(rawValue: RawValue) { | ||
self = DiscreteChoiceGene.init(choice: rawValue) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters