浏览代码

Fix: wrong internal connections in coupled model

Eric Ramat 10 年之前
父节点
当前提交
630448502a

+ 20 - 0
src/common/Links.hpp

@@ -67,6 +67,26 @@ public:
                                                 in_model, in_port_name)));
     }
 
+    bool exist(Model < Time, SchedulerHandle >* out_model,
+               const std::string& out_port_name,
+               Model < Time, SchedulerHandle >* in_model,
+               const std::string& in_port_name) const
+    {
+        typename Links < Time, SchedulerHandle >::const_iterator it =
+            std::multimap < Node < Time, SchedulerHandle >,
+                            Node < Time, SchedulerHandle > >::find(
+                                Node < Time, SchedulerHandle >(out_model,
+                                                               out_port_name));
+        bool found = false;
+
+        while (not found and it != Links < Time, SchedulerHandle >::end()) {
+            found = it->second == Node < Time, SchedulerHandle >(
+                in_model, in_port_name);
+            ++it;
+        }
+        return found;
+    }
+
     Links::Result find(Model < Time, SchedulerHandle >* out_model,
                        const std::string& out_port_name) const
     {

+ 9 - 0
src/kernel/pdevs/GraphManager.hpp

@@ -111,6 +111,15 @@ public:
         }
     }
 
+    bool exist_link(common::Model < Time, SchedulerHandle >* src_model,
+                    const std::string& src_port_name,
+                    common::Model < Time, SchedulerHandle >* dst_model,
+                    const std::string& dst_port_name) const
+    {
+        return _link_list.exist(src_model, src_port_name, dst_model,
+                                dst_port_name);
+    }
+
     common::Coordinator < Time, SchedulerHandle >* get_coordinator() const
     { return _coordinator; }
 

+ 1 - 1
src/tests/boost_graph/graph_builder.hpp

@@ -154,7 +154,7 @@ public:
         }
         {
             // input S1
-        	input_edges.push_back(InputEdges());
+            input_edges.push_back(InputEdges());
             // input S2
             input_edges.push_back(InputEdges());
             input_edges[1].push_back(Edge(1, 0));

+ 69 - 28
src/tests/boost_graph/graph_manager.hpp

@@ -107,9 +107,14 @@ public:
     {
         OrientedGraph::vertex_iterator vertexIt, vertexEnd;
 
+        std::cout << "CREATE flat graph "
+                  << FlatGraphManager <
+                      SchedulerHandle, Parameters >::get_coordinator()
+            ->get_name()
+                  << std::endl;
+
         boost::tie(vertexIt, vertexEnd) = boost::vertices(g);
-	for (; vertexIt != vertexEnd; ++vertexIt)
-	{
+        for (; vertexIt != vertexEnd; ++vertexIt) {
             std::ostringstream ss;
 
             ss << "a" << g[*vertexIt]._index;
@@ -126,20 +131,41 @@ public:
                 break;
             case NORMAL_PIXEL:
                 unsigned int n = 0;
-                OrientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
+                OrientedGraph::vertex_iterator vertexIt2, vertexEnd2;
+
+                boost::tie(vertexIt2, vertexEnd2) = boost::vertices(g);
+                for (; vertexIt2 != vertexEnd2; ++vertexIt2) {
+                    OrientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
+
+                    std::cout << "CHECKING ... " << *vertexIt << " "
+                              << g[*vertexIt2]._index << std::endl;
+
+                    boost::tie(neighbourIt, neighbourEnd) =
+                        boost::adjacent_vertices(*vertexIt2, g);
+                    for (; neighbourIt != neighbourEnd; ++neighbourIt) {
+
+                        std::cout << "CHECK " << *neighbourIt << std::endl;
 
-                boost::tie(neighbourIt, neighbourEnd) =
-                    boost::adjacent_vertices(*vertexIt, g);
-                for (; neighbourIt != neighbourEnd; ++neighbourIt) {
-                    ++n;
+                        if (g[*neighbourIt]._index == g[*vertexIt]._index) {
+                            ++n;
+                        }
+                    }
                 }
+
                 for (InputEdges::const_iterator it = inputs.begin();
                      it != inputs.end(); ++it) {
+
+                    std::cout << "CHECK (" << it->first << "," << it->second
+                              << ")" << std::endl;
+
                     if (g[*vertexIt]._index == it->second) {
                         ++n;
                     }
                 }
 
+                std::cout << "create normal : " << ss.str() << " => "
+                          << n << std::endl;
+
                 _normal_simulators[g[*vertexIt]._index] =
                     new pdevs::Simulator <
                         common::DoubleTime, NormalPixel < SchedulerHandle >,
@@ -148,7 +174,7 @@ public:
                 _normal_simulators[g[*vertexIt]._index]->add_in_port("in");
                 _normal_simulators[g[*vertexIt]._index]->add_out_port("out");
                 FlatGraphManager < SchedulerHandle, Parameters >::add_child(
-                        _normal_simulators[g[*vertexIt]._index]);
+                    _normal_simulators[g[*vertexIt]._index]);
                 break;
             };
         }
@@ -158,8 +184,8 @@ public:
             Parameters >::get_coordinator()->get_name() << ":" << std::endl;
 
         boost::tie(vertexIt, vertexEnd) = boost::vertices(g);
-	for (; vertexIt != vertexEnd; ++vertexIt)
-	{
+        for (; vertexIt != vertexEnd; ++vertexIt)
+        {
             OrientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
 
             boost::tie(neighbourIt, neighbourEnd) =
@@ -188,7 +214,7 @@ public:
                           << b->get_name() << "::in" << std::endl;
 
             }
-	}
+        }
     }
 
 protected:
