openalea.core.graph.interface package#

Submodules#

openalea.core.graph.interface.graph module#

This module provide a set of graph concepts to form a graph interface

exception openalea.core.graph.interface.graph.GraphError[source]#

Bases: Exception

base class of all graph exceptions

class openalea.core.graph.interface.graph.ICopyGraph[source]#

Bases: object

allow the graph to be copied

copy()[source]#

make a shallow copy of the graph, for a deep copy use the constructor __init__

class openalea.core.graph.interface.graph.IEdgeListGraph[source]#

Bases: object

Definition of a graph seen as a list of edges

edges(vid=None)[source]#

retrieve the edges linked to a specified vertex, all if vid is None

Parameters:

vid (vid) – id of the reference vertex, default=None

Return type:

iter of eid

in_edges(vid)[source]#

retrieve the edges linked to a specified vertex, oriented inside the vertex

Parameters:

vid (vid) – id of the reference vertex, default=None

Return type:

iter of eid

nb_edges(vid=None)[source]#

number of edges linked to a specified vertex, total number if vid is None

Parameters:

vid (vid) – id of the reference vertex, default=None

Return type:

iter of eid

nb_in_edges(vid)[source]#

number of edges linked to a specified vertex, oriented inside vertex

Parameters:

vid (vid) – id of the reference vertex, default=None

Return type:

iter of eid

nb_out_edges(vid)[source]#

number of edges linked to a specified vertex, oriented outside vertex

Parameters:

vid (vid) – id of the reference vertex, default=None

Return type:

iter of eid

out_edges(vid)[source]#

retrieve the edges linked to a specified vertex, oriented outside the vertex

Parameters:

vid (vid) – id of the reference vertex, default=None

Return type:

iter of eid

class openalea.core.graph.interface.graph.IExtendGraph[source]#

Bases: object

allow the graph to be extended by another graph

extend(graph)[source]#

add the specified graph to self, create new vid and eid

Parameters:

graph (Graph) – the graph to add

Returns:

two dictionnary specifying correspondence between graph id and self id

Return type:

({vid:vid},{eid:eid})

class openalea.core.graph.interface.graph.IGraph[source]#

Bases: object

Directed graph definition

edge(source, target)[source]#

find the matching edges with same source and same target return None if it don’t succeed

Parameters:
  • source : id of the source vertex

  • target : id of the target vertex

Types:
  • source : vid

  • target : vid

Return type:

eid|iter of eid|None

has_edge(eid)[source]#

test wether an edge belong to the graph

Parameters:

eid (eid) – edge id to test

Return type:

bool

has_vertex(vid)[source]#

test wether a vertex belong to the graph

Parameters:

vid (vid) – vertex id to test

Return type:

bool

is_valid()[source]#

test the validity of the graph

Return type:

bool

source(eid)[source]#

retrieve the source of an edge

Parameters:

eid (eid) – id of the edge

Return type:

vid

target(eid)[source]#

retrieve the target of an edge

Parameters:

eid (eid) – id of the edge

Return type:

vid

class openalea.core.graph.interface.graph.IMutableEdgeGraph[source]#

Bases: object

definition of graph edition methods for edges

add_edge(edge=(None, None), eid=None)[source]#

add an edge to the graph, if eid is not provided create a new eid

Parameters:
  • edge : a tuple (vertex source,vertex target)

  • eid : the id of the created edge

Types:
  • edge : (vid,vid)

  • eid : eid

Returns:

the id of the newly created edge

Return type:

eid

clear_edges()[source]#

remove all the edges of the graph don’t change references to objects

remove_edge(eid)[source]#

remove a specified edge from the graph

Parameters:

eid (eid) – id of the edge to remove

class openalea.core.graph.interface.graph.IMutableVertexGraph[source]#

Bases: object

definition of graph edition methods for vertices

add_vertex(vid=None)[source]#

add a vertex to the graph, if vid is not provided create a new vid

Parameters:

vid (vid) – the id of the vertex to add, default=None

Returns:

the id of the created vertex

Return type:

vid

clear()[source]#

remove all vertices and edges don’t change references to objects

remove_vertex(vid)[source]#

remove a specified vertex of the graph remove all the edges attached to it

