예제 #1
0
def solve(Q, W, K, R, mR, M, P, teams, resource2team, T, maxT, E, C, U_plus, U_minus, N_wk, shift, mr, ar, phi, TeamConstr=False):
   
    start_time = time.time()

    print "============================ FULL LP relaxation =============================="
    obj_relax, n_value0, overflow_value0, y_value, s_value0, p, attset, f = LPsolver(W, K, R, mR, M, P, teams, resource2team, T, E, C, U_plus, U_minus, N_wk, shift, mr, ar, phi, integer=0, OverConstr=False, TeamConstr=TeamConstr, MaxT=maxT, Q=Q)
    
    
    minr = np.zeros((W,R))

    for w in range(W):
        for r in range(R):
            minr[w][r] = math.floor(y_value[w][r])
            #print y_value[w][r]
    
    q = np.zeros(Q)
    for i in range(Q):
        q[i] = float(1)/Q
        
    
    objyn, n, ns,ys = KStrategiesYNcomb(Q, W, K, R, M, P, resource2team, T, maxT, E, C, U_plus, U_minus, N_wk, shift, mr, minr, q, p, s_value0, ar, phi, integer=0, OverConstr=False, OverConstr2=False)
            
    #print "============================ Binary Y / single relaxed n_wtk (allocated arrivals) MIP ======================"
    #[x] = KStrategiesY( Q, W, K, R, mR, M, P, teams, resource2team, T, maxT, E, C, U_plus, U_minus, N_wk, shift, mr, minr, ar, phi, integer=0, OverConstr=True,  TeamConstr=TeamConstr), 
    #objy, n_value, overflow_value, y_value, ys,  s_value, p_value, q, t1
    
    #[objy, y_value, ys,  s_value, p_value, q, t1] = [x[0],x[3],x[4],x[5],x[6],x[7],x[8]]
    #print "============================ multiple relaxed n_wtk (allocated arrivals) MIP ==============================="

    #objyn, n_val, n, t2 = KStrategiesYN(Q, W, K, R, M, P, resource2team, T,maxT,  E, C, U_plus, U_minus, N_wk, shift, mr, y_value, ys, q, p_value, s_value, ar, phi, integer=0, OverConstr=True, OverConstr2=False)
    
    #minn = np.zeros((Q,W,T,K))
    
    #for i in range(Q):
    #    for w in range(W):
    #        for k in range(K):
    #            sum = 0 
    #            for t in range(T):
    #                minn[i][w][t][k] = math.floor(n[i][w][t][k])
    #                sum += math.floor(n[i][w][t][k])
    
    print "============================ Integer n_wtk  MIP ==============================="

    #obj, rt, t3  = KStrategiesYNB(Q, W, K, R, M, resource2team, T, maxT, E, C, U_plus, U_minus, N_wk, y_value, ys, minn, p, s_value, phi, integer=0, OverConstr=True, OverConstr2=False)
    #walltime = time.time() - start_time
    
    #print "Runtime/walltime ", rt, " ", walltime
    
    print obj_relax, objyn#, objyn, obj
    
    return [obj_relax, objyn]#, walltime, [t1, t2, t3]
예제 #2
0
 K = 10
 P = 10
 
 for z in range(Z):
     seed = random.randint(1,1000)
     for zc in range(ZC):
         W = zc+6
         # Construct random instances
         resource2team, T, Er, E, C, U_plus, U_minus, N_wk, shift, mr, ar, phi = randomSetting(seed, W, K ,R, mR, M, P, teams, shift)
     
         minr = np.zeros((W,R))   
         
         
         start_time_relax = time.time()
         # Solve full LP relaxation
         obj_relax[z][zc], n_value0, overflow_value, y_value, s_value0, p,z_value = LPsolver(W, K, R, mR, M, P, teams, resource2team, T, E, C, U_plus, U_minus, N_wk, shift, mr, minr, ar, phi, integer=0, binary_y=0, OverConstr = 0)
         
         #time_relax[z][zq] = time.time() - start_time_relax
            
         for w in range(W):
             for r in range(R):
                 minr[w][r] = math.floor(y_value[w][r])
                 #print y_value[w][r]
         
         
         # find Q strategies for y, using binaries and lower bound minr, n integer for each ys.    
         start_time_yn = time.time()
         
         
         
         q = np.zeros(Q)
