Source code for pacman.model.graphs.abstract_vertex

# 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
# 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 <>.

from pacman.exceptions import PacmanConfigurationException
from pacman.model.graphs.common import ChipAndCore

class AbstractVertex(object):
    """ A vertex in a graph.

    __slots__ = [
        # Indicates if the Vertex has been added to a graph
        # Label for the vertex. Changable until added to graph
        # the x, y (and p) this vertex MUST be placed on

    def __init__(self, label=None):
        :param str label: The optional name of the vertex
        :param fixed_location:
            The optional fixed location of the vertex.
            Only if the Vertex is fixed before placement.
        self._label = label
        self._added_to_graph = False
        self._fixed_location = None

    def label(self):
        """ The current label to the vertex.

        This label could change when the vertex is added to the graph.

        :rtype: str
        return self._label

[docs] def set_label(self, label): """ Changes the label for a vertex *not yet added* to a graph. :param str label: new value for the label :raises PacmanConfigurationException: If there is an attempt to change the label once the vertex has been added to a graph """ if self._added_to_graph: raise PacmanConfigurationException( "As Labels are also IDs they can not be changed.") self._label = label
[docs] def addedToGraph(self): """ Records that the vertex has been added to a graph :raises PacmanConfigurationException: If there is an attempt to add the same vertex more than once """ self._added_to_graph = True
[docs] def get_fixed_location(self): """ The x, y and possibly p the vertex MUST be placed on. Typically NONE! Does not have the value of a normal placememts. Used instead of ChipAndCoreConstraint :rtype: None or ChipAndCore """ return self._fixed_location
[docs] def set_fixed_location(self, x, y, p=None): """ :param ChipAndCore fixed_location: """ fixed_location = ChipAndCore(x, y, p) if self._fixed_location is not None: if fixed_location == self._fixed_location: return raise PacmanConfigurationException( "Once set to a value fixed_location can not be changed") self._fixed_location = fixed_location