3 releases
0.1.2 | Apr 30, 2023 |
---|---|
0.1.1 | Apr 30, 2023 |
0.1.0 | Apr 29, 2023 |
#198 in Simulation
600KB
177 lines
simple-pso-demo-rs
English | 简体中文
A simple application of Particle Swarm Optimization (PSO):
Calculate the most valuable goods based on PSO, implemented in Rust.
According to course requirements, part of the code was generated by ChatGPT and modified.
Problem to Solve
Simulate the selection of the relatively most valuable goods from different brands of the same type of goods and solve it using PSO.
In this project, goods are simply defined as follows:
pub struct Product {
/// Individual fitness
p_best: f64,
/// There is a three-dimensional space, whose coordinate axis x, y, z's meaning
/// is below:
///
/// x.0 (x)- restocking_price
///
/// x.1 (y)- selling_price
///
/// x.2 (z)- market_demand
///
/// Score value is 1.
x: (f64, f64, f64),
/// Velocity vector
v: (i32, i32, i32),
w1: f64,
w2: f64,
}
The fitness (value) of a single particle (goods) is calculated using the following formula:
((purchase price - selling price) * w1) * market demand * w2
All particles (goods) are located in a two-dimensional space, and through PSO, the most valuable goods in the current space are calculated in a specified number of iterations.
The basic unit of step length for all particles is 1. When the selling price is lower than the purchase price, the particle only updates the velocity without displacement.