Exemplo n.º 1
0
def InitFeas(A, b, c, c_form=0):

    if c_form == 0:
        (A, c) = stdForm(A, c)
    (AP, cP) = rep(A, b)
    x, s, u = longpathPC(AP, b, cP)
    r_A, c_A = np.shape(A)
    D = np.concatenate((A.T, np.identity(c_A)), axis=1)
    (T, w) = rep(D, c)

    y, s, u = longpathPC(T, c, w)
    return (x[0:c_A], y)
Exemplo n.º 2
0
from MehrotraMethod2 import mehrotra2

from LPFMethod_PC import longpathPC
from matplotlib.ticker import NullFormatter  # useful for `logit` scale
import pandas as pd  # Export to excel
import matplotlib.pyplot as plt  # Create graphics
from mpl_toolkits.mplot3d import Axes3D
'''    _PLOT THE PATHs_   '''

# Recall lp istance with dimension 2
(A, b, c) = input_data(0)

xm, sm, um = mehrotra2(A, b, c)
#um = pd.DataFrame(um, columns = ['it', 'g', 'Current x', 'Current s', 'rb', 'rc'])

xl, sl, ul = longpathPC(A, b, c)
#ul = pd.DataFrame(ul, columns = ['it', 'g', 'Current x', 'Current s', 'rb', 'rc'])

# Create 3d point x*s for mehrotra
x1 = []
y1 = []
z1 = []
for i in range(len(um)):
    g = um[i][2] * um[i][3]
    x1.append(g[0].copy())
    y1.append(g[1].copy())
    z1.append(g[2].copy())

# Create 3d point x*s for Long-path predictor corrector
x2 = []
y2 = []
Exemplo n.º 3
0
    x, s , u = affine(A, b, c, c_form = 1, info = 1, ip = 1)
    dfu = cent_meas(x, u, label = 'Affine', plot = 0) # 17 it
    
    """                             LPF1                                    """
    #                        161 iterations
    x, s, u = longpath1(A, b, c, c_form = 1, info = 1, ip = 0)
    dful = cent_meas(x, u, label = 'LPF', plot = 0) 
    
    """                             LPF2                                    """
    #                             13 it
    x, s, u, sigma_l2 = longpath2(A, b, c, c_form = 1, info = 1, ip = 1)    
    dfc = cent_meas(x, u, label = 'LPF2', plot = 0)
    
    """                    LPF predictor corrector                          """
    #                          14 iterations
    x, s, u, sigma_pc = longpathPC(A, b, c, c_form = 1, info = 1, ip = 0)
    dfpc = cent_meas(x, u, label = 'LPF PC', plot = 0) 
    
    """                          Mehrotra                                   """
    #                            8 iterations
    x, s, u, sigma_m = mehrotra(A, b, c, c_form = 1, info = 1, ip = 1)
    dfm = cent_meas(x, u, label = 'Mehrotra', plot = 0) 



    """ Recall the simplex method """
    
    (A2, b2, c2) = ssteel2()
    P, u = SimplexMethod(A, b, c, rule = 1, c_form = 1) # 17!!!
    #        Start phase II
    #Iteration: 12
Exemplo n.º 4
0
if __name__ == "__main__":
    (A, b, c) = tubprod()  # canonical form!
    """                              Affine                                 """
    #                                 29 it
    x, s, u = affine(A, b, c, ip=1)
    dfu = cent_meas(x, u, label='Affine', plot=0)
    """                            LPF1                                     """
    #                              IT DOESN'T WORK!!!
    #    x_l, s_l, u_l = longpath1(A, b, c, info = 1, ip = 1)
    """                            LPF2                                     """
    #                              21 it
    x, s, u, sigma_l2 = longpath2(A, b, c, info=1, ip=0)
    dfc = cent_meas(x, u, label='LPF2', plot=0)
    """                 LPF predictor corrector                           """
    #                          20 iterations
    x, s, u, sigma_pc = longpathPC(A, b, c, info=1, ip=1)
    dfpc = cent_meas(x, u, label='LPF PC', plot=0)
    """                        Mehrotra                                     """
    #                             10 iterations
    start = time.time()
    x_m, s_m, u_m, sigma_m = mehrotra(A, b, c, info=1, ip=1)
    dfm = cent_meas(x_m, u_m, label='Mehrotra', plot=0)
    plt.plot(sigma_m)

    " Recall the simplex method "

    #P, u = SimplexMethod(A, b, c, rule = 1) # 51 it
    # it doesn't work with rule = 0
    #dfu = pd.DataFrame(u)
    x = linprog(c, method='simplex', A_ub=A, b_ub=b)  # Exact solution
Exemplo n.º 5
0
dful = cent_meas(x_l, u_l, label = 'LPF', plot = 0) 

"""                                     LPF2                                """
#                                      12 it
start = time.time()
x_c, s_c, u_c, sigma_l2 = longpath2(A, b, c, c_form = 1, info = 1) 
time_lpf2 = time.time()-start
print('Time of the algorithm is {} \n\n'.format("%2.2e"%time_lpf2))

