Connecting Tech Pros Worldwide Help | Site Map

Help with writing algorithm

  #1  
Old March 18th, 2009, 01:54 AM
Newbie
 
Join Date: Mar 2009
Posts: 2
I writing a economic statistics program..

I need to allocate billions of dollars and I
have been shown projects to consider and ith project estimates
its cost to be dollars and claims to generate jobs.

So I have B billions of dollars
n projects
ci dollars
Ji jobs
I guess I have one objective function and one constraint.

Can someone help me with just write the psuedocode to determine which projects to choose to "maximize" job creation
and an estimate of "how many" jobs will be created.

Do you think I should use a greedy algorithm like Prim's or am I off? I not really knowledgable about these types of algorthims

V. Dugall
  #2  
Old March 18th, 2009, 08:48 AM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Help with writing algorithm


If you get j_i jobs for c_i dollars for project i you can use a greedy algorithm where you select the project i that gives you the most jobs for your dollar, i.e. the ratio j_i/c_i is maximal. Repeat while you still have dollars and projects left.

Your single constraint is:

sum(c_i) <= B

and your cost function is

maximize: sum(j_i)

kind regards,

Jos
  #3  
Old March 19th, 2009, 09:38 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

re: Help with writing algorithm


http://en.wikipedia.org/wiki/Knapsack_problem
Greedy algorithm is probably the best way to go.
  #4  
Old March 21st, 2009, 01:03 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Help with writing algorithm


Quote:
Originally Posted by jkmyoung View Post
Greedy algorithm is probably the best way to go.
For sure it is: pick the project that gives you the most jobs for the dollar; any other choice is a worse choice. Repeat until you're out of dollars. There are never any 'uphill' steps to take so a steepest descent greedy algorithm will do the job.

kind regards,

Jos
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for help with a loop algorithm Kasterborus answers 5 January 10th, 2008 02:55 AM
Help with peak detection algorithm kester83@singnet.com.sg answers 1 September 17th, 2007 09:55 AM
Help with writing codes for routing algorithm ricky answers 2 April 5th, 2007 10:45 AM
Help with vectors Chandrashekar answers 6 July 19th, 2005 04:25 PM