AIM: Write a program in Lisp to perform roulette wheel selection.
Post by: Sohrab Vakharia
(Enter a population of binary strings. Consider fitness value as the number of repetitions of a specified bit (say 1) in the string.)
Source Code:
Output:
Post by: Sohrab Vakharia
(Enter a population of binary strings. Consider fitness value as the number of repetitions of a specified bit (say 1) in the string.)
Source Code:
(defun wheel(list1 list2 list3 list4)
(setq llist1 (funlist list1))
(setq llist2 (funlist list2))
(setq llist3 (funlist list3))
(setq llist4 (funlist list4))
(print "The highest fitness of string is: ")
(setq m1(max llist1 llist2 llist3 llist4))
(print m1)
(if (= m1 llist1)(print "First String is Strongest")())
(if (= m1 llist2)(print "Second String is Strongest")())
(if (= m1 llist3)(print "Third String is Strongest")())
(if (= m1 llist4)(print "Fourth String is Strongest")())
)
(defun funlist(list1)
(setq list1 (reverse list1))
(setq len (length list1))
(setq sum1 0)
(setq count 1)
(setq sum 0)
(setq co 1)
(setq cn 2)
(setq fr (car list1))
(setq list1 (cdr list1))
(setq cn1 1)
(setq sum (* fir 1))
(setq sum1 (+ sum1 sum))
(loop
(when (>= count len) (return))
(setq fir (car list1))
(setq list1 (cdr list1))
(setq cn1 (* cn cn1))
(setq sum (* fir cn1))
(setq sum1 (+ sum1 sum))
(incf count)
)
(print "sum1")
(print sum1)
)
(setq llist1 (funlist list1))
(setq llist2 (funlist list2))
(setq llist3 (funlist list3))
(setq llist4 (funlist list4))
(print "The highest fitness of string is: ")
(setq m1(max llist1 llist2 llist3 llist4))
(print m1)
(if (= m1 llist1)(print "First String is Strongest")())
(if (= m1 llist2)(print "Second String is Strongest")())
(if (= m1 llist3)(print "Third String is Strongest")())
(if (= m1 llist4)(print "Fourth String is Strongest")())
)
(defun funlist(list1)
(setq list1 (reverse list1))
(setq len (length list1))
(setq sum1 0)
(setq count 1)
(setq sum 0)
(setq co 1)
(setq cn 2)
(setq fr (car list1))
(setq list1 (cdr list1))
(setq cn1 1)
(setq sum (* fir 1))
(setq sum1 (+ sum1 sum))
(loop
(when (>= count len) (return))
(setq fir (car list1))
(setq list1 (cdr list1))
(setq cn1 (* cn cn1))
(setq sum (* fir cn1))
(setq sum1 (+ sum1 sum))
(incf count)
)
(print "sum1")
(print sum1)
)
Output:
0 comments:
Confused? Feel free to ask
Post a Comment