Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
45 views
in Technique[技术] by (71.8m points)

python 3.x - Genetic algorithm is not working properly?

i am trying to built a time table generator using python and my algorithm is not able to produce a solution with 0 conflicts. I ends up giving me genome with 1 or 2 conflicts doesn't matter for how many generation i run it for? i think the issue is with the mutation function can anybody tell me how can i write smart mutation function.

My mutation function looks like this

def multi_point_crossover(a,b):
    if len(a) != len(b):
        raise ValueError("Genomes a and b are must be of same Lenght")
    lenght = len(a)
    aaa,bbb = a[:],b[:]
    p = randint(1,lenght - 1)
    rday = randint(1,lenght-1)
    ip = randint(1,len(a[0]))
    aaa[rday],bbb[rday] = a[rday][:ip] +b[rday][ip:],b[rday][:ip] +a[rday][ip:]
    return aaa[:p]+bbb[p:],bbb[:p]+aaa[p:]

and remember my genome is a 2d list [[day1],[day2],[day3],[day4],[day5]]. and each day looks like this [1,4,2,None,3,3,None] and then i can map it to the time slots according to the index and i can also get lecture according to the index value.

question from:https://stackoverflow.com/questions/65920143/genetic-algorithm-is-not-working-properly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...