abstract_graph 1.0.0

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.
Files changed (59) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.rdoc +43 -0
  5. data/Rakefile +14 -0
  6. data/abstract_graph.gemspec +22 -0
  7. data/lib/abstract_graph.rb +10 -0
  8. data/lib/abstract_graph/composition.rb +11 -0
  9. data/lib/abstract_graph/composition/edge.rb +21 -0
  10. data/lib/abstract_graph/composition/edge/initialize.rb +18 -0
  11. data/lib/abstract_graph/composition/edge/is_coincident.rb +15 -0
  12. data/lib/abstract_graph/composition/uniquenamecollection.rb +21 -0
  13. data/lib/abstract_graph/composition/uniquenamecollection/add.rb +19 -0
  14. data/lib/abstract_graph/composition/uniquenamecollection/dup.rb +20 -0
  15. data/lib/abstract_graph/composition/uniquenamecollection/initialize.rb +14 -0
  16. data/lib/abstract_graph/composition/uniquenamecollection/link.rb +32 -0
  17. data/lib/abstract_graph/composition/uniquenamecollection/method_missing.rb +14 -0
  18. data/lib/abstract_graph/composition/vertex.rb +21 -0
  19. data/lib/abstract_graph/composition/vertex/delete.rb +12 -0
  20. data/lib/abstract_graph/composition/vertex/initialize.rb +14 -0
  21. data/lib/abstract_graph/graph.rb +25 -0
  22. data/lib/abstract_graph/graph/add_edge.rb +30 -0
  23. data/lib/abstract_graph/graph/add_vertex.rb +16 -0
  24. data/lib/abstract_graph/graph/delete_edge.rb +21 -0
  25. data/lib/abstract_graph/graph/delete_vertex.rb +21 -0
  26. data/lib/abstract_graph/graph/dup.rb +14 -0
  27. data/lib/abstract_graph/graph/has_edge.rb +13 -0
  28. data/lib/abstract_graph/graph/has_vertex.rb +13 -0
  29. data/lib/abstract_graph/graph/initialize.rb +16 -0
  30. data/lib/abstract_graph/version.rb +5 -0
  31. data/spec/abstract_graph/composition/edge/initialize_spec.rb +38 -0
  32. data/spec/abstract_graph/composition/edge/is_coincident_spec.rb +33 -0
  33. data/spec/abstract_graph/composition/edge/name_spec.rb +53 -0
  34. data/spec/abstract_graph/composition/edge/vertices_spec.rb +32 -0
  35. data/spec/abstract_graph/composition/edge_spec.rb +8 -0
  36. data/spec/abstract_graph/composition/uniquenamecollection/add_spec.rb +41 -0
  37. data/spec/abstract_graph/composition/uniquenamecollection/dup_spec.rb +29 -0
  38. data/spec/abstract_graph/composition/uniquenamecollection/initialize_spec.rb +21 -0
  39. data/spec/abstract_graph/composition/uniquenamecollection/link_spec.rb +67 -0
  40. data/spec/abstract_graph/composition/uniquenamecollection/method_missing_spec.rb +50 -0
  41. data/spec/abstract_graph/composition/uniquenamecollection_spec.rb +8 -0
  42. data/spec/abstract_graph/composition/vertex/delete_spec.rb +12 -0
  43. data/spec/abstract_graph/composition/vertex/initialize_spec.rb +45 -0
  44. data/spec/abstract_graph/composition/vertex/name_spec.rb +47 -0
  45. data/spec/abstract_graph/composition/vertex/value_spec.rb +46 -0
  46. data/spec/abstract_graph/composition/vertex_spec.rb +8 -0
  47. data/spec/abstract_graph/graph/add_edge_spec.rb +46 -0
  48. data/spec/abstract_graph/graph/add_vertex_spec.rb +29 -0
  49. data/spec/abstract_graph/graph/delete_edge_spec.rb +56 -0
  50. data/spec/abstract_graph/graph/delete_vertex_spec.rb +48 -0
  51. data/spec/abstract_graph/graph/dup_spec.rb +37 -0
  52. data/spec/abstract_graph/graph/has_edge_spec.rb +31 -0
  53. data/spec/abstract_graph/graph/has_vertex_spec.rb +27 -0
  54. data/spec/abstract_graph/graph/intialize_spec.rb +17 -0
  55. data/spec/abstract_graph/graph_spec.rb +6 -0
  56. data/spec/abstract_graph_spec.rb +7 -0
  57. data/spec/dummy_helper.rb +4 -0
  58. data/spec/spec_helper.rb +11 -0
  59. metadata +149 -0
