This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
EM.run do | |
EM.add_periodic_timer(1) do | |
puts "time elapsed" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
EM.run do | |
EM.add_timer(10) do | |
puts "STOP" | |
EM.stop_event_loop | |
end | |
EM.add_periodic_timer(1) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
EM.run do | |
EM.add_periodic_timer(1) do | |
puts "time elapsed" | |
end | |
EM.defer do | |
logs = IO.readlines('/var/log/kernel.log') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
EM.run do | |
spawned_process = EM.spawn do |did_what| | |
puts "I just " + did_what | |
end | |
EM.add_periodic_timer(1) do | |
spawned_process.notify "ate" | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fitness(n): | |
return n^0b1010 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chromosome | |
attr_accessor :bitstring | |
attr_accessor :fitness | |
def generate_random(length) | |
i = 0 | |
@bitstring = "" | |
while i < length | |
@bitstring += rand(2).to_s | |
i += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chromosome | |
attr_accessor :bitstring | |
def fitness_func(n) | |
return n^0b1010 | |
end | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chromosome | |
... | |
def self.set_roulette(chrs) | |
@@roulette = [] | |
chrs.each do |f| | |
i = 0 | |
while i < f.fitness | |
@@roulette.push(f) | |
i += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chromosome | |
... | |
def self.produce_new(chrs) | |
roulette(chrs) | |
newchrs = [] | |
chrs.each do |c| | |
newchrs.push(roulette(chrs)) | |
end | |
fitnesses(newchrs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chromosome | |
... | |
def self.get_mates(chrs) | |
i = 0 | |
res = {} | |
#again, the counting is very important (and mistakes are very hard to catch) | |
#so, we are writing it out in full | |
while i < chrs.length | |
res[i] = i+1 |