pairings (version $Revision: Python 3.11)
index
/home/bisdorff/Documents/GitHub/Digraph3/pyDoc/pairings.py

Python3 implementation of solvers for fair inter- and intragroup pairing problems
 
Copyright (C) 2023 Raymond Bisdorff
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 
Classes
       
graphs.BipartiteGraph(graphs.Graph)
InterGroupPairing
BestCopelandInterGroupMatching
FairestGaleShapleyMatching
FairestInterGroupPairing
FairnessEnhancedInterGroupMatching
graphs.Graph(builtins.object)
IntraGroupPairing
BestCopelandIntraGroupMatching
FairestIntraGroupPairing
FairnessEnhancedIntraGroupMatching

 
class BestCopelandInterGroupMatching(InterGroupPairing)
    BestCopelandInterGroupMatching(vpA, vpB, Comments=False, Debug=False)
 
The class computes the individual Copeland ranking scores and
constructs a best determined perfect intergroup matching
with a ranked pairs rule
 
*Parameters*:
 
   * *vpA* : any VotingProfile instance
   * *vpB* : reciprocal VotingProfile instance
   
See the :ref:`tutorial on computing fair intergroup pairings <Fair-InterGroup-Pairings-label>`.
 
 
Method resolution order:
BestCopelandInterGroupMatching
InterGroupPairing
graphs.BipartiteGraph
graphs.Graph
builtins.object

Methods defined here:
__init__(self, vpA, vpB, Comments=False, Debug=False)
Abstract class entry

Methods inherited from InterGroupPairing:
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, vpA, a, b)
Replacement for the linear voting profiles information
when searching for promising swapping candidates
computeGaleShapleyMatching(self, Reverse=False)
Documentation:
https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
 
When *Reverse==False*, group *A* is proposing.
Otherwise, group *B* is proposing
computeIndividualCorrelations(self, matching, Debug=False)
Individual correlations for groups A and B
returns a tuple called fitness with following content
fitness=(matching,avgCorr,stdCorr,avgCorr-stdCorr,
groupAScores,groupBScores,
abs(avgCorrA-avgCorrB))
computePermutation(self, matching)
Renders the matching's permutation of *A* and *B* indexes.
 
.. note:: The prefix of group *A* voters must preceed the prefix of the group *B* voters in alphabetic order
computePermutationGraph(self, matching)
Renders the permutation graph of the matching
enhanceMatchingGeneralFairness(self, matching, maxIterations=10, Comments=False, Debug=False)
Enahance fairness of a given matching using any reciprocal voting profiles
enhanceMatchingLVFairness(self, matching, Reversed=False, maxIterations=10, Comments=False, Debug=False)
Enhance fairness of given matching by using reciprocal linear voting profiles
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for bipartite graph drawing filtering.
isStableMatching(self, matching, Comments=True, Debug=False)
Test for the existance of matching instabilities.
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
showCopelandRankingScores(self)
Print the individual Copeland ranking scores
showMatchingFairness(self, matching=None, WithGroupCorrelations=True, WithIndividualCorrelations=True)
showPairing(self, matching=None)

Methods inherited from graphs.BipartiteGraph:
computeBestDeterminedMaximalMatching(self, Comments=True, Debug=True)
Using the ranked pairs rule for assembling a best determined maximal matching
exportGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', edgeColor='blue', bgcolor='cornsilk', lineWidth=1, Debug=True)
Exports GraphViz dot file  for bipartite graph drawing filtering.
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class BestCopelandIntraGroupMatching(IntraGroupPairing)
    BestCopelandIntraGroupMatching(vpA, Comments=False, Debug=False)
 
The class computes the individual Copeland ranking scores and
construct the best determined perfect matching with a ranked pairs rule
from the reciprocal Copeland ranking scores graph 
 
*Parameters*:
 
   * *vpA* : intragroup *VotingProfile* instance
   
See the :ref:`tutorial on computing fair intergroup pairings <Fair-InterGroup-Pairings-label>`.
 
 
Method resolution order:
BestCopelandIntraGroupMatching
IntraGroupPairing
graphs.Graph
builtins.object

