Exemplo n.º 1
0
 def testPerformPivot(self):
     s = Simplex(testMatrix2)
     row, column = s.choosePivot()
     self.assertEqual((row, column), (1, 0))
     s.performPivot(row, column)
     expected = Array([
         [F(0), F(7, 2), F(-1, 2), F(5, 2), F(0), F(0), F(25, 2)],
         [F(1), F(3, 2), F(1, 2), F(1, 2), F(0), F(0), F(5, 2)],
         [F(0), F(-5), F(0), F(-2), F(1), F(0), F(1)],
         [F(0), F(-1, 2), F(1, 2), F(-3, 2), F(0), F(1), F(1, 2)],
     ])
     for i in range(len(expected)):
         self.assertEqual(s.tableaux[i], expected[i], "(row %d)" % i)
     self.assertEqual(s.basicVariables[1:], [0, 4, 5])
     row, column = s.choosePivot()
     self.assertEqual((row, column), (3, 2))
     s.performPivot(row, column)
     expected = Array([
         [F(0), F(3), F(0), F(1), F(0), F(1), F(13)],
         [F(1), F(2), F(0), F(2), F(0), F(-1), F(2)],
         [F(0), F(-5), F(0), F(-2), F(1), F(0), F(1)],
         [F(0), F(-1), F(1), F(-3), F(0), F(2), F(1)],
     ])
     for i in range(len(expected)):
         self.assertEqual(s.tableaux[i], expected[i], "(row %d)" % i)
     self.assertEqual(s.basicVariables[1:], [0, 4, 2])
Exemplo n.º 2
0
 def testChosePivot(self):
     s = Simplex(testMatrix2)
     row, column = s.choosePivot()
     self.assertEqual(column, 0)
     self.assertEqual(row, 1)
     for i in range(3):
         s.tableaux[0][i] = F(1)
     with self.assertRaises(EndOfAlgorithm):
         row, column = s.choosePivot()
     s.tableaux[0][0] = F(-1)
     for i in range(1, 4):
         s.tableaux[i][0] = F(-1)
     with self.assertRaises(Unbounded):
         row, column = s.choosePivot()