Git Product home page Git Product logo

gasol's Introduction

GASol

A general Genetic Algorithm Solver in C++

Build Status codecov License

Build

Clone GASol

git clone --recursive [email protected]:PytLab/GASol.git

Create dir for building.

cd GASol
mkdir build
cd build

Build GASol

  • Serial version
cmake ..
make
  • MPI parallel version
export CXX=/<mpi_path>/mpicxx
cmake -DMPI=true ..
make

Run test

make unittest
./unittest/unittest

Run example

make example
./example/example

Quick start

Find the maxima of f(x) = x + 10sin(5x) + 7cos(4x)

#include "mpiutils.h"
#include "engine.h"

#include <cmath>
#include <vector>
#include <utility>

using namespace gasol;

// Define fitness function. 
double fitness(const Individual & indv)
{
    double x = indv.solution()[0];
    return x + 10*std::sin(5*x) + 7*std::cos(4*x);
}

int main()
{
    // Initialize MPI environment.
    MPIUtils::init();
    // Variable range.
    std::vector<std::pair<double, double>> ranges {{0.0, 10.0}};
    // Decrete precision.
    std::vector<double> precisions {0.001};

    // Create population.
    size_t size = 50;
    std::vector<Individual> individuals;
    for (size_t i = 0; i < size; i++)
    {
        gasol::Individual indv(ranges, precisions);
        individuals.push_back(indv);
    }
    Population population(individuals, &fitness);

    // Genetic operators.
    RouletteWheelSelection selection;
    UniformCrossover crossover(0.8, 0.5);
    FlipBitMutation mutation(0.1);

    // Create engine.
    Engine engine(population, selection, crossover, mutation);

    // Run 1000 generations.
    engine.run(1000);

    // Finalize MPI env.
    MPIUtils::finalize();

    return 0;
}

gasol's People

Contributors

pytlab avatar

Stargazers

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

Watchers

 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.