@@ -251,16 +277,20 @@ public:
             if (not coordinator->exist_out_port(ss_out.str())) {
                 coordinator->add_out_port(ss_out.str());
             }
-            BuiltFlatGraphManager < SchedulerHandle>::add_link(
+            if (not BuiltFlatGraphManager < SchedulerHandle>::exist_link(
                 BuiltFlatGraphManager <
                     SchedulerHandle >::_normal_simulators[it->first], "out",
-                coordinator, ss_out.str());
-
-            std::cout << BuiltFlatGraphManager <
-                SchedulerHandle >::_normal_simulators[it->first]->get_name()
-                      << "::out -> " << coordinator->get_name()
-                      << "::" << ss_out.str() << std::endl;
-
+                coordinator, ss_out.str())) {
+                BuiltFlatGraphManager < SchedulerHandle>::add_link(
+                    BuiltFlatGraphManager <
+                        SchedulerHandle >::_normal_simulators[it->first], "out",
+                    coordinator, ss_out.str());
+
+                std::cout << BuiltFlatGraphManager <
+                    SchedulerHandle >::_normal_simulators[it->first]->get_name()
+                          << "::out -> " << coordinator->get_name()
+                          << "::" << ss_out.str() << std::endl;
+            }
         }
     }
 
@@ -355,16 +385,27 @@ public:
 
             ss_out << "out_" << connection.first.second;
             ss_in << "in_" << connection.first.second;
-            HierarchicalGraphManager <
-                SchedulerHandle, GraphBuilder >::add_link(
-                    _coordinators[connection.first.first - 1], ss_out.str(),
-                    _coordinators[connection.second.first - 1], ss_in.str());
-
-            std::cout << _coordinators[connection.first.first - 1]->get_name()
-                      << "::" << ss_out.str() << " -> "
-                      << _coordinators[connection.second.first - 1]->get_name()
-                      << "::" << ss_in.str() << std::endl;
 
+            if (not HierarchicalGraphManager <
+                    SchedulerHandle, GraphBuilder >::exist_link(
+                        _coordinators[connection.first.first - 1],
+                        ss_out.str(),
+                        _coordinators[connection.second.first - 1],
+                        ss_in.str())) {
+                HierarchicalGraphManager <
+                    SchedulerHandle, GraphBuilder >::add_link(
+                        _coordinators[connection.first.first - 1],
+                        ss_out.str(),
+                        _coordinators[connection.second.first - 1],
+                        ss_in.str());
+
+                std::cout << _coordinators[connection.first.first - 1]
+                    ->get_name()
+                          << "::" << ss_out.str() << " -> "
+                          << _coordinators[connection.second.first - 1]
+                    ->get_name()
+                          << "::" << ss_in.str() << std::endl;
+            }
         }
     }
 

+ 1 - 1
src/tests/boost_graph/graph_partitioning.hpp