Methods defined here:
__init__(self, vpA, Comments=False, Debug=False)
Constructor for Graph objects.

Methods inherited from IntraGroupPairing:
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, a, b)
Computes fitness of swapping candidates
computeIndividualCorrelations(self, matching=None, Debug=False)
Individual correlations for intragroup pairing solution
returns a tuple called fitness with following content
avgCorr,stdCorr, groupScores
enhanceMatchingFairness(self, matching, Comments=False, Debug=False)
Heuristic for fairness enhancing of given matching
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=2)
Exports GraphViz dot file for pairing graph drawing filtering.
showMatchingFairness(self, matching=None, WithIndividualCorrelations=True)
Shows the intragroup faines of a given matching.
When *matching is None* the fairest matching of the class is used
showPairing(self, matching=None)
shows the intragroup pairing solution when *matching is None*

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computePermutation(self, seq1=None, seq2=None, Comments=True)
Tests whether the graph instance *self* is a permutation graph
and renders, in case the test is positive,
the corresponding permutation.
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', WithSpanningTree=False, WithVertexColoring=False, matching=None, layout=None, arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file  for graph drawing filtering.
 
Example:
   >>> g = Graph(numberOfVertices=5,edgeProbability=0.3)
   >>> g.exportGraphViz('randomGraph')
 
.. image:: randomGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class FairestGaleShapleyMatching(InterGroupPairing)
    FairestGaleShapleyMatching(lvA, lvB, Comments=False)
 
The class computes both Gale-Shapley matchings -- group A proposes and group B proposes--
and renders the fairest of both.
 
*Parameters*:
 
   * *lvA* : LinearVotingProfile instance
   * *lvB* : reciprocal LinearVotingProfile
   
See the :ref:`tutorial on computing fair intergroup pairings <Fair-InterGroup-Pairings-label>`.
 
 
Method resolution order:
FairestGaleShapleyMatching
InterGroupPairing
graphs.BipartiteGraph
graphs.Graph
builtins.object

Methods defined here:
__init__(self, lvA, lvB, Comments=False)
Abstract class entry

Methods inherited from InterGroupPairing:
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, vpA, a, b)
Replacement for the linear voting profiles information
when searching for promising swapping candidates
computeGaleShapleyMatching(self, Reverse=False)
Documentation:
https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
 
When *Reverse==False*, group *A* is proposing.
Otherwise, group *B* is proposing
computeIndividualCorrelations(self, matching, Debug=False)
Individual correlations for groups A and B
returns a tuple called fitness with following content
fitness=(matching,avgCorr,stdCorr,avgCorr-stdCorr,
groupAScores,groupBScores,
abs(avgCorrA-avgCorrB))
computePermutation(self, matching)
Renders the matching's permutation of *A* and *B* indexes.
 
.. note:: The prefix of group *A* voters must preceed the prefix of the group *B* voters in alphabetic order
computePermutationGraph(self, matching)
Renders the permutation graph of the matching
enhanceMatchingGeneralFairness(self, matching, maxIterations=10, Comments=False, Debug=False)
Enahance fairness of a given matching using any reciprocal voting profiles
enhanceMatchingLVFairness(self, matching, Reversed=False, maxIterations=10, Comments=False, Debug=False)
Enhance fairness of given matching by using reciprocal linear voting profiles
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for bipartite graph drawing filtering.
isStableMatching(self, matching, Comments=True, Debug=False)
Test for the existance of matching instabilities.
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
showCopelandRankingScores(self)
Print the individual Copeland ranking scores
showMatchingFairness(self, matching=None, WithGroupCorrelations=True, WithIndividualCorrelations=True)
showPairing(self, matching=None)

Methods inherited from graphs.BipartiteGraph:
computeBestDeterminedMaximalMatching(self, Comments=True, Debug=True)
Using the ranked pairs rule for assembling a best determined maximal matching
exportGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', edgeColor='blue', bgcolor='cornsilk', lineWidth=1, Debug=True)
Exports GraphViz dot file  for bipartite graph drawing filtering.
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class FairestInterGroupPairing(InterGroupPairing)
    FairestInterGroupPairing(vpA, vpB, orderLimit=6, StableMatchings=False, Comments=False, Debug=False)
 
