Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac #34075: fix merge conflict with 9.7.beta8
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoudert committed Aug 9, 2022
2 parents 12be2d9 + 65aa3cd commit 7c4d823
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 55 deletions.
29 changes: 15 additions & 14 deletions src/sage/graphs/bipartite_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def __init__(self, data=None, partition=None, check=True, *args, **kwds):

if check:
if (any(left.intersection(self.neighbor_iterator(a)) for a in left) or
any(right.intersection(self.neighbor_iterator(a)) for a in right)):
any(right.intersection(self.neighbor_iterator(a)) for a in right)):
raise TypeError("input graph is not bipartite with "
"respect to the given partition")
else:
Expand All @@ -453,9 +453,8 @@ def __init__(self, data=None, partition=None, check=True, *args, **kwds):
elif is_Matrix(data):
# sanity check for mutually exclusive keywords
if kwds.get("multiedges", False) and kwds.get("weighted", False):
raise TypeError(
"weighted multi-edge bipartite graphs from reduced "
"adjacency matrix not supported")
raise TypeError("weighted multi-edge bipartite graphs from "
"reduced adjacency matrix not supported")
Graph.__init__(self, *args, **kwds)
ncols = data.ncols()
nrows = data.nrows()
Expand Down Expand Up @@ -509,13 +508,12 @@ def __init__(self, data=None, partition=None, check=True, *args, **kwds):
elif data.node_type[v] == "Top":
self.right.add(v)
else:
raise TypeError(
"NetworkX node_type defies bipartite "
"assumption (is not 'Top' or 'Bottom')")
raise TypeError("NetworkX node_type defies bipartite "
"assumption (is not 'Top' or 'Bottom')")
elif partition:
if check:
if (any(left.intersection(self.neighbor_iterator(a)) for a in left) or
any(right.intersection(self.neighbor_iterator(a)) for a in right)):
any(right.intersection(self.neighbor_iterator(a)) for a in right)):
raise TypeError("input graph is not bipartite with "
"respect to the given partition")
else:
Expand Down Expand Up @@ -672,7 +670,7 @@ def add_vertex(self, name=None, left=False, right=False):
# do nothing if we already have this vertex (idempotent)
if name is not None and name in self:
if ((left and name in self.left) or
(right and name in self.right)):
(right and name in self.right)):
return
else:
raise RuntimeError("cannot add duplicate vertex to other partition")
Expand Down Expand Up @@ -772,10 +770,9 @@ def add_vertices(self, vertices, left=False, right=False):
# check that we're not trying to add vertices to the wrong sets
# or that a vertex is to be placed in both
if ((new_left & self.right) or
(new_right & self.left) or
(new_right & new_left)):
raise RuntimeError(
"cannot add duplicate vertex to other partition")
(new_right & self.left) or
(new_right & new_left)):
raise RuntimeError("cannot add duplicate vertex to other partition")

# add vertices
Graph.add_vertices(self, vertices)
Expand Down Expand Up @@ -2400,7 +2397,11 @@ class by some canonization function `c`. If `G` and `H` are graphs,
"""

if certificate:
C, cert = GenericGraph.canonical_label(self, partition=partition, certificate=certificate, edge_labels=edge_labels, algorithm=algorithm, return_graph=return_graph)
C, cert = GenericGraph.canonical_label(self, partition=partition,
certificate=certificate,
edge_labels=edge_labels,
algorithm=algorithm,
return_graph=return_graph)

else:
from sage.groups.perm_gps.partn_ref.refinement_graphs import search_tree
Expand Down
19 changes: 13 additions & 6 deletions src/sage/graphs/digraph_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,14 @@ def nauty_directg(self, graphs, options="", debug=False):
if out:
print(out)

for l in out.split('\n'):
for line in out.split('\n'):
# directg return graphs in the digraph6 format.
# digraph6 is very similar with the dig6 format used in sage :
# digraph6_string = '&' + dig6_string
# digraph6 specifications:
# http://users.cecs.anu.edu.au/~bdm/data/formats.txt
if l and l[0] == '&':
yield DiGraph(l[1:], format='dig6')
if line and line[0] == '&':
yield DiGraph(line[1:], format='dig6')

def Complete(self, n, loops=False):
r"""
Expand Down Expand Up @@ -1095,12 +1095,19 @@ def Kautz(self, k, D, vertices='strings'):
sage: K = digraphs.Kautz([1,'a','B'], 2)
sage: K.edges(sort=True)
[('1B', 'B1', '1'), ('1B', 'Ba', 'a'), ('1a', 'a1', '1'), ('1a', 'aB', 'B'), ('B1', '1B', 'B'), ('B1', '1a', 'a'), ('Ba', 'a1', '1'), ('Ba', 'aB', 'B'), ('a1', '1B', 'B'), ('a1', '1a', 'a'), ('aB', 'B1', '1'), ('aB', 'Ba', 'a')]
[('1B', 'B1', '1'), ('1B', 'Ba', 'a'), ('1a', 'a1', '1'),
('1a', 'aB', 'B'), ('B1', '1B', 'B'), ('B1', '1a', 'a'),
('Ba', 'a1', '1'), ('Ba', 'aB', 'B'), ('a1', '1B', 'B'),
('a1', '1a', 'a'), ('aB', 'B1', '1'), ('aB', 'Ba', 'a')]
sage: K = digraphs.Kautz([1,'aA','BB'], 2)
sage: K.edges(sort=True)
[('1,BB', 'BB,1', '1'), ('1,BB', 'BB,aA', 'aA'), ('1,aA', 'aA,1', '1'), ('1,aA', 'aA,BB', 'BB'), ('BB,1', '1,BB', 'BB'), ('BB,1', '1,aA', 'aA'), ('BB,aA', 'aA,1', '1'), ('BB,aA', 'aA,BB', 'BB'), ('aA,1', '1,BB', 'BB'), ('aA,1', '1,aA', 'aA'), ('aA,BB', 'BB,1', '1'), ('aA,BB', 'BB,aA', 'aA')]
[('1,BB', 'BB,1', '1'), ('1,BB', 'BB,aA', 'aA'),
('1,aA', 'aA,1', '1'), ('1,aA', 'aA,BB', 'BB'),
('BB,1', '1,BB', 'BB'), ('BB,1', '1,aA', 'aA'),
('BB,aA', 'aA,1', '1'), ('BB,aA', 'aA,BB', 'BB'),
('aA,1', '1,BB', 'BB'), ('aA,1', '1,aA', 'aA'),
('aA,BB', 'BB,1', '1'), ('aA,BB', 'BB,aA', 'aA')]
TESTS:
Expand Down
5 changes: 5 additions & 0 deletions src/sage/graphs/domination.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from copy import copy
from sage.rings.integer import Integer


