Definition of Communication Structures

A communication structure is a labeled graph. Labels are vector of quantities (Defining a Label). COSI defines two basic data structures that implement graphs: cosi::IdGraph for directed graphs and cosi::IdUndirectedGraph for undirected graphs. A communication structure derives this two base classes and adds the label on top of them.

Since any label can be attached to a nodes and links of a graph, a communication structure is a template that takes a label as paramter. A communication structure then derives not only the basic graph data structure but also a data structure that attaches labels to the components of a communication structure (i.e. to the nodes and links). This data structure is implemented by the template class cosi::LabelMap. This class implementes an interface to set and get the label attached to a node or a link of a graph. In particular, a useful operator is the operator[]. This operator takes a node or a link of a graph and returns a reference to the label. Therefore it can be used to either get or set a label on a component.

The following code shows the definition of a communication structure

//============================================================================
// Author      : Alessandro Pinto <apinto@eecs.berkeley.edu>
//               University of California, Berkeley
//               545 Cory Hall, Berkeley, CA 94720
// Copyright   : See COPYING file that comes with this distribution
//============================================================================

#ifndef COMMUNICATIONSTRUCTURE_HPP_
#define COMMUNICATIONSTRUCTURE_HPP_

#include <string>
#include "IdGraph.h"
#include "IdUndirectedGraph.h"
#include "../label/LabelMap.hpp"

namespace cosi {

#define PRJ(x) x::

template<class L> class CommunicationStructure : public IdGraph,
        public LabelMap<L> {
public:

        CommunicationStructure() :
                IdGraph("Unknown") {
        }
        ;

        CommunicationStructure(std::string pName) :
                IdGraph(pName) {
        }
        ;

        int AddVertex() {
                int Id = IdGraph::AddVertex();
                LabelMap<L>::Set(Id, L()) ;
                return Id ;
        }
        ;

        void AddVertex(int Id) {
                IdGraph::AddVertex(Id);
                LabelMap<L>::Set(Id, L()) ;
        }
        ;

        void DeleteVertex(int Id) {
                IdGraph::DeleteVertex(Id);
                LabelMap<L>::Erase(Id);
        }
        ;

        void AddEdge(int i, int j) {
                IdGraph::AddEdge(i, j);
                LabelMap<L>::Set(Edge(i, j), L());
        }
        ;

        void AddEdge(Edge pE) {
                IdGraph::AddEdge(pE);
                LabelMap<L>::Set(pE, L());
        }
        ;

        void DeleteEdge(int i, int j) {
                IdGraph::DeleteEdge(i, j);
                LabelMap<L>::Erase(Edge(i, j));
        }
        ;

        void DeleteEdge(Edge pE) {
                IdGraph::DeleteEdge(pE);
                LabelMap<L>::Erase(pE);
        }
        ;

        L& operator[](Vertex V) {
                return LabelMap<L>::Get(V) ;
        }
        ;

        L& operator[](Edge E) {
                return LabelMap<L>::Get(E) ;
        }
        ;

        std::string PrintNode(int V) {
                std::string s;
                s += IdGraph::PrintNode(V) ;
                s += (*this)[V].Print() ;
                return s ;
        }

        std::string PrintEdge(int U, int V) {
                std::string s;
                s+= IdGraph::PrintEdge(U, V) ;
                s+= (*this)[Edge(U,V)].Print() ;
                return s ;
        }

        std::string PrintEdge(Edge pE) {
                std::string s;
                s+= IdGraph::PrintEdge(pE) ;
                s+= (*this)[pE].Print() ;
                return s ;
        }

};

template<class L> class U_CommunicationStructure : public IdUndirectedGraph,
        public LabelMap<L> {
public:

        U_CommunicationStructure() :
                IdUndirectedGraph("Unknown") {
        }
        ;

        U_CommunicationStructure(std::string pName) :
                IdUndirectedGraph(pName) {
        }
        ;

        void AddVertex(int Id) {
                IdUndirectedGraph::AddVertex(Id);
                LabelMap<L>::Set(Id, L()) ;
        }
        ;

        void DeleteVertex(int Id) {
                IdUndirectedGraph::DeleteVertex(Id);
                LabelMap<L>::Erase(Id);
        }
        ;

        void AddEdge(int i, int j) {
                IdUndirectedGraph::AddEdge(i, j);
                LabelMap<L>::Set(Edge(i, j), L());
                LabelMap<L>::Set(Edge(j, i), L());
        }
        ;

        void AddEdge(Edge pE) {
                IdUndirectedGraph::AddEdge(pE);
                LabelMap<L>::Set(pE, L());
                Edge E(pE.V() , pE.U());
                LabelMap<L>::Set(E, L());
        }
        ;

        void DeleteEdge(int i, int j) {
                IdUndirectedGraph::DeleteEdge(i, j);
                LabelMap<L>::Erase(Edge(i, j));
                LabelMap<L>::Erase(Edge(j, i));
        }
        ;

        void DeleteEdge(Edge pE) {
                IdUndirectedGraph::DeleteEdge(pE);
                LabelMap<L>::Erase(pE);
                Edge E(pE.V() , pE.U());
                LabelMap<L>::Erase(E);
        }
        ;

        L& operator[](Vertex V) {
                return LabelMap<L>::Get(V) ;
        }
        ;

        L& operator[](Edge E) {
                if ( !(LabelMap<L>::Get(E)).IsBot() )
                        return LabelMap<L>::Get(E) ;
                Edge Re ;
                Re.U(E.V()) ;
                Re.V(E.U()) ;
                if ( !(LabelMap<L>::Get(Re)).IsBot() )
                        return LabelMap<L>::Get(Re) ;
                return  LabelMap<L>::Get(E);
        }
        ;

        std::string PrintNode(int V) {
                std::string s;
                s += IdUndirectedGraph::PrintNode(V) ;
                s += (*this)[V].Print() ;
                return s ;
        }

        std::string PrintEdge(int U, int V) {
                std::string s;
                s+= IdUndirectedGraph::PrintEdge(U, V) ;
                s+= (*this)[Edge(U,V)].Print() ;
                return s ;
        }

        std::string PrintEdge(Edge pE) {
                std::string s;
                s+= IdUndirectedGraph::PrintEdge(pE) ;
                s+= (*this)[pE].Print() ;
                return s ;
        }

};

}

