Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2009, 02:30 AM
noob_devshed noob_devshed is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 1 noob_devshed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m
Reputation Power: 0
Algorithm for finding out the cheapst combination

Hello, I have a few sets which are like

SET A(1,2,3,11,10) - $30
SET B(2,5,8) - $20
SET C(6) -$25
SET D(6,8) -$30
SET E(7,5) -$20
SET F(5,6,7,8,9,10) -$60
.
.
.

and so on... All are random, Now consider sets D,E and F I want to buy the cheapest combination for a set, SET Q(7,8,6,5) the answer should be SET D + SET E, not the SET F

Please link... thanks

Reply With Quote
  #2  
Old October 9th, 2009, 01:44 PM
jwdonahue's Avatar
jwdonahue jwdonahue is offline
Bellevue WA, USA
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: May 2004
Location: Bellevue Washington, USA
Posts: 3,398 jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 48 m 17 sec
Reputation Power: 886
First eliminate all sets that have members that aren't in Q. Sort the remaining sets by size, insert the remaining sets that equal to Q into a binary tree of sets of set references (is there a faster structure for this? Hash table perhaps?) then starting with the largest sets that aren't equal to Q, search for single sets that will complete them, then search for pairs of sets that will complete them, etc., building up the tree. Note that the search would be limited to size(Q) - size(s), no point in trying combinations that would exceed the length of Q. Then visit all the nodes, inserting into a sorted list based on total cost of the sets in that node. The cheapest combination will be on one end of that list.

We're talking NP Complete here so if the total number of sets is high enough, the Universe might expire before you get the result (assuming you have sufficient storage space, which itself could increase the entropy of the Universe substantially).

You might have to alter your criteria to "cheap enough" rather than "cheapest". For instance, after eliminating sets that have members not in Q, you could do a statistical analysis of the costs of the individual sets to get some figure of the expected distribution of costs, and then pick a point somewhere in the middle and when you find a combination that is lower than that point, just quit searching.

Also, you might find it's acceptable to buy a set that has extra members! Particularly if you can sell off that extra unit. But this just makes the problem even harder to solve if cheapest is indeed the only acceptable goal.

Good luck! Wish I had more time to dive into this one.
__________________
My worst nightmare was a pointless infinite loop.
Work in progress; don't poke the curmudgeon!
http://www.odonahue.com/

Last edited by jwdonahue : October 9th, 2009 at 01:48 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Algorithm for finding out the cheapst combination

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap