lgp
Core Rust library for Linear Genetic Programming.
Overview
lgp provides a trait-based framework for evolving sequences of register-based instructions to solve reinforcement learning and classification tasks. It includes built-in support for OpenAI Gym environments, Iris classification, and hybrid LGP + Q-Learning.
Installation
Add to your Cargo.toml:
[]
= "1.3"
To enable OpenAI Gym environment support:
[]
= { = "1.3", = ["gym"] }
Core Traits
The framework is built around these key traits:
State- Represents an environment state with value access and action executionRlState- ExtendsStatefor RL environments with terminal state detectionCore- Main trait defining the genetic algorithm components (registers, instructions, individuals)Fitness- Evaluates individual performance on a set of statesBreed- Two-point crossover for creating offspringMutate- Mutation operators for genetic variation
Modules
| Module | Description |
|---|---|
core |
Core LGP engine — registers, instructions, individuals, and evolutionary loop |
problems |
Built-in problem implementations (CartPole, MountainCar, Iris) |
extensions |
Extended functionality including Q-Learning integration |
utils |
Utility functions for tracing, serialization, and configuration |
Quick Example
use CoreEngine;
use IrisLgp;
See the examples directory and extension guide for more.
Features
| Feature | Default | Description |
|---|---|---|
gym |
No | Enables OpenAI Gym environment support via gymnasia |
Supported Environments
| Environment | Type | Inputs | Actions |
|---|---|---|---|
| CartPole | RL | 4 | 2 |
| MountainCar | RL | 2 | 3 |
| Iris | Classification | 4 | 3 |