@@ -44,7 +44,7 @@ public:
                OutputEdgeList& output_edges,
                Connections& parent_connections)
     {
-        srand(time(NULL));
+        srand(7266);
 
         UnorientedGraph* g = new UnorientedGraph();
         OrientedGraph* go = new OrientedGraph();

+ 10 - 10
src/tests/boost_graph/partitioning/graph_build.cpp

@@ -64,17 +64,17 @@ void build_graph(UnorientedGraph& ug, OrientedGraph& og)
     add_edge(v7, v8, EdgeProperties(1.), og);
     add_edge(v9, v10, EdgeProperties(1.), og);
 
-    og[v6] = VertexProperties(6, 1.5, TOP_PIXEL);
-    og[v8] = VertexProperties(8, 1., TOP_PIXEL);
-    og[v10] = VertexProperties(10, 1.5, TOP_PIXEL);
+    og[v6] = VertexProperties(6, 1.5, NORMAL_PIXEL);
+    og[v8] = VertexProperties(8, 1., NORMAL_PIXEL);
+    og[v10] = VertexProperties(10, 1.5, NORMAL_PIXEL);
     og[v0] = VertexProperties(0, 3, NORMAL_PIXEL);
     og[v1] = VertexProperties(1, 2, NORMAL_PIXEL);
     og[v2] = VertexProperties(2, 2, NORMAL_PIXEL);
     og[v3] = VertexProperties(3, 2, NORMAL_PIXEL);
     og[v4] = VertexProperties(4, 1.5, NORMAL_PIXEL);
     og[v5] = VertexProperties(5, 1.5, NORMAL_PIXEL);
-    og[v7] = VertexProperties(7, 1., NORMAL_PIXEL);
-    og[v9] = VertexProperties(9, 1.5, NORMAL_PIXEL);
+    og[v7] = VertexProperties(7, 1., TOP_PIXEL);
+    og[v9] = VertexProperties(9, 1.5, TOP_PIXEL);
 
     /*
      * construction graphe Non Oriente
@@ -110,17 +110,17 @@ void build_graph(UnorientedGraph& ug, OrientedGraph& og)
     boost::add_edge(v71, v81, EdgeProperties(1.), ug);
     boost::add_edge(v91, v101, EdgeProperties(1.), ug);
 
-    ug[v61] = VertexProperties(60, 1.5, TOP_PIXEL);
-    ug[v81] = VertexProperties(80, 1, TOP_PIXEL);
-    ug[v101] = VertexProperties(100, 1.5, TOP_PIXEL);
+    ug[v61] = VertexProperties(60, 1.5, NORMAL_PIXEL);
+    ug[v81] = VertexProperties(80, 1, NORMAL_PIXEL);
+    ug[v101] = VertexProperties(100, 1.5, NORMAL_PIXEL);
     ug[v01] = VertexProperties(0, 3, NORMAL_PIXEL);
     ug[v11] = VertexProperties(10, 2, NORMAL_PIXEL);
     ug[v21] = VertexProperties(20, 2, NORMAL_PIXEL);
     ug[v31] = VertexProperties(30, 2, NORMAL_PIXEL);
     ug[v41] = VertexProperties(40, 1.5, NORMAL_PIXEL);
     ug[v51] = VertexProperties(50, 1.5, NORMAL_PIXEL);
-    ug[v71] = VertexProperties(70, 1, NORMAL_PIXEL);
-    ug[v91] = VertexProperties(90, 1.5, NORMAL_PIXEL);
+    ug[v71] = VertexProperties(70, 1, TOP_PIXEL);
+    ug[v91] = VertexProperties(90, 1.5, TOP_PIXEL);
 
 }
 

+ 1 - 1
src/tests/boost_graph/partitioning/main.cpp

@@ -43,7 +43,7 @@ int main()
 {
     boost::timer t;
 
-    srand((unsigned)time(NULL));
+    srand(7266);
 
     UnorientedGraph* g = new UnorientedGraph();
     OrientedGraph* go = new OrientedGraph();

+ 1 - 1
src/tests/boost_graph/tests.cpp

@@ -87,7 +87,7 @@ void partitionning_test()
             paradevs::common::NoParameters >
         > rc(0, 100, "root", NoParameters(), NoParameters());
 
-//    rc.run();
+    rc.run();
 }
 
 int main()