The class computes the fitness scores of the complete set of maximal matchings between
two groups *A* and *B* of persons of equal number *k* and delivers, based on these fitness scores, a fairest pairing of the persons of both groups.
 
*Parameters*:
 
   * *vpA* : any type of VotingProfile instance
   * *vpB* : reciprocal VotingProfile instance
   * *oderLimit* : preventing a potential CPU memory or time overflow
   * *StableMatchings* : False (default) / True limits to only stable matchings
 
See the :ref:`tutorial on computing fair intergroup pairings <Fair-InterGroup-Pairings-label>`.
 
 
Method resolution order:
FairestInterGroupPairing
InterGroupPairing
graphs.BipartiteGraph
graphs.Graph
builtins.object

Methods defined here:
__init__(self, vpA, vpB, orderLimit=6, StableMatchings=False, Comments=False, Debug=False)
Abstract class entry
computeMatchingFairnessIndex(self, matching, Comments=False)
Renders the index position of the given matching in the
fairness ranked self.pairings list.
showFairestPairing(self, rank=1, WithIndividualCorrelations=False)
Setting the *rank* parameter to a value > 1,
gives access to lesser fitting pairings.
 
The *WithIndividualCorrelations* flag shows the correlations with
the individual pairing preferences.

Methods inherited from InterGroupPairing:
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, vpA, a, b)
Replacement for the linear voting profiles information
when searching for promising swapping candidates
computeGaleShapleyMatching(self, Reverse=False)
Documentation:
https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
 
When *Reverse==False*, group *A* is proposing.
Otherwise, group *B* is proposing
computeIndividualCorrelations(self, matching, Debug=False)
Individual correlations for groups A and B
returns a tuple called fitness with following content
fitness=(matching,avgCorr,stdCorr,avgCorr-stdCorr,
groupAScores,groupBScores,
abs(avgCorrA-avgCorrB))
computePermutation(self, matching)
Renders the matching's permutation of *A* and *B* indexes.
 
.. note:: The prefix of group *A* voters must preceed the prefix of the group *B* voters in alphabetic order
computePermutationGraph(self, matching)
Renders the permutation graph of the matching
enhanceMatchingGeneralFairness(self, matching, maxIterations=10, Comments=False, Debug=False)
Enahance fairness of a given matching using any reciprocal voting profiles
enhanceMatchingLVFairness(self, matching, Reversed=False, maxIterations=10, Comments=False, Debug=False)
Enhance fairness of given matching by using reciprocal linear voting profiles
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for bipartite graph drawing filtering.
isStableMatching(self, matching, Comments=True, Debug=False)
Test for the existance of matching instabilities.
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
showCopelandRankingScores(self)
Print the individual Copeland ranking scores
showMatchingFairness(self, matching=None, WithGroupCorrelations=True, WithIndividualCorrelations=True)
showPairing(self, matching=None)

Methods inherited from graphs.BipartiteGraph:
computeBestDeterminedMaximalMatching(self, Comments=True, Debug=True)
Using the ranked pairs rule for assembling a best determined maximal matching
exportGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', edgeColor='blue', bgcolor='cornsilk', lineWidth=1, Debug=True)
Exports GraphViz dot file  for bipartite graph drawing filtering.
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class FairestIntraGroupPairing(IntraGroupPairing)
    FairestIntraGroupPairing(vp, orderLimit=6, Comments=False, Debug=False)
 
The class computes average ordinal correlations for the complete set of maximal IntraGroup matchings
of an een-sized set of persons and delivers, based on these correlations scores, 
a fairest possible pairing of the persons
 
*Parameters*:
 
   * *vpA* : any type of VotingProfile instance
   * *oderLimit* : preventing a potential CPU memory or time overflow
 
See the :ref:`tutorial on computing fair intragroup pairings <Fair-IntraGroup-Pairings-label>`.
 
 
Method resolution order:
FairestIntraGroupPairing
IntraGroupPairing
graphs.Graph
builtins.object

