-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Genetic Algorithm: String to List Individuals #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@MrDupin Would it make sense to replace I only suggest this because then the code will truly mirror the pseudocode, which is desirable in my opinion. It won't have the extra lines and different parameter lists like it does right now. I would be happy to make this change if you like, else you can just add it to this PR. |
@kaivalyar: This is more or less how I had it initially, but as per Darius' suggestion, I changed the implementation to the current version due to performance issues. It would take a very long time to complete due to the added computational cost. The difference in performance was quite astute and older machines could previously run only small and trivial-ish problems. There are, as I see it, three main ways to go about it: a) Keep it as is, choosing performance over two additional lines of code + the function parameters of b) Follow the pseudocode to the letter, writing some possibly ugly and harder to follow code on the side to relieve the computational pressure. c) Keep it as is, but change the
part to something like:
Which will reduce the additional lines to just 1. It is a bit uglier in my opinion though. Whichever way we choose, we should definitely have The first (current) and third options already accomplish that. For the second to work, we have to define Personally, I believe we should leave it as is. The only difference from the pseudocode is the two additional lines to compute |
Woah. This turned out to be a lot more complicated than I imagined. I think you're right, let's stick with the way things are currently. We can always further update the code later. In the meanwhile, let me explore if this can be solved differently somehow... |
No problem. If you need any help/feedback/discussion, reach out to me. I would love to help any way I can. |
There is another, more elegant solution, now that I think about it. Define a function that will calculate the fitnesses and return the
And then inside the generations loop, replace
with I will make this change (assuming no other solution is found till then) once this PR gets merged. |
I think @MrDupin has a good solution for now. If/when we go to Python 3.6, there is a new random.choices function which does a similar thing. |
As per the discussion on #347, I changed the individuals from string to list. Updated tests accordingly.
I broke the Graph Coloring test into three mini-tests, one for each of the three main variable types (char/string, integer, boolean).
NOTE: I have updated the notebook too, but I am waiting till #522 gets merged to avoid dealing with conflicts.