https://github.com/cyypherus/swift-slime
A lightweight stochastic optimizer based on slime mold (Slime Mold Algorithm)
https://github.com/cyypherus/swift-slime
algorithm optimization optimization-algorithms stochastic-optimization swift
Last synced: 3 months ago
JSON representation
A lightweight stochastic optimizer based on slime mold (Slime Mold Algorithm)
- Host: GitHub
- URL: https://github.com/cyypherus/swift-slime
- Owner: cyypherus
- Created: 2022-05-11T02:18:36.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-18T23:44:20.000Z (almost 3 years ago)
- Last Synced: 2024-12-18T09:12:51.797Z (6 months ago)
- Topics: algorithm, optimization, optimization-algorithms, stochastic-optimization, swift
- Language: Swift
- Homepage:
- Size: 41 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Slime
This is a Swift implementation of a Slime Mold Algorithm - a stochastic optimizer - generally based on this [paper](https://doi.org/10.1016/j.future.2020.03.055)
The only dependency required by Slime is `SwiftNumerics`
# Visual Examples
Searching for the global maxima of
`-abs(x + 100000) - abs(y + 100000) + sin(10 * x)`
![]()
Searching for the shortest path visiting 50 locations (traveling salesman)
# Use the Slime
In a SwiftPM project:
Add the following line to the dependencies in your Package.swift file:
```swift
.package(url: "https://github.com/ejjonny/slime", from: "2.0.0"),
```Add Slime as a dependency for your target:
```swift
.target(
name: "MyTarget",
dependencies: [
.product(name: "Slime", package: "Slime"),
]
),
```Add `import Slime` to your swift file.
```swift
var slime = Slime(
populationSize: 10,
maxIterations: 100,
lower: SIMD2(-1, -1),
upper: SIMD2(1, 1),
method: .minimize, // Use .maximize if higher fitness values are better
fitnessEvaluation: { vector in
let x = vector[0]
let y = vector[1]
// Return a fitness value Double using the proposed vector
}
)
slime.run() // This runs the fitness evaluation many times, among other busy work, & will usually be expensiveslime.bestCells // An array of the top 3 Cells. Use Cell.position for the associated vectors
```This example is using a 2 dimensional solution space. The algorithm will work with any number of vector components if you're looking for a solution in *hyperspace*.
# More Info
*[wikiversity](https://en.wikiversity.org/wiki/Slime_Mould_Algorithm)*
> *"Slime mold algorithm (SMA) is a population-based optimization technique which is proposed based on the oscillation style of slime mold in nature. The SMA has a unique mathematical model that simulates positive and negative feedbacks of the propagation wave of slime mold. It has a dynamic structure with a stable balance between global and local search drifts."*# TODO:
- Readme walkthrough of the math used in the algorithm
- Explore some deterministic changes