Parameters:

vid (vid) – the id of the vertex to remove

class openalea.core.graph.interface.graph.IVertexListGraph[source]#

Bases: object

interface of a graph seen as a vertex list

in_neighbors(vid)[source]#

iterator on the neighbors of vid where edges are directed from neighbor to vid

Parameters:

vid (vid) – id of the reference vertex

Return type:

iter of vid

nb_in_neighbors(vid)[source]#

number of neighbors such as edges are directed from neighbor to vid

Parameters:

vid (vid) – id of the reference vertex

Return type:

int

nb_neighbors(vid)[source]#

number of neighbors regardless of the orientation of the edge

Parameters:

vid (vid) – id of the reference vertex

Return type:

int

nb_out_neighbors(vid)[source]#

number of neighbors such as edges are directed from vid to neighbor

Parameters:

vid (vid) – id of the reference vertex

Return type:

int

nb_vertices()[source]#

return the total number of vertices

Return type:

int

neighbors(vid)[source]#

iterator on the neighbors of vid regardless of the orientation of the edge

Parameters:

vid (vid) – id of the reference vertex

Return type:

iter of vid

out_neighbors(vid)[source]#

iterator on the neighbors of vid where edges are directed from vid to neighbor

Parameters:

vid (vid) – id of the reference vertex

Return type:

iter of vid

vertices()[source]#

iterator on vertices

Return type:

iter of vid

exception openalea.core.graph.interface.graph.InvalidEdge[source]#

Bases: GraphError, KeyError

exception raised when a wrong edge id is provided

exception openalea.core.graph.interface.graph.InvalidVertex[source]#

Bases: GraphError, KeyError

exception raised when a wrong vertex id is provided

openalea.core.graph.interface.graphconcept module#

A graph Interface.

class openalea.core.graph.interface.graphconcept.CopyConcept[source]#

Bases: object

Copy Concept.

copy()[source]#

Make a shallow copy

class openalea.core.graph.interface.graphconcept.EdgeListGraphConcept[source]#

Bases: GraphConcept

Edge List Graph Concept

edges(vtx_id=None)[source]#

Return an iterator of edge identifier. If vtx_id is specified, return input and output edges of vtx_id

Parameters:
  • vtx_id

Return:

iter of edge id

in_edges(vtx_id)[source]#

Return input edges of vtx_id

Parameters:
  • vtx_id

Return:

iter of edges

nb_edges(vid=None)[source]#
Return:

int

nb_in_edges(vtx_id)[source]#
Return:

int

nb_out_edges(vtx_id)[source]#
Return:

int

out_edges(vtx_id)[source]#

Return output edges of vtx_id

Parameters:
  • vtx_id

Return:

iter of edges

class openalea.core.graph.interface.graphconcept.ExtendConcept[source]#

Bases: object

Extend the actul data structure with an other.

extend(graph)[source]#

Extend the actual graph with graph PB: shift vertex id & edge id?

Parameters:
  • graph : a valid graph

class openalea.core.graph.interface.graphconcept.GraphConcept[source]#

Bases: object

Graph concept or graph interface. To separate algo and data structures.

edge(source, target)[source]#

Return the edge identifier or an iterator if the graph is a multiplegraph.

Parameters:
  • source: vtx_id

  • target: vtx_id

Return:

iter of edge_id

has_edge(edge_id)[source]#

Test the existence of an edge in the graph.

Parameters:
  • edge_id: The edge identifier.

Return:

bool

has_vertex(vtx_id)[source]#

Test the existence of a vertex in the graph.

Parameters:
  • vtx_id: The vertex identifier.

Return:

bool

is_valid()[source]#

Is the graph valid?

Return:

bool

source(edge_id)[source]#

Return the source vertex of the edge.

Parameters:
  • edge_id: The edge identifier.

Types:
  • edge_id: id

Return:

vertex identifier

target(edge_id)[source]#

Return the target vertex of the edge.

Parameters:
  • edge_id: The edge identifier.

Return:

vertex identifier

exception openalea.core.graph.interface.graphconcept.GraphError[source]#

Bases: Exception

todo

exception openalea.core.graph.interface.graphconcept.InexistingVertex[source]#

