# Path: tensorflow_constrained_optimization/python/candidates.py
# def _find_best_candidate_distribution_helper(objective_vector,
#                                              constraints_matrix,
#                                              maximum_violation=0.0,
#                                              linprog_method="simplex",
#                                              linprog_options=None):
# def find_best_candidate_distribution(objective_vector,
#                                      constraints_matrix,
#                                      epsilon=0.0,
#                                      linprog_method="simplex",
#                                      linprog_options=None):
# def find_best_candidate_index(objective_vector,
#                               constraints_matrix,
#                               rank_objectives=True,
#                               max_constraints=True):


import numpy as np
import tensorflow as tf
from tensorflow_constrained_optimization.python import candidates
        self._objective_vector, self._constraints_matrix)
    # Verify that the solution is a probability distribution.
    self.assertTrue(np.all(distribution >= -1e-6))
    self.assertAlmostEqual(np.sum(distribution), 1.0)
    # Verify that the solution satisfies the constraints.
    maximum_constraint_violation = np.amax(
        np.tensordot(self._constraints_matrix, distribution, axes=(0, 0)))
    self.assertLessEqual(maximum_constraint_violation, 1e-6)
    # Verify that the solution matches that which we expect.
    expected_distribution = np.array([0.37872711, 0.62127289, 0, 0])
    self.assertAllClose(expected_distribution, distribution, rtol=0, atol=1e-6)

  def test_best_index_rank_objectives_true_max_constraints_false(self):
    """Index should match known solution."""
    # To see why the expected answer is 1, 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, 3].
    index = candidates.find_best_candidate_index(
        self._objective_vector,
        self._constraints_matrix,
        rank_objectives=True,
        max_constraints=False)
    self.assertEqual(1, index)

  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]

# Path: tensorflow_constrained_optimization/python/candidates.py
# def _find_best_candidate_distribution_helper(objective_vector,
#                                              constraints_matrix,
#                                              maximum_violation=0.0,
#                                              linprog_method="simplex",
#                                              linprog_options=None):
# def find_best_candidate_distribution(objective_vector,
#                                      constraints_matrix,
#                                      epsilon=0.0,
#                                      linprog_method="simplex",
#                                      linprog_options=None):
# def find_best_candidate_index(objective_vector,
#                               constraints_matrix,
#                               rank_objectives=True,
#                               max_constraints=True):


# Path: tensorflow_constrained_optimization/python/candidates_test.py
import numpy as np
import tensorflow as tf
from tensorflow_constrained_optimization.python import candidates

        self._objective_vector, self._constraints_matrix)
    # Verify that the solution is a probability distribution.
    self.assertTrue(np.all(distribution >= -1e-6))
    self.assertAlmostEqual(np.sum(distribution), 1.0)
    # Verify that the solution satisfies the constraints.
    maximum_constraint_violation = np.amax(
        np.tensordot(self._constraints_matrix, distribution, axes=(0, 0)))
    self.assertLessEqual(maximum_constraint_violation, 1e-6)
    # Verify that the solution matches that which we expect.
    expected_distribution = np.array([0.37872711, 0.62127289, 0, 0])
    self.assertAllClose(expected_distribution, distribution, rtol=0, atol=1e-6)

  def test_best_index_rank_objectives_true_max_constraints_false(self):
    """Index should match known solution."""
    # To see why the expected answer is 1, 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, 3].
    index = candidates.find_best_candidate_index(
        self._objective_vector,
        self._constraints_matrix,
        rank_objectives=True,
        max_constraints=False)
    self.assertEqual(1, index)

  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(