Python | SymPy Permutation.get_precedence_distance() method
Last Updated :
27 Aug, 2019
Permutation.get_precedence_distance() : get_precedence_distance() is a sympy Python library function that calculates the precedence distance between two permutations.
p and q represent n jobs. The precedence metric counts the no. of times a job n is preceded by job m in both p and q. This is a commutative matrix.
Syntax :
sympy.combinatorics.permutations.Permutation.get_precedence_distance()
Return :
precedence distance between two permutations
Code #1 : get_precedence_distance() Example
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
a = Permutation([ 2 , 0 , 3 , 1 , 5 , 4 ])
b = Permutation([ 3 , 1 , 2 , 5 , 4 , 0 ])
c = Permutation([ 0 , 1 , 3 , 4 , 5 , 2 ])
print ( "a - get_precedence_distance form b: " , a.get_precedence_distance(b))
print ( "b - get_precedence_distance form c: " , b.get_precedence_distance(c))
|
Output :
a – get_precedence_distance form b: 6
b – get_precedence_distance form c: 9
Code #2 : get_precedence_distance() Example – 2D Permutation
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
a = Permutation([[ 2 , 4 , 0 ],
[ 7 , 1 , 3 ],
[ 8 , 5 , 6 ]])
b = Permutation([[ 8 , 4 , 0 ],
[ 2 , 7 , 0 ],
[ 1 , 6 , 7 ]])
print ( "a get_precedence_distance form b : " , a.get_precedence_distance(b))
|
Output :
a get_precedence_distance form b : 22
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...