Ejemplo n.º 1
0
def f(m,s, justValue=False, returnProcedure=False, checkCorrect=False): #put it all together and calculate f(m,s)
    if m <= s:
        print("scott's algorithm only works for m>s")
        return

    m = Fraction(m)
    s = Fraction(s)
    V = interval.findV(m,s)
    sV, sVm1 = interval.getShares(m,s,V)
    #sV are majors, sVm1 are minors
    muffins, majors, minors = scott((m,Fraction(1),Fraction(2)),(sV,m/s,V),(sVm1,m/s,V-1))

    if checkCorrect:
        if checkProcedure(muffins, majors + minors, m, s):
            print("procedure is correct")
        else:
            print("procedure is not valid!!")

    if justValue:
        return max(min([piece for muffin in muffins for piece in muffin]), Fraction(1,3))

    if returnProcedure:
        if muffins[0][0] < Fraction(1,3):
            print("scott's algorithm only works if f(m,s) > 1/3")
        return (muffins, majors, minors)

    
    for muffin in muffins:
        print("Muffin: " + pfmap(muffin))
    for student in majors+minors:
        print("Student: " + pfmap(student))
Ejemplo n.º 2
0
def f(m,s):
    m = Fraction(m)
    s = Fraction(s)
    V = interval.findV(m,s)
    sV, sVm1 = interval.getShares(m,s,V)
    #sV are majors, sVm1 are minors
    return scott((m,1,2),(sV,m/s,V),(sVm1,m/s,V-1))
Ejemplo n.º 3
0
def doit(m, s):
    V = interval.findV(m, s)
    Q = findq.findQ(m, s, spew=False)
    (sV, sVm1) = interval.getShares(m, s, V)
    intervals = getIntervals(m, s, Q, V)
    #print (sV, sVm1, V)
    return intervals
Ejemplo n.º 4
0
def findQ(m, s, spew=True):
    m = Fraction(m)
    s = Fraction(s)

    if (m < s and spew):
        print("The interval therum only works when m>s")
        return 1

    V = interval.findV(m, s)
    (sV, sVm1) = interval.getShares(m, s, V)

    if sV == 0 or sVm1 == 0:  #TODO: tell bill about this
        return 1  #this means everyone gets same number of pieces

    dat = (m, s, V, sV, sVm1)

    if spew: print("V: " + str(V))
    if spew: print("sV: " + str(sV))
    if spew: print("sVm1: " + str(sVm1))

    if (sVm1 == 0 and spew):
        print(
            "sVm1 is zero, so this in not a case handled by the interval theorum."
        )
        return 1

    Q1 = findQ1(dat)
    Q2 = findQ2(dat)
    Q3 = (V - (m / s) - Fraction(3, 2)) / (V - 2)
    if not PREM3(dat, Q3):
        Q3 = 1
    Q4 = (m / s - Fraction(1, 2)) / (V - 1)
    if not PREM4(dat, Q4):
        Q4 = 1
    #Q5 = (V - 2) / (2*V - 3)
    Q5 = (m / s - Fraction(1) / 2) / (V - 1)
    if not PREM5(dat, Q5):
        Q5 = 1
    #Q6 = (V - 2) / (2*V - 3)
    Q6 = (V - Fraction(3) / 2 - m / s) / (V - 2)
    if not PREM6(dat, Q6):
        Q6 = 1

    Q7 = findQ7(m, s, sV, sVm1, V)
    Q8 = findQ8(m, s, sV, sVm1, V)
    Q9 = findQ9(m, s, sV, sVm1, V)
    Q10 = findQ10(m, s, sV, sVm1, V)

    if spew:
        print("Qs: " + str([Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10]))

    Q = min([Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8])
    return max(Fraction(1) / 3, m / (s * (V + 1)), 1 - m / (s * (V - 2)), Q)
Ejemplo n.º 5
0
def constrain(m, s, Qs):
    m, s = Fraction(m), Fraction(s)
    V = interval.findV(m, s)
    sV, sVm1 = interval.getShares(m, s, V)

    Q = Value(1, 0)
    M = [Interval(Q, 1 + -1 * Q)]
    A = [Interval(Q, 1 + -1 * Q)]
    B = [Interval(Q, 1 + -1 * Q)]

    Qmin = 0  #Qs

    #note to self: adding thing where if A or B is [], then just return current Qmin
    while True:
        print("A, B")
        print(A)
        print(B)
        print("with Qmin = " + str(Qmin))
        oldA, oldB, oldM = A, B, M
        (M, Qminm) = constrainToSumT(M, 2, 1, Qs)
        (A, Qmina) = constrainToSumT(A, V - 1, m / s, Qs)
        (B, Qminb) = constrainToSumT(B, V, m / s, Qs)
        Qmin = max(Qmin, Qmina, Qminb, Qminm)
        print("with Qmin after constrain = " + str(Qmin) +
              "and Qmina=%s, Qminb=%s, Qminc=%s" %
              (str(Qmina), str(Qminb), str(Qminm)))
        print("A, B, M after constrain")
        print(A)
        print(B)
        print(M)
        (A, Qmina) = intersection(A, M, Qs)
        (B, Qminb) = intersection(B, M, Qs)
        (M, Qminm) = union(A + B, Qs)
        Qmin = max(Qmin, Qmina, Qminb, Qminm)
        #print("with Qmin after intersection = " + str(Qmin))
        if oldA == A and oldB == B and oldM == M:
            break
        if A == [] or B == []:
            print('breaking because empty: A = ' + str(A) + ' B = ' + str(B))
            break
    return M, Qmin