Methods defined here:
__init__(self, vp, orderLimit=6, Comments=False, Debug=False)
Constructor for Graph objects.
computeMatchingFairnessIndex(self, matching, Comments=False)
Renders the index position of the given matching in the
fairness ranked self.pairings list.

Methods inherited from IntraGroupPairing:
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, a, b)
Computes fitness of swapping candidates
computeIndividualCorrelations(self, matching=None, Debug=False)
Individual correlations for intragroup pairing solution
returns a tuple called fitness with following content
avgCorr,stdCorr, groupScores
enhanceMatchingFairness(self, matching, Comments=False, Debug=False)
Heuristic for fairness enhancing of given matching
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=2)
Exports GraphViz dot file for pairing graph drawing filtering.
showMatchingFairness(self, matching=None, WithIndividualCorrelations=True)
Shows the intragroup faines of a given matching.
When *matching is None* the fairest matching of the class is used
showPairing(self, matching=None)
shows the intragroup pairing solution when *matching is None*

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computePermutation(self, seq1=None, seq2=None, Comments=True)
Tests whether the graph instance *self* is a permutation graph
and renders, in case the test is positive,
the corresponding permutation.
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', WithSpanningTree=False, WithVertexColoring=False, matching=None, layout=None, arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file  for graph drawing filtering.
 
Example:
   >>> g = Graph(numberOfVertices=5,edgeProbability=0.3)
   >>> g.exportGraphViz('randomGraph')
 
.. image:: randomGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class FairnessEnhancedInterGroupMatching(InterGroupPairing)
    FairnessEnhancedInterGroupMatching(vpA, vpB, initialMatching=None, seed=None, maxIterations=None, Comments=False, Debug=False)
 
The class enhances the fairness of a given matching.
 
*Parameters*:
 
   * *vpA* : any VotingProfile instance
   * *vpB* : reciprocal VotingProfile instance
   * *initialMatching* : a given perfect matching
     if *None* a matching is being previously constructed
     elif 'bestCopeland' a best Copeland intergroup matching is used,
     elif 'Random' a shuffled version of the bi is matched to the ai,
   * The *seed* parameter is used for allowing to repete the same experiment
   
See the :ref:`tutorial on computing fair intergroup pairings <Fair-InterGroup-Pairings-label>`.
 
 
Method resolution order:
FairnessEnhancedInterGroupMatching
InterGroupPairing
graphs.BipartiteGraph
graphs.Graph
builtins.object

Methods defined here:
__init__(self, vpA, vpB, initialMatching=None, seed=None, maxIterations=None, Comments=False, Debug=False)
Abstract class entry

Methods inherited from InterGroupPairing:
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, vpA, a, b)
Replacement for the linear voting profiles information
when searching for promising swapping candidates
computeGaleShapleyMatching(self, Reverse=False)
Documentation:
https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
 
When *Reverse==False*, group *A* is proposing.
Otherwise, group *B* is proposing
computeIndividualCorrelations(self, matching, Debug=False)
Individual correlations for groups A and B
returns a tuple called fitness with following content
fitness=(matching,avgCorr,stdCorr,avgCorr-stdCorr,
groupAScores,groupBScores,
abs(avgCorrA-avgCorrB))
computePermutation(self, matching)
Renders the matching's permutation of *A* and *B* indexes.
 
.. note:: The prefix of group *A* voters must preceed the prefix of the group *B* voters in alphabetic order
computePermutationGraph(self, matching)
Renders the permutation graph of the matching
enhanceMatchingGeneralFairness(self, matching, maxIterations=10, Comments=False, Debug=False)
Enahance fairness of a given matching using any reciprocal voting profiles
enhanceMatchingLVFairness(self, matching, Reversed=False, maxIterations=10, Comments=False, Debug=False)
Enhance fairness of given matching by using reciprocal linear voting profiles
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for bipartite graph drawing filtering.
isStableMatching(self, matching, Comments=True, Debug=False)
Test for the existance of matching instabilities.
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
showCopelandRankingScores(self)
Print the individual Copeland ranking scores
showMatchingFairness(self, matching=None, WithGroupCorrelations=True, WithIndividualCorrelations=True)
showPairing(self, matching=None)

