Package elections :: Module node :: Class Node
[frames] | no frames]

Class Node

source code

object --+
         |
        Node

A basic tree node with a value and children and IRV-specific methods.

Instance Methods
 
__init__(self, value=0, children=None)
Create a new node with an optional value and children nodes.
source code
string
__repr__(self)
Return a representation of self.
source code
boolean
has_child(self, c)
Return True if the node has a child with name c.
source code
Node
get_child(self, c)
Return the child node, creating it first, if necessary.
source code
 
delete_child(self, c)
Delete the child.
source code
 
eliminate(self, c)
Remove the child c and merge c's children with self's children.
source code
 
reduce(self, elim_order)
Reduce the ballot tree modulo an elimination order.
source code
set
children(self)
Return a set of children names.
source code
number
num_children(self)
Return the number of children.
source code
iterator
__iter__(self)
Iterate over the set of children.
source code
iterator
iterchildren(self)
Iterate over the dictionary of children.
source code
 
__copy__(self)
This always raises an exception.
source code
Node
__deepcopy__(self, memo)
Return a deep copy of the node.
source code
Node
deepcopy(self)
Return a deep copy of the node.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables
number value
The value of the node, including the sum of the values of its children.
Properties

Inherited from object: __class__

Method Details

__init__(self, value=0, children=None)
(Constructor)

source code 

Create a new node with an optional value and children nodes.

Parameters:
  • value (number) - The initial value of the node.
  • children (dict) - The initial children.
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

Return a representation of self.

Returns: string
Returns a string representation of the node.
Overrides: object.__repr__

has_child(self, c)

source code 

Return True if the node has a child with name c.

Parameters:
  • c (number) - The child.
Returns: boolean
Returns True if the node has a child with name c.

get_child(self, c)

source code 

Return the child node, creating it first, if necessary.

Parameters:
  • c (number) - The child.
Returns: Node
Returns the child node.

delete_child(self, c)

source code 

Delete the child.

Parameters:
  • c (number) - The child.

eliminate(self, c)

source code 

Remove the child c and merge c's children with self's children.

Parameters:
  • c (number) - The child.

reduce(self, elim_order)

source code 

Reduce the ballot tree modulo an elimination order.

Assuming that the elimination order of the election is elim_order, reduce the number and type of ballots represented in the tree by weeding out ballots that do not contribute. For example, if i preceeds j in elim_order and there is a ballot in which j preceeds i, then i can be removed from the ballot completely.

Parameters:
  • elim_order (list) - The elimination order.

children(self)

source code 

Return a set of children names.

Returns: set
Returns the set of children.

num_children(self)

source code 

Return the number of children.

Returns: number
Returns the number of children.

__iter__(self)

source code 

Iterate over the set of children.

Returns: iterator
Returns an iterator which can be used to iterate over the children.

iterchildren(self)

source code 

Iterate over the dictionary of children.

Returns: iterator
Returns an iterator that can be used to iterate over the children and the corresponding nodes at the same time.

__copy__(self)

source code 

This always raises an exception. Shallow copies are not permitted.

Raises:
  • Exception - Always raises an exception.

__deepcopy__(self, memo)

source code 

Return a deep copy of the node.

Returns: Node
Returns a deep copy.

deepcopy(self)

source code 

Return a deep copy of the node.

Returns: Node
Returns a deep copy.