惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
Y
Y Combinator Blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 【当耐特】
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
J
Java Code Geeks
美团技术团队
Google DeepMind News
Google DeepMind News
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
T
The Blog of Author Tim Ferriss

DEV Community

How to audit what your IDE extension actually sends to the cloud I Migrated 23 Make.com Scenarios to n8n and Cut My Bill by 60% — Complete Migration Guide (2026) Claude Code Skills Explained: What They Are & When to Use Them (2026) Maintaining Apache Iceberg Tables: Compaction, Expiry, and Cleanup Zero-Idle Local LLMs: Running Llama 3 in AWS Lambda Containers We scanned 8 B2B SaaS companies across 5 categories. ChatGPT named the same 12 brands in every answer. Unit Testing vs System Testing: Key Differences, Use Cases, and Best Practices for 2026 A game design textbook explains why products with fewer features win How to Build a Raydium Launchpad Bonding Curve in 5 Minutes with forgekit How to turn an AI prototype into a production system How Data Lake Table Storage Degrades Over Time Partition and Sort Keys on DynamoDB: Modeling data for batch-and-stream convergence Auto-Generate Optimized GitHub Actions Workflows For Any Stack With This New CLI Tool Unchaining the African Creator Economy The Treasure Hunt Engine Gotcha - A Lesson in Constrained Performance great_cto v2.17 - no more tambourine dance When Catalogs Are Embedded in Storage SafeMind AI: Instant Health & Safety Intelligence What Is PKCE, How It Works & Flow Examples AI Agent Failure Modes Beyond Hallucination Fastest Way to Understand Stryker Solana Accounts Explained to a Web2 Developer TV Yayın Akışı Sitesi Geliştirirken Öğrendiğim Teknik Dersler $500 Challenge Drop My First Look at Google's Gemma 4: A Quick Introduction How I use an LLM as a translation judge Best Calendar and Scheduling API for Developers — 2026 Comparison Agentic AI in Travel: Why UCP Isn't Travel-Ready Yet — and What We Measured I Finished Machine Learning. And Then Changed The Plan. The Five-Thousand-Line File The AI Whirlwind: Why Your Local Agent Matters More Than Ever I Built an Oracle DBA That Lives in Telegram. It Cut a 500K-Row Scan to 5 - After Asking Permission. The Day 2 Reality of Running a Kubernetes Lab on Your Mac: Stop/Start, CKS Scenarios, and What I Learned Building It. n8n for Airtable Power Users: 5 Automations That Take Your Base to the Next Level Validating Gemma 4 for Industrial IoT: A Governance Pattern VS Code Now Credits Copilot on Every Commit by Default Astro and Islands Architecture: Why Your Portfolio Doesn't Need React for Everything Booting from FAT12: How I added file reading to my x86 kernel Unity’s AI agent went public: the developers of a static analysis tool on what that means for code quality Anna's Archive publica un llms.txt para los LLMs que rastrean su catálogo CRDTs for Offline-First Mobile Sync Why I Built Mneme HQ: Preventing AI Agent Architectural Drift Google Antigravity 2.0 Is the I/O 2026 Announcement You Should Actually Care About I Built a Pay-Per-Call Crypto Signal API with x402 — Heres the Architecture JWT Token Refresh Patterns in React 19: Avoiding the Silent Auth Death Spiral 🚀 “From Prompts to Autonomous Agents: What Google I/O 2026 Changed” The Power of Distributed Consensus in Autonomous SOCs Sixteen TUI components, copy-paste, no dependency The Boring Reliability Layer Every Autonomous Agent Needs Nven - Secret manager Building Multi-Tenant Row-Level Security in PostgreSQL: A Production Pattern The Hardest Part of Being a Developer Isn't Coding Building Vylo — Looking for Collaborators, Partners & Early Support I Thought Memory Fades With Time. It Actually Fades With Information. ORA-00064 오류 원인과 해결 방법 완벽 가이드 I registered an AI agent at 1 AM and something cracked open in my head Pitch: Nven - Sync secrets. Ship faster. Why y=mx+b is the heart of AI From Routines to a Crew — Building a System That Plans Its Own Work & executes it 25 React Interview Questions 2026 (With Answers) — Hooks, React 19, Concurrent Mode An open source LLM eval tool with two independent quality signals Using Dashboard Filtering to Get Customer Usage in Seconds from TBs of Data Skills, Java 17, And Theme Accents 4 Hard Lessons on Optimizing AI Coding Agents Arctype: Cross-Platform Database GUI for LLM Artifacts Your robots.txt says GPTBot is welcome. Your server says 403. Organizing How to Use AWS Glue Workflow 5 n8n Automations Every Digital Agency Should Be Running (Bill More, Work Less) Getting Started with TorchGeo — Remote Sensing with PyTorch Designing a Scalable Cross-Platform Appium Framework Google Antigravity 2.0 & Slash Commands Building a Unified Adaptive Learning Intelligence with Gemma 4, Flutter, and Multi-Model Orchestration Looking for beta testers for a £60 server management application The Disk-Pressure Incident That Taught Me to Always Set LimitRanges and Other Lessons from Mirroring EKS Locally. Why AI Should Not Write SQL Against ERP Databases Vibe coding works until it doesn't. The debt is real. Shipping at the Edge: Migrating a Coffee Subscription Platform to Cloudflare Workers Stop Tab-Switching: A Developer's Guide to Color Tools That Actually Fit the Workflow DevOps vs MLOps vs AIOps: What Changes, What Stays, and a Simple Roadmap to Get Started Run Powerful AI Coding Locally on a Normal Laptop 5 n8n Automations Every WooCommerce Store Needs (Save 10+ Hours/Week) What I Learned Building My Own AI Harness Hytale Servers Will Fail Treasure Hunts Until We Fix Our Event Handling Redux in React: Managing Global State Like a Pro Unfreezing Your GitHub Actions: Troubleshooting Stuck Deployments and Protecting Your Git Repo Statistics Unlocking Project Discoverability on GHES: A Key to Software Engineering Productivity When the Cleanup Code Becomes the Project Rockpack 8.0 - A React Scaffolder Built for the Age of AI-Assisted Development Mismanaging the Treasure Hunt Engine in Hytale Servers Will Get You Killed Stop Calling It an AI Assistant. It’s Already Managing Your Company Why Hardcoded Automations Fail AI Agents Why I built a post-quantum signing API (and why JWT is on borrowed time) Weekend Thought: Frontend Build Tools Suffer From Work Amnesia AI Is Changing Engineering Culture More Than We Realize A 10-Line Playwright Trick That Saved Me Hours on Every Sephora Run Everyone Was Focused on Gemini, But Infinite Scaler Was the Real Twister "Gemma 4 Analyzed My Bank Statements – Apparently I 'Have a Problem' with Coffee and Late-Night Apps" #css #webdev #beginners #codenewbie The Hidden Layer Every AI Developer Must Learn AlphaEvolve: Google DeepMind's Gemini-Powered Evolutionary Coding Agent
Solving a Logistics Problem Using Genetic Algorithms
Mayank Singh · 2026-05-22 · via DEV Community

