Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 November 16th, 2004, 09:32 AM
rev40oz rev40oz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 rev40oz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking Categorized averaging algorithm

Hi everyone,

I am writing an application that is going to receive inputs ranging from 18-24. I have 5 target containers that can hold 3 of these values at a time. Each container's contents must average out to as close to 21 as possible. A value can only be stored in a container where all the values are within 4 or the current input.

Basically, I need to have an algorithm to determine the best place to put the incoming value so all containers average out to as close to 21 as possible. I am currently using a "best-fit" kind of algorithm to determine placement, but was wondering if any of you smart-ones had any ideas of a better algorithm. The inputs are Brix values for wine. Don't worry about the availability times of the vats, that's kind of external. The containers are big vats where the wine can be stored. Here's basically the pseudo-code for what I have now:

When we receive input and time from system
{
If any vat becomes available at this time
{
Mark the vats as available
Empty vat contents
}

For each vat available
{
If any value in the vat is more than 4 from our input
{
We can't use this vat, continue to the next one
}
Else
{
Find current average of this vat
Calculate current distance of average from 21 or (|21 - current average|)

Find the average of the vat if we were to add the new input
Calculate possible distance of new average from 21 or (|21 - Possible average|)

Find and store the overall change of adding this input to this vat or (Current distance - possible distance)
}
}

Place the input into the vat with the greatest overall change

If target vat has become full
{
Set the vat as unavailable
Store time vat will become available
}

1) If we are put in a situation where we CANNOT get 21 averages or adhere to the "within 4" constraint, we can just put it in the place that hurts us the least (ie, moves one vat the least amount away from 21).
2) After a vat is filled, it becomes inactive for x hours (the wine is processed). After those x hours, it's emptied and available for use.
3) The "within 4" constraint must be met whenever possible, even if it's not optimal placement.
4) Inputs are not equally likely. We basically have two tanks feeding these vats and they output one after the other. For example, input 1 comes from tank 1, input 2 from tank 2, input 3 from tank 1, input 4 from tank 2, etc. Here's the probabilities of the two tanks:

Tank 1:
18 - 10%
19 - 20%
20 - 40%
21 - 20%
22 - 10%

Tank 2:
20 - 10%
21 - 20%
22 - 40%
23 - 20%
24 - 10%

If anyone can see a better way of doing this, please discuss it with me! Thanks a bunch.
Chuck Reed

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Categorized averaging algorithm


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT