def crea_primo_tableau(self):
        for i in range(len(self.cons)):
            self.rows[i].insert(0, self.cons[i])
        self.obj = array([self.term_noto] + self.obj)

        dim = len(self.rows)
        dim2 = len(self.obj)
        for i in range(dim):
            self.basis += ["s_" + str(1 + i)]

        for i in range(1, dim2):
            self.nonbasis += ["x_" + str(i)]
        self.id = [[f.l(0) for r in range(len(self.basis))]
                   for k in range(len(self.basis))]
        for i in range(len(self.basis)):
            self.id[i][i] = f.l(1)
 def _variabile_uscente_duale(self, ind_entr):
     low = f.l(0)
     indice = 0
     for i in range(len(self.rows)):
         if self.rows[i][0].minore(low):
             low = self.rows[i][0]
             indice = i
     return (indice)
 def _variabile_entrante_duale(self):
     low = f.l(0)
     indice = 0
     for i in range(1, len(self.obj)):
         if self.obj[i].minore(low):
             indice = i
             low = self.obj[i]
     #print(self.nonbasis[indice-1])
     return (indice)
 def __init__(self, obj, prob_type, term_noto=0):
     self.rows = []
     self.cons = []
     self.nonbasis = []
     self.basis = []
     self.obj = []
     self.id = []
     self.term_noto = f.l(term_noto)
     self.prob_type = prob_type
     if prob_type == 'max':
         self.obj = [f.l(x) for x in obj]
     elif prob_type == 'min':
         array = [f.l(x) for x in obj]
         for j in range(len(obj)):
             array[j].cambiosegni()
         for j in range(len(obj)):
             self.obj.append(array[j])
         self.term_noto.cambiosegni()
    def _variabile_uscente(self, ind_entr):
        vettore = []
        indice = 0
        for i in range(len(self.rows)):
            if self.rows[i][ind_entr].diverso(f.l(0)):
                vettore.append(self.rows[i][0].diviso(self.rows[i][ind_entr]))
            else:
                vettore.append(f.l(0))
        low = f.l(0)
        for j in range(len(vettore)):
            if vettore[j].minore(low):
                low = vettore[j]
        for j in range(len(vettore)):
            if vettore[j].minore(f.l(0)):
                if vettore[j].maggioreug(low):
                    indice = j
                    low = vettore[j]

        #print(self.basis[indice])
        return (indice)
 def is_optimal(self):
     b = True
     for i in range(1, len(self.obj)):
         if (self.obj[i]).maggiore(f.l(0)):
             b = False
     return b
 def aggiungi_vincolo(self, expression, value):
     self.cons.append(f.l(value))
     array = [f.l(x) for x in expression]
     for j in range(len(expression)):
         array[j].cambiosegni()
     self.rows.append(array)
 def is_feasible(self):
     b = True
     for i in range(len(self.cons)):
         if (self.rows[i][0]).minore(f.l(0)):
             b = False
     return b