A week back, I started exploring Genetic Algorithms — and honestly,
the concept blew my mind a little. The idea that you can solve complex optimization problems by mimicking how evolution works felt almost too clever to be real.

So I needed a problem to test it on. Something non-trivial, something with real-world relevance. That's when I stumbled upon the Vehicle Routing Problem — figuring out the efficient routes for a fleet of vehicles to visit a set of locations and return to a depot.

Here's how it went.


What Even Are Genetic Algorithms?

The idea is borrowed directly from Darwin's theory of evolution.
In nature, organisms that are better adapted to their environment
survive and reproduce, passing their traits to the next generation.
Over time, the population gets better and better at surviving.
"Survival of the fittest".

GAs do the exact same thing — but with solutions to a problem.

Here's the basic loop:

  1. Population — Start with a bunch of random solutions
  2. Fitness — Evaluate how good each solution is
  3. Selection — Pick the better solutions to "reproduce"
  4. Crossover — Combine two solutions to create new ones
  5. Mutation — Randomly tweak solutions to maintain diversity
  6. Repeat — Do this for number of generations

Each generation, usually population of solutions gets a little bit better (better fitness).
Not guaranteed to find the perfect solution — but surprisingly good
at finding a very good one, very fast.

That's the magic of it.


The Vehicle Routing Problem

Now, the problem I chose to throw this at.

Imagine I run a delivery company. You have a central depot, a fleet of vehicles, and a bunch of locations to deliver to. My job is to figure out which vehicle visits which locations, and in what order — such that the total distance traveled is minimized and the workload is roughly balanced across vehicles.

This is the Vehicle Routing Problem (VRP), and it shows up everywhere — Amazon delivery routes, food delivery apps, garbage collection, even school bus scheduling.

