Source code for pacman.model.graphs.abstract_graph

# Copyright (c) 2017-2019 The University of Manchester
#
# 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, see <http://www.gnu.org/licenses/>.

from six import add_metaclass
from spinn_utilities.abstract_base import (
    AbstractBase, abstractmethod, abstractproperty)


[docs]@add_metaclass(AbstractBase) class AbstractGraph(object): """ A graph. """ __slots__ = () @abstractproperty def label(self): """ The label of the graph. :return: The label :rtype: str :raise None: Raises no known exceptions """ @abstractproperty def constraints(self): """ The constraints of the graph. :rtype: iterable(:py:class:`AbstractConstraint`) """
[docs] @abstractmethod def add_constraint(self, constraint): """ Add a constraint to the graph. :param constraint: The constraint to add :type constraint: :py:class:`AbstractConstraint` """
[docs] def add_constraints(self, constraints): """ Add a list of constraints to the graph. :param constraints: The list of constraints to add :type constraints: list(:py:class:`AbstractConstraint`) """ for constraint in constraints: self.add_constraint(constraint)
[docs] @abstractmethod def add_vertex(self, vertex): """ Add a vertex to the graph. :param vertex: The vertex to add :type vertex: :py:class:`pacman.model.graphs.AbstractVertex` :raises PacmanInvalidParameterException:\ If the vertex is not of a valid type :raises PacmanConfigurationException: If there is an attempt to add the same vertex more than once """
[docs] def add_vertices(self, vertices): """ Add a collection of vertices to the graph. :param vertices: The vertices to add :type vertices: \ iterable(:py:class:`pacman.model.graphs.AbstractVertex`) :raises PacmanInvalidParameterException:\ If any vertex is not of a valid type :raises PacmanConfigurationException: If there is an attempt to add the same vertex more than once """ for v in vertices: self.add_vertex(v)
[docs] @abstractmethod def add_edge(self, edge, outgoing_edge_partition_name): """ Add an edge to the graph. :param edge: The edge to add :type edge: :py:class:`pacman.model.graphs.AbstractEdge` :param outgoing_edge_partition_name: \ The name of the edge partition to add the edge to; each edge\ partition is the partition of edges that start at the same vertex :type outgoing_edge_partition_name: str :raises PacmanInvalidParameterException:\ If the edge is not of a valid type or if edges have already been\ added to this partition that start at a different vertex to this\ one """
[docs] def add_edges(self, edges, outgoing_edge_partition_name): """ Add a collection of edges to the graph. :param edges: The edges to add :type edges: iterable(:py:class:`pacman.model.graphs.AbstractEdge`) :param outgoing_edge_partition_name: \ The name of the edge partition to add the edges to; each edge\ partition is the partition of edges that start at the same vertex :type outgoing_edge_partition_name: str :raises PacmanInvalidParameterException:\ If any edge is not of a valid type or if edges have already been\ added to this partition that start at a different vertex to this\ one """ for e in edges: self.add_edge(e, outgoing_edge_partition_name)
[docs] @abstractmethod def add_outgoing_edge_partition(self, outgoing_edge_partition): """ Add an outgoing edge partition to the graph. :param outgoing_edge_partition: The outgoing edge partition to add :type outgoing_edge_partition:\ :py:class:`pacman.model.graphs.AbstractOutgoingEdgePartition` :raises PacmanAlreadyExistsException:\ If a partition already exists with the same pre_vertex and\ identifier """
@abstractproperty def vertices(self): """ The vertices in the graph. :rtype: iterable(:py:class:`pacman.model.graphs.AbstractVertex`) """ @abstractproperty def n_vertices(self): """ The number of vertices in the graph. :rtype: int """ @abstractproperty def edges(self): """ The edges in the graph :rtype: iterable(:py:class:`pacman.model.graphs.AbstractEdge`) """ @abstractproperty def outgoing_edge_partitions(self): """ The outgoing edge partitions in the graph. :rtype: \ iterable(:py:class:`pacman.model.graphs.AbstractOutgoingEdgePartition`) """ @abstractproperty def n_outgoing_edge_partitions(self): """ The number of outgoing edge partitions in the graph. :rtype: int """
[docs] @abstractmethod def get_edges_starting_at_vertex(self, vertex): """ Get all the edges that start at the given vertex. :param vertex: The vertex at which the edges to get start :type vertex: :py:class:`pacman.model.graphs.AbstractVertex` :rtype: iterable(:py:class:`pacman.model.graphs.AbstractEdge`) """
[docs] @abstractmethod def get_outgoing_partition_for_edge(self, edge): """ gets the outgoing partition this edge is associated with. :param edge: the edge to find associated partition :type edge: :py:class:`pacman.model.graphs.AbstractEdge` :return: the outgoing partition :rtype: :py:class:`pacman.model.graphs.AbstractOutgoingEdgePartition` """
[docs] @abstractmethod def get_edges_ending_at_vertex(self, vertex): """ Get all the edges that end at the given vertex. :param vertex: The vertex at which the edges to get end :type vertex: :py:class:`pacman.model.graphs.AbstractVertex` :rtype: iterable(:py:class:`pacman.model.graphs.AbstractEdge`) """
[docs] @abstractmethod def get_edges_ending_at_vertex_with_partition_name( self, vertex, partition_name): """ Get all the edges that end at the given vertex, and reside in the\ correct partition ID. :param vertex: The vertex at which the edges to get end :type vertex: :py:class:`pacman.model.graphs.AbstractVertex` :param partition_name: the label for the partition :type partition_name: str :return: iterable(:py:class:`pacman.model.graphs.AbstractEdge`) """
[docs] @abstractmethod def get_outgoing_edge_partitions_starting_at_vertex(self, vertex): """ Get all the edge partitions that start at the given vertex. :param vertex: The vertex at which the edge partitions to find starts :type vertex: :py:class:`pacman.model.graphs.AbstractVertex` :rtype: \ iterable(:py:class:`pacman.model.graphs.AbstractOutgoingEdgePartition`) """
[docs] @abstractmethod def get_outgoing_edge_partition_starting_at_vertex( self, vertex, outgoing_edge_partition_name): """ Get the given outgoing edge partition that starts at the\ given vertex, or None if no such edge partition exists. :param vertex: The vertex at the start of the edges in the partition :type vertex: :py:class:`pacman.model.graphs.AbstractVertex` :param outgoing_edge_partition_name: The name of the edge partition :type outgoing_edge_partition_name: str :rtype:\ :py:class:`pacman.model.graphs.AbstractOutgoingEdgePartition` """