Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monit_x<-c()
- monit_y<-c()
- monit_z<-c()
- ind<-0
- moni<-function(obj){
- bchromo<-which.min(obj$evaluations)
- chromo<-obj$population[bchromo,]
- monit_x[ind]<<-chromo[1]
- monit_y[ind]<<-chromo[2]
- monit_z[ind]<<- -min(obj$evaluations)
- ind<<-ind+1
- }
- library(genalg)
- iter<-100
- rbga.results <- rbga(c(-6, -6), c(6, 6),
- evalFunc=rfunk, mutationChance=0.01, iters = iter,
- popSize = 5, elitism = 1,monitorFunc = moni)#speciali lai GA grutak atrast
- solis=0.1# 0.1 0.2 0.05 ... cik vajag
- x <- seq(-6, 6, by = solis)
- y <- seq(-6, 6, by = solis)
- z<-matrix(nrow=length(y),ncol=length(x))
- for (i in 1:length(x)){
- for (j in 1:length(y)){
- z[i,j]<- rfunk(c(x[i],y[j]))
- }
- }
- image(x, y, -z,col=rainbow(24))#vienmer prasa ENTER
- points(x=monit_x,y=monit_y,pch = 19, cex = 1)
- image(x, y, -z,col=terrain.colors(24))
- points(x=monit_x,y=monit_y,pch = 19, cex = 1)
- animate_plot3 <- function() {
- for (i in seq(1, iter)) {
- image(x, y, -z,col=terrain.colors(24))
- points(x=monit_x[1:i],y=monit_y[1:i],pch = 19, cex = 1)
- }
- }
- library(animation)
- saveVideo(animate_plot3(), interval = 0.5, outdir = getwd(),video.name = "rastrigin.mp4")#dorabativatj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement