def test_inconsistent_shapes_for_best_index(self):
   """An error is raised when parameters have inconsistent shapes."""
   objective_vector = np.array([1, 2, 3])
   constraints_matrix = np.array([[1, 5], [2, 6], [3, 7], [4, 8]])
   with self.assertRaises(ValueError):
     _ = candidates.find_best_candidate_index(objective_vector,
                                              constraints_matrix)
Esempio n. 2
0
 def test_best_index_rank_objectives_true_max_constraints_true(self):
     """Index should match known solution."""
     # To see why the expected answer is 0, notice that:
     #   self._objective_vector ranks = [2, 1, 4, 3].
     #   self._constraints_matrix maximum ranks = [2, 3, 4, 1]
     index = candidates.find_best_candidate_index(self._objective_vector,
                                                  self._constraints_matrix,
                                                  rank_objectives=True,
                                                  max_constraints=True)
     self.assertEqual(0, index)
Esempio n. 3
0
 def test_best_index_rank_objectives_false_max_constraints_false(self):
     """Index should match known solution."""
     # To see why the expected answer is 3, notice that:
     #   self._objective_vector ranks = [2, 1, 4, 3].
     #   self._constraints_matrix ranks = [[1, 4], [3, 1], [4, 1], [1, 1]].
     #   Maximum ranks = [4, 3, 4, 1].
     index = candidates.find_best_candidate_index(self._objective_vector,
                                                  self._constraints_matrix,
                                                  rank_objectives=False,
                                                  max_constraints=False)
     self.assertEqual(3, index)