Parcourir la source

Create file with graph builder

Eric Ramat il y a 11 ans
Parent
commit
09cea005ea
2 fichiers modifiés avec 3 ajouts et 188 suppressions
  1. 1 1
      src/tests/boost_graph/CMakeLists.txt
  2. 2 187
      src/tests/boost_graph/graph_manager.hpp

+ 1 - 1
src/tests/boost_graph/CMakeLists.txt

@@ -11,7 +11,7 @@ LINK_DIRECTORIES(
 
 # graph tests
 ADD_EXECUTABLE(graph-tests ${COMMON_HPP} ${COMMON_SCHEDULER_HPP} ${PDEVS_HPP}
-  graph_manager.hpp tests.cpp models.hpp)
+  graph_builder.hpp graph_manager.hpp tests.cpp models.hpp)
 SET_TARGET_PROPERTIES(graph-tests PROPERTIES ${PARADEVS_APP_PROPERTIES})
 
 TARGET_LINK_LIBRARIES(graph-tests

+ 2 - 187
src/tests/boost_graph/graph_manager.hpp

@@ -27,8 +27,6 @@
 #ifndef __TESTS_BOOST_GRAPH_GRAPH_MANAGER_HPP
 #define __TESTS_BOOST_GRAPH_GRAPH_MANAGER_HPP 1
 
-#include <boost/graph/adjacency_list.hpp>
-
 #include <common/scheduler/HeapScheduler.hpp>
 #include <common/scheduler/VectorScheduler.hpp>
 
@@ -37,47 +35,10 @@
 #include <pdevs/Simulator.hpp>
 
 #include <tests/boost_graph/models.hpp>
+#include <tests/boost_graph/graph_builder.hpp>
 
 namespace paradevs { namespace tests { namespace boost_graph {
 
-struct VertexProperties
-{
-    int          _index;
-    double       _weight;
-    DynamicsType _type;
-
-    VertexProperties() : _index(0), _weight(0), _type(NORMAL_PIXEL)
-    { }
-    VertexProperties(int index, double weight, DynamicsType type) :
-        _index(index), _weight(weight), _type(type)
-    { }
-};
-
-struct EdgeProperties
-{
-    double       _weight;
-
-    EdgeProperties() : _weight(0)
-    { }
-    EdgeProperties(double weight) : _weight(weight)
-    { }
-};
-
-typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS,
-                                VertexProperties, EdgeProperties> Graph;
-typedef std::vector < Graph > Graphs;
-
-typedef std::pair < int, int > Edge;
-typedef std::vector < Edge > Edges;
-typedef Edges OutputEdges;
-typedef Edges InputEdges;
-typedef std::vector < OutputEdges > OutputEdgeList;
-typedef std::vector < InputEdges > InputEdgeList;
-
-typedef std::pair < int, int > Port;
-typedef std::pair < Port, Port > Connection;
-typedef std::vector < Connection > Connections;
-
 struct GraphParameters
 {
     Graph       _graph;
@@ -184,7 +145,7 @@ protected:
                                 TopPixelParameters >* > TopSimulators;
     typedef std::map < int, pdevs::Simulator <
                                 MyTime, NormalPixel,
-                                NormalPixelParameters>* > NormalSimulators;
+                                NormalPixelParameters >* > NormalSimulators;
 
     TopSimulators    _top_simulators;
     NormalSimulators _normal_simulators;
@@ -249,64 +210,6 @@ public:
     { }
 };
 
-class FlatGraphBuilder
-{
-public:
-    FlatGraphBuilder()
-    { }
-
-    void build(Graphs& graphs, InputEdgeList& /* input_edges */,
-               OutputEdgeList& /* output_edges */,
-               Connections& /* parent_connections */)
-    {
-        Graph graph;
-
-        Graph::vertex_descriptor v0 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v1 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v2 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v3 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v4 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v5 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v6 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v7 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v8 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v9 = boost::add_vertex(graph);
-        Graph::vertex_descriptor v10 = boost::add_vertex(graph);
-
-        boost::add_edge(v0, v1, 1, graph);
-	boost::add_edge(v0, v2, 1, graph);
-	boost::add_edge(v0, v3, 1, graph);
-	boost::add_edge(v1, v2, 1, graph);
-	boost::add_edge(v1, v4, 1, graph);
-	boost::add_edge(v1, v5, 1, graph);
-	boost::add_edge(v1, v6, 1, graph);
-	boost::add_edge(v2, v6, 1, graph);
-	boost::add_edge(v2, v3, 1, graph);
-	boost::add_edge(v3, v9, 1, graph);
-	boost::add_edge(v3, v10, 1, graph);
-	boost::add_edge(v4, v5, 1, graph);
-	boost::add_edge(v5, v6, 1, graph);
-	boost::add_edge(v4, v7, 1, graph);
-	boost::add_edge(v4, v8, 1, graph);
-	boost::add_edge(v7, v8, 1, graph);
-	boost::add_edge(v9, v10, 1, graph);
-
-        graph[v6] = VertexProperties(6, 1, TOP_PIXEL);
-        graph[v8] = VertexProperties(8, 1, TOP_PIXEL);
-        graph[v10] = VertexProperties(10, 1, TOP_PIXEL);
-        graph[v0] = VertexProperties(0, 1, NORMAL_PIXEL);
-        graph[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
-        graph[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
-        graph[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
-        graph[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
-        graph[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
-        graph[v7] = VertexProperties(7, 1, NORMAL_PIXEL);
-        graph[v9] = VertexProperties(9, 1, NORMAL_PIXEL);
-
-        graphs.push_back(graph);
-    }
-};
-
 template < class GraphBuilder >
 class HierarchicalGraphManager :
     public paradevs::pdevs::GraphManager < MyTime,
@@ -379,94 +282,6 @@ private:
     Coordinators _coordinators;
 };
 
-class HierarchicalGraphBuilder
-{
-public:
-    HierarchicalGraphBuilder()
-    { }
-
-    void build(Graphs& graphs, InputEdgeList& input_edges,
-               OutputEdgeList& output_edges, Connections& parent_connections)
-    {
-        // S1
-        {
-            Graph graph;
-
-            Graph::vertex_descriptor v1 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v2 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v4 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v5 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v6 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v7 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v8 = boost::add_vertex(graph);
-
-            boost::add_edge(v1, v2, 1, graph);
-            boost::add_edge(v1, v4, 1, graph);
-            boost::add_edge(v1, v5, 1, graph);
-            boost::add_edge(v1, v6, 1, graph);
-            boost::add_edge(v2, v6, 1, graph);
-            boost::add_edge(v4, v5, 1, graph);
-            boost::add_edge(v5, v6, 1, graph);
-            boost::add_edge(v4, v7, 1, graph);
-            boost::add_edge(v4, v8, 1, graph);
-            boost::add_edge(v7, v8, 1, graph);
-
-            graph[v6] = VertexProperties(6, 1, TOP_PIXEL);
-            graph[v8] = VertexProperties(8, 1, TOP_PIXEL);
-            graph[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
-            graph[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
-            graph[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
-            graph[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
-            graph[v7] = VertexProperties(7, 1, NORMAL_PIXEL);
-
-            graphs.push_back(graph);
-        }
-        // S2
-        {
-            Graph graph;
-
-            Graph::vertex_descriptor v0 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v3 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v9 = boost::add_vertex(graph);
-            Graph::vertex_descriptor v10 = boost::add_vertex(graph);
-
-            boost::add_edge(v0, v3, 1, graph);
-            boost::add_edge(v3, v10, 1, graph);
-            boost::add_edge(v9, v10, 1, graph);
-            boost::add_edge(v3, v9, 1, graph);
-
-            graph[v10] = VertexProperties(10, 1, TOP_PIXEL);
-            graph[v0] = VertexProperties(0, 1, NORMAL_PIXEL);
-            graph[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
-            graph[v9] = VertexProperties(9, 1, NORMAL_PIXEL);
-
-            graphs.push_back(graph);
-        }
-        {
-            // input S1
-            input_edges.push_back(InputEdges());
-            input_edges[0].push_back(Edge(3, 2));
-            // input S2
-            input_edges.push_back(InputEdges());
-            input_edges[0].push_back(Edge(1, 0));
-            input_edges[0].push_back(Edge(2, 0));
-
-            // output S1
-            output_edges.push_back(OutputEdges());
-            output_edges[0].push_back(Edge(1, 0));
-            output_edges[0].push_back(Edge(2, 0));
-            // output S2
-            output_edges.push_back(OutputEdges());
-            output_edges[0].push_back(Edge(3, 2));
-
-            // parent
-            parent_connections.push_back(Connection(Port(1,1),Port(2,0)));
-            parent_connections.push_back(Connection(Port(1,2),Port(2,0)));
-            parent_connections.push_back(Connection(Port(2,3),Port(1,2)));
-        }
-    }
-};
-
 } } } // namespace paradevs tests boost_graph
 
 #endif