예제 #3
0
    #resource2team, T, E, C, U_plus, U_minus, N_wk, shift, mr, ar, phi = bigSetting( W, K , mR,  P, teams, shift)

    minr = np.zeros((W, R))

    obj_relaxed_all15, n_value0, overflow_value0, y_value0, s_value0, p_value0 = LPsolver(
        W,
        K,
        R,
        mR,
        M,
        P,
        teams,
        resource2team,
        T,
        E,
        C,
        U_plus,
        U_minus,
        N_wk,
        shift,
        mr,
        minr,
        ar,
        phi,
        integer=0,
        binary_y=0,
        OverConstr=True)

    for w in range(W):
        for r in range(R):
            minr[w][r] = math.floor(y_value0[w][r])
예제 #4
0
def fullYNcombined(W, K, R, mR, M, P, teams, resource2team, T, E, C, U_plus,
                   U_minus, N_wk, shift, mr, ar, phi, Q, maxT):
    minr = np.zeros((W, R))
    obj_relax, n_value0, overflow_value, y_value, s_value0, p, z_value = LPsolver(
        W,
        K,
        R,
        mR,
        M,
        P,
        teams,
        resource2team,
        T,
        E,
        C,
        U_plus,
        U_minus,
        N_wk,
        shift,
        mr,
        minr,
        ar,
        phi,
        integer=0,
        binary_y=0,
        OverConstr=0)
    for w in range(W):
        for r in range(R):
            minr[w][r] = math.floor(y_value[w][r])

    q = np.zeros(Q)
    for i in range(Q):
        q[i] = float(1) / Q
    #q = [0.25, 0.75]

    print "============================ K strategies Y, N combined =============================="
    objyn1, n, ns, ys, z_value, p, s, y = KStrategiesYNcomb(Q,
                                                            W,
                                                            K,
                                                            R,
                                                            M,
                                                            P,
                                                            resource2team,
                                                            T,
                                                            maxT,
                                                            E,
                                                            C,
                                                            U_plus,
                                                            U_minus,
                                                            N_wk,
                                                            shift,
                                                            mr,
                                                            minr,
                                                            q,
                                                            ar,
                                                            phi,
                                                            integer=0,
                                                            OverConstr=False,
                                                            OverConstr2=False)
    minn = np.zeros((Q, W, T, K))

    for i in range(Q):
        for w in range(W):
            for k in range(K):
                #sum = 0
                for t in range(T):
                    minn[i][w][t][k] = math.floor(ns[i][w][t][k])
                    #sum += math.floor(ns[i][w][t][k])

    print "============================ K strategies Y, N, B new =============================="
    obj1, rt, t3, ni_value, O_value, q_value, overflow_value = KStrategiesYNBnew(
        Q,
        W,
        K,
        R,
        M,
        resource2team,
        T,
        maxT,
        E,
        C,
        U_plus,
        U_minus,
        N_wk,
        ys,
        minn,
        p,
        s,
        phi,
        integer=0,
        OverConstr=False,
        OverConstr2=False)
    print obj_relax, objyn1, obj1

    new_O_value = np.zeros((Q, W, R))
    for i in range(Q):
        for w in range(W):
            for r in range(R):
                if w > 0:
                    new_O_value[i][w][r] = max(
                        new_O_value[i][w - 1][r] + np.sum([
                            ni_value[i][w][t][k] for k in range(K)
                            for t in resource2team[r]
                        ]) - ys[i][w][r] * C[r], 0)
                else:
                    new_O_value[i][w][r] = max(
                        np.sum([
                            ni_value[i][w][t][k] for k in range(K)
                            for t in resource2team[r]
                        ]) - ys[i][w][r] * C[r], 0)

    new_overflow = np.zeros((W, R))
    for i in range(Q):
        new_overflow += new_O_value[i] * q_value[i]
    print "old overflow: {0}".format(overflow_value)
    print "new overflow: {0}".format(new_overflow)

    strategySet = []
    for i in range(Q):
        tmp_strategy = {}
        tmp_strategy["n"] = ni_value[i]
        tmp_strategy["overflow"] = new_O_value[i]
        tmp_strategy["y"] = ys[i]
        tmp_strategy["s"] = s
        strategySet.append(tmp_strategy)

    return strategySet, obj_relax, objyn1, obj1, q_value
