{"id":31696608,"url":"https://github.com/tahernezhad/neuroevolution-graph-neural-network","last_synced_at":"2026-05-18T10:37:19.854Z","repository":{"id":317277070,"uuid":"1066650940","full_name":"Tahernezhad/Neuroevolution-Graph-Neural-Network","owner":"Tahernezhad","description":"A neuroevolutionary framework for structural optimization that trains Graph Neural Networks (GNNs) with a genetic algorithm.","archived":false,"fork":false,"pushed_at":"2025-09-29T22:02:00.000Z","size":5118,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-30T00:11:00.877Z","etag":null,"topics":["evolutionary-algorithms","genetic-algorithm","gnn","gnn-model","graph-attention-networks","graph-convolutional-networks","graph-neural-networks","graph-sage","neuroevolution","pytorch","torch-geometric","truss-optimization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tahernezhad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-29T19:20:50.000Z","updated_at":"2025-09-29T22:02:03.000Z","dependencies_parsed_at":"2025-09-30T00:23:17.006Z","dependency_job_id":null,"html_url":"https://github.com/Tahernezhad/Neuroevolution-Graph-Neural-Network","commit_stats":null,"previous_names":["tahernezhad/neuroevolution-graph-neural-network"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Tahernezhad/Neuroevolution-Graph-Neural-Network","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tahernezhad%2FNeuroevolution-Graph-Neural-Network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tahernezhad%2FNeuroevolution-Graph-Neural-Network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tahernezhad%2FNeuroevolution-Graph-Neural-Network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tahernezhad%2FNeuroevolution-Graph-Neural-Network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tahernezhad","download_url":"https://codeload.github.com/Tahernezhad/Neuroevolution-Graph-Neural-Network/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tahernezhad%2FNeuroevolution-Graph-Neural-Network/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278981518,"owners_count":26079640,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["evolutionary-algorithms","genetic-algorithm","gnn","gnn-model","graph-attention-networks","graph-convolutional-networks","graph-neural-networks","graph-sage","neuroevolution","pytorch","torch-geometric","truss-optimization"],"created_at":"2025-10-08T17:09:42.821Z","updated_at":"2025-10-08T17:09:43.928Z","avatar_url":"https://github.com/Tahernezhad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neuroevolution for Graph Neural Networks (Truss Design)\n\nEvolutionary optimisation of Graph Neural Networks (**GCN/GAT/GraphSAGE**, PyTorch‑Geometric) for **truss design**.  \nA genetic algorithm (GA) evolves network weights using **Simulated Binary Crossover (SBX)** and **Polynomial Mutation (PM)**, while a GNN controller iteratively “develops” a seed truss by adjusting **node coordinates** and **member cross‑sectional areas** under fixed loads/reactions.\n\n- **Backbones:** GCN (Graph Convolutional Network), GAT (Graph Attention Network), GraphSAGE (PyTorch‑Geometric).\n- **Physics Loop:** strain energy, volume, stresses computed per step; fitness = normalised strain energy + volume.\n- **EA Operators:** SBX + PM.\n- **Provenance:** Environment/organism logic adapted from the **RIED** project; this repo adds PyG models (GCN/GAT/SAGE), vectorised EA ops, and extra reward/visualisation utilities.\n\n\u003e Reference codebase (RIED EvoDevo): https://gitlab.com/riedproject \n\u003e \n\u003e Earlier NumPy GCN ideas were tested there. My repo re‑implements the GNN controller in PyTorch‑Geometric and extends it.\n\n---\n\n## Quick Outputs\n\nTraining writes a timestamped folder under `./data/` with:\n- `reward_plot.csv` — best \u0026 average reward per generation\n- `best_network.pkl` — pickled best controller\n- `results/best_devo.gif` — replayed developmental process (from `replay.py`)\n- `results/gnn_evo_plot.jpg`, `results/gnn_devo_plot.jpg` — plots\n\n---\n\n## Repository Structure\n\n```\n.\n├─ main.py                        # run evolutionary training\n├─ replay.py                      # visualise best controller; export GIF/CSVs/plots\n├─ src/\n│  ├─ genetic_algorithm.py        # GA + tournament selection\n│  ├─ ea_utils.py                 # SBX + PM (vectorised, bound‑aware)\n│  ├─ gnn_model.py                # GCN/GAT/GraphSAGE heads (node Δ, edge Δ)\n│  ├─ network.py                  # wrapper: init, eval loop per organism\n│  ├─ organism.py                 # truss state, graph features, fitness, updates\n│  ├─ environment.py              # statics: equilibrium, forces, strain energy, volume\n│  └─ utils.py                    # run‑dir helper, feature normaliser\n└─ data/                          # autogenerated per run (plots, logs, pickles)\n```\n\n---\n\n## Installation\n\n1) Create a virtual environment and install dependencies (ensure your PyTorch \u0026 PyG wheels match CPU/CUDA):\n```bash\npython -m venv .venv\nsource .venv/bin/activate      # (Windows: .venv\\Scripts\\activate)\npip install numpy matplotlib imageio torch torch_geometric\n```\n\u003e If PyG fails, first install a matching **PyTorch** (CPU or CUDA), then `torch_geometric` per your platform’s instructions.\n\n---\n\n## How to Run\n\n### 1) Train (evolutionary loop)\n```bash\npython main.py\n```\nDefaults live in `main.py`:\n```python\nmodel_name       = \"gcn\"     # \"gcn\" | \"gat\" | \"sage\"\nhidden_dim       = 120\nnum_layers       = 3\ndropout_rate     = 0.1\n\nnum_generations  = 150\npopulation_size  = 512\nnum_devo_steps   = 10\n\ncrossover_prob   = 0.9\ncrossover_eta    = 20.0\nmutation_prob    = 0.1\nmutation_eta     = 20.0\n\nWEIGHT_MIN, WEIGHT_MAX = -5.0, 5.0\n```\n\n### 2) Replay the best controller\n```bash\npython replay.py\n```\n- Set `run_dir` at the bottom of `replay.py` to your latest `data/\u003ctimestamp\u003e/`.\n- Produces `results/best_devo.gif`, CSVs for node positions/edge areas, and plots of strain energy/volume/total cost per developmental step.\n\n---\n\n## Configuration Notes\n\n- **Model backbone:** switch `model_name` among `gcn`, `gat`, `sage` in `main.py`.\n- **Reward (fitness):** sum of normalised strain energy + normalised volume (see `Organism.get_fitness`).\n- **EA operators:** implemented on flattened parameter vectors for speed and consistent per‑weight behaviour (`src/ea_utils.py`).\n- **Weight bounds:** defaults to `[-5, 5]`; tune via `WEIGHT_MIN/MAX` in `main.py`.\n- **Seedling \u0026 loads:** geometry, supports, and loads are defined in helpers within `main.py`/`replay.py`.\n\n---\n\n## Acknowledgements\n\nThis repository re‑implements the controller in PyTorch‑Geometric (GCN/GAT/GraphSAGE), adds vectorised SBX/Mutation, and expands logging/visualisation for truss development. Environment modelling concepts originate from the **RIED** project (GitLab): https://gitlab.com/riedproject\n\n- [PyTorch](https://pytorch.org/)\n- [TorchGeometric](https://pytorch-geometric.readthedocs.io/en/latest/)\n---\n\n## Troubleshooting\n\n- **PyG install issues:** ensure your PyTorch and CUDA/CPU versions match PyG wheels.\n- **Singular matrix / unstable truss:** large penalties are applied when the equilibrium system is ill‑posed; adjust seedling geometry, supports, or loads.\n- **No replay output:** confirm `best_network.pkl` exists under your chosen `run_dir`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftahernezhad%2Fneuroevolution-graph-neural-network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftahernezhad%2Fneuroevolution-graph-neural-network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftahernezhad%2Fneuroevolution-graph-neural-network/lists"}