Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 1st, 2006, 5:53 PM   #1
scm007
Newbie
 
Join Date: Jan 2006
Posts: 27
Rep Power: 0 scm007 is on a distinguished road
Has anybody done a knapsack problem in VB-- I'd like your script!

Does anybody have a working script to solve a knapsack problem using VB? I need to use it on an Excel file and VB seems the easiest way to do so. If you have a working knapsack, or other optimization script/program I'd really like to mod it for my purposes. ThANKS!
scm007 is offline   Reply With Quote
Old Nov 2nd, 2006, 12:20 AM   #2
melbolt
Professional Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 254
Rep Power: 4 melbolt is on a distinguished road
homework?

I'm not totally familiar with the knapsack problem, but from googling a bit it sounds like you're headed for some recursion.

you're going to have to explain the problem a little better, as far as i can tell you have a sack that can hold an unspecified amount of items. each item may come in stacks of an unspecified number of identical "brother" items? each item has a size and weight right?

the sack has a limit as to how much volume but not weight right? and you are trying to get the sack to weigh as much as possible?


the questions i have for you are:

what are your constraints? are there a specified number of items to work with or is it 0 to N number of items, each weighing 0 to N lbs and having a volume with 0 to N? I'm afraid without this info it would be pointless to continue.

I assume you will supply a two dimensional array or even better, an array of a class or struct you build. something with the given items to work with? one dimension holding the weight of the object, the other holding the volume of the object. and you will also supply the max volume of the sack(N).

what you would want to do in this situation is a recursive algorithm trying different combinations and find out which combination returns the largest weight.

will be a somewhat processor demanding algorithm but will get you your answer.

feel free to post whatever code you got and I(or we) will try to give you a hand. I'm not gonna do your homework for you
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt

Last edited by melbolt; Nov 2nd, 2006 at 12:39 AM.
melbolt is offline   Reply With Quote
Old Nov 3rd, 2006, 3:53 AM   #3
scm007
Newbie
 
Join Date: Jan 2006
Posts: 27
Rep Power: 0 scm007 is on a distinguished road
Sort of. Imagine an x,y,z space filled with points. I need to find a solution set of points whos average falls within a box of some dimensions. Basically I'm going to take a seed set of values, then recursively determine the best move and ... well it would be better if I explained it a different way. Say there are 2000 points.

Take a seed of 1000 points (x,y,z), assume the average is outside of the defined box.
There are 3000 possible moves to make. Adding 1 of 1000 points, subtracting 1 of 1000 points, or swapping 1 point in the set for 1 of the 1000 points outside of the set.
Pick the move that minimizes the value relative std. deviation
sqrt[(x/x_desired)^2 + (y/y_desired)^2 + (z/z_desired)^2]
the _desired variables would be the coordinates of the center of the box.
Recurse until the average falls within the box.
Or if the function gets stuck, reseed.

Help?

Last edited by scm007; Nov 3rd, 2006 at 4:43 AM.
scm007 is offline   Reply With Quote
Old Nov 4th, 2006, 3:06 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
please don't cross-post.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Action Script Problem? quadra-tec Other Scripting Languages 1 Nov 1st, 2006 1:56 PM
Odd problem with login script SlickTheNick PHP 5 Oct 22nd, 2006 8:29 PM
cgi/perl script + IE problem joyceshee Perl 2 Jan 24th, 2006 12:10 PM
Problem with Perl script eclipsed4utoo Perl 1 Dec 2nd, 2005 2:33 PM
Java script problem zeotrex JavaScript and Client-Side Browser Scripting 5 Sep 2nd, 2005 6:30 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC