genetic-delivery-man

๐Ÿšš A genetic model written in Python for minimizing the delay time of delivery routes.๏ผˆไฝฟ็”จPython็ผ–ๅ†™็š„็”จไบŽๆœ€ๅฐๅŒ–็‰ฉๆต้…้€ๆ—ถ้—ด็š„้—ไผ ็ฎ—ๆณ•ใ€‚๏ผ‰

https://github.com/zhuagenborn/genetic-delivery-man

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • โœ“
    CITATION.cff file
    Found CITATION.cff file
  • โœ“
    codemeta.json file
    Found codemeta.json file
  • โœ“
    .zenodo.json file
    Found .zenodo.json file
  • โ—‹
    DOI references
  • โ—‹
    Academic publication links
  • โ—‹
    Academic email domains
  • โ—‹
    Institutional organization owner
  • โ—‹
    JOSS paper metadata
  • โ—‹
    Scientific vocabulary similarity
    Low similarity (11.5%) to scientific vocabulary

Keywords

delivery-optimization genetic-algorithm traveling-salesman-problem
Last synced: 6 months ago · JSON representation ·

Repository

๐Ÿšš A genetic model written in Python for minimizing the delay time of delivery routes.๏ผˆไฝฟ็”จPython็ผ–ๅ†™็š„็”จไบŽๆœ€ๅฐๅŒ–็‰ฉๆต้…้€ๆ—ถ้—ด็š„้—ไผ ็ฎ—ๆณ•ใ€‚๏ผ‰

Basic Info
  • Host: GitHub
  • Owner: Zhuagenborn
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 435 KB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
delivery-optimization genetic-algorithm traveling-salesman-problem
Created over 4 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Citation

README.md

Genetic Delivery Man

Python License

Introduction

Cover

This project uses a genetic model to solve a derivative version of the traveling salesman problem with time consideration.

A delivery man needs to deliver some goods to customers in different cities. Every customer has been waiting for a while and has a time limit on the delivery. If the time needed is greater than a customer's limit, the exceeded is treated as a delay.

The genetic model needs to find a route that minimizes the total delay time for all customers.

Getting Started

Prerequisites

bash pip install -r requirements.txt

Running

bash python main.py

Configurations

The configuration is in the src/config.json file.

Data

All data are stored in the src/data folder.

Cities

The city information is in the cities.csv file. The first city will automatically be set as the location of the delivery company, in other words, the starting point. And the location of each city have the following constraints:

  • 0 โ‰ค X โ‰ค mapSize.width
  • 0 โ‰ค Y โ‰ค mapSize.height

The values of mapSize.width and mapSize.height can be set in the configuration file.

json "mapSize": { "height": 600, "width": 800 }

Orders

The order information is in the orders.csv file. Each order has the following attributes:

| Attribute | Description | | :---------: | :-------------------------------------: | | ID | Unique order ID. | | City | The destination. | | WaitTime | The time the customer has been waiting. | | TimeLimit | The time limit on delivery. |

For example, if a order's WaitTime is 5 and TimeLimit is 20, it means the customer has been waiting for 5 minutes and the delivery must be sent within the next 15 minutes. Otherwise there will be a delay.

If all orders' WaitTime and TimeLimit are equal to 0, the problem will be the same as the traveling salesman. The model is actually trying to find the shortest route.

Genetic Model

Fitness

fitness

Crossover

The model uses ordered crossover. It randomly selects a subsequence of the first route, then fills the remainder with orders from the second route in the order in which they appear, without duplicate.

crossover

Mutation

The mutation randomly swaps two orders in a route.

mutation

Elitism

Keep the best route from the previous generation unchanged and replace the worst in the current generation with it.

Iteration

The maximum iteration number can be set in the configuration file. There are two variables:

json "maxIter": { "total": 2000, "unchanged": 0 }

The model will stop evolution if it's iteration reaches the value of maxIter.total. It is always effective.

maxIter.unchanged can be set to 0 and the model will not consider it. When it is larger than 0, the model will stop if the best individual remains unchanged over maxIter.unchanged iterations.

The console will show the detail of iterations.

console (344) Update the shortest delay: 1180.45 -> 1149.62 0 -> 1 -> 4 -> 5 -> 13 -> 7 -> 8 -> 11 -> 3 -> 12 -> 2 -> 10 -> 6 -> 9 (416) Update the shortest delay: 1149.62 -> 1145.07 0 -> 1 -> 4 -> 5 -> 13 -> 7 -> 8 -> 11 -> 12 -> 2 -> 10 -> 3 -> 6 -> 9 The shortest delay: 1145.07 0 -> 1 -> 4 -> 5 -> 13 -> 7 -> 8 -> 11 -> 12 -> 2 -> 10 -> 3 -> 6 -> 9

Test Statistics

The default configuration is:

```json { "speed": 100,

"mapSize": {
    "height": 600,
    "width": 800
},

"elitism": true,

"populationSize": 100,

"rate": {
    "cross": 0.4,
    "mutate": 0.01
},

"maxIter": {
    "total": 2000,
    "unchanged": 0
}

} ```

Before the test, 50 orders were randomly generated. Each order has a unique city as its destination. Their WaitTime and TimeLimit are equal to 0.

ID,City,WaitTime,TimeLimit 0,1,0.0,0.0 1,2,0.0,0.0 2,3,0.0,0.0 3,4,0.0,0.0

When testing a variable, the others are fixed.

Population Size

population-test

Crossover Rate

crossover-test

Mutation Rate

mutation-test

Elitism

elitism-test

Class Diagram

```mermaid classDiagram

class City { float x float y distance(City) float }

class Map { distance(from, to) float }

Map o-- City

class Order { City city float waittime float timelimit }

Order --> City

class OrderList { random_route() Route }

OrderList o-- Order OrderList ..> Route

class TimeOnWay { Map map float speed }

TimeOnWay --> Map

class Route { Map map TimeOnWay timeonway City origin float delay }

Route --> TimeOnWay

class Item { Route route float fitness list~Order~ dna }

Item --> Route Item --> Order

class Population { list~Item~ items list~float~ fitness generate(size) }

Population o-- Item

class Genetic { Population population float crossrate float mutaterate evolve(maxiter, maxunchanged_iter) }

Genetic --> Population ```

Dependencies

License

Distributed under the MIT License. See LICENSE for more information.

Owner

  • Name: Zhuagenborn
  • Login: Zhuagenborn
  • Kind: organization
  • Location: Ireland

Software Development | Artificial Intelligence | Reverse Engineering.

Citation (CITATION.cff)

cff-version: 1.2.0
authors:
- family-names: Chen
  given-names: Zhenshuo
  orcid: https://orcid.org/0000-0003-2091-4160
- family-names: Liu
  given-names: Guowen
  orcid: https://orcid.org/0000-0002-8375-5729
title: Genetic Delivery Man
date-released: 2021-05-28
url: https://github.com/Zhuagenborn/Genetic-Delivery-Man

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

requirements.txt pypi
  • numpy *
  • pandas *
  • pygame *