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

Click For Summary

Discussion Overview

The discussion centers around the need for a solved numerical example of a genetic algorithm, specifically for one iteration, with a focus on the knapsack problem. Participants express a desire for clear, step-by-step explanations suitable for exam preparation.

Discussion Character

  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant requests a clear, hand-solved example of a genetic algorithm, expressing frustration at the lack of resources available online.
  • Another participant suggests downloading Python code examples and using a debugger to understand the algorithm better.
  • Some participants challenge the availability of downloadable code, stating that most resources are libraries rather than standalone examples.
  • There is a disagreement regarding the usefulness of a specific GitHub repository, with some participants finding it inadequate for their needs.
  • One participant emphasizes that the code linked may not be in the conventional 'worked example' format but still serves as a solved example.
  • Another participant outlines specific exam requirements, including explaining the steps of the genetic algorithm and performing one round of the algorithm using a given fitness function.
  • There is mention of variability in the number of generations required to find optimal solutions due to randomization in genetic algorithms.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the adequacy of the provided code examples or the clarity of the resources available. Some believe the linked code is a valid example, while others find it insufficient for their understanding.

Contextual Notes

Participants express varying levels of familiarity with genetic algorithms and coding, which affects their ability to engage with the provided resources. The discussion reflects differing expectations regarding the format and detail of examples needed for academic purposes.

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   Reactions: 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   Reactions: 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   Reactions: 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 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
Replies
3
Views
3K