comparison env/lib/python3.9/site-packages/networkx/exception.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """
2 **********
3 Exceptions
4 **********
5
6 Base exceptions and errors for NetworkX.
7 """
8
9 __all__ = [
10 "HasACycle",
11 "NodeNotFound",
12 "PowerIterationFailedConvergence",
13 "ExceededMaxIterations",
14 "AmbiguousSolution",
15 "NetworkXAlgorithmError",
16 "NetworkXException",
17 "NetworkXError",
18 "NetworkXNoCycle",
19 "NetworkXNoPath",
20 "NetworkXNotImplemented",
21 "NetworkXPointlessConcept",
22 "NetworkXUnbounded",
23 "NetworkXUnfeasible",
24 ]
25
26
27 class NetworkXException(Exception):
28 """Base class for exceptions in NetworkX."""
29
30
31 class NetworkXError(NetworkXException):
32 """Exception for a serious error in NetworkX"""
33
34
35 class NetworkXPointlessConcept(NetworkXException):
36 """Raised when a null graph is provided as input to an algorithm
37 that cannot use it.
38
39 The null graph is sometimes considered a pointless concept [1]_,
40 thus the name of the exception.
41
42 References
43 ----------
44 .. [1] Harary, F. and Read, R. "Is the Null Graph a Pointless
45 Concept?" In Graphs and Combinatorics Conference, George
46 Washington University. New York: Springer-Verlag, 1973.
47
48 """
49
50
51 class NetworkXAlgorithmError(NetworkXException):
52 """Exception for unexpected termination of algorithms."""
53
54
55 class NetworkXUnfeasible(NetworkXAlgorithmError):
56 """Exception raised by algorithms trying to solve a problem
57 instance that has no feasible solution."""
58
59
60 class NetworkXNoPath(NetworkXUnfeasible):
61 """Exception for algorithms that should return a path when running
62 on graphs where such a path does not exist."""
63
64
65 class NetworkXNoCycle(NetworkXUnfeasible):
66 """Exception for algorithms that should return a cycle when running
67 on graphs where such a cycle does not exist."""
68
69
70 class HasACycle(NetworkXException):
71 """Raised if a graph has a cycle when an algorithm expects that it
72 will have no cycles.
73
74 """
75
76
77 class NetworkXUnbounded(NetworkXAlgorithmError):
78 """Exception raised by algorithms trying to solve a maximization
79 or a minimization problem instance that is unbounded."""
80
81
82 class NetworkXNotImplemented(NetworkXException):
83 """Exception raised by algorithms not implemented for a type of graph."""
84
85
86 class NodeNotFound(NetworkXException):
87 """Exception raised if requested node is not present in the graph"""
88
89
90 class AmbiguousSolution(NetworkXException):
91 """Raised if more than one valid solution exists for an intermediary step
92 of an algorithm.
93
94 In the face of ambiguity, refuse the temptation to guess.
95 This may occur, for example, when trying to determine the
96 bipartite node sets in a disconnected bipartite graph when
97 computing bipartite matchings.
98
99 """
100
101
102 class ExceededMaxIterations(NetworkXException):
103 """Raised if a loop iterates too many times without breaking.
104
105 This may occur, for example, in an algorithm that computes
106 progressively better approximations to a value but exceeds an
107 iteration bound specified by the user.
108
109 """
110
111
112 class PowerIterationFailedConvergence(ExceededMaxIterations):
113 """Raised when the power iteration method fails to converge within a
114 specified iteration limit.
115
116 `num_iterations` is the number of iterations that have been
117 completed when this exception was raised.
118
119 """
120
121 def __init__(self, num_iterations, *args, **kw):
122 msg = f"power iteration failed to converge within {num_iterations} iterations"
123 exception_message = msg
124 superinit = super().__init__
125 superinit(self, exception_message, *args, **kw)