예제 #5
0
def solve(Q,
          W,
          K,
          R,
          mR,
          M,
          P,
          teams,
          resource2team,
          T,
          maxT,
          E,
          C,
          U_plus,
          U_minus,
          N_wk,
          shift,
          mr,
          ar,
          phi,
          TeamConstr=False,
          verbose=True):

    #print "============================ FULL LP relaxation =============================="
    start_time = time.time()
    minr = np.zeros((W, R))

    obj_relax, n_value0, overflow_value, y_value, s_value0, p, z_value = LPsolver(
        W,
        K,
        R,
        mR,
        M,
        P,
        teams,
        resource2team,
        T,
        E,
        C,
        U_plus,
        U_minus,
        N_wk,
        shift,
        mr,
        minr,
        ar,
        phi,
        integer=0,
        binary_y=0,
        OverConstr=0,
        verbose=verbose)
    #start_time_after_relax = time.time()
    rt_relax = time.time() - start_time

    for w in range(W):
        for r in range(R):
            minr[w][r] = math.floor(y_value[w][r])
            #print y_value[w][r]

    #objyn1, n_value0, overflow_value, y_value, s_value0, p,z_value = LPsolver(W, K, R, mR, M, P, teams, resource2team, T, E, C, U_plus, U_minus, N_wk, shift, mr, minr, ar, phi, integer=0, binary_y=1, OverConstr = 0)

    q = np.zeros(Q)
    for i in range(Q):
        q[i] = float(1) / Q
    #q = [0.25, 0.75]

    #print "============================ K strategies Y, N combined =============================="
    objyn1, n, ns, ys, z_value, p, s, y = KStrategiesYNcomb(Q,
                                                            W,
                                                            K,
                                                            R,
                                                            M,
                                                            P,
                                                            resource2team,
                                                            T,
                                                            maxT,
                                                            E,
                                                            C,
                                                            U_plus,
                                                            U_minus,
                                                            N_wk,
                                                            shift,
                                                            mr,
                                                            minr,
                                                            q,
                                                            ar,
                                                            phi,
                                                            integer=0,
                                                            OverConstr=False,
                                                            OverConstr2=False,
                                                            verbose=verbose)
    minn = np.zeros((Q, W, T, K))

    #rt_yncomb = time.time() - start_time_after_relax

    for i in range(Q):
        for w in range(W):
            for k in range(K):
                #sum = 0
                for t in range(T):
                    minn[i][w][t][k] = math.floor(ns[i][w][t][k])
                    #sum += math.floor(ns[i][w][t][k])

    #print "============================ K strategies Y, N, B new =============================="
    obj, runtime, team_val, ni_value, O_value, q_value, overflow_value = KStrategiesYNBnew(
        Q,
        W,
        K,
        R,
        M,
        resource2team,
        T,
        maxT,
        E,
        C,
        U_plus,
        U_minus,
        N_wk,
        ys,
        minn,
        p,
        s,
        phi,
        integer=0,
        OverConstr=False,
        OverConstr2=False,
        verbose=verbose)

    rt = time.time() - start_time
    return obj_relax, objyn1, obj, rt, rt_relax