


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
     import torch

     from transformers.generation import DisjunctiveConstraint







@require_torch
class 		_snake_case  (      unittest.TestCase							):




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       # For consistency across different places the DisjunctiveConstraint is called,
       # dc.token_ids is a list of integers. It is also initialized only by integers.

       a						:Tuple 							=       [[1, 2, 4], [1, 2, 3, 4]]
       a						:str 							=       DisjunctiveConstraint(_lowerCamelCase    )
       self.assertTrue(isinstance(dc.token_ids					,  _lowerCamelCase    )    )

       with self.assertRaises(_lowerCamelCase    ):
             DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]    )    )

       with self.assertRaises(_lowerCamelCase    ):
             DisjunctiveConstraint([torch.LongTensor([1, 2, 4]    ), torch.LongTensor([1, 2, 3, 4, 5]    )]    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       # We can't have constraints that are complete subsets of another. This leads to a preverse
       # interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
       # It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
       # fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
       # will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
       a						:Optional[int] 							=       [[1, 2], [1, 2, 3, 4]]

       with self.assertRaises(_lowerCamelCase    ):
             DisjunctiveConstraint(_lowerCamelCase    )  # fails here




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:Tuple 							=       [[1, 2, 3], [1, 2, 4]]

       a						:Dict 							=       DisjunctiveConstraint(_lowerCamelCase    )

       a							,				a							,				a						:Union[str, Any] 							=       dc.update(1    )
       a						:Optional[Any] 							=       stepped is True and completed is False and reset is False
       self.assertTrue(_lowerCamelCase    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1]    )

       a							,				a							,				a						:Optional[Any] 							=       dc.update(2    )
       a						:Union[str, Any] 							=       stepped is True and completed is False and reset is False
       self.assertTrue(_lowerCamelCase    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1, 2]    )

       a							,				a							,				a						:Union[str, Any] 							=       dc.update(3    )
       a						:Optional[int] 							=       stepped is True and completed is True and reset is False
       self.assertTrue(_lowerCamelCase    )
       self.assertTrue(dc.completed    )  # Completed!
       self.assertTrue(dc.current_seq == [1, 2, 3]    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:List[str] 							=       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

       a						:List[str] 							=       DisjunctiveConstraint(_lowerCamelCase    )

       a							,				a							,				a						:Tuple 							=       dc.update(1    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1]    )

       a							,				a							,				a						:Dict 							=       dc.update(2    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1, 2]    )

       a							,				a							,				a						:Dict 							=       dc.update(4    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1, 2, 4]    )

       a							,				a							,				a						:Optional[int] 							=       dc.update(5    )
       self.assertTrue(dc.completed    )  # Completed!
       self.assertTrue(dc.current_seq == [1, 2, 4, 5]    )

       dc.reset()

       a							,				a							,				a						:List[str] 							=       dc.update(1    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.remaining() == 3    )
       self.assertTrue(dc.current_seq == [1]    )

       a							,				a							,				a						:Dict 							=       dc.update(2    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.remaining() == 2    )
       self.assertTrue(dc.current_seq == [1, 2]    )

       a							,				a							,				a						:List[Any] 							=       dc.update(5    )
       self.assertTrue(dc.completed    )  # Completed!
       self.assertTrue(dc.remaining() == 0    )
       self.assertTrue(dc.current_seq == [1, 2, 5]    )









import math







class 		_snake_case  :




 def __init__(		self					,  _lowerCamelCase=0    ):  # a graph with Node 0,1,...,N-1
       a						:Optional[int] 							=       n
       a						:Union[str, Any] 							=       [
           [math.inf for j in range(0					,  _lowerCamelCase    )] for i in range(0					,  _lowerCamelCase    )
       ]  # adjacency matrix for weight
       a						:List[Any] 							=       [
           [math.inf for j in range(0					,  _lowerCamelCase    )] for i in range(0					,  _lowerCamelCase    )
       ]  # dp[i][j] stores minimum distance from i to j




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase					,  _lowerCamelCase    ):
       a						:Tuple 							=       w




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       for k in range(0					,  self.n    ):
             for i in range(0					,  self.n    ):
                   for j in range(0					,  self.n    ):
                         a						:Union[str, Any] 							=       min(self.dp[i][j]					,  self.dp[i][k] + self.dp[k][j]    )




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase    ):
       return self.dp[u][v]


if __name__ == "__main__":
     snake_case				:    str       				=     Graph(5)
     graph.add_edge(0, 2, 9)
     graph.add_edge(0, 4, 10)
     graph.add_edge(1, 3, 5)
     graph.add_edge(2, 3, 7)
     graph.add_edge(3, 0, 10)
     graph.add_edge(3, 1, 2)
     graph.add_edge(3, 2, 1)
     graph.add_edge(3, 4, 6)
     graph.add_edge(4, 1, 3)
     graph.add_edge(4, 2, 4)
     graph.add_edge(4, 3, 9)
     graph.floyd_warshall()
     graph.show_min(1, 4)
     graph.show_min(0, 3)