dfc = cent_meas(x_c, u_c, label = 'LPF2', plot= 0)

"""                         LPF predictor corrector                         """
#                              12 iterations/ 14 iteraions
start = time.time()
x_pc, s_pc, u_pc, sigma_pc = longpathPC(A, b, c, c_form = 1, info = 1, ip = 0)
time_lpfpc = time.time()-start
print('Time of the algorithm is {} \n\n'.format("%2.2e"%time_lpfpc))

dfpc = cent_meas(x_pc, u_pc, label = 'LPF PC', plot = 0) 
 
"""                              Mehrotra                                   """
#                              7 iterations
start = time.time()
x_m, s_m, u_m, sigma_m = mehrotra(A, b, c, c_form = 1, info = 1, ip = 0)
time_mer = time.time()-start
print('Time of the algorithm is {} \n\n'.format("%2.2e"%time_mer))

dfm = cent_meas(x_m, u_m, label = 'Mehrotra', plot = 0) 

Exemplo n.º 6
0
Compute: W = [ max|b - Ax_{k}| ] with x_{k} sequence generated by LPF2

         Z = [ max|b - Ax_{k}| ] with x_{k} sequence generated by LPF_PC

Plot the speed of the convergence of the error of feasibility
"""
i = 0

A, b, c = input_data(i)

x2, s2, u2, sig2 = longpath2(A, b, c)
dlpf = cent_meas(x2, u2, 'LPF', plot = 0)
W = dlpf['pf']

x3, s3, u3, sig3 = longpathPC(A, b, c)
ul = cent_meas(x3, u3, 'LPF Predictor corrector', plot = 0)
Z = ul['pf']

plt.figure()
plt.subplot(211)
plt.plot(W)
plt.title('Speed error LPF2')
locs, labels = plt.xticks(np.arange(0, len(W), step = 1))
plt.yscale('log')
plt.grid(b = True)

plt.subplot(212)
plt.plot(Z)
plt.title('Speed error LPF_PC')
locs, labels = plt.xticks(np.arange(0, len(Z), step = 1))
Exemplo n.º 7
0
(A, b, c) = onb()  # input data in canonical form
IP = 0
"""                           Affine                                        """
# IP = 1 doesn't work
x, s, u = affine(A, b, c, ip=IP)
dfu = cent_meas(x, u, label='Affine', plot=0)  # 29 it
"""                          LPF1                                          """
#                         307 iterations
x, s, u = longpath1(A, b, c, c_form=0, info=1, ip=IP)
dfu = cent_meas(x, u, label='LPF', plot=0)
"""                                 LPF2                                    """
#                                  16 it
x, s, u, sigma_l2 = longpath2(A, b, c, c_form=0, info=1, ip=1)
"""                        LPF predictor corrector                          """
#                            41 iterations / 17 iterations ip = 1
x_pc, s_pc, u_pc, sigma_pc = longpathPC(A, b, c, c_form=0, info=0)
x_pc, s_pc, u_pc, sigma_pc = longpathPC(A, b, c, c_form=0, info=0, ip=1)

dfpc = cent_meas(x_pc, u_pc, label='LPF PC', plot=0)
"""                          Mehrotra                                       """
#                          8 iterations

x_m, s_m, u_m, sigma_m = mehrotra2(A, b, c, c_form=0,
                                   info=1)  # Mehrotra1 doesn't work
x_m, s_m, u_m, sigma_m1 = mehrotra2(A, b, c, c_form=0, info=1,
                                    ip=1)  # Mehrotra1 doesn't work

dfm = cent_meas(x_m, u_m, label='Mehrotra', plot=0)

" Recall the simplex method "
Exemplo n.º 8
0
Y = []
W = []
Z = []
O = []
P = []

q = np.log(2)
for i in range(29):
    print(i)
    if not i in {4, 20, 23, 25}:
        (A, b, c) = input_data(i)
        x, s, u, sigma_m = mehrotra2(A, b, c, info=1)
        #        x, v = SimplexMethod(A, b, c, rule = 0)
        x, s, o = longpath1(A, b, c, c_form=0, info=1, ip=0)
        x, s, p, sigma_2 = longpath2(A, b, c, c_form=0, info=1)
        x, s, z, sigma_pc = longpathPC(A, b, c, info=1)

        B.append(np.log(len(u) - 1))
        #        W.append(np.log(len(v)))
        Z.append(np.log(len(z) - 1))
        O.append(np.log(len(o) - 1))
        P.append(np.log(len(p) - 1))
        r = sum(A.shape)
        a.append([q, np.log(r)])
        Y.append(np.log(r))
        it.append(i)
for i in range(29, 34):  # we compute the models
    it.append(i)
    if i == 29:  # FOREST
        (A, b, c) = input_data(i)
        B.append(np.log(8))