[prev in list] [next in list] [prev in thread] [next in thread] 

List:       puppet-commit
Subject:    [Puppet-commit] puppet revision 1981
From:       svn () madstop ! com
Date:       2006-12-29 0:01:53
Message-ID: 20061229000153.0E20A1439B5 () culain ! madstop ! com
[Download RAW message or body]

luke 2006-12-28 18:01:52 -0600 (Thu, 28 Dec 2006)
Some tweaks to graph splicing, although I do not think it will be enough to handle \
                some of the edge cases.
Modified: trunk/lib/puppet/pgraph.rb
===================================================================
--- trunk/lib/puppet/pgraph.rb	2006-12-28 19:14:11 UTC (rev 1980)
+++ trunk/lib/puppet/pgraph.rb	2006-12-29 00:01:52 UTC (rev 1981)
@@ -96,7 +96,8 @@
     def splice!(other, type)
         vertices.find_all { |v| v.is_a?(type) }.each do |vertex|
             # Get the list of children from the other graph.
-            children = other.adjacent(vertex, :direction => :out)
+            #children = other.adjacent(vertex, :direction => :out)
+            children = other.leaves(vertex)
 
             # Just remove the container if it's empty.
             if children.empty?
@@ -107,29 +108,46 @@
             # First create new edges for each of the :in edges
             [:in, :out].each do |dir|
                 adjacent(vertex, :direction => dir, :type => :edges).each do |edge|
-                    children.each do |leaf|
-                        if dir == :in
-                            s = edge.source
-                            t = leaf
-                        else
-                            s = leaf
-                            t = edge.target
-                        end
+                    if dir == :in
+                        nvertex = edge.source
+                    else
+                        nvertex = edge.target
+                    end
+                    if nvertex.is_a?(type)
+                        neighbors = other.leaves(nvertex)
+                    else
+                        neighbors = [nvertex]
+                    end
 
-                        # It *appears* that we're having a problem
-                        # with multigraphs.
-                        next if edge?(s, t)
-                        add_edge!(s, t, edge.label)
-                        if cyclic?
-                            raise ArgumentError,
-                                "%s => %s results in a loop" %
-                                [s, t]
+                    children.each do |child|
+                        neighbors.each do |neighbor|
+                            if dir == :in
+                                s = neighbor
+                                t = child
+                            else
+                                s = child
+                                t = neighbor
+                            end
+                            if s.is_a?(type)
+                                raise "Source %s is still a container" % s
+                            end
+                            if t.is_a?(type)
+                                raise "Target %s is still a container" % t
+                            end
+
+                            # It *appears* that we're having a problem
+                            # with multigraphs.
+                            next if edge?(s, t)
+                            add_edge!(s, t, edge.label)
+                            if cyclic?
+                                raise ArgumentError,
+                                    "%s => %s results in a loop" %
+                                    [s, t]
+                            end
                         end
                     end
                 end
             end
-            
-            # And finally, remove the vertex entirely.
             remove_vertex!(vertex)
         end
     end

Modified: trunk/test/other/pgraph.rb
===================================================================
--- trunk/test/other/pgraph.rb	2006-12-28 19:14:11 UTC (rev 1980)
+++ trunk/test/other/pgraph.rb	2006-12-29 00:01:52 UTC (rev 1981)
@@ -71,15 +71,15 @@
     
     # Test that we can take a containment graph and rearrange it by dependencies
     def test_splice
-        one, two, middle, top = build_tree
+        one, two, three, middle, top = build_tree
         empty = Container.new("empty", [])
         # Also, add an empty container to top
         top.push empty
         
         contgraph = top.to_graph
         
-        # Now add a couple of child files, so that we can test whether all \
                containers
-        # get spliced, rather than just components.
+        # Now add a couple of child files, so that we can test whether all
+        # containers get spliced, rather than just components.
         
         # Now make a dependency graph
         deps = Puppet::PGraph.new
@@ -90,14 +90,24 @@
         
         # We have to specify a relationship to our empty container, else it
         # never makes it into the dep graph in the first place.
-        {one => two, "f" => "c", "h" => middle, "c" => empty}.each do |source, \
                target|
-            deps.add_edge!(source, target, :callback => :refresh)
+        #{one => two, three => [middle, two, "c"], "f" => "c", "h" => middle, "c" => \
empty}.each do |source, targets| +        {one => two, two => three, middle => three, \
"f" => "c", "h" => middle, "c" => [three, empty]}.each do |source, targets| +         \
targets = [targets] unless targets.is_a?(Array) +            targets.each do |target|
+                deps.add_edge!(source, target, :callback => :refresh)
+            end
         end
+
+        #num = 6
+        #contgraph.to_jpg(File.expand_path("~/tmp/graphs"), "containers#{num}")
+        #contgraph.reversal.to_jpg(File.expand_path("~/tmp/graphs"), \
"reversal#{num}") +        #deps.to_jpg(File.expand_path("~/tmp/graphs"), \
"relationships#{num}")  
         deps.splice!(contgraph, Container)
+        #deps.to_jpg(File.expand_path("~/tmp/graphs"), "after_relationships#{num}")
         
         assert(! deps.cyclic?, "Created a cyclic graph")
-        
+
         # Make sure there are no container objects remaining
         c = deps.vertices.find_all { |v| v.is_a?(Container) }
         assert(c.empty?, "Still have containers %s" % c.inspect)