Methods inherited from graphs.BipartiteGraph:
computeBestDeterminedMaximalMatching(self, Comments=True, Debug=True)
Using the ranked pairs rule for assembling a best determined maximal matching
exportGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', edgeColor='blue', bgcolor='cornsilk', lineWidth=1, Debug=True)
Exports GraphViz dot file  for bipartite graph drawing filtering.
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class FairnessEnhancedIntraGroupMatching(IntraGroupPairing)
    FairnessEnhancedIntraGroupMatching(intraVp=None, maxIterations=None, initialMatching=None, _nbrOfSwappingRetrials=None, seed=None, Comments=True, Debug=False)
 
Solver for computing fair IntraGroup pairings using a similar hill climbing heuristic as the
one for the intergroup pairing problem. The enhancing is guided by Copeland ranking scores.
 
*Parameters*:   
    * *intraVp* : a IntraGroup voting profile instance with *2k* voters where the *2k-1* candidates of
      each person are the other persons
    * *initialMatching* : the matching from which the fairness enhancing algorithm is starting
      If *None*, a right --[pi,pi+1] for i = 1..2k-1 step 3-- and a left --[pi,p-i] for i = 1..k-- initial matching will be used
      elif 'random' a random maximal matching will be used with given *seed*
      elif 'bestCopeland' the best Copeland matching will be used as initial matching
 
See the :ref:`tutorial on computing fair intragroup pairings <Fair-IntraGroup-Pairings-label>`.
 
 
Method resolution order:
FairnessEnhancedIntraGroupMatching
IntraGroupPairing
graphs.Graph
builtins.object

Methods defined here:
__init__(self, intraVp=None, maxIterations=None, initialMatching=None, _nbrOfSwappingRetrials=None, seed=None, Comments=True, Debug=False)
Constructor for Graph objects.

Methods inherited from IntraGroupPairing:
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, a, b)
Computes fitness of swapping candidates
computeIndividualCorrelations(self, matching=None, Debug=False)
Individual correlations for intragroup pairing solution
returns a tuple called fitness with following content
avgCorr,stdCorr, groupScores
enhanceMatchingFairness(self, matching, Comments=False, Debug=False)
Heuristic for fairness enhancing of given matching
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=2)
Exports GraphViz dot file for pairing graph drawing filtering.
showMatchingFairness(self, matching=None, WithIndividualCorrelations=True)
Shows the intragroup faines of a given matching.
When *matching is None* the fairest matching of the class is used
showPairing(self, matching=None)
shows the intragroup pairing solution when *matching is None*

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computePermutation(self, seq1=None, seq2=None, Comments=True)
Tests whether the graph instance *self* is a permutation graph
and renders, in case the test is positive,
the corresponding permutation.
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', WithSpanningTree=False, WithVertexColoring=False, matching=None, layout=None, arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file  for graph drawing filtering.
 
Example:
   >>> g = Graph(numberOfVertices=5,edgeProbability=0.3)
   >>> g.exportGraphViz('randomGraph')
 
.. image:: randomGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class InterGroupPairing(graphs.BipartiteGraph)
    Abstract root class with private and public methods for intergroup pairing graphs
 
 
Method resolution order:
InterGroupPairing
graphs.BipartiteGraph
graphs.Graph
builtins.object

Methods defined here:
__init__(self)
Abstract class entry
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, vpA, a, b)
Replacement for the linear voting profiles information
when searching for promising swapping candidates
computeGaleShapleyMatching(self, Reverse=False)
Documentation:
https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
 
When *Reverse==False*, group *A* is proposing.
Otherwise, group *B* is proposing
computeIndividualCorrelations(self, matching, Debug=False)
Individual correlations for groups A and B
returns a tuple called fitness with following content
fitness=(matching,avgCorr,stdCorr,avgCorr-stdCorr,
groupAScores,groupBScores,
abs(avgCorrA-avgCorrB))
computePermutation(self, matching)
Renders the matching's permutation of *A* and *B* indexes.
 
