Boost logo

Boost Users :

Subject: [Boost-users] [graph] Overkill to use graph library for 'small' graphs?
From: Rainer Thaden (RThaden_at_[hidden])
Date: 2008-09-10 05:22:48


Hi all,

I have to manage connections between different items in an audio control
software. Currently, I am using several maps to manage "connections".
I was thinking of using a graph for this but there are several questions
arising. Maybe, someone can enlighten this:

I am controlling a hardware which has several inputs and outputs and
between it a layer of nodes. The inputs are connected to the nodes as
well as the outputs. An input can be connected to several nodes, an
output only to one node.
So, the graph has to represent connections between inputs, nodes, and
outputs. (Actually, there are more layers, but to keep it simple I show
only these 3).
The inputs, outputs, etc. in the end are integers, which are sent to the
device. I represent them as enums.
So I have, e.g.

        enum Inputs{
                        Input1 = 0,
                        Input2,
                        InputNone
                };

        enum Nodes{
                        NodeM=0,
                        NodeN,
                        NodeNone
                };

        enum Outputs{
                        AnalogOut1 = 0,
                        AnalogOut2
                        OutputNone
                };

Now, to use graphs, I have to define vertices. These have to be of "one"
type, as far as I understand that. How do I use the enums as shown
above? A vertice-value may be in enum Inputs or Nodes or Outputs.
Do I have to use a graph with elements of type ints and cast them to my
enums?

 From the introduction to BGL, modified:

     const int num_vertices = InputNone + NodeNone + OutputNone;

     // writing out the edges in the graph
     typedef std::pair<int, int> Edge;
     Edge edge_array[] =
     { Edge(Input1,NodeM), Edge(Input2,NodeN),
Edge(AnalogOut1,NodeM), Edge(AnalogOut2,NodeN)};
     const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);

     // declare a graph object
     Graph g(num_vertices);

     // add the edges to the graph object
     for (int i = 0; i < num_edges; ++i)
       add_edge(edge_array[i].first, edge_array[i].second, g);

When I e.g. need all vertices, connected to NodeM, I get two ints. One
of them represents a member of enum Inputs, the other one a member of
enum Outputs. Their numbers overlap, so I can not tell which is an Input
and which is an Output (the hardware device needs the numbers starting
from 0).
Any idea how do solve this?

Secondly, is there a big advantage of using a graph? There are about 25
different inputs, 8 nodes and 10 outputs and 2-3 additional layers. It
may be more elegant to use one graph instead of several maps. I can not
estimate the effort and performance of the graph. Would it be overkill
in both, performance and time to implement to use a graph for that?

Thanks in advance and regards,

Rainer


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net