Exemplo n.º 1
0
   def make_FPI(self):
       #Faz matriz A da FPI
       self.FPI_A = pl.make_frac_matrix(np.zeros((self.m, self.n + self.m)))
       self.FPI_A[:,:-self.m] = self.A
       self.FPI_A[:,self.n:] = pl.make_frac_matrix(np.identity(self.m))

       #Faz o vetor c
       self.FPI_c = pl.make_frac_matrix(np.zeros(self.n + self.m))
       self.FPI_c[0, :-self.m] = self.c * (-1)

       self.FPI_y = pl.make_frac_matrix(np.zeros(self.m))
       self.FPI_b = self.b
Exemplo n.º 2
0
def cut_planes(progL_methods, file_f):
    c = 0
    while (check_end(progL_methods) == 0):
        for i in range(len(progL_methods.FPI_b)):
            check_floor = floor(progL_methods.FPI_b[i])
            if (check_floor != progL_methods.FPI_b[i]):
                for j in range(len(progL_methods.i_variables)):
                    if (progL_methods.base[i] == progL_methods.i_variables[j]):

                        #montando a nova PL com a nova restrição
                        new_lines = floor_line(progL_methods, i)
                        size = np.shape(progL_methods.FPI_A)
                        new_progL_A = pl.make_frac_matrix(
                            np.zeros((size[0] + 1, size[1] + 1)))
                        new_progL_op_matrix = pl.make_frac_matrix(
                            np.zeros((size[0] + 1, size[0] + 1)))
                        new_progL_b = pl.make_frac_matrix(
                            np.zeros((size[0] + 1, 1)))
                        new_progL_c = pl.make_frac_matrix(
                            np.zeros((1, size[1] + 1)))
                        new_progL_y = pl.make_frac_matrix(
                            np.zeros((1, size[0] + 1)))

                        new_progL_A[:-1, :-1] = progL_methods.FPI_A
                        new_progL_op_matrix[:-1, :
                                            -1] = progL_methods.FPI_op_matrix
                        new_progL_b[:-1] = progL_methods.FPI_b
                        new_progL_c[:, :-1] = progL_methods.FPI_c
                        new_progL_y[:, :-1] = progL_methods.FPI_y

                        new_progL_A[size[0], :-1] = new_lines[0]
                        new_progL_A[size[0], size[1]] = 1
                        new_progL_op_matrix[size[0], size[0]] = 1
                        new_progL_b[size[0]] = new_lines[1]

                        progL_methods.FPI_A = new_progL_A
                        progL_methods.FPI_op_matrix = new_progL_op_matrix
                        progL_methods.FPI_b = new_progL_b
                        progL_methods.FPI_c = new_progL_c
                        progL_methods.FPI_y = new_progL_y

                        add_correct_lines(progL_methods)
                        progL_methods.base[size[0]] = size[1]

                        result = simplex.simplex_d(progL_methods, file_f)
Exemplo n.º 3
0
input_pl = np.array(json.loads(hue), dtype=float)

#converts to fraction matrix
input_pl = np.matrix(input_pl)
input_pl = input_pl.astype('object')
for i in range(input_pl.shape[0]):
    for j in range(input_pl.shape[1]):
        input_pl[i, j] = fractions.Fraction(input_pl[i, j])

#constructs matrix A, in a numpy array format, separating from c vector
Amatrix = input_pl[1:, :-1]
Bmatrix = input_pl[1:, int(n):]
Cmatrix = input_pl[0, :-1]
base = {}

j = 1
for i in range(int(m), 0, -1):
    base[i - 1] = (int(n) + int(m) - j)
    j += 1

op_matrix = pl.make_frac_matrix(np.identity(int(m)))

#PL contruction
progL = pl.PL(Amatrix, Cmatrix, Bmatrix, int(n), int(m), op_matrix, base)

#puts it in FPI format

progL.make_FPI()

simplex.simplex(progL)
Exemplo n.º 4
0
            return 1
    return 0


#chooses var to make b&b restrictions
def choose_var(progL):
    for i in range(len(progL.i_variables)):
        floor_value = floor(progL.FPI_b[i])
        if (floor_value != progL.FPI_b[i]):
            return i


#Funtion used for the B&B extra restrictions
def bb_restrict(progL, case, line, size):
    floor_value = floor(progL.FPI_b[line])
    new_line_A = pl.make_frac_matrix(np.zeros(
        (1, size[1] + 1)))  #nova linha da restrição
    if (case == 0):  #case Função chão
        new_line_A[0, line] = 1
        new_line_A[0, size[1]] = 1
        new_line_b = floor_value
    else:  #case função teto, ou chão + 1
        new_line_A[0, line] = 1
        new_line_A[0, size[1]] = -1
        new_line_b = floor_value + 1

    #monta nova PL
    new_progL_A = pl.make_frac_matrix(np.zeros((size[0] + 1, size[1] + 1)))
    new_progL_op_matrix = pl.make_frac_matrix(
        np.zeros((size[0] + 1, size[0] + 1)))
    new_progL_b = pl.make_frac_matrix(np.zeros((size[0] + 1, 1)))
    new_progL_c = pl.make_frac_matrix(np.zeros((1, size[1] + 1)))
def simplex_aux(progL, file_f, extra_col, aux_base):
    #creating aux matrix
    new_c = pl.make_frac_matrix(np.zeros(progL.n + progL.m + extra_col))
    for i in range(extra_col):
        new_c[0, progL.n + progL.m:] = 1 / 1

    new_A = pl.make_frac_matrix(
        np.zeros((progL.m, progL.n + progL.m + extra_col)))
    for i in range(progL.m):
        new_A[i, aux_base[i]] = 1

    for i in range(len(aux_base)):
        new_A[i, aux_base[i]] = 1

    for i in range(progL.m):
        for j in range(progL.n + progL.m):
            new_A[i, j] = progL.FPI_A[i, j]

    base = aux_base

    progL_aux = pl.PL(progL.A, progL.c, progL.FPI_b, progL.n, progL.m,
                      progL.FPI_op_matrix, base)
    progL_aux.make_FPI()

    progL_aux.FPI_c = new_c
    progL_aux.FPI_A = new_A

    for i in range(progL.m):
        progL_aux.FPI_c[progL.n + progL.m:] = 1
    print_step(progL_aux, file_f)
    for i in range(progL.m):
        progL_aux.add_lines(i, i, -1, 1)
    print_step(progL_aux, file_f)

    aux_result = simplex_p(progL_aux, file_f)

    check = progL_aux.vo[0] * -1
    if (progL_aux.vo[0] < 0 and check < 0.0000001):
        progL_aux.vo[0] = 0
    if (progL_aux.vo[0] < 0.0000001 and check < 0):
        progL_aux.vo[0] = 0

    if (progL_aux.vo < 0):
        return (2, progL_aux.FPI_y)  #case unfeasible

    #case use aux on original PL
    elif (progL_aux.vo == 0):
        progL.FPI_A[:, :] = progL_aux.FPI_A[:, :-extra_col]
        progL.base = progL_aux.base
        print_step(progL, file_f)

        for i in range(len(progL_aux.base)):
            col = progL_aux.base[i]
            progL.divide_line(i, progL.FPI_A[i, col])
            sub_0 = progL.FPI_c[0, col] / progL.FPI_A[i, col]
            progL.add_lines(i, i, sub_0 * -1, 1)
            for j in range(progL.m):
                if (j != i):
                    sub_others = progL.FPI_A[j, col] / progL.FPI_A[i, col]
                    progL.add_lines(j, i, sub_others * -1, 0)

        aux_result = simplex_p(progL, file_f)

        return aux_result