.. note:: The prefix of group *A* voters must preceed the prefix of the group *B* voters in alphabetic order
computePermutationGraph(self, matching)
Renders the permutation graph of the matching
enhanceMatchingGeneralFairness(self, matching, maxIterations=10, Comments=False, Debug=False)
Enahance fairness of a given matching using any reciprocal voting profiles
enhanceMatchingLVFairness(self, matching, Reversed=False, maxIterations=10, Comments=False, Debug=False)
Enhance fairness of given matching by using reciprocal linear voting profiles
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for bipartite graph drawing filtering.
isStableMatching(self, matching, Comments=True, Debug=False)
Test for the existance of matching instabilities.
Our implementation is inspired by
https://johnlekberg.com/blog/2020-08-22-stable-matching.html
showCopelandRankingScores(self)
Print the individual Copeland ranking scores
showMatchingFairness(self, matching=None, WithGroupCorrelations=True, WithIndividualCorrelations=True)
showPairing(self, matching=None)

Methods inherited from graphs.BipartiteGraph:
computeBestDeterminedMaximalMatching(self, Comments=True, Debug=True)
Using the ranked pairs rule for assembling a best determined maximal matching
exportGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', edgeColor='blue', bgcolor='cornsilk', lineWidth=1, Debug=True)
Exports GraphViz dot file  for bipartite graph drawing filtering.
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class IntraGroupPairing(graphs.Graph)
    Abstract root class for IntraGroup pairing solutions
 
 
Method resolution order:
IntraGroupPairing
graphs.Graph
builtins.object

Methods defined here:
__init__()
Constructor for Graph objects.
__repr__(self)
Default description for FairPairing instances.
computeCopelandScore(self, a, b)
Computes fitness of swapping candidates
computeIndividualCorrelations(self, matching=None, Debug=False)
Individual correlations for intragroup pairing solution
returns a tuple called fitness with following content
avgCorr,stdCorr, groupScores
enhanceMatchingFairness(self, matching, Comments=False, Debug=False)
Heuristic for fairness enhancing of given matching
exportPairingGraphViz(self, fileName=None, Comments=True, graphType='png', graphSize='7,7', matching=None, edgeColor='blue', bgcolor='cornsilk', lineWidth=2)
Exports GraphViz dot file for pairing graph drawing filtering.
showMatchingFairness(self, matching=None, WithIndividualCorrelations=True)
Shows the intragroup faines of a given matching.
When *matching is None* the fairest matching of the class is used
showPairing(self, matching=None)
shows the intragroup pairing solution when *matching is None*

Methods inherited from graphs.Graph:
__neg__(self)
Make the negation operator -self available for Graph instances.
Returns a DualGraph instance of self.
breadthFirstSearch(self, s, alphabeticOrder=True, Warnings=True, Debug=False)
Breadth first search through a graph in lexicographical order
of the vertex keys.
 
Renders a list of vertice keys in
increasing distance from the origin *s*. Ties in the distances
are resolved by alphabetic ordering of the vertice keys.
 
A warning is issued when the graph is not connected and the resulting
search does not cover the whole set of graph vertices. 
 
Source: Cormen, Leiserson, Rivest & Stein, *Introduction to Algorithms* 2d Ed., MIT Press 2001.
computeChordlessCycles(self, Cycle3=False, Comments=False, Debug=False)
Renders the set of all chordless cycles observed in a Graph
intance. Inspired from Dias, Castonguay, Longo & Jradi,
Algorithmica 2015.
 
.. note::
 
     By default, a chordless cycle must have at least length 4.If the Cycle3 flag is set to True,
     the cyclicly closed triplets will be inserted as 3-cycles in the result.
computeCliques(self, Comments=False)
Computes all cliques, ie maximal complete subgraphs in self:
 
.. Note::
 
    - Computes the maximal independent vertex sets in the dual of self.
    - Result is stored in self.cliques.
computeComponents(self)
Computes the connected components of a graph instance.
Returns a partition of the vertices as a list
computeDegreeDistribution(self, Comments=False)
Renders the distribution of vertex degrees.
computeDiameter(self, Oriented=False)
Renders the diameter (maximal neighbourhood depth) of the digraph instance.
 
