Best Fit Algorithm

Hi,
My problem is as follows:
I have a bunch of files that I would like to copy to a CD. The total size of these files let's say needs four to five CD's, depending on the way that you arrange the files. I need an algorithm that takes the sized of these files, and distribute them on the Maximum capacity of each CD, in a way to utilize the space of each CD.
Example:
Let's say a CD can contain 20 MB.
items:
(A) 10
(B) 5
(C) 4
(D) 3
(E) 2
if you sort the files based on their size - like above - most likely you'll choose the files as follows:
(A) 10, (B) 5, (C) 4, the total will be 19 MB and there will be 1 MB unused.
However, if you replace (C) with (D) and (E), you'll fill the remaining unused space efficiently.
Of course, this example is very easy to solve manually with a glance. But in case of more complicated scenarios with many files with different sizes, that task will be much harder.
So, any help :)

Thanks a lot, it was really close, but what I actually needed was this:
[http://en.wikipedia.org/wiki/Bin_packing_problem|Bin Packing Problem]
I found many project in the Source Forge about it.
[http://sourceforge.net/search/?type_of_search=soft&type_of_search=soft&words=Bin+Packing+Problem|Source Forge Projects]

Similar Messages

  • From round robin to best-fit

    Hi all,
    I am trying to develop a mechanism to know which machine can handle a user job (by providing his Requirements) for now I wrote this method but it is a Round robin, I am trying to modify it to a best-fit algorithm can anybody give me tips about how should I begin?
    public static String canDo(Resources userReq,Hashtable hash){
                    //getResourceInfo() is a method that store the machine name
                   //and thier resources(cpu,memory,disk) in a hashtable
             Hashtable resourceInfo = connectData.getResourcesInfo();
             Enumeration en = resourceInfo.keys();
             String status ="";
             String machineName;
              Resources machineRec;
            while(en.hasMoreElements()) {
                     machineName = (String)en.nextElement();
                     status = "the following machine has been allocated to you: "+machineName;
                     //resourc
                     machineRec = (Resources)resourceInfo.get(machineName);
                     if(machineRec.getCpu().getCpuIdle()>=userReq.getCpu().getCpuIdle())
                     if(machineRec.getMemory().getFreeMemory()>=userReq.getMemory().getFreeMemory())
                     if(machineRec.getDisk().getFreeSpace()>=userReq.getDisk().getFreeSpace()){
                          break;
             return status;
        }

    you mustn't have seen the replies here
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=016520

  • Best fit curve

    I want to implement the best fit curve for the data coming in to the array. I've tried looking at the examples with no end results and have also implemented the Levenberg VI to do so with the same outcome.
    How can I plot the best fit curve for the points?
    Thanks in advance!
    Attachments:
    best fit lines.vi ‏47 KB

    FredFred,
    So are you having trouble graphing multiple plots or actually getting a
    best fit algorithm to work?  I did a small test using the Curve
    Fit Express VI and after configuring the options, I was able to wire
    the array data to the Signals input and then use the output to display
    the best fit of the data on a graph.  The output of the Express
    VIs are dynamic data type (DDT) so you should use the From DDT Express
    VI (Express >> Signal Manipulation palette) to convert it back to
    an 1D array of scalars.  Then I built a 2D array using the Build
    Array function and then wired that to a graph.  Is this what you
    are looking for?
    Hope this helps!
    Andy F.
    Message Edited by Andy F. on 11-30-2005 04:31 PM
    National Instruments
    Attachments:
    best fit.PNG ‏5 KB

  • I have several 20,000+ point scatter plots that I'd like to graph with a best fit. Whats the best way to do this?

    Since they're so large and occupy the same range of y values, I'm kind of reluctant to plot them one over another so a best fit line would, I think, be the most helpful in analysing the data. I'm not quite sure however how to go about this since the data can be random

    Well, here's a very primitive way to decimate the data without any fancy algorithm. For this particular case, it looks pretty good. Each loop makes the array 3x smaller, averaging 3 adjacent elements. 4 iterations seem to be perfect. (I have included your raw data in diagram constants).
    For a polynomial fit, the more complex the data, the higher the order polynomial is needed to describe it. If it is a simple "banana" (my example above) you're OK with an order of 2 (up to quadratic), if it is s-shaped, you need at least 3rd order, etc. I tried your data with much higher orders (up to 40!) and it did not work.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Best_Fit2.vi ‏370 KB

  • Best fit lines for loops and sine waves

    I am trying to find a best fit line that will work for sine waves and loops (hysteresis loops). I can get the sine wave just fine, but when I switch to a hysteresis it just puts a line across the middle (I assume because of the 2 y values for every x). I am doing data acquisition that will take in both forms and graph them. I tried a polynomial fit and it doesn't work at least the way I implemented it and I tried a few others but it looks like they are all function based. Also, my y values are coming out of a Bessel filter. I don't think this would be affecting anything but I thought I would put it in here incase it does.
    Did I miss one that I haven't tried that works for my application?
    Thanks
    Patrick

    RiversDaddy wrote:
    ... currently I am doing it by looping and reducing the error towards zero to fit the amplitude and phase. (I know the frequency).  If this is what you are looking to do then I will help, or should I be doing things differently? All of the functions I have found to filter or extract tones seem to introduce a larger frequency of phase error than i get using this method, but am I missing something?
    "looping" is a bit vague. What is the actual algorithm to find better estimates (e.g. levenberg marquardt, etc.)
    What problems did you have with extract single tone. Can you show some data where the results from it are not good?
    LabVIEW Champion . Do more with less code and in less time .

  • Best-fit Heap

    Hi
    I am trying to change a heap allocation from first fit to best fit. I understand that for best it i will have to traverse the whole memory block and find the block which is closest to the one asked for. But, how do i keep track of the differences.
    Here is the chunk of code for first fit
    for (x = free, back = -1; block [x] != -1; back = x, x = block [x+1])
      if (block[x] > size) break; //size is the size that is needed for the running programnow for best fit i am assuming that i 'let' the first block be the best case and then traverse through the list.
    If some one could give me a few hints...i would really apreciate it
    -bhaarat

    thx i came up w/ another algorithm though...it seems about right to me please have a look at it and tell me what you think.
    best = free;
    for(x = free, back = -1; ((x != -1)&&(block[x] != -1)); back =x, x = block[x + 1])//have the && statement cuz sometimes when x = -1 i get a run time error
                 if (block[best] == size)     break;
                 else if (block [best] > size)
                      diff = block [best] - size;//calculate the difference
                            if (block[best+1] != -1)//if the next loc of heap has -1 in it then there is no need to compare as we dont have neother choice but to split a block. 
                           if (((block[block[best+1]] -size > 0) && (block[block[best+1]] -size < 10)) && (block[block[best+1]] -size < diff))
                                best = block [best +1];
                   if (x == 0) break;
            }-bhaarat

  • Bessel function best fit

    Hi all,
    Quite new to LabVIEW. I am capturing diffraction images that are described by Bessel J functions. The maxima of the diffraction correspond to the maxima of the Bessel J functions ( or zeros of 1st derivative).  I wish to fit the diffraction image intensities to a Bessel J function , pixel value -> best fit to x in J(x). Has anyone previously done this before? I know the order n of the Bessel function but not necessarilly the pixel where x=0.
    Similarly, I hope to fit the diffraction image of a pinhole which is an Airy Disk to use as calibration ie pixel -> m^-1.
    Any help or suggestions would be gratefully accepted.
    Regards,
    Leeser 

    Leeser,
    Considering you are relatively new to labVIEW, your program was very well structured and seems to approach the problem in the right manner. As you correctly guessed right from the beginning, no-one it seems has attempted fitting a Bessel function to their data. The 'best-fit' VI's found in the 'Fitting Pallette' are more generally concerned with parametric, powers and exponential type functions, rather than more complex differentials such as the Bessel. In cases similar to yours, it seems that people haave tried adopting the Levenberg-Marquardt algorithm which is a Non-Linear Fitting VI found in the Fitting Pallette. This is the Lev-Mar VI which Kristie Elam reccomended you using for the Airy disc. This function allows one to define the equation with which they wish to fit their data, but due to the complexity of the Bessel function, this may be quite tricky.
    I have been working on an example VI which provides the basic structure of what you need to implement in to your program. The Bestfit VI converts a picture using the IMAQ functions and then plots the converted data. You can manipulate the row control to choose which row of pixels you wish to analyse. The VI then calls the Lev-Mar Best Fit function which in itself calls the Bessel Formulae VI which is a template for the Bessel Formulae that the Lev-Mar function will use in its best-fit approximation. It is within this VI that you will need to enter the neccessary formulae to produce your theoretical Bessel function. The Lev-Mar Bestfit function can then use this data to plot a Least Squares Best Fit approximation against your spectrum.
    Aswell as the Bestfit and Bessel Formulae VI's, I have attached a Gaussian Example VI which gives a complete example of a Bestfit approximation using this method. Furthermore, I have attached a couple of VI's that I found which I hope may help you to develop the Bessel formulae. These include a table of Bessel roots, which you may be able to use to produce a table of the derivative roots, those found on your schematic.
    I really hope this information and the files I have attached will be of use to you, I'm just sorry there isn't a direct tool with which you can produce the bestfit approximation. Keep me posted on your progress as I've been working on this for a few days now and would like to see how it goes!
    With regards to the Airy disc, I would keep on with the files that you received from Kristie Elam, hopefully using the same method with both the Bessel functions and Airy disc might make things easier for you.
    I hope this informtaion is of use to you, best wishes and good luck!
    Rob
    Rob L
    NI Applications Engineer
    UK & Ireland
    It only takes a click to rate this message ;-)
    Attachments:
    Bessel Bestfit.zip ‏98 KB

  • How do i find where 2 best fit lines cross?

    Hi
    I was wondering if anyone knows a way to find where 2 best fit lines cross, I don't have the equation for the lines and i'm not sure if I can get it.
    I currently have the program tracing the lines and comparing y values however it will only increment in steps of 0.1 on the x-axis and i need an accuraccy of 0.0001

    If you have or can get a series of XY value pairs for both of the lines, getting the equation of the line is as simple as calling Linear Fit.vi.  Once you have the equations of both lines, the intersection is simple algebra, subject to the accuracy of your fit.  If the XY data pairs describe a curve, not a line, and you want more accuracy, you can try a polynomial fit using General Polynomial Fit.vi.  To find the intersection, set one polynomial equation equal to the other, compute the coefficients of the resulting polynomial equation, and find the root using Polynomial Roots.vi.  All this assumes you have a Pro or better version of LabVIEW.  If you don't, you can still do it, but you will need to write some code for the fits and roots.  Check out a copy of Numerical Recipes in C, by Press et. al. from your local library and it will give you the equations for all the above.  With LabVIEW's native matrix handling capabilities, the rest is straighforward.
    Let us know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • How to Make a Line of Best Fit/Best Fit Line/Trendline in iWork Numbers '09

    I'm not sure if this is well-known or has been answered elsewhere already, but multiple Google searches have not shown this solution on how to create a line of best fit in Numbers '09 (there is another method that involves drawing a line yourself, but this is much easier and more accurate).
    I stumbled across this trying the above self-draw technique and got so excited I wanted to post the technique. So here is what you do:
    1) Type out your X and Y data
    2) Select the data and select Charts, then select the Scatter Plot
    3) Open up Inspector and select the Chart tab
    4) Select the "Series" tab below the picture of the Scatter Plot and the "Chart Colors..." button
    5) At the bottom of the Inspector window, open the "Advanced" arrow
    6) Select the "Trendline" tab and select the "Linear" trendline from the drop-down bar
    That's it! You can even select the options to show the line equation or the R-squared value!
    Here is a picture of the selected options and what your graph should look like (check that nice R-squared value!).
    http://i.imgur.com/AvfPv.png
    I hope this helps and hope it moves up to the top of the Google search page for this feature.

    Hi Asclepius37,
    Why not just search "trend" or "trendline" in the Numbers '09 User Guide?
    That would take you to page 149 of the guide and the article "Showing Trendlines in Charts," which lists a set of instructions very similar to those in your post.
    The Numbers '09 User Guide and the iWork Formulas and Functions User Guide are searchable pdf files, and may both be downloaded through kinks in the Help menu in Numbers. Both are excellent resources to have on hand.
    Regards,
    Barry
    PS: Searching "best fit" will return zero results, but "best" or "best-fit" will get you to the same article.
    B

  • Best fit line

    regarding a graph made from spreadsheet data...
    how do i make a best fit line to a set of points?
    also, is there a way to find the slope and intercept of this line?
    Thank you!

    Hello
    The named functions are not available in AppleWorks.
    One way to mimic them is to use AppleScripts .
    Here is an old one which calculate the slope.
    --{SCRIPT}
    tell application "AppleWorks 6"
    activate
    tell front document
    set laSelection to get object specifier of the selection
    set debutCible to name of first cell of laSelection
    -- nom de la première cellule cible
    -- • name of first dest cell
    set premColonne to item 1 of (index of first column of laSelection) as list
    set premRangee to item 1 of (index of first row of laSelection) as list
    set dernColonne to item 1 of (index of last column of laSelection) as list
    set dernRangee to item 1 of (index of last row of laSelection) as list
    set nb_Rangees to dernRangee - premRangee + 1
    if not (dernColonne - premColonne) = 1 then error 8088
    set cell11 to name of row premRangee of column premColonne
    set cell12 to name of row dernRangee of column premColonne
    set cell21 to name of row premRangee of column dernColonne
    set cell22 to name of row dernRangee of column dernColonne
    set vX to get select (cells cell11 thru cell12)
    set the clipboard to vX
    set vY to get select (cells cell21 thru cell22)
    set nb to count of vX
    set {X, Y, XY, x2} to {0, 0, 0, 0}
    repeat with i from 1 to nb
    set xi to vX's item i
    set yi to vY's item i
    set X to X + xi
    set Y to Y + yi
    set XY to XY + (xi * yi)
    set x2 to x2 + (xi * xi)
    end repeat
    set slope to (XY - (X * Y) / nb) / (x2 - (X * X) / nb)
    select menu item 4 of menu 3 (* copier *)
    set slope to my calcule(nb_Rangees)
    display dialog "" & slope
    end tell
    end tell
    on calcule(nb_)
    tell application "AppleWorks 6"
    activate
    set AWversion to (version as text)
    select menu item 2 of menu item 1 of menu 2 (* Nouveau tableur
    • New spreadsheet *)
    tell front document
    select cell "A1"
    select menu item 5 of menu 3 (* Colle • Paste *)
    set formula of cell "C1" to "=A1*B1"
    set formula of cell "D1" to "=A1^2"
    select cell ("C1..D" & nb_)
    select menu item 3 of menu 5 (* Recopier vers le bas
    • Fill down *)
    if AWversion starts with "FU1-" then
    set formula of cell "E1" to "=(SOMME(C1..C" & nb_ & ")-SOMME(A1..A" & nb_ & ")*SOMME(B1..B" & nb_ & ")/NOMBRE(A1..A" & nb_ & "))/(SOMME(D1..D" & nb_ & ")-SOMME(A1..A" & nb_ & ")^2/NOMBRE(A1..A" & nb_ & "))"
    else
    set formula of cell "E1" to "=(SUM(C1..C" & nb_ & ")-SUM(A1..A" & nb_ & ")*SUM(B1..B" & nb_ & ")/count(A1..A" & nb_ & "))/(SUM(D1..D" & nb_ & ")-SUM(A1..A" & nb_ & ")^2/count(A1..A" & nb_ & "))"
    end if
    set slope_ to cell "E1"
    end tell
    close document 1 without saving
    end tell
    return {slope_}
    end calcule
    --{/SCRIPT}
    Yvan KOENIG (from FRANCE mercredi 1 août 2007 06:51:46)
    edit:
    When I edit my message, the script appears but when I look in the forum it doesn't appear.
    It appears that it is a recent "feature" of this forum;
    I made a last attempt.
    If it doesn't work, you may send a mail to
    koenig then a dot then yvan then an @ then tele2 then a dot then fr
    I will send you the script as a mail attachment.
    Yvan KOENIG (from FRANCE mercredi 1 août 2007 07:07:17)
    Message was edited by: KOENIG Yvan

  • Best fit/ linear equation in Numbers on the IPad?

    Does anyone know how to find the best fit line equation on Numbers for the IPad? I know how to find it in IWork for the MacBook and how to find the line on the Ipad. Thanks

    Can you tell me where line of best fit is in the iOS version? I havent seen it yet.
    You can search on the Internet for the linear regression formul, and compute the equation yourself. Then you could plot that series of points on your chart to show the line if it is not part of iOS.
    Jason

  • How do I make a best fit line on a scatter plot?

    I have a set of data and I made a scatter plot on numbers, but how do I put a best fit line in there?

    select the graph, then open the Charts Inspector.
    Open the series section (from the options at the top "Chart", "Axis", "Series"), Then select the "Trendline" in the "Advanced" section near the bottom.  Finally select the type of trendline

  • Help with Line of Best Fit equation!

    Alright, I'm making a graphing program where the user can input up to 10 coordinates (all ints) and when they click draw, the points will be graphed on a cartesian plain and the program will calculate and draw the line of best fit... including displaying the equation.
    I've got the yIntercept to work perfectly, but sometimes the slope comes out to be 0.0, and such.
    The equation to do it can be found on this site (in the big white space)
    http://people.hofstra.edu/faculty/Stefan_Waner/RealWorld/calctopic1/regression.html
    There are several things you must do first:
    - Find the sum of all the X values
    - Find the sum of all the Y values
    - Find the sum of all the X*Y values
    - Find the sum of all the X^2 values
    You then stick it into the equation (you can see on that site) and you will get the slope. You then take the slope value and insert it into another equation to get the y-intercept
    I was just wondering if you could just look over my calculation and see where I may be going wrong. (Sometimes, I get an error in the console saying I cannot divide by 0)
    public void lineOfBestFit(int numOfPoints, int largeNumX, float increment, float incrementY)
         Graphics g = canvas.getGraphics();
         float sumX = 0;
         float sumY = 0;
         float sumXY = 0;
         float sumXSqr = 0;
         int smallNumX=9999999;
         int firstPoint, lastPoint;
         //Creates the variables for the line of best fit equation
         for(int j=0;j<numOfPoints;j++)
              sumX+=xValue[j];
              sumY+=yValue[j];
              sumXY+=(xValue[j]*yValue[j]);
              sumXSqr+=(Math.pow(xValue[j],2));
         //Line of best fit equation
         float slope = ((numOfPoints*sumXY)-(sumX*sumY))/((numOfPoints*sumXSqr)-(sumX*sumX));
         float yInt = (sumY - (slope*sumX))/numOfPoints;
         for(int j=0;j<numOfPoints;j++)
              if(xValue[j]<smallNumX)
                   smallNumX=xValue[j];
         firstPoint=((int)((slope*smallNumX)+yInt)*50/(int)incrementY+210);
         lastPoint=((int)(slope*largeNumX+yInt)*50/(int)incrementY+210);
         int firstX=((int)(smallNumX*50/(int)increment+210));
         int lastX=((int)(largeNumX*50/(int)increment+210));
         g.drawLine(firstX,firstPoint,lastX,lastPoint);
         //Rounds and displays the line of best fit equation
         slope = (Math.round(slope*100))/100;
         yInt = (Math.round(yInt*100))/100;
         if(numOfPoints>1)
                     if(yInt < 0)
              g.drawString("y = " +slope+ "x " +yInt,250,350);
              else
                   g.drawString("y = " +slope+ "x +" +yInt,250,350);

    I think I may have solved it.... seems to be working now.
    I casted all the numOfPoints as (float) .... and commented out the rounding. Since some of the slopes were coming out to be 0.00003, that would display 0.0 if I rounded.

  • Extrapolation and Line of Best Fit

    Hello,
    I'm working on a project and I need to make a line of best fit for a scatter plot graph as well as make an extrapolation on the graph...any possibility someone could help me with these two questions?
    Thank you,
    Mike

    Mike,
    Numbers 08 have functions that you can use to calculate your lines of best fit, then chart the line calculations along with your data.
    See INTERCEPT and SLOPE for 1st order lines.
    Numbers 09 added quite a few new functions and also automatic Trendline generation.
    Jerry

  • How to I insert a line of best fit on a scatter plot????

    I have data already organized in tables, and I created a scatter plot. NOw I need to insert a line of best fit and get the equation. How do I do this??? I already calculated a and b (for y=a+bx) but I have no idea how to insert it on the plot. Every search tells me to "insert a trendline"..... but numbers doesnt have that function. Help please???

    Open inspector
    Go to chart tab
    Series
    Click on the "Advanced" to reveal the menu
    Trendline
    Choose the desired trendline (linear etc)
    Hope this helps.
    Dimitris

Maybe you are looking for

  • Remove Blank Space from Crystal report

    Hello, i am new in crystal report work. recently, i have created one crystal report which display item and remaining other detail like tax detail,item grand total, Some extra remark,etc. But my scenario is that if i take three or more item then it ta

  • Let addon run even after browser window is closed.

    I want to use this addon - "Pushbullet" even after the browser window is closed. Such an option was available in Chrome when I used it last. I migrated to Firefox recently, and would like to know how to implement the same here. Thanks, Raj

  • Mini + Wii remote + Frontrow (maybe)

    Scenario: I have a G4 mini (with no Frontrow pre-installed) and I don't own a Wii (yet) Questions: If I purchase a Wii remote don't I need the motion sensor bar? I've read that installing Frontrow on your own requires an Apple remote? Or any bluetoot

  • Applel Tv

    How can I see my desktop on Apple TV

  • How Do I Get My Music On The Radio.

    Hey there, looking for everyones oppinions When your projects are final and ready, what are the nessary steps onto getting your music played on radio. A&R? other method? Opon acceptance, do most radio stations pay you a figure per play? What is the r