Debugging Algorithm Logic: 2 Iterations & Finding Right/Wrong Answers

In summary: In this problem, the parameters are adjusted by randomly selecting one of the chromosomes (c1 in this case) and changing one of its values.
  • #1
shivajikobardan
674
54
https://lh3.googleusercontent.com/J-M_R31KFl76aXCRE4sxzAWI6iAldXG9fMI2k4YRMZo6vZY0w1DPUfV7tLc1w5IsVQX8uUkjgThzROZrbb3bc6kluAEmyiH63Z4BsXKT5Xr7X7mLxOwbR1L0y3ttoLitS6bOnwz-

Here is a solution, part of which doesn’t make any sense to me-:


->Why did we select c3,c1 and c3,c2 for 2nd generation?
-> why did we select os1,os2,c3,c2 for 3rd generation? (And what the heck is happening here? We are already in 3rd generation when even 2nd one is not complete?
-> then we mutate. Why are we mutating c1 lol. It doesn’t make any sense. We need to mutate one of the os1,os2,c3 or c2 according to my logic.

Anyway i have tried solving 2 iterations of it. If you can help me with 2 iterations of this problem, please do so.
Also test out my 2 iterations of this algorithm. What is right and wrong. I have used 1 point crossover.
https://lh6.googleusercontent.com/KBOysPzIzjJT1A6dcranIw0zlpoX1qk7z1v44yL1ETofHJAqfUNVsXBVskNW96EgHhIad8mBooghUFVNG0rFXQAVBciQqBMkom-eP6coHtimC9hbzpfWkovo5U9W1pjGfcNncNNM
https://lh6.googleusercontent.com/WboorstzOIHVGxS1ffZa7pPQ3maJ2y7CEoxiLDbTOPDUJWjU8VGbqbYwIZsfeOEx0zUo48haao6zWf-rv-vE_dpHHSJyNapyFQWvhYGXTBs9tklfEX-0IwFg8O9xnOzEVA59dp0s
https://lh5.googleusercontent.com/uGyX0E1s_0NRQSyx5RqL4zJTpzBEfPPplUkOs2QXno1DMQDSw3M3u-q1uL4cCE6_1OEW6H81IxLSQP_yfGo5W-7ABdhqdHlCbBA67Qshvybt6WAEAM8ZHM13OX0Hj9BvREEaCwDy
https://lh6.googleusercontent.com/qMfgkHqfOnR4uAEdPtYWwCdUO8tv85YhGYgx94cbvXiPJcaHoYtXTaLTNUdpAs2E2Bqmzi2uNIPa3mljZqxWMdCybhNAD643FTzy4f2b7Za1tFcQV2r9srNDZafZ69cr2c4EaCUn

I just want 2 iterations of this and know when to stop and check if I am right or wrong..And understand that first solved example video that I shared above.. this is getting confusing more and more I see it. Is this something where I can do anything randomly and get marks in exam lol...I feel like so looking at it. And the internet. Internet sucks. 1 easy thing then there are 5 lakhs of posts explaining the same thing. 1 hard thing and suddenly there is no one even remotely trying to explain it. Few explanations are there but they are very contradictory to each other.
 
Technology news on Phys.org
  • #2
The above problem is a genetic algorithm problem. It is used to find the optimal solution for a given problem. The first step is to generate the initial population. This is done by randomly selecting some individuals (called chromosomes) from the given population. Then, we use crossover and mutation operators to create new generations of individuals. In this problem, the initial population is created by randomly selecting three chromosomes: c1, c2 and c3. Then, we use a one-point crossover operator to create two new chromosomes from the previous generation: c3, c1 and c3, c2. The next step is to apply the mutation operator. This is done by randomly selecting one of the chromosomes (c1 in this case) and changing one of its values. The new chromosome is then added to the current population.Finally, we check if the optimal solution has been found. If not, we repeat the process until the optimal solution is found. It is important to note that the parameters of the genetic algorithm should be adjusted to ensure that the optimal solution is found.
 

What is debugging?

Debugging is the process of identifying and fixing errors or bugs in a computer program or algorithm. It involves carefully analyzing the code and testing it to locate and correct any issues that may be causing the program to not function correctly.

Why is debugging important?

Debugging is important because it ensures that a program runs smoothly and produces the intended results. Without debugging, errors in the code could cause the program to crash, produce incorrect results, or not function at all.

What is an algorithm?

An algorithm is a set of step-by-step instructions or rules that are followed to solve a problem or complete a task. In computer science, algorithms are used to solve complex problems and are an essential part of programming.

What is the difference between an iteration and a recursive function?

An iteration is a repetitive process that involves repeating a set of instructions until a certain condition is met. A recursive function, on the other hand, is a function that calls itself until a base case is reached. In other words, a recursive function is a type of iteration, but not all iterations are recursive functions.

How can I find and fix errors in my algorithm logic?

One way to find and fix errors in algorithm logic is to use a debugger, which is a tool that allows you to step through the code and track the values of variables as the program is running. Additionally, writing thorough test cases and carefully examining the code for any potential logic errors can also help in identifying and fixing bugs.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
4
Views
1K
Back
Top