#endif /*COMMUNICATIONSTRUCTURE_HPP_*/
Notice the redefinition of the functions to add new nodes (i.e. vertexes) and new links (i.e. edges). When a new component is added to the graph, the communication structure will add an emptu label to it. An empty label is simply a vector of quantities with no values. The communication strucuture class aslo alredy defines functions to print the properties of each component which simply prints the component itself (i.e. the id of anode or the pair of ids of a link) and the label attachet to it.

For instance the communication strucutre that captures the specification of a communication problem for wired building automation systems looks like the following

 typedef Label_5<Type,Ports,Position,ThreadSet,RealLatency> SpecificationLabel;
 class Specification : public CommunicationStructure< SpecificationLabel > {
   public:
     Specification(std::string pName);
     ~Specification();
     Specification operator+(Specification pC);
 };

Each communication structure should define a composition operator +. The composition operator is only componse the quantities. If there or platform dependent composition rules, they should be defined outside the communication strucuture and checked separately. For an example of such rules see cosi::rules::wiredbas::WiringRule.

We report here an example of how to use this data structure. For instance, we can instantiate a specification, add a couple of nodes to it with assigned positions, and add an edge with a latency constraint as follows:

 cosi::commstruct::wiredbas::Specification Spec("My first spec");
 Spec.AddVertex(0) ;
 cosi::Position P(0,0,0) ;
 Spec[0].PRJ(Position)Set(P);
 //Another node
 int SecondNodeId = Spec.AddVertex() ;
 P.SetX(1) ;
 P.SetY(1) ;
 P.SetZ(1) ;
 Spec[SecondNodeId].PRJ(Position)Set(P) ;
 // Constraint from 0 to SecondNodeId with maximum latency equal to 100ms
 Spec.AddEdge(0,SecondNodeId) ;
 Spec[Edge(0,SecondNodeId)].PRJ(RealLatency)SetValue(0.1) ;
 std::cout << Spec.Print() << std::endl ;
The last line prints out the entire communication structrue.
Generated on Sun Sep 7 18:37:44 2008 for COSI by  doxygen 1.5.4
Contact 
©2002-2018 U.C. Regents