-1

Hi I need to code a Genetic Algorithm to solve the Knapsack Problem. The synopsis of the problem can be found on wikipedia, sorry for not providing the link I can currently only post 2 links.

I have been able to fully understand and implement a basic binary GA, which can be found at:

https://github.com/DraosT/GA/tree/master/GA2/src

Now that I have that basic framework coded, I have no idea how I can adapt it to the problem at hand. Any pseudo code or Java code that you could provide would definitely help to sate my curiosity on this subject and hopefully let me complete this task faster.

I tried to edit the code to solve the problem

https://github.com/DraosT/GA.git

but it still does not work, not exactly sure why

*Edit - Updated the code with a couple of different "fixes", still not working. If anyone could help me spot the error I would still be grateful.

user3881294
  • 1
  • 1
  • 4
  • 4
    Nah. No offense, but that'll get you nowhere on here. This site is not intended to post complete solutions to homework assignments and similar. We love to help with specific problems, like if you get stuck while actually trying :-) Sooooo: what have you tried? What errors are you getting? – hiergiltdiestfu Aug 07 '14 at 13:02
  • Sorry if it came across that way, but I never intended to get a full answer out of this post. My plan is to create a size variable for the knapsack, say it is 2000, as well a array of ints representing the different objects sizes, then the fitness would be how much of the 2000 the individual is able to fill, then I suppose a good way of doing it is to cancel if there are no changes in 25 or so generations. Thoughts? And sorry again, I should have been more specific in my question. Re-reading it again it does seem kind of like I am just straight up asking for the answer. – user3881294 Aug 07 '14 at 13:18
  • Ok I made some test code, would you mind looking at it. It does not work and I don't get why. https://github.com/DraosT/GA2 – user3881294 Aug 07 '14 at 13:56
  • Thanks for updating your question! :) Have you looked at the Related Problems SO generates in the side bar to your question? – hiergiltdiestfu Aug 08 '14 at 09:51

1 Answers1

-1

Program you write is not smarter then you are. Do not make assumption that others will help you if you do not even try. I, for example assume you Google'd the problem and tried to find why your program failed, but did not look hard enough.

Try again and see if you can find : http://rosettacode.org/wiki/Knapsack_problem/0-1

Margus
  • 19,694
  • 14
  • 55
  • 103