X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Fgraph.njae%2Fgraph.rb;h=b1de59b324be4297ceed4ef6c1a8dd2fdfe890df;hb=353a5d54ad4014af126c76617d9b02029a3ee98c;hp=e08a1ad8544d12aec4cacf3a095ca5e1e5df6aea;hpb=c73f1676c10ecc3418eae98d3fb1e306fb86ec4e;p=graph.njae.git

diff --git a/lib/graph.njae/graph.rb b/lib/graph.njae/graph.rb
index e08a1ad..b1de59b 100644
--- a/lib/graph.njae/graph.rb
+++ b/lib/graph.njae/graph.rb
@@ -7,8 +7,8 @@ module GraphNjae
   # A container for all the parts of a graph.  The graph can have arbitrary attributes,
   # treated as method names.
   class Graph < OpenStruct
-    def initialize
-      super
+    def initialize(values = {})
+      super(values)
       self.edges = Array.new
       self.vertices = Array.new
       self
@@ -23,5 +23,20 @@ module GraphNjae
       end
       self
     end
-  end
+    
+    # Form a product graph of this graph and the other.
+    # Return the new graph.
+    def product(other)
+      product_graph = Graph.new
+      self.vertices.each do |v1|
+        other.vertices.each do |v2|
+          product_vertex = Vertex.new
+          product_vertex.left_node = v1
+          product_vertex.right_node = v2
+          product_graph << product_vertex
+        end
+      end
+    end
+    
+  end # class
 end