.. Note::
 
    The diameter of a disconnected graph is considered to be *infinite*
    (results in a value -1) !
computeGirth(self, girthType='any', Comments=False)
Renders the *girth* of self, i.e. the length of the shortest chordless cycle in the graph.
 
*Parameter*:
    * *girthType* = "any" (default) | "odd" | "even"
computeGraphCentres(self)
Renders the vertices of minimal Neighborhood depth.
computeMIS(self, Comments=False)
Prints all maximal independent vertex sets:
 
.. Note::
 
    - Result is stored in self.misset !
computeMaximumMatching(self, Comments=False)
Renders a maximum matching in *self* by computing
a maximum MIS of the line graph of *self*.
computeNeighbourhoodDepth(self, vertex, Debug=False)
Renders the distribtion of neighbourhood depths.
computeNeighbourhoodDepthDistribution(self, Comments=False, Debug=False)
Renders the distribtion of neighbourhood depths.
computeOrientedDigraph(self, PartiallyDetermined=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the adjacent vertices' numbers.
If self is a PermutationGraph instance, the orientation will be transitive.
 
The parameter *PartiallyDetermined*: {True|False by default], converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,seed=101)
>>> dg = g.computeOrientedDigraph()
>>> dg
*------- Digraph instance description ------*
Instance class   : Digraph
Instance name    : oriented_randomGraph
Digraph Order      : 6
Digraph Size       : 5
Valuation domain : [-1.00; 1.00]
Determinateness  : 100.000
Attributes       : ['name','order','actions','valuationdomain',
                    'relation', 'gamma', 'notGamma',
                    'size', 'transitivityDegree']
>>> dg.transitivityDegree
Decimal('0.7142857142857142857142857143')
computePermutation(self, seq1=None, seq2=None, Comments=True)
Tests whether the graph instance *self* is a permutation graph
and renders, in case the test is positive,
the corresponding permutation.
computeSize(self)
Renders the number of positively characterised edges of this graph instance
(result is stored in self.size).
computeTransitivelyOrientedDigraph(self, PartiallyDetermined=False, Debug=False)
Renders a digraph where each edge of the permutation graph *self*
is converted into an arc oriented in increasing order of the ranks of implication classes
detected with the :py:func:`digraphs.Digraph.isComparabilityGraph` test and stored in self.edgeOrientations.
 
