module Roby::Relations::DirectedRelationSupport

Base support for relations. It is mixed in objects on which a Relations::Space applies on, like Task for TaskStructure and EventGenerator for EventStructure.

See also the definition of Relations::Graph#add_relation and Relations::Graph#remove_relation for the possibility to define hooks that get called when a new edge involving self as a vertex gets added and removed

Attributes

relation_graphs[R]

Public Instance Methods

[](object, graph) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 259
def [](object, graph)
    relation_graphs[graph].edge_info(self, object)
end
[]=(object, relation, value) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 263
def []=(object, relation, value)
    relation_graphs[relation].set_edge_info(self, object, value)
end
add_child_object(child, relation, info = nil) click to toggle source

Add a new child object in the relation relation. This calls

  • adding_child_object on self and adding_parent_object on child just before the relation is added

  • added_child_object on self and added_parent_object on child just after

# File lib/roby/relations/directed_relation_support.rb, line 171
def add_child_object(child, relation, info = nil)
    relation_graphs[relation].add_relation(self, child, info)
end
add_parent_object(parent, relation, info = nil) click to toggle source

Add a new parent object in the relation relation

  • adding_child_object on parent and adding_parent_object on self just before the relation is added

  • added_child_object on parent and added_child_object on self just after

# File lib/roby/relations/directed_relation_support.rb, line 180
def add_parent_object(parent, relation, info = nil)
    relation_graphs[parent].add_child_object(self, relation, info)
end
child_object?(object, relation = nil) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 68
def child_object?(object, relation = nil)
    relation_graphs[relation].has_edge?(self, object)
end
child_objects(relation) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 162
def child_objects(relation)
    relation_graphs[relation].out_neighbours(self)
end
clear_relations(remove_strong: true)
Alias for: clear_vertex
clear_vertex(remove_strong: true) click to toggle source

Removes self from all the graphs it is included in.

# File lib/roby/relations/directed_relation_support.rb, line 110
def clear_vertex(remove_strong: true)
    for rel in sorted_relations
        graph = relation_graphs[rel]
        if remove_strong || !graph.strong?
            if graph.remove_vertex(self)
                removed = true
            end
        end
    end
    removed
end
Also aliased as: clear_relations
each_child_object(graph, &block) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 88
def each_child_object(graph, &block)
    relation_graphs[graph].each_out_neighbour(self, &block)
end
each_in_neighbour(graph, &block) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 84
def each_in_neighbour(graph, &block)
    relation_graphs[graph].each_in_neighbour(self, &block)
end
each_out_neighbour(graph, &block) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 92
def each_out_neighbour(graph, &block)
    relation_graphs[graph].each_out_neighbour(self, &block)
end
each_parent_object(graph, &block) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 80
def each_parent_object(graph, &block)
    relation_graphs[graph].each_in_neighbour(self, &block)
end
each_relation() { |k| ... } click to toggle source

Enumerate all relations that are relevant for this plan object

