Giter VIP home page Giter VIP logo

genetictsp's Introduction

GeneticAlgorithm For TSP (Java)

This is a project to solve TSP by GeneticAlgorithm. If you look the source code, please click here.

Demo

I use processing to visual this algorithm and test it.

geneticdemo

If you processing ide, download floder named GeneticP5Visaul. Then open GeneticP5Visaul.pde and run it, you will visual view. But you don't processing ide, you can load processing library or you run src/GeneticTest.java, you will watch it in console.

Processing Demo Java Demo

Example

Method 1

If you use this method, you are better in a thread. Because it will return result untill MaxGeneration.

// get a GeneticAlgorithm instance
GeneticAlgorithm ga = GeneticAlgorithm.getInstance();
ga.setMaxGeneration(1000);
ga.setAutoNextGeneration(true);
// points is a array of all point, the function of getdist() is get adjacency matrix
best = ga.tsp(getDist(points));
System.out.print("best path:");
for (int i = 0; i < best.length; i++) {
    System.out.print(best[i] + " ");
}
System.out.println();

Method 2

If you use this method, you will control it by yourselt and using nextGeneration() function.

GeneticAlgorithm ga = new GeneticAlgorithm();
best = ga.tsp(getDist(points));

int n = 0;
while (n++ < 100) {
    best = ga.nextGeneration();

    System.out.println("best distance:" + ga.getBestDist() + " current generation:" + ga.getCurrentGeneration() + " mutation times:" + ga.getMutationTimes());
    System.out.print("best path:");
    for (int i = 0; i < best.length; i++) {
        System.out.print(best[i] + " ");
    }
    System.out.println();
}

About me

Welcome to pull requests.

If you have any new idea about this project, feel free to contact me. ๐Ÿ˜ƒ

genetictsp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.