Genetic Algorithm for Graph Optimization
Project description
GraphEvo: Genetic Algorithm for Graph Optimization
GraphEvo is a powerful C++ library with Python bindings that implements genetic algorithms for graph optimization problems. It provides efficient tools for evolving and optimizing graph structures using genetic algorithms.
Features
- Genetic Algorithm Implementation: Core genetic algorithm operations including selection, crossover, and mutation
- Graph Generation: Tools for generating and evolving graph structures
- Fitness Evaluation: Customizable fitness functions for graph optimization
- High Performance: C++ implementation with Python bindings for optimal performance
Installation
From PyPI
pip install graphevo
From Source
# Clone the repository
git clone https://github.com/Js-Hwang1/GraphEvo.git
cd GraphEvo/python
# Install in development mode
pip install -e .
Requirements
- Python 3.7 or higher
- C++17 compatible compiler
- CMake 3.10 or higher
- Eigen3
- pybind11
Quick Start
import graphevo as ge
import networkx as nx
# Create a graph generator
generator = ge.GraphGenerator()
# Generate an initial population
population = generator.generate_population(
population_size=100,
num_nodes=50,
edge_probability=0.3
)
# Create a genetic algorithm instance
ga = ge.GeneticAlgorithm(
population=population,
mutation_rate=0.1,
crossover_rate=0.8,
elite_size=5
)
# Run the genetic algorithm
best_graph = ga.evolve(
generations=100,
fitness_function=lambda g: nx.density(g) # Example fitness function
)
# Access the best graph
print(f"Best graph density: {nx.density(best_graph)}")
Core Components
GraphGenerator
- Generates random graphs
- Creates initial populations
- Supports various graph generation strategies
GeneticAlgorithm
- Implements the core genetic algorithm
- Handles selection, crossover, and mutation
- Supports customizable fitness functions
GeneticOperators
- Provides mutation and crossover operations
- Customizable for different graph types
- Optimized for performance
FitnessEvaluator
- Evaluates graph fitness
- Supports custom fitness functions
- Handles multi-objective optimization
Advanced Usage
Custom Fitness Functions
def custom_fitness(graph):
# Calculate graph properties
density = nx.density(graph)
clustering = nx.average_clustering(graph)
# Combine into a single fitness score
return density * clustering
# Use in genetic algorithm
ga = ge.GeneticAlgorithm(
population=population,
fitness_function=custom_fitness
)
Custom Genetic Operators
def custom_mutation(graph):
# Implement custom mutation logic
return mutated_graph
def custom_crossover(parent1, parent2):
# Implement custom crossover logic
return child_graph
# Use custom operators
ga.set_mutation_operator(custom_mutation)
ga.set_crossover_operator(custom_crossover)
Citation
If you use GraphEvo in your research, please cite:
@software{GraphEvo,
author = {Junsung Hwang},
title = {GraphEvo: Genetic Algorithm for Graph Optimization},
year = {2025},
publisher = {GitHub},
url = {https://github.com/Js-Hwang1/GraphEvo}
}
Contact
- Author: Junsung Hwang
- Email: hwang30916@gmail.com
- GitHub: Js-Hwang1
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphevo-0.1.0.tar.gz.
File metadata
- Download URL: graphevo-0.1.0.tar.gz
- Upload date:
- Size: 94.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
feb2281670185f4b18a4248c7df9e7c82ccf56f7f96f53895a03dc8aa188ce92
|
|
| MD5 |
690fb5dc4d4f4ab41301fe135927b9de
|
|
| BLAKE2b-256 |
ab5797e7057b7699421d4c9fe38da4b09ebe054a2ccc93551d52fe908b1633c7
|
File details
Details for the file graphevo-0.1.0-cp313-cp313-macosx_15_0_arm64.whl.
File metadata
- Download URL: graphevo-0.1.0-cp313-cp313-macosx_15_0_arm64.whl
- Upload date:
- Size: 218.9 kB
- Tags: CPython 3.13, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31d40d842a6e9bff3f2e6953a545c666c921eaf399e7c7857da00281b42be84c
|
|
| MD5 |
cc9116b5f6b296a56dec254a2de2605b
|
|
| BLAKE2b-256 |
f3bceef35df371509db874b4cb6c528cec6498af95a4591c2b91a29664e907af
|