The parameter *PartiallyDetermined*: {True|False (by default), converts if *True* all absent
edges of the graph into indeterminate symmetric relations in the resulting digraph.
Verifies if the graph instance is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
 
>>> from graphs import RandomGraph
>>> g = RandomGraph(order=6,edgeProbability=0.5,seed=100)
>>> og = g.computeTransitivelyOrientedDigraph()
>>> if og is not None:
...     print(og)
...     print('Transitivity degree: %.3f' % og.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveDigraph
  Instance name    : trans_oriented_randomGraph
  Digraph Order      : 6
  Digraph Size       : 7
  Valuation domain : [-1.00 - 1.00]
  Determinateness  : 46.667
  Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                     'gamma', 'notGamma', 'size', 
                     'transitivityDegree']
 Transitivity degree: 1.000
 
>>> gd = -g
>>> ogd = gd.computeTransitivelyOrientedDigraph()
>>> if ogd is not None:
...     print(ogd)
...     print('Dual transitivity degree: %.3f' % ogd.transitivityDegree)
 *------- Digraph instance description ------*
  Instance class   : TransitiveOrder
  Instance name    : trans_oriented_dual_randomGraph
  Digraph Order      : 6
 Digraph Size       : 8
 Valuation domain : [-1.00 - 1.00]
 Determinateness  : 53.333
 Attributes       : ['name', 'order', 'actions', 
                     'valuationdomain', 'relation',
                    'gamma', 'notGamma', 'size', 
                    'transitivityDegree']
Dual transitivity degree: 1.000
depthFirstSearch(self, Debug=False)
Depth first search through a graph in lexicographical order
of the vertex keys.
exportEdgeOrientationsGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', layout=None, arcColor='black', lineWidth=1, palette=1, bgcolor='cornsilk', Debug=False)
Exports GraphViz dot file for oriented graph drawing filtering.
 
Example:
   >>> from graphs import *
   >>> g = RandomGraph(order=6,seed=100)
   >>> if g.isComparabilityGraph():
   ...     g.exportEdgeOrientationsGraphViz('orientedGraph')
 
.. image:: orientedGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportGraphViz(self, fileName=None, verticesSubset=None, Comments=True, graphType='png', graphSize='7,7', WithSpanningTree=False, WithVertexColoring=False, matching=None, layout=None, arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file  for graph drawing filtering.
 
Example:
   >>> g = Graph(numberOfVertices=5,edgeProbability=0.3)
   >>> g.exportGraphViz('randomGraph')
 
.. image:: randomGraph.png
   :alt: Random graph
   :width: 300 px
   :align: center
exportPermutationGraphViz(self, fileName=None, permutation=None, Comments=True, WithEdgeColoring=True, hspace=100, vspace=70, graphType='png', graphSize='7,7', arcColor='black', bgcolor='cornsilk', lineWidth=1)
Exports GraphViz dot file for permutation drawing filtering.
 
Horizontal (default=100) and vertical (default=75) spaces betwen the vertices'
positions may be explicitely given in *hspace* and *vspace* parameters.
 
.. note::
    If no *permutation* is provided, it is supposed to exist a self.permutation attribute.
gammaSets(self, Debug=False)
renders the gamma function as dictionary
generateIndependent(self, U)
Generator for all independent vertices sets
with neighborhoods of a graph instance:
 
.. note::
 
       * Initiate with U = self._singletons().
       * Yields [independent set, covered set, all vertices - covered set)].
       * If independent set == (all vertices - covered set), the given independent set is maximal !
graph2Digraph(self)
Converts a Graph object into a symmetric Digraph object.
isComparabilityGraph(self, Debug=False)
Verifies if the graph instance is a comparability graph.
If yes, a tranditive orientation of the edges is stored 
in self.edgeOrientations
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 129-132.
isConnected(self)
Cheks if self is a connected graph instance.
isIntervalGraph(self, Comments=False)
Checks whether the graph self is triangulated and
its dual is a comparability graph.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isPerfectGraph(self, Comments=False, Debug=False)
A graph *g* is perfect when neither *g*, nor *-g*, contain any chordless
cycle of odd length.
isPermutationGraph(self, Comments=False)
Checks whether the graph self and
its dual are comparability graphs.
 
*Source*: M. Ch. Golumbic (2004) Algorithmic Graph Thery and Perfect Graphs,
Annals of Discrete Mathematics 57, Elsevier, p. 16.
isSplitGraph(self, Comments=False)
Checks whether the graph ' *self* ' and its dual ' *-self* ' are
triangulated graphs
isTree(self)
Checks if self is a tree by verifing the required number of
edges: order-1; and the existence of leaves.
isTriangulated(self)
Checks if a graph contains no chordless cycle of
length greater or equal to 4.
randomDepthFirstSearch(self, seed=None, Debug=False)
Depth first search through a graph in random order of the vertex keys.
 
.. Note::
 
    The resulting spanning tree (or forest) is by far not uniformly selected
    among all possible trees. Spanning stars will indeed be much less
    probably selected then streight walks !
recodeValuation(self, newMin=-1, newMax=1, ndigits=2, Debug=False)
Recodes the characteristic valuation domain according
to the parameters given.
 
.. note::
 
    Default values gives a normalized valuation domain
save(self, fileName='tempGraph', Debug=False)
Persistent storage of a Graph class instance in the form of a python source code file.
setEdgeValue(self, edge, value, Comments=False)
Wrapper for updating the characteristic valuation of a Graph instance.
The egde parameter consists in a pair of vertices;
edge = ('v1','v2') for instance.
The new value must be in the limits of the valuation domain.
showCliques(self)
showEdgesCharacteristicValues(self, ndigits=2)
Prints the edge links of the bipartite graph instance
showMIS(self)
showMore(self)
Generic show method for Graph instances.
showShort(self)
Generic show method for Graph instances.

Data descriptors inherited from graphs.Graph:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)