Unlike {#each_relation_graph}, which enumerate only the graphs that include self, it enumerates all possible relations for self

@yieldparam [Class<Graph>]

# File lib/roby/relations/directed_relation_support.rb, line 24
def each_relation
    return enum_for(__method__) if !block_given?
    relation_graphs.each do |k, g|
        yield(k) if k != g
    end
end
each_relation_graph() { |g| ... } click to toggle source

Enumerate the relation graphs that include this vertex

@yieldparam [Graph]

# File lib/roby/relations/directed_relation_support.rb, line 34
def each_relation_graph
    return enum_for(__method__) if !block_given?
    relation_graphs.each do |k, g|
        yield(g) if g.has_vertex?(self) && (k == g)
    end
end
each_relation_sorted(&block) click to toggle source

Yields each relation this vertex is part of, starting with the most specialized relations

# File lib/roby/relations/directed_relation_support.rb, line 105
def each_relation_sorted(&block)
    sorted_relations.each(&block)
end
each_root_relation_graph() { |g| ... } click to toggle source

Enumerate the relation graphs that include this vertex and that are subgraphs of no other graphs

@yieldparam [Graph]

# File lib/roby/relations/directed_relation_support.rb, line 45
def each_root_relation_graph
    return enum_for(__method__) if !block_given?
    each_relation_graph do |g|
        yield(g) if g.root_relation?
    end
end
enum_child_objects(relation) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 157
def enum_child_objects(relation)
    Roby.warn_deprecated "#enum_child_objects is deprecated, use #parent_objects or #each_parent_object instead"
    child_objects(relation)
end
enum_parent_objects(relation) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 148
def enum_parent_objects(relation)
    Roby.warn_deprecated "#enum_parent_objects is deprecated, use #parent_objects or #each_parent_object instead"
    parent_objects(relation)
end
enum_relations() click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 123
def enum_relations
    Roby.warn_deprecated "DirectedRelationSupport#enum_relations is deprecated, use #each_relation instead"
    each_relation
end
leaf?(relation = nil) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 60
def leaf?(relation = nil)
    if relation
        relation_graphs[relation].leaf?(self)
    else
        each_relation_graph.all? { |g| g.leaf?(self) }
    end
end
parent_object?(object, relation = nil) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 72
def parent_object?(object, relation = nil)
    relation_graphs[relation].has_edge?(object, self)
end
parent_objects(relation) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 153
def parent_objects(relation)
    relation_graphs[relation].in_neighbours(self)
end
relation_graph_for(rel) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 14
def relation_graph_for(rel)
    relation_graphs.fetch(rel)
end
relations() click to toggle source

The array of relations this object is part of

# File lib/roby/relations/directed_relation_support.rb, line 129
def relations; each_relation.to_a end
remove_child_object(child, relation = nil) click to toggle source

Remove all edges in which self is the source and child the target. If relation is given, it removes only the edge in that relation graph.

# File lib/roby/relations/directed_relation_support.rb, line 187
def remove_child_object(child, relation = nil)
    if !relation
        for rel in sorted_relations
            rel.remove_relation(self, child)
        end
    else
        relation_graphs[relation].remove_relation(self, child)
    end
end
remove_children(relation = nil) click to toggle source

Remove all edges in which self is the source. If relation is given, it removes only the edges in that relation graph.

# File lib/roby/relations/directed_relation_support.rb, line 199
def remove_children(relation = nil)
    if !relation
        for rel in sorted_relations
            remove_children(rel)
        end
        return
    end

    children = child_objects(relation).to_a
    for child in children
        remove_child_object(child, relation)
    end
end
remove_parent_object(parent, relation = nil) click to toggle source

Remove all edges in which child is the source and self the target. If relation is given, it removes only the edge in that relation graph.

# File lib/roby/relations/directed_relation_support.rb, line 216
def remove_parent_object(parent, relation = nil)
    parent.remove_child_object(self, relation)
end
remove_parents(relation = nil) click to toggle source

Remove all edges in which self is the target. If relation is given, it removes only the edges in that relation graph.

# File lib/roby/relations/directed_relation_support.rb, line 222
def remove_parents(relation = nil)
    if !relation
        for rel in sorted_relations
            remove_parents(rel)
        end
        return
    end

    parents = parent_objects(relation).to_a
    for parent in parents
        remove_parent_object(relation, parent)
    end
end
remove_relations(relation = nil) click to toggle source

Remove all relations that point to or come from to If to is nil, it removes all edges in which self is involved.

If relation is not nil, only edges of that relation graph are removed.

# File lib/roby/relations/directed_relation_support.rb, line 240
def remove_relations(relation = nil)
    if !relation
        for rel in sorted_relations
            remove_relations(rel)
        end
        return
    end
    relation = relation_graphs[relation]
    return if !relation.has_vertex?(self)

    each_parent_object(relation).to_a.each do |parent|
        relation.remove_relation(parent, self)
    end

    each_child_object(relation).to_a.each do |child|
        relation.remove_relation(self, child)
    end
end
root?(relation = nil) click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 52
def root?(relation = nil)
    if relation
        relation_graphs[relation].root?(self)
    else
        each_relation_graph.all? { |g| g.root?(self) }
    end
end
sorted_relations() click to toggle source
# File lib/roby/relations/directed_relation_support.rb, line 96
def sorted_relations
    Relations.all_relations.
        find_all do |rel|
            (rel = relation_graphs.fetch(rel, nil)) && rel.has_vertex?(self)
        end
end