Comp Sci I need a solved numerical example on genetic algorithm for 1 iteration

AI Thread Summary
The discussion centers around the need for a clear, hand-solved example of a genetic algorithm, particularly for the knapsack problem, to aid in exam preparation. Users express frustration with the lack of straightforward resources and suggest looking for Python code examples to understand the algorithm better. One participant shares a GitHub link to a relevant code file, but others find it insufficient for their needs, citing the complexity of the code. The conversation highlights the importance of understanding the algorithm's steps and requirements for the exam, emphasizing that the provided code, while not in a traditional format, can still serve as a valuable resource. Overall, the thread underscores the challenge of finding accessible educational materials on genetic algorithms.
shivajikobardan
Messages
637
Reaction score
54
Homework Statement
genetic algorithm
Relevant Equations
none
Really need this. Tried googling but not many. 1 or 2 are there. I want this algorithm solved by hand to some problem. IDK what kinds of problems exists. but one is knapsack problem. there is analytics vidya's tutorial but I want something else, more direct, more clear...Any resource you can show to me? I really need it. This is important for my exam. Asked almost 70% of time.

if you search "genetic algorithm-smita tiwari" in youtube, that is exactly kind of answer I want. step by step 1 iteration of genetic algorithm..clearly written so that I can understand it easily.
 
Last edited by a moderator:
Physics news on Phys.org
I did a search for "genetic algorithm knapsack problem" and got lots of hits. What I would do, rather than look at a video, is to download one of the many Python code examples out there, and run it, preferably using a debugger to step through the code a line at a time.

If you don't know how to use a debugger, there's a simple one called pdb that comes with Python distros. I wrote a two-part Insights article a few years ago with some tips about debugging Python code. See https://www.physicsforums.com/insights/simple-python-debugging-pdb-part-1/ and https://www.physicsforums.com/insights/simple-python-debugging-pdb-part-2/
 
  • Informative
  • Like
Likes sysprog and berkeman
Mark44 said:
I did a search for "genetic algorithm knapsack problem" and got lots of hits. What I would do, rather than look at a video, is to download one of the many Python code examples out there, and run it, preferably using a debugger to step through the code a line at a time.

If you don't know how to use a debugger, there's a simple one called pdb that comes with Python distros. I wrote a two-part Insights article a few years ago with some tips about debugging Python code. See https://www.physicsforums.com/insights/simple-python-debugging-pdb-part-1/ and https://www.physicsforums.com/insights/simple-python-debugging-pdb-part-2/
I don't find any codes for it that can be downloaded tbh. Most are libraries...
 
shivajikobardan said:
I don't find any codes for it that can be downloaded tbh. Most are libraries...
I'm not sure that's true. Here's one that looks like it's just one Python file: https://github.com/Pantzan/KnapsackGA
 
Mark44 said:
I'm not sure that's true. Here's one that looks like it's just one Python file: https://github.com/Pantzan/KnapsackGA
that code doesn't give any information to me. tells solution found in 1 generation.
 
shivajikobardan said:
that code doesn't give any information to me. tells solution found in 1 generation.
It looks to me like what @Mark44 linked to was a very good source for what you said you were seeking. I think that your response is maybe too hasty and dismissive. Have you read and understood that code and commentary?
 
  • Love
Likes Mark44
shivajikobardan said:
that code doesn't give any information to me. tells solution found in 1 generation.
I just ran the code, and it says that the opt. solution was found in 7 generations.
 
  • Like
Likes sysprog and berkeman
sysprog said:
It looks to me like what @Mark44 linked to was a very good source for what you said you were seeking. I think that your response is maybe too hasty and dismissive. Have you read and understood that code and commentary?
Hmm no I haven't understood much of that code..I currently need a solved example. That kind of code is beyond the level I need in my exams.
 
shivajikobardan said:
Hmm no I haven't understood much of that code..I currently need a solved example. That kind of code is beyond the level I need in my exams.
Then can you please elaborate on what the exam requirements are? What you specified, i.e. a genetic algorithm e.g. for solving the knapsack problem, is not 'elementary'. That code is a "solved example", even though it's not presented in the 'worked example' academic form. I think that if you study it well, you will come to understand it well.
 
Last edited:
  • #10
sysprog said:
Then can you please elaborate on what the exam requirements are? What you specified, i.e. a genetic algorithm e.g. for solving the knapsack problem, is not 'elementary'.
1) Explain all the steps in genetic algorithm with block diagram and operators-8 marks out of 80 marks
2) List down steps involved in genetic algorithm with example-4 marks out of 80 marks
3) x=abcdefgh is the form of chromosome.
f(x)=a+b-(c+d)+e+f-(g+h) is fitness function do 1 round of genetic algorithm in it
 
  • #11
shivajikobardan said:
1) Explain all the steps in genetic algorithm with block diagram and operators-8 marks out of 80 marks
2) List down steps involved in genetic algorithm with example-4 marks out of 80 marks
3) x=abcdefgh is the form of chromosome.
f(x)=a+b-(c+d)+e+f-(g+h) is fitness function do 1 round of genetic algorithm in it
In my apprehension, this detailing serves to reinforce my impression that your reading and studying and understanding the code and commentary at the link that @Mark44 provided would be appropriate for your stated purposes. That code and commentary does meet a reasonable definition of a "solved example", even though it's not presented in exactly the conventional 'worked example' format, and it's precisely relevant. I think that you would do well to give it some more attention.
 
  • #12
Mark44 said:
I just ran the code, and it says that the opt. solution was found in 7 generations.
I think due to randomization, some solutions are being given in 1 generations, some in 7 some in 2.
 

Similar threads

Replies
1
Views
2K
Replies
2
Views
2K
Replies
5
Views
2K
Replies
15
Views
2K
Replies
8
Views
2K
Replies
1
Views
2K
Back
Top