The reason it's hard: the number of possible routes explodes combinatorially as you add more locations. For example, with 40 locations and 4 vehicles, brute-forcing every possible combination is completely out of the question. I need a smarter approach.
(Keep this example in mind, I have used it to explain my approach)

Enter the Genetic Algorithm.


Implementation

I built this using Python and the DEAP library, which provides me
the building blocks for evolutionary algorithms.

Representing a Solution

Keep in mind

The first design decision is how to encode a solution. I used a
permutation of location indices — a shuffled list of numbers from
0 to 39, where the order determines which locations each vehicle visits.

Vehicles are assigned stops in a round-robin fashion:

  • Vehicle 1 gets indices 0, 4, 8, ...
  • Vehicle 2 gets indices 1, 5, 9, ...
  • Vehicle 1 gets indices 2, 6, 10, ...
  • Vehicle 2 gets indices 3, 7, 11, ...

This keeps the representation simple and makes crossover and
mutation straightforward.

Fitness Function

The fitness function evaluates how good a solution is. Mine tracks
two things:

  1. Total distance — sum of all routes across all vehicles (primary objective, weight = -100)
  2. Standard deviation of distances — how balanced the workload is across vehicles (secondary objective, weight = -1)

Both are minimized. The high weight on total distance means the GA
primarily optimizes for shorter routes, but also nudges toward
balanced workloads.

Genetic Operators

  • Crossover — Ordered Crossover (OX): Preserves the relative
    order of locations from one parent while filling in the rest from
    the other, prevents duplicate visits.

  • Mutation — Shuffle Indexes: Randomly swaps a few locations
    in the route. Keeps solutions valid while introducing variation.

  • Selection — Tournament Selection: Picks the best individual
    from a random subset of certain size(=pop_size) from the population. Tournament size controls selection pressure — larger tournaments = stronger pressure toward the best solutions.

Elitism

One thing I added on top of the standard GA loop is elitism —
after each generation, I force the all-time best solution back
into the population. This prevents the algorithm from accidentally
losing a great solution during a heavy mutation phase.

pop[-1] = toolbox.clone(hof[0])  # Elitism

Enter fullscreen mode Exit fullscreen mode

Small change, big impact on convergence stability.


Experimentation and Results

This is where things got interesting. I ran two phases of experiments to understand how each hyperparameter affects the algorithm's behavior.

Phase 1 — Parameter Sweeps

I tested three parameters independently:

Population Size (5, 50, 500)
Larger populations explore more of the solution space but are slower per generation. Too small and the GA gets stuck early. 500 gave noticeably better final distances than 5 or 50.

Mutation Rate (0.008, 0.08, 0.8)
Too low and the population converges prematurely — everyone looks
the same and improvement stalls. Too high and you're basically
random search. 0.08 hit the sweet spot in my experiments.

Tournament Size (2, 20, 200)
This controls selection pressure. A tournament size of 200 in a
population of 300 means almost always picking the very best —
which sounds good but kills diversity fast. Size 2 is too random.
20 worked better.

Phase 2 — Diversity vs Convergence

I then ran four full configurations over 300 generations and tracked both the best distance and population diversity (std dev of fitness):

Configuration Mutation Tournament Behavior
Base 0.4 200 Fast convergence, low diversity
Low Selection 0.4 3 Slow convergence, high diversity
Low Mutation 0.05 200 Premature convergence
Balanced 0.2 5 Best overall trade-off

The key insight: high selection pressure + low mutation = premature convergence. The population homogenizes too quickly and gets stuck in a local optimum. You need enough mutation to keep exploring even as the population converges.

The balanced configuration consistently gave the best results —
not the fastest to converge, but the lowest final distance.


Conclusion

Going into this, I expected genetic algorithms to feel like a black
box — tweak some parameters, hope for the best. What I actually found was a surprisingly interpretable system where each design choice has a clear, observable effect on behavior.

A few things that stuck with me:

  • Representation matters more than I expected. The round-robin
    assignment is simple but works well. A different encoding could
    change everything.

  • Diversity is underrated. It's tempting to crank up selection
    pressure to get fast convergence, but you pay for it later when
    the algorithm gets stuck.

  • Elitism is a small change with a big payoff. Without it, good solutions can get lost during mutation-heavy phases.

The VRP is just one application — the same GA framework could be
adapted for scheduling, network design, or any combinatorial
optimization problem where brute force isn't an option.

If you want to dig into the code, the full notebook is on GitHub:
Vehicle Routing Optimization

Also I have uploaded some images showing progress of generations.