Ticket #9392: trac_9392.patch

File trac_9392.patch, 1.2 KB (added by ncohen, 9 years ago)
  • sage/numerical/optimize.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1277876785 -7200
    # Node ID 415efe09065e11cb108eec6034845dbd44b0077f
    # Parent  f7eb1d1dedf067a86f71c36de29e1d420bcdec44
    trac 9392 -- Broken docstring in binpacking
    
    diff -r f7eb1d1dedf0 -r 415efe09065e sage/numerical/optimize.py
    a b  
    697697    `1/5, 1/4, 2/3, 3/4, 5/7`::
    698698
    699699        sage: from sage.numerical.optimize import binpacking
    700         sage: print sorted(binpacking([1/5,1/3,2/3,3/4, 5/7])) # optional - GLPK, CBC
    701         [[1/5, 3/4], [1/3, 2/3], [5/7]]
     700        sage: values = [1/5, 1/3, 2/3, 3/4, 5/7]
     701        sage: bins = binpacking(values) # optional - GLPK, CBC
     702        sage: len(bins)
     703        3
     704
     705    Checking the bins are of correct size ::
     706
     707        sage: all([ sum(b)<= 1 for b in bins ])
     708        True
     709
     710    Checking every item is in a bin ::
     711
     712        sage: b1, b2, b3 = bins
     713        sage: all([ (v in b1 or v in b2 or v in b3) for v in values ])
     714        True
    702715
    703716    One way to use only three boxes (which is best possible) is to put
    704717    `1/5 + 3/4` together in a box, `1/3+2/3` in another, and `5/7`