def is_dominating(G, dom, focus=None):
r"""
Check whether ``dom`` is a dominating set of ``G``.
Expand Down Expand Up @@ -101,6 +102,7 @@ def is_dominating(G, dom, focus=None):

return not to_dom


def is_redundant(G, dom, focus=None):
r"""
Check whether ``dom`` has redundant vertices.
Expand Down Expand Up @@ -166,6 +168,7 @@ def is_redundant(G, dom, focus=None):
# with_private != set(dom)
return len(with_private) != len(dom)


def private_neighbors(G, vertex, dom):
r"""
Return the private neighbors of a vertex with respect to other vertices.
Expand Down Expand Up @@ -361,6 +364,7 @@ def neighbors_iter(x):
dom = [v for v in g if b[v]]
return Integer(len(dom)) if value_only else dom


# ==============================================================================
# Enumeration of minimal dominating set as described in [BDHPR2019]_
# ==============================================================================
Expand Down Expand Up @@ -785,6 +789,7 @@ def tree_search(H, plng, dom, i):
for dom in tree_search(G, peeling, set(), 0):
yield {int_to_vertex[v] for v in dom}


# ==============================================================================
# Greedy heuristic for dominating set
# ==============================================================================
Expand Down
19 changes: 11 additions & 8 deletions src/sage/graphs/dot2tex_utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
r"""
This file contains some utility functions for the interface with dot2tex
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2010 Nicolas M. Thiery <nicolas.thiery at u-psud.fr>
#
# Distributed under the terms of the GNU General Public License (GPL)
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

import re
from sage.misc.latex import latex
from sage.misc.cachefunc import cached_function


@cached_function
def have_dot2tex():
"""
Expand All @@ -28,7 +29,7 @@ def have_dot2tex():
try:
import dot2tex
# Test for this required feature from dot2tex 2.8.7
return dot2tex.dot2tex("graph {}", format = "positions") == {}
return dot2tex.dot2tex("graph {}", format="positions") == {}
except (Exception, SystemExit):
return False

Expand Down Expand Up @@ -60,11 +61,12 @@ def assert_have_dot2tex():
import dot2tex
except ImportError:
print(import_error_string)
raise # re-raise current exception
raise # re-raise current exception
else:
if dot2tex.dot2tex("graph {}", format = "positions") != {}:
if dot2tex.dot2tex("graph {}", format="positions") != {}:
raise RuntimeError(check_error_string)


def quoted_latex(x):
"""
Strips the latex representation of ``x`` to make it suitable for a
Expand All @@ -75,7 +77,8 @@ def quoted_latex(x):
sage: sage.graphs.dot2tex_utils.quoted_latex(matrix([[1,1],[0,1],[0,0]]))
'\\left(\\begin{array}{rr}1 & 1 \\\\0 & 1 \\\\0 & 0\\end{array}\\right)'
"""
return re.sub("\"|\r|(%[^\n]*)?\n","", latex(x))
return re.sub("\"|\r|(%[^\n]*)?\n", "", latex(x))



def quoted_str(x):
Expand All @@ -94,4 +97,4 @@ def quoted_str(x):
[0 1]\n\
[0 0]
"""
return re.sub("\n",r"\\n\\"+"\n", re.sub("\"|\r|}|{","", str(x)))
return re.sub("\n", r"\\n\\"+"\n", re.sub("\"|\r|}|{", "", str(x)))
Loading

0 comments on commit 7c4d823

Please sign in to comment.