abstract_graph 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +13 -5
- data/Rakefile +11 -1
- data/lib/abstract_graph.rb +1 -0
- data/lib/abstract_graph/composition.rb +1 -1
- data/lib/abstract_graph/composition/edge.rb +5 -0
- data/lib/abstract_graph/composition/edge/initialize.rb +6 -0
- data/lib/abstract_graph/composition/edge/is_coincident.rb +5 -2
- data/lib/abstract_graph/composition/unique_name_collection.rb +28 -0
- data/lib/abstract_graph/composition/unique_name_collection/add.rb +23 -0
- data/lib/abstract_graph/composition/unique_name_collection/delete.rb +20 -0
- data/lib/abstract_graph/composition/unique_name_collection/dup.rb +24 -0
- data/lib/abstract_graph/composition/unique_name_collection/each.rb +18 -0
- data/lib/abstract_graph/composition/unique_name_collection/find.rb +18 -0
- data/lib/abstract_graph/composition/unique_name_collection/initialize.rb +22 -0
- data/lib/abstract_graph/composition/unique_name_collection/link.rb +42 -0
- data/lib/abstract_graph/composition/unique_name_collection/method_missing.rb +18 -0
- data/lib/abstract_graph/composition/unique_name_collection/rename.rb +34 -0
- data/lib/abstract_graph/composition/unique_name_collection/ticket.rb +18 -0
- data/lib/abstract_graph/composition/unique_name_collection/ticket/get.rb +20 -0
- data/lib/abstract_graph/composition/unique_name_collection/ticket/initialize.rb +20 -0
- data/lib/abstract_graph/composition/unique_name_collection/ticket/set.rb +20 -0
- data/lib/abstract_graph/composition/vertex.rb +5 -1
- data/lib/abstract_graph/composition/vertex/initialize.rb +6 -0
- data/lib/abstract_graph/graph.rb +1 -0
- data/lib/abstract_graph/graph/add_edge.rb +9 -8
- data/lib/abstract_graph/graph/add_vertex.rb +5 -2
- data/lib/abstract_graph/graph/adjacency_list.rb +8 -3
- data/lib/abstract_graph/graph/change_edge_name.rb +6 -4
- data/lib/abstract_graph/graph/change_vertex_name.rb +5 -3
- data/lib/abstract_graph/graph/connected.rb +36 -0
- data/lib/abstract_graph/graph/delete_edge.rb +5 -4
- data/lib/abstract_graph/graph/delete_vertex.rb +5 -4
- data/lib/abstract_graph/graph/dup.rb +8 -3
- data/lib/abstract_graph/graph/get_edge_name.rb +7 -4
- data/lib/abstract_graph/graph/has_edge.rb +6 -3
- data/lib/abstract_graph/graph/has_vertex.rb +6 -3
- data/lib/abstract_graph/graph/initialize.rb +5 -1
- data/lib/abstract_graph/graph/is_adjacent.rb +9 -7
- data/lib/abstract_graph/graph/merge_vertices.rb +16 -14
- data/lib/abstract_graph/graph/split_vertex.rb +10 -7
- data/lib/abstract_graph/graph/templates/complete_bipartite_graph.rb +7 -5
- data/lib/abstract_graph/graph/templates/complete_graph.rb +8 -6
- data/lib/abstract_graph/graph/templates/cycle_graph.rb +6 -5
- data/lib/abstract_graph/graph/templates/path_graph.rb +6 -4
- data/lib/abstract_graph/graph/templates/petersen_graph.rb +8 -2
- data/lib/abstract_graph/version.rb +1 -1
- data/spec/abstract_graph/composition/{uniquenamecollection → unique_name_collection}/add_spec.rb +0 -0
- data/spec/abstract_graph/composition/{uniquenamecollection → unique_name_collection}/dup_spec.rb +0 -0
- data/spec/abstract_graph/composition/unique_name_collection/each_spec.rb +38 -0
- data/spec/abstract_graph/composition/unique_name_collection/find_spec.rb +33 -0
- data/spec/abstract_graph/composition/{uniquenamecollection → unique_name_collection}/initialize_spec.rb +0 -0
- data/spec/abstract_graph/composition/{uniquenamecollection → unique_name_collection}/link_spec.rb +0 -0
- data/spec/abstract_graph/composition/{uniquenamecollection → unique_name_collection}/method_missing_spec.rb +4 -15
- data/spec/abstract_graph/composition/{uniquenamecollection → unique_name_collection}/rename_spec.rb +1 -1
- data/spec/abstract_graph/composition/{uniquenamecollection_spec.rb → unique_name_collection_spec.rb} +0 -0
- data/spec/abstract_graph/graph/add_edge_spec.rb +1 -1
- data/spec/abstract_graph/graph/connected_spec.rb +39 -0
- data/tasks/benchmark.rb +47 -0
- data/tasks/create_method.rb +64 -0
- data/tasks/list_methods.rb +5 -0
- metadata +45 -32
- data/lib/abstract_graph/composition/uniquenamecollection.rb +0 -22
- data/lib/abstract_graph/composition/uniquenamecollection/add.rb +0 -19
- data/lib/abstract_graph/composition/uniquenamecollection/dup.rb +0 -20
- data/lib/abstract_graph/composition/uniquenamecollection/initialize.rb +0 -14
- data/lib/abstract_graph/composition/uniquenamecollection/link.rb +0 -32
- data/lib/abstract_graph/composition/uniquenamecollection/method_missing.rb +0 -14
- data/lib/abstract_graph/composition/uniquenamecollection/rename.rb +0 -28
- data/lib/abstract_graph/composition/vertex/delete.rb +0 -12
- data/spec/abstract_graph/composition/vertex/delete_spec.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTk2OWI3Y2Y4YmU0NDAyNjBkNjI2N2RhMTk2OGY2NjAzM2Y4YmQ5OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTFmYmYwOTFjNzQ3OThlNGU4OTM0MjFkY2MzN2U1MmM5ODQ5YWNjYw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Mzg5OGFkMDY1ZmMwMzFiYjJlMDA5MDljZTljNGE0ZGE1NTU3ZDNlODQ4MTBj
|
10
|
+
Mzc1MTQ1MWY2OGRkOTcwZDE1M2FmZjI1NWQ5NGU2ZjVhODJiMzM3NGE4ZDI5
|
11
|
+
Yzc0N2Y0NDU3YWQzNTRjNmM1MDAzM2YyMjY2ZTExYmMyZGFkODE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Yjk5NWMwMDRkMWM0ZWVkNGM3YmQxZGM5N2I2ZjUwMWZhN2Q4YWMwNzc3YWZj
|
14
|
+
MjIxNGJjOGY1NzU3YTRiN2RhYjc2MWM2MWNjOGVkMDJhMDU3YzVlMWRjNzEx
|
15
|
+
YmY2NmQ3ZTE2ZTFjMWEzNGY5OTAzZjUwMzc2MTdmODEwZmU3ZmU=
|
data/Rakefile
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
3
2
|
|
3
|
+
# Add paths
|
4
|
+
$:.unshift File.expand_path('..', __FILE__)
|
5
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
6
|
+
|
7
|
+
require "lib/abstract_graph"
|
8
|
+
require "bundler/gem_tasks"
|
4
9
|
require "rspec/core/rake_task"
|
5
10
|
|
6
11
|
desc "Run specs"
|
@@ -12,3 +17,8 @@ task :default => :spec
|
|
12
17
|
|
13
18
|
desc "Run tests (same as rake spec)"
|
14
19
|
task :test => :spec
|
20
|
+
|
21
|
+
require "tasks/create_method"
|
22
|
+
require "tasks/list_methods"
|
23
|
+
require "tasks/benchmark"
|
24
|
+
|
data/lib/abstract_graph.rb
CHANGED
@@ -8,6 +8,11 @@ module AbstractGraph
|
|
8
8
|
attr_reader :name
|
9
9
|
attr_accessor :vertices
|
10
10
|
|
11
|
+
# d: Set the name of edge.
|
12
|
+
# a: Throw an ArgumentError if the name is not a string
|
13
|
+
# t: constant
|
14
|
+
# p: name should be string
|
15
|
+
# r: The name
|
11
16
|
def name=(name)
|
12
17
|
raise ArgumentError if name.class != String
|
13
18
|
@name = name
|
@@ -4,6 +4,12 @@ module AbstractGraph
|
|
4
4
|
module Composition
|
5
5
|
class Edge
|
6
6
|
|
7
|
+
# d: Create an edge with a name and two vertices
|
8
|
+
# a: Check if a string is passed, otherwise, the next two must be the vertices
|
9
|
+
# t: constant
|
10
|
+
# p: name if we want to name our edge, otherwise it'll be ""
|
11
|
+
# The next two args are the two vertices that this edge connects
|
12
|
+
# r: Edge object
|
7
13
|
def initialize ( *args )
|
8
14
|
if args[0].class == String
|
9
15
|
@name = args[0]
|
@@ -4,10 +4,13 @@ module AbstractGraph
|
|
4
4
|
module Composition
|
5
5
|
class Edge
|
6
6
|
|
7
|
-
#
|
7
|
+
# d: Check if two edges are covering the same vertices.
|
8
|
+
# a: Compare the object_id, by extracting them and sorting them.
|
9
|
+
# t: constant
|
8
10
|
# p: Edge e is the comparing edge
|
11
|
+
# r: true or false depending on coincident
|
9
12
|
def is_coincident? e
|
10
|
-
return
|
13
|
+
return e.vertices.map{|v| v.object_id}.sort == @vertices.map{|v| v.object_id}.sort
|
11
14
|
end
|
12
15
|
|
13
16
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# required in "abstract_graph/composition"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
|
6
|
+
# public UniqueNameCollection class
|
7
|
+
# Note that the collection of this
|
8
|
+
# class must implement #name
|
9
|
+
class UniqueNameCollection
|
10
|
+
attr_accessor :collection
|
11
|
+
attr_accessor :namespace_ticket
|
12
|
+
@@namespace = {}
|
13
|
+
@@namespace_counter = 0
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "abstract_graph/composition/unique_name_collection/initialize"
|
20
|
+
require "abstract_graph/composition/unique_name_collection/add"
|
21
|
+
require "abstract_graph/composition/unique_name_collection/dup"
|
22
|
+
require "abstract_graph/composition/unique_name_collection/method_missing"
|
23
|
+
require "abstract_graph/composition/unique_name_collection/link"
|
24
|
+
require "abstract_graph/composition/unique_name_collection/rename"
|
25
|
+
require "abstract_graph/composition/unique_name_collection/each"
|
26
|
+
require "abstract_graph/composition/unique_name_collection/ticket"
|
27
|
+
require "abstract_graph/composition/unique_name_collection/delete"
|
28
|
+
require "abstract_graph/composition/unique_name_collection/find"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Adds the object to our UNC.
|
8
|
+
# a: Ensure that our namespace doesn't already have the object name and
|
9
|
+
# then add the object to namespace and collection.
|
10
|
+
# t: constant
|
11
|
+
# p: Object o that implements #name
|
12
|
+
# r: The object o itself
|
13
|
+
def add( o )
|
14
|
+
set = @@namespace[@namespace_ticket.get][0]
|
15
|
+
raise IndexError if set.include? o.name
|
16
|
+
set << o.name
|
17
|
+
@collection[o.name] = o
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Delete the object from the collection
|
8
|
+
# a: Delete the object from the collection and from the nameserver
|
9
|
+
# t: constant
|
10
|
+
# p: name of object we want to delete
|
11
|
+
# r: object that was deleted
|
12
|
+
def delete( name )
|
13
|
+
return nil unless @collection[name]
|
14
|
+
@@namespace[@namespace_ticket.get][0].delete name
|
15
|
+
@collection.delete name
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Deep copies our object.
|
8
|
+
# a: Does a deep copy of the object, in otherwords
|
9
|
+
# copies every object in the collection.
|
10
|
+
# t: |collection|
|
11
|
+
# p:
|
12
|
+
# r: the copy of the UNC
|
13
|
+
def dup
|
14
|
+
other = self.class.new
|
15
|
+
# copy each object in our collection over
|
16
|
+
@collection.each_value do |o|
|
17
|
+
other.add o.dup
|
18
|
+
end
|
19
|
+
other
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Iterate through all objects.
|
8
|
+
# a: Enumerates through every object.
|
9
|
+
# t: constant
|
10
|
+
# p: block that we pass in each object
|
11
|
+
# r: Enumerable if no block, collection if yes block
|
12
|
+
def each( &block )
|
13
|
+
@collection.each_value( &block )
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Finds a stored object given the name.
|
8
|
+
# a: Goes into collection and retrieves based on key.
|
9
|
+
# t: constant
|
10
|
+
# p: name of object
|
11
|
+
# r: object
|
12
|
+
def find(name)
|
13
|
+
@collection[name]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Initializes the UNC.
|
8
|
+
# a: Assign itself a namespace_ticket and start the collection by adding
|
9
|
+
# the namespace a set of names and backreference of tickets
|
10
|
+
# t: constant
|
11
|
+
# p:
|
12
|
+
# r: new UNC
|
13
|
+
def initialize
|
14
|
+
@collection = Hash.new
|
15
|
+
@@namespace_counter += 1
|
16
|
+
@namespace_ticket = Ticket.new(@@namespace_counter)
|
17
|
+
@@namespace[@@namespace_counter] = [Set.new, Set.new([@namespace_ticket])]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Links the UNC so they have unique namespace.
|
8
|
+
# a: check the intersection of namespace so that there's no collision, then
|
9
|
+
# reset the namespace to contain the shared namespaces and update tickets
|
10
|
+
# t: |intersection and size of ticket|
|
11
|
+
# p: UniqueNameCollection unc is the other collection we want to link
|
12
|
+
# r: false if the two collections are not already mutually unique
|
13
|
+
# UNC if it succeeds
|
14
|
+
def link( unc )
|
15
|
+
our_ticket = @namespace_ticket.get
|
16
|
+
other_ticket = unc.namespace_ticket.get
|
17
|
+
our_namespace = @@namespace[our_ticket]
|
18
|
+
other_namespace = @@namespace[other_ticket]
|
19
|
+
|
20
|
+
namespace_intersection = our_namespace[0] & other_namespace[0]
|
21
|
+
return nil unless namespace_intersection.empty?
|
22
|
+
|
23
|
+
# Create the assumption that |our_namespace| >= |other_namespace|
|
24
|
+
if other_namespace[0].size > our_namespace[0].size
|
25
|
+
our_namespace, other_namespace = other_namespace, our_namespace
|
26
|
+
our_ticket, other_ticket = other_ticket, our_ticket
|
27
|
+
end
|
28
|
+
|
29
|
+
# Assume it is fine to link now, add to the larger namespace
|
30
|
+
our_namespace[0].merge other_namespace[0]
|
31
|
+
other_namespace[1].map do |ticket|
|
32
|
+
ticket.set our_ticket
|
33
|
+
end
|
34
|
+
our_namespace[1].merge other_namespace[1]
|
35
|
+
|
36
|
+
@@namespace.delete other_ticket
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Handles everything.
|
8
|
+
# a: Pass all methods into the hash.
|
9
|
+
# t:
|
10
|
+
# p:
|
11
|
+
# r:
|
12
|
+
def method_missing( m, *args, &block )
|
13
|
+
@collection.values.send( m.to_sym, *args, &block )
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: Change the name of a vertex in our graph.
|
8
|
+
# a: Check the namespace otherwise, set collection and add to namespace
|
9
|
+
# t: constant
|
10
|
+
# p: String oldname represents the current vertex's name
|
11
|
+
# String newname represents the new name of our vertex
|
12
|
+
# r: UNC itself
|
13
|
+
def rename( oldname, newname )
|
14
|
+
return nil unless @collection.has_key? oldname
|
15
|
+
|
16
|
+
nameserver = @@namespace[@namespace_ticket.get][0]
|
17
|
+
throw Exception if nameserver.include? newname
|
18
|
+
|
19
|
+
# change the nameserver
|
20
|
+
nameserver.delete oldname
|
21
|
+
nameserver << newname
|
22
|
+
|
23
|
+
# rename the object itself
|
24
|
+
@collection[oldname].name = newname
|
25
|
+
# remap the name
|
26
|
+
@collection[newname] = @collection[oldname]
|
27
|
+
# clear the old name
|
28
|
+
@collection.delete oldname
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
|
7
|
+
# d: This is the ticket for the nameserver in UNC
|
8
|
+
class Ticket
|
9
|
+
attr_accessor :number
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require "abstract_graph/composition/unique_name_collection/ticket/initialize"
|
17
|
+
require "abstract_graph/composition/unique_name_collection/ticket/get"
|
18
|
+
require "abstract_graph/composition/unique_name_collection/ticket/set"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection/ticket"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
class Ticket
|
7
|
+
|
8
|
+
# d: Returns the number
|
9
|
+
# a:
|
10
|
+
# t: constant
|
11
|
+
# p:
|
12
|
+
# r: @number
|
13
|
+
def get
|
14
|
+
@number
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection/ticket"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
class Ticket
|
7
|
+
|
8
|
+
# d: Returns the Ticket object
|
9
|
+
# a: Sets number
|
10
|
+
# t: constant
|
11
|
+
# p: number to initialize with
|
12
|
+
# r: self
|
13
|
+
def initialize( number )
|
14
|
+
@number = number
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# required in "abstract_graph/composition/unique_name_collection/ticket"
|
2
|
+
|
3
|
+
module AbstractGraph
|
4
|
+
module Composition
|
5
|
+
class UniqueNameCollection
|
6
|
+
class Ticket
|
7
|
+
|
8
|
+
# d: Sets the Ticket number.
|
9
|
+
# a: Sets number
|
10
|
+
# t: constant
|
11
|
+
# p: number to set to
|
12
|
+
# r: self
|
13
|
+
def set( number )
|
14
|
+
@number = number
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|