Bases: GraphError

todo

exception openalea.core.graph.interface.graphconcept.InvalidEdge[source]#

Bases: GraphError, KeyError

todo

exception openalea.core.graph.interface.graphconcept.InvalidGraph[source]#

Bases: GraphError

todo

exception openalea.core.graph.interface.graphconcept.InvalidVertex[source]#

Bases: GraphError, KeyError

todo

class openalea.core.graph.interface.graphconcept.MutableEdgeGraphConcept[source]#

Bases: EdgeListGraphConcept

Mutable Edge Graph Concept.

add_edge(edge, edge_id=None, create_vertex=False)[source]#

Add an edge to the graph.

Parameters:
  • edge: (vertex id, vertex id)

  • edge_id: optional edge identifier

  • create_vertex: optional flag for automatic vertices creation

clear_edges()[source]#

Remove all edges.

edge_id()[source]#

Return a free edge identifier

Return:

edge_id

remove_edge(edge_id)[source]#

Remove edge_id from the graph

Parameters:
  • edge_id : edge identifier

class openalea.core.graph.interface.graphconcept.MutableVertexGraphConcept[source]#

Bases: VertexListGraphConcept

Mutable Vertex Graph Concept

add_vertex(vtx_id=None)[source]#

Add a vertex to the graph.

Parameters:

vtx_id – optional vertex identifier

clear()[source]#

Clear vertices and edges of the graph.

remove_vertex(vtx_id)[source]#

Remove vertex from the graph

Parameters:

vtx_id – todo

vertex_id()[source]#

Return a free vertex identifier

Returns:

vtx_id

class openalea.core.graph.interface.graphconcept.VertexListGraphConcept[source]#

Bases: GraphConcept

Vertex List Graph Concept.

in_neighbors(vtx_id)[source]#
Return:

iter of vertex_id

nb_in_neighbors(vtx_id)[source]#
Return:

int

nb_neighbors(vtx_id)[source]#
Return:

int

nb_out_neighbors(vtx_id)[source]#
Return:

int

nb_vertices()[source]#

Return the number of vertices.

Return:

int

neighbors(vtx_id)[source]#
Return:

iter of vertex_id

out_neighbors(vtx_id)[source]#
Return:

iter of vertex_id

vertices()[source]#
Return:

iter of vertex_id

openalea.core.graph.interface.latticeconcept module#

Lattice Interface

class openalea.core.graph.interface.latticeconcept.Container[source]#

Bases: object

Container Interface (tree, graph or other data structure)

elements()[source]#
Return:

iter of element id

has_element(eid)[source]#

Test if eid exist in self.

Parameters:
  • eid: element identifier

Return:

bool

nb_elements()[source]#

Return the number of elements

class openalea.core.graph.interface.latticeconcept.MultiscaleContainer[source]#

Bases: ScaleLattice, Container

A multiscale container interface. seid= (eid,sid) seid: scale and element identifier

complex(seid, sid)[source]#

Return the complex of the component seid at the scale sid

Parameters:
  • seid: the component scale and element identifier

  • sid: the complex scale identifier

Return:

seid

components(seid, sid)[source]#

Return the components of the complex seid at the scale sid

Parameters:
  • seid: the complex scale and element identifier

  • sid: the components scale identifier

Return:

iter of seid

container(sid)[source]#

Return a ref on the container associated to sid.

Parameters:
  • sid: scale identifier

Return:

container (a reference, not a copy)

element(seid)[source]#

Return the element identifier

Return:

elemet id

nb_components(seid, sid)[source]#

Return the number of components of the complex seid at the scale sid

Parameters:
  • seid: the complex scale and element identifier

  • sid: the components scale identifier

Return:

int

scale(seid)[source]#

Return the scale identifier :Return: scale id

class openalea.core.graph.interface.latticeconcept.MultiscaleTree[source]#

Bases: MultiscaleContainer

A MultiscaleTree interface.

class openalea.core.graph.interface.latticeconcept.MutableMultiscaleContainer[source]#

Bases: MutableScaleLattice, MultiscaleContainer

Interface of a mutable MultiscaleContainer

class openalea.core.graph.interface.latticeconcept.MutableMultiscaleTree[source]#

