TODO:
TODO:
TODO:
Liquid and solid rocket design using algorithmic evolution. Reach a target apogee while minimizing drift and ensuring static stability. Built on RocketPy. Supports genetic, memetic, and Bayesian optimization with customizable wind layers.
GeneticAlgorithm/
├── archive
├── engine/
│ ├── algorithms/ # genetic.py, memetic.py, bayesian.py
│ ├── backtests/ # CSV logs from optimization runs
│ ├── data/ # thrust curves, ullage CSVs, fluid properties
│ ├── environment_settings.py # Environment factory and wind management
│ ├── evaluator.py # Parallel evaluation and worker pool
│ ├── fitness.py # Fitness function (apogee error, drift, stability)
│ ├── logger.py # CSV logger
│ ├── main.py # Optimization entry point
│ ├── optimizer.py # Abstract base class for algorithms
│ ├── printer.py # Console output
│ ├── rocket_builder.py # Rocket and motor assembly
│ ├── single_flight.py # Single-design flight simulation
│ └── visualizer.py # Post-run analysis and plotting
└── misc
- Python 3.10+
- RocketPy >= 1.3.0
- NumPy, SciPy, scikit-learn, pandas, matplotlib, seaborn
pip install rocketpy numpy scipy scikit-learn pandas matplotlib seabornpython main.py [--algo {genetic,memetic,bayesian}] [options]| Argument | Description | Default |
|---|---|---|
--algo |
Algorithm: genetic, memetic, bayesian | bayesian |
--max_gen |
Number of generations | 15 |
--iter_per_gen |
Population size per generation | 20 |
--selection_method |
Parent selection: rank, boltzmann, tournament | rank |
--sp |
Selection pressure (rank only) | 1.5 |
--local_search_prob |
Local search probability (memetic only) | 0.35 |
--local_search_evals |
Max local search steps (memetic only) | 12 |
--random-wind |
Use random wind layers (different each run unless seed is set) | off |
--strong-wind |
Apply constant 50 m/s wind for drift testing | off |
--seed |
Integer seed for reproducible random wind | None |
Examples:
# Genetic algorithm, 10 generations, default population
python main.py --algo genetic --max_gen 10
# Bayesian optimization with 30 samples per generation
python main.py --algo bayesian --iter_per_gen 30
# Memetic algorithm with random wind layers
python main.py --algo memetic --random-wind
# Strong wind test (50 m/s from West)
python main.py --algo genetic --max_gen 5 --strong-wind
# Reproducible random wind using a seed
python main.py --algo bayesian --random-wind --seed 42Edit the DESIGN dictionary in single_flight.py to set your parameters, then:
python single_flight.py [--random-wind] [--strong-wind] [--upright] [--seed N]Each run saves a CSV in backtests/. To plot:
# Auto-select latest log
python visualizer.py
# Specific file
python visualizer.py backtests/backtest_20260713181149_bayesian.csvGenerated plots: best fitness, mean fitness with error bars, best apogee, drift and stability margin evolution, parameter traces, correlation heatmap, fitness vs apogee scatter, feasible/infeasible counts.
- Initialization: The algorithm creates an initial population of random designs within predefined bounds. Bayesian optimizer starts with a few random points before fitting its surrogate model.
- Evaluation: Each design is converted into a RocketPy rocket and simulated in parallel in a standard atmosphere with wind (if specified).
- Fitness: Rewards designs approaching the target apogee (3000 m) with low drift (bonus within 200 m), penalizing stability margins outside 1.5–5.0.
- Variation & Selection: Genetic/memetic algorithms apply crossover, mutation, and selection (memetic adds local random walk). Bayesian optimizer maximizes Expected Improvement via a Gaussian process.
- Elitism: The best individual is carried to the next generation.
- Logging: All evaluated designs are written to a timestamped CSV in
backtests/.
- Add parameters: Extend
VARIABLE_GENE_BOUNDSandINTEGER_GENESinmain.py, then updateRocketBuilderto use them. - Change fitness: Modify
fitness.pyto adjust weights or add objectives. - New wind models: Add cases in
environment_settings.py'sget_environment_parameters()function. - New algorithm: Create a class in
algorithms/that inherits fromOptimizerBaseand implementsrun_generation(evaluator)to be automatically available via--algo.
This project is provided for educational and research purposes. Refer to the RocketPy license for its terms.
This project is provided for educational and research purposes. Refer to the RocketPy license for its terms.