Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jan 5th, 2006, 4:00 PM   #1
scm007
Newbie
 
Join Date: Jan 2006
Posts: 27
Rep Power: 0 scm007 is on a distinguished road
Summation help

OK, here is what I need, but I don't really know how to get Java to do it for me. I have a data set of 2000 numbers, some positive, some negative. I need to find one summation (if possible) of 1500 numbers which is equal to zero. And I need to do it very efficiently. Thanks!
scm007 is offline   Reply With Quote
Old Jan 5th, 2006, 4:08 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Is this a homework assignment?

C'mon, man, show us you've tried, at least. Google a bit. Think.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 5th, 2006, 4:30 PM   #3
alcdotcom
Programmer
 
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0 alcdotcom is on a distinguished road
Quote:
Originally Posted by scm007
OK, here is what I need, but I don't really know how to get Java to do it for me. I have a data set of 2000 numbers, some positive, some negative. I need to find one summation (if possible) of 1500 numbers which is equal to zero. And I need to do it very efficiently. Thanks!
You want to find 1500 out of the 2000 that sum to zero (if possible), yes? To echo Ooble, can you show us what you've got so far?
alcdotcom is offline   Reply With Quote
Old Jan 6th, 2006, 4:22 PM   #4
scm007
Newbie
 
Join Date: Jan 2006
Posts: 27
Rep Power: 0 scm007 is on a distinguished road
No this isn't a homework assignment, it's something that my dad uses in his business and would save him a lot of time. I don't know how to get started. Actually, the problem is different than I stated, my apologies. There are x numbers, all of them greater than zero, and all of them some dollar amount so like 1452.32, then the user would define a number and the program would find the summation of numbers which is closest to the defined number. If that would require too much computing power, then I guess the user could define a range and then the program would find a solution in that range using a semi random sampling, so that the program just doesn't sum all of the smallest numbers. Can anybody help me wit hthat?
scm007 is offline   Reply With Quote
Old Jan 6th, 2006, 11:06 PM   #5
alcdotcom
Programmer
 
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0 alcdotcom is on a distinguished road
Well, there are probably really efficient ways of doing this, and hopefully someone with a better knowledge of algorithms than I will post one. The easy way of doing it would be just to test every combination x sets of numbers in the array and get the combintion closest to the required value. Then, test every combination of x+1 sets of numbers in the array, then X+2, then X+3 then ... finally X+N where N < ( (array size) / 2 ). Since my solution requires testing all combinations then there is no need to sort the array. This is not a very efficient way of doing it and a very large array might take some time. Another consideration is what to do if a combination is exactly the same as the required number. Do you stop there or do you test to see if there is another combination that is exactly the same as the required number. If there is more than one, then which one will be chosen? This may not matter, but since I don't know the context of the problem I thought I'd bring it up as a possible headache.
alcdotcom is offline   Reply With Quote
Old Jan 6th, 2006, 11:21 PM   #6
Vinaaron
Newbie
 
Join Date: Jan 2006
Posts: 6
Rep Power: 0 Vinaaron is on a distinguished road
I think I know the solution for this one.
We've done this already in algorithm course.
I'll try to see if it is still in my archive...
__________________
Contented with little, yet wishing for more..
Vinaaron is offline   Reply With Quote
Old Jan 7th, 2006, 3:54 PM   #7
Klipt
Hobbyist Programmer
 
Join Date: Dec 2005
Posts: 118
Rep Power: 0 Klipt is an unknown quantity at this point
You can find solutions to within a certain resolution (i.e. rounding intermediate figures to, say, the nearest dollar) using dynamic programming. The better the resolution the more memory you need, so there is a limit. It also limits the range of numbers you can test (e.g. less than $1 000 000). But it will run very fast.

It's basically a special case of the knapsack problem (with 0 cost - or the bin packing problem with 1 bin). Try reading these:

http://en.wikipedia.org/wiki/Knapsack_problem
http://en.wikipedia.org/wiki/Knapsac...mming_solution

If you need an example just ask.

EDIT: if the total can be bigger than the figure you want then it's not technically a knapsack problem, but you can change the algorithm without too much difficulty.
Klipt is offline   Reply With Quote
Old Jan 9th, 2006, 1:30 AM   #8
scm007
Newbie
 
Join Date: Jan 2006
Posts: 27
Rep Power: 0 scm007 is on a distinguished road
Klipt, thanks for the info!

Vinaaron, could you find it?

Also I could pay someone for their time if they wrote this program. Essentially there is an Excel spreadsheet with 1000-10000 entries. Each of which has a code, a price, and a risk. Then the program would go through and find a solution set such that the total price as specified by the user is in some range AND the weighted risk, i.e. the sum of (risk*price)/(total price) for all prices in the solution set is in some range. Then the program would output the corresponding codes for the entries which validate these criteria. Could anybody do this?

Last edited by scm007; Jan 9th, 2006 at 1:41 AM.
scm007 is offline   Reply With Quote
Old Jan 9th, 2006, 8:31 AM   #9
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Since these values are stored in Excel (per your other post)... why code in Java? PM me with a figure, and we'll talk about a solution.
\
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jan 9th, 2006, 7:30 PM   #10
scm007
Newbie
 
Join Date: Jan 2006
Posts: 27
Rep Power: 0 scm007 is on a distinguished road
I just wrote it in the Java forum because I had the intention of doing it myself, and Java is hte only programming language that I know anything about, but very little. It would probably be easier just to pay someone, but I can't really afford to pay a lot, so just give me an estimate on how long it will take you and I will give you a figure. How much do you think it would cost?
scm007 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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:30 AM.

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