|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Categorized averaging algorithm |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|