Bases: MutableMultiscaleContainer, MultiscaleTree

A mutable MultiscaleTree

class openalea.core.graph.interface.latticeconcept.MutableScaleLattice[source]#

Bases: ScaleLattice

A mutable scale lattice. (sic)

add_scale(sid, min_id, max_id)[source]#

Add a scale sid between min_id and max_id. If min_id is coarsest(), add sid after coarsest If max_id is finest() then add sid before finest Else add sid between min_id and max_id

Parameters:
  • sid: the scale identifier to add

  • min_id: finer scale identifier

  • max_id: coarser scale identifier

remove_scale(sid)[source]#

Remove a scale sid.

Parameters:
  • sid: the scale identifier to add

scale_id()[source]#

Return a free scale identifier

Return:

a scale identifier

class openalea.core.graph.interface.latticeconcept.ScaleLattice[source]#

Bases: object

todo

coarser(sid)[source]#

Return the coarser scales of sid

Parameters:
  • sid: scale identifier

Return:

iter of scale_id

coarsest()[source]#

Return the coarsest scale identifier

finer(sid)[source]#

Return the coarser scales of sid

Parameters:
  • sid: scale identifier

Return:

iter of scale_id

finest()[source]#

Return the finest scale identifier

max(sid1, sid2)[source]#

Return the finer scale of common coarser scales of sid1 and sid2

Parameters:
  • sid1: scale identifier

  • sid2: scale identifier

Return:

a scale identifier

min(sid1, sid2)[source]#

Return the coarser scale of common finer scales of sid1 and sid2

Parameters:
  • sid1: scale identifier

  • sid2: scale identifier

Return:

a scale identifier

nb_coarser(sid)[source]#

Return the number of coarser scale identifier

nb_finer(sid)[source]#

Return the number of finer scale identifier

nb_scales()[source]#

Return the number of scales

scales()[source]#

Return scale_id iterator

openalea.core.graph.interface.port_graph module#

This module provide a set of concepts to add properties to graph elements

class openalea.core.graph.interface.port_graph.IPortGraph[source]#

Bases: object

Directed graph with connections between in_ports of vertices and out_port of vertices

add_in_port(vid, local_pid, pid=None)[source]#

todo

add_out_port(vid, local_pid, pid=None)[source]#

todo

capacity(pid)[source]#

todo

connect(source_pid, target_pid, eid=None)[source]#

todo

disconnect(eid)[source]#

todo

in_port(vid, local_pid)[source]#

todo

in_ports(vid=None)[source]#

todo

is_in_port(pid)[source]#

todo

is_out_port(pid)[source]#

todo

out_port(vid, local_pid)[source]#

todo

out_ports(vid=None)[source]#

todo

port(pid)[source]#

todo

port_edges(pid)[source]#

todo

port_neighbors(pid)[source]#

todo

ports(vid=None)[source]#

todo

remove_port(pid)[source]#

todo

set_capacity(pid, capacity)[source]#

todo

source_port(eid)[source]#

todo

target_port(eid)[source]#

todo

vertex(pid)[source]#

todo

openalea.core.graph.interface.property_graph module#

This module provide a set of concepts to add properties to graph elements

class openalea.core.graph.interface.property_graph.IPropertyGraph[source]#

Bases: object

Directed graph with properties associated with edges and vertices Properties may not be defined on all elements Properties may be empty on some elements A property is a map between an element id (vid or eid) and a data

add_edge_property(property_name)[source]#

add a new map between eid and a data do not fill this property for any edge

add_vertex_property(property_name)[source]#

add a new map between vid and a data do not fill this property for any vertex

edge_property(property_name)[source]#

return a map between eid and data for all edges where property_name is defined

Return type:

dict of {eid:data}

edge_property_names()[source]#

iter on names of all property maps defined on edge return iter of keys

remove_edge_property(property_name)[source]#

remove the map called property_name from the graph

remove_vertex_property(property_name)[source]#

remove the map called property_name from the graph

vertex_property(property_name)[source]#

return a map between vid and data for all vertices where property_name is defined

Return type:

dict of {vid:data}

vertex_property_names()[source]#