@@ -0,0 +1,18 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in abstract_graph.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Austin Lee ~D4L
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ = This is AbstractGraph.
2
+
3
+ -n a graph is an abstract representation of a set of objects where pairs of objects are connected. Not to be confused with the 2 dimensional plane that plots correlation
4
+
5
+ == How to Install
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'abstract_graph'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install abstract_graph
18
+
19
+ Or you can compile the project yourself:
20
+
21
+ $ git clone https://github.com/D4L/abstractGraph.git
22
+ $ rake build
23
+
24
+ == Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ == Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
35
+
36
+ == Authors
37
+
38
+ Austin.L <b>~D4L</b>
39
+
40
+
41
+
42
+ ---
43
+ noli umquam oblivisci: cogito ergo sum
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.rspec_opts = %w(-fs --color)
9
+ end
10
+
11
+ task :default => :spec
12
+
13
+ desc "Run tests (same as rake spec)"
14
+ task :test => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/abstract_graph/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "abstract_graph"
6
+ gem.version = AbstractGraph::VERSION
7
+
8
+ gem.authors = ["Austin Lee ~D4L"]
9
+ gem.email = ["Austin.Lee.D4L@gmail.com"]
10
+ gem.description = %q{Abstract Graph is a graphing library that can create
11
+ mathematical graphs and perform operatations on them.}
12
+ gem.summary = %q{Mathmatical graph analysis software.}
13
+ gem.homepage = "https://github.com/D4L/abstractGraph"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency 'rspec', '~> 2.5'
22
+ end
@@ -0,0 +1,10 @@
1
+ require "abstract_graph/version"
2
+ require "abstract_graph/composition"
3
+ require "abstract_graph/graph"
4
+
5
+ module AbstractGraph
6
+
7
+ def self.version_string
8
+ "AbstractGraph version #{AbstractGraph::VERSION}"
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # required in "abstract_graph"
2
+
3
+ require "abstract_graph/composition/vertex"
4
+ require "abstract_graph/composition/edge"
5
+ require "abstract_graph/composition/uniquenamecollection"
6
+
7
+ module AbstractGraph
8
+ module Composition
9
+
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ # required in "abstract_graph/composition"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+
6
+ # public Edge class
7
+ class Edge
8
+ attr_reader :name
9
+ attr_accessor :vertices
10
+
11
+ def name=(name)
12
+ raise ArgumentError if name.class != String
13
+ @name = name
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+
20
+ require "abstract_graph/composition/edge/initialize"
21
+ require "abstract_graph/composition/edge/is_coincident"
@@ -0,0 +1,18 @@
1
+ # required in "abstract_graph/composition/edge"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class Edge
6
+
7
+ def initialize ( *args )
8
+ if args[0].class == String
9
+ @name = args[0]
10
+ else
11
+ @name = ""
12
+ end
13
+ @vertices = args[-2, 2]
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # required in "abstract_graph/composition/edge"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class Edge
6
+
7
+ # returns whether or not e covers the same two vertices
8
+ # p: Edge e is the comparing edge
9
+ def is_coincident? e
10
+ return ( ( e.vertices | @vertices ) - ( e.vertices & @vertices ) ).empty?
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
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 :otherUnique
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ require "abstract_graph/composition/uniquenamecollection/initialize"
18
+ require "abstract_graph/composition/uniquenamecollection/add"
19
+ require "abstract_graph/composition/uniquenamecollection/dup"
20
+ require "abstract_graph/composition/uniquenamecollection/method_missing"
21
+ require "abstract_graph/composition/uniquenamecollection/link"
@@ -0,0 +1,19 @@
1
+ # required in "abstract_graph/composition/uniquenamecollection"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class UniqueNameCollection
6
+
7
+ # adds an object o into the collection
8
+ # p: Object o that implements #name
9
+ def add( o )
10
+ # note that otherUnique includes ourself
11
+ @otherUnique.each do |unc|
12
+ raise IndexError if unc[o.name]
13
+ end
14
+ @collection[o.name] = o
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # required in "abstract_graph/composition/uniquenamecollection"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class UniqueNameCollection
6
+
7
+ # does a deep copy of the object, in otherwords
8
+ # copies every object in the collection
9
+ def dup
10
+ other = UniqueNameCollection.new
11
+ # copy each object in our collection over
12
+ @collection.each_value do |o|
13
+ other.add o
14
+ end
15
+ other
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # required in "abstract_graph/composition/uniquenamecollection"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class UniqueNameCollection
6
+
7
+ def initialize
8
+ @collection = Hash.new
9
+ @otherUnique = [self]
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ # required in "abstract_graph/composition/uniquenamecollection"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class UniqueNameCollection
6
+
7
+ # links two collections together so that their names
8
+ # will be mutually unique
9
+ # p: UniqueNameCollection unc is the other collection
10
+ # we want to link
11
+ # r: false if the two collections are not already
12
+ # mutually unique
13
+ def link( unc )
14
+ # note that either otherUnique may be alot
15
+ combinedUnique = @otherUnique | unc.otherUnique
16
+
17
+ # check if there are already any duplicates
18
+ allNames = []
19
+ combinedUnique.each do |tunc|
20
+ return nil if not ( tunc.keys & allNames ).empty?
21
+ allNames |= tunc.keys
22
+ end
23
+
24
+ # set each one to have the same uniquespace
25
+ combinedUnique.each do |tunc|
26
+ tunc.otherUnique = combinedUnique
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ # required in "abstract_graph/composition/uniquenamecollection"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class UniqueNameCollection
6
+
7
+ # pass all methods into the hash
8
+ def method_missing( m, *args, &block )
9
+ @collection.send( m.to_sym, *args, &block )
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # required in "abstract_graph/composition"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+
6
+ # public Vertex class
7
+ class Vertex
8
+ attr_reader :name
9
+ attr_accessor :value
10
+
11
+ def name=(name)
12
+ raise ArgumentError if name.class != String
13
+ @name = name
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+
20
+ require "abstract_graph/composition/vertex/initialize"
21
+ require "abstract_graph/composition/vertex/delete"
@@ -0,0 +1,12 @@
1
+ # required in "abstract_graph/composition/vertex"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class Vertex
6
+
7
+ def delete
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # required in "abstract_graph/composition/vertex"
2
+
3
+ module AbstractGraph
4
+ module Composition
5
+ class Vertex
6
+
7
+ def initialize (name="", value=nil)
8
+ @name = name
9
+ @value = value
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ # required in "abstract_graph"
2
+
3
+ module AbstractGraph
4
+
5
+ # public Graph class
6
+ class Graph
7
+
8
+ # Add the vertex and edge classes
9
+ include Composition
10
+
11
+ attr_accessor :vertices
12
+ attr_accessor :edges
13
+
14
+ end
15
+
16
+ end
17
+
18
+ require "abstract_graph/graph/initialize"
19
+ require "abstract_graph/graph/add_vertex"
20
+ require "abstract_graph/graph/has_vertex"
21
+ require "abstract_graph/graph/dup"
22
+ require "abstract_graph/graph/delete_vertex"
23
+ require "abstract_graph/graph/add_edge"
24
+ require "abstract_graph/graph/has_edge"
25
+ require "abstract_graph/graph/delete_edge"
@@ -0,0 +1,30 @@
1
+ # required in "abstract_graph/graph"
2
+
3
+ module AbstractGraph
4
+ class Graph
5
+
6
+ # add a vertex named s to the graph joining
7
+ # the vertices named v1 and v2
8
+ # p: String s represents name
9
+ # Vertex name v1 and v2 are the two vertices
10
+ # r: errors when v1, v2 doesn't exist, loop, or multiple edge
11
+ def add_edge( s, v1, v2 )
12
+ v1 = @vertices[v1] or return nil
13
+ v2 = @vertices[v2] or return nil
14
+
15
+ raise Exception if v1 == v2
16
+
17
+ # create the edge
18
+ edge = Edge.new s, v1, v2
19
+
20
+ # check if it's an multiple edge
21
+ @edges.each_value do |e|
22
+ raise Exception if e.is_coincident? edge
23
+ end
24
+
25
+ @edges.add edge
26
+ self
27
+ end
28
+
29
+ end
30
+ end