Coder Social home page Coder Social logo

Comments (2)

dorkrawk avatar dorkrawk commented on September 15, 2024

Sure, you can define your fitness method any way you want. For example you could write something like this:

require 'darwinning'

class Triple
  include Darwinning

  ...

  def initialize(target_sum)
    @target_sum = target_sum
  end

  def fitness
    # Try to get the sum of the 3 digits to add up to 100
    (first_number + second_number + third_number - @target_sum).abs
  end
end

from darwinning.

davetapley avatar davetapley commented on September 15, 2024

So, I wrote something similar to that also, but when I used the snippet showing how to call evolve!, I get the following error:

in `initialize': wrong number of arguments (given 0, expected 1) (ArgumentError)
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning/population.rb:101:in `new'
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning/population.rb:101:in `build_member'
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning/population.rb:31:in `block in build_population'
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning/population.rb:30:in `times'
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning/population.rb:30:in `build_population'
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning/population.rb:25:in `initialize'
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning.rb:18:in `new'
        from /usr/local/bundle/gems/darwinning-0.1.1/lib/darwinning.rb:18:in `build_population'
        from test.rb:25:in `<main>'

⬆️ that is from this.

from darwinning.

Related Issues (12)

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.