iter on names of all property maps defined on vertices return iter of keys

exception openalea.core.graph.interface.property_graph.PropertyError[source]#

Bases: Exception

todo

openalea.core.graph.interface.treeconcept module#

Tree Concept.

class openalea.core.graph.interface.treeconcept.EditableTreeConcept[source]#

Bases: MutableTreeConcept

add_child_tree(parent, tree)[source]#

Add a tree after the children of the parent vertex. Complexity have to be O(1) if tree == sub_tree()

Parameters:
  • parent – vertex identifier

  • tree – a rooted tree

insert_sibling_tree(vid, tree)[source]#

Insert a tree before the vid. vid and the root of the tree are siblings. Complexity have to be O(1) if tree comes from the actual tree ( tree= sef.sub_tree() )

Parameters:
  • vid – vertex identifier

  • tree – a rooted tree

sub_tree(vtx_id)[source]#

Return a reference of the tree rooted on vtx_id in O(1).

Returns:

Editable Tree

class openalea.core.graph.interface.treeconcept.MutableTreeConcept[source]#

Bases: RootedTreeConcept, MutableVertexGraphConcept

A mutable rooted tree. The substitute method is defined outside the interface. substitute(self,vid,tree)

add_child(parent, child)[source]#

Add a child at the end of children

Parameters:
  • parent – The parent identifier.

  • child – The child identifier.

insert_parent(vtx_id, parent_id)[source]#

Insert parent_id between vtx_id and its actual parent.

Parameters:
  • vtx_id – a vertex identifier

  • parent_id – a vertex identifier

insert_sibling(vid1, vid2)[source]#

Insert vid2 before vid1.

Parameters:
  • vid1 – a vertex identifier

  • vid2 – the vertex to insert

class openalea.core.graph.interface.treeconcept.OrderedTreeConcept[source]#

Bases: RootedTreeConcept

An ordered tree is a rooted tree where an order relation is defined between chidren.

first_child(vid)[source]#

Return the first child of vid

Parameters:

vid – The vertex identifier.

Returns:

vid

last_child(vid)[source]#

Return the last child of vid

Parameters:

vid – The vertex identifier.

Returns:

vid

next_sibling(vid)[source]#

Return next sibling

Parameters:

vid – The vertex identifier.

Returns:

vid

previous_sibling(vid)[source]#

Return previous sibling

Parameters:

vid – The vertex identifier.

Returns:

vid

class openalea.core.graph.interface.treeconcept.RootedTreeConcept[source]#

Bases: VertexListGraphConcept

Rooted Tree interface.

depth(vid), depth() and sub_tree(vid) can be extenal algorithms.

children(vtx_id)[source]#

Return a vertex iterator

Parameters:

vtx_id – The vertex identifier.

Returns:

iter of vertex identifier

get_root()[source]#

Return the tree root.

Returns:

vertex identifier

is_leaf(vtx_id)[source]#

Test if vtx_id is a leaf.

Returns:

bool

nb_children(vtx_id)[source]#

Return the number of children

Parameters:

vtx_id – The vertex identifier.

Return type:

int

nb_siblings(vtx_id)[source]#

Return the number of siblings

Returns:

int

parent(vtx_id)[source]#

Return the parent of vtx_id.

Parameters:

vtx_id – The vertex identifier.

Returns:

vertex identifier

property root#

Return the tree root.

Returns:

vertex identifier

set_root(vtx_id)[source]#

Set the tree root.

Parameters:

vtx_id – The vertex identifier.

siblings(vtx_id)[source]#

Return an iterator of vtx_id siblings. vtx_id is not include in siblings.

Parameters:

vtx_id – The vertex identifier.

Returns:

iter of vertex identifier

class openalea.core.graph.interface.treeconcept.Visitor[source]#

Bases: object

Used during a tree traversal.

post_order(vtx_id)[source]#

todo

pre_order(vtx_id)[source]#

todo

openalea.core.graph.interface.treeconcept.traverse_tree(tree, vtx_id, visitor)[source]#

Traverse a tree in a prefix or postfix way.

We call a visitor for each vertex. This is usefull for printing, cmputing or storing vertices in a specific order.

See boost.graph.

Module contents#