[Attachment #3 (text/html)]

<p><b>luke</b> 2006-12-28 18:01:52 -0600 (Thu, 28 Dec 2006)</p><p>Some tweaks to \
graph splicing, although I do not think it will be enough to handle some of the edge \
cases.<br> </p><hr noshade><pre><font color="gray">Modified: \
trunk/lib/puppet/pgraph.rb \
                ===================================================================
--- trunk/lib/puppet/pgraph.rb	2006-12-28 19:14:11 UTC (rev 1980)
+++ trunk/lib/puppet/pgraph.rb	2006-12-29 00:01:52 UTC (rev 1981)
@@ -96,7 +96,8 @@
     def splice!(other, type)
         vertices.find_all { |v| v.is_a?(type) }.each do |vertex|
             # Get the list of children from the other graph.
-            children = other.adjacent(vertex, :direction =&gt; :out)
+            #children = other.adjacent(vertex, :direction =&gt; :out)
+            children = other.leaves(vertex)
 
             # Just remove the container if it's empty.
             if children.empty?
@@ -107,29 +108,46 @@
             # First create new edges for each of the :in edges
             [:in, :out].each do |dir|
                 adjacent(vertex, :direction =&gt; dir, :type =&gt; :edges).each do \
                |edge|
-                    children.each do |leaf|
-                        if dir == :in
-                            s = edge.source
-                            t = leaf
-                        else
-                            s = leaf
-                            t = edge.target
-                        end
+                    if dir == :in
+                        nvertex = edge.source
+                    else
+                        nvertex = edge.target
+                    end
+                    if nvertex.is_a?(type)
+                        neighbors = other.leaves(nvertex)
+                    else
+                        neighbors = [nvertex]
+                    end
 
-                        # It *appears* that we're having a problem
-                        # with multigraphs.
-                        next if edge?(s, t)
-                        add_edge!(s, t, edge.label)
-                        if cyclic?
-                            raise ArgumentError,
-                                &quot;%s =&gt; %s results in a loop&quot; %
-                                [s, t]
+                    children.each do |child|
+                        neighbors.each do |neighbor|
+                            if dir == :in
+                                s = neighbor
+                                t = child
+                            else
+                                s = child
+                                t = neighbor
+                            end
+                            if s.is_a?(type)
+                                raise &quot;Source %s is still a container&quot; % s
+                            end
+                            if t.is_a?(type)
+                                raise &quot;Target %s is still a container&quot; % t
+                            end
+
+                            # It *appears* that we're having a problem
+                            # with multigraphs.
+                            next if edge?(s, t)
+                            add_edge!(s, t, edge.label)
+                            if cyclic?
+                                raise ArgumentError,
+                                    &quot;%s =&gt; %s results in a loop&quot; %
+                                    [s, t]
+                            end
                         end
                     end
                 end
             end
-            
-            # And finally, remove the vertex entirely.
             remove_vertex!(vertex)
         end
     end

Modified: trunk/test/other/pgraph.rb
===================================================================
--- trunk/test/other/pgraph.rb	2006-12-28 19:14:11 UTC (rev 1980)
+++ trunk/test/other/pgraph.rb	2006-12-29 00:01:52 UTC (rev 1981)
@@ -71,15 +71,15 @@
     
     # Test that we can take a containment graph and rearrange it by dependencies
     def test_splice
-        one, two, middle, top = build_tree
+        one, two, three, middle, top = build_tree
         empty = Container.new(&quot;empty&quot;, [])
         # Also, add an empty container to top
         top.push empty
         
         contgraph = top.to_graph
         
-        # Now add a couple of child files, so that we can test whether all \
                containers
-        # get spliced, rather than just components.
+        # Now add a couple of child files, so that we can test whether all
+        # containers get spliced, rather than just components.
         
         # Now make a dependency graph
         deps = Puppet::PGraph.new
@@ -90,14 +90,24 @@
         
         # We have to specify a relationship to our empty container, else it
         # never makes it into the dep graph in the first place.
-        {one =&gt; two, &quot;f&quot; =&gt; &quot;c&quot;, &quot;h&quot; =&gt; \
                middle, &quot;c&quot; =&gt; empty}.each do |source, target|
-            deps.add_edge!(source, target, :callback =&gt; :refresh)
+        #{one =&gt; two, three =&gt; [middle, two, &quot;c&quot;], &quot;f&quot; \
=&gt; &quot;c&quot;, &quot;h&quot; =&gt; middle, &quot;c&quot; =&gt; empty}.each do \
|source, targets| +        {one =&gt; two, two =&gt; three, middle =&gt; three, \
&quot;f&quot; =&gt; &quot;c&quot;, &quot;h&quot; =&gt; middle, &quot;c&quot; =&gt; \
[three, empty]}.each do |source, targets| +            targets = [targets] unless \
targets.is_a?(Array) +            targets.each do |target|
+                deps.add_edge!(source, target, :callback =&gt; :refresh)
+            end
         end
+
+        #num = 6
+        #contgraph.to_jpg(File.expand_path(&quot;~/tmp/graphs&quot;), \
&quot;containers#{num}&quot;) +        \
#contgraph.reversal.to_jpg(File.expand_path(&quot;~/tmp/graphs&quot;), \
&quot;reversal#{num}&quot;) +        \
#deps.to_jpg(File.expand_path(&quot;~/tmp/graphs&quot;), \
&quot;relationships#{num}&quot;)  
         deps.splice!(contgraph, Container)
+        #deps.to_jpg(File.expand_path(&quot;~/tmp/graphs&quot;), \
&quot;after_relationships#{num}&quot;)  
         assert(! deps.cyclic?, &quot;Created a cyclic graph&quot;)
-        
+
         # Make sure there are no container objects remaining
         c = deps.vertices.find_all { |v| v.is_a?(Container) }
         assert(c.empty?, &quot;Still have containers %s&quot; % c.inspect)

</font>
</pre>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic