simplicial_complex 0.0.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 +7 -0
- data/lib/simplicial_complex.rb +4 -0
- data/lib/simplicial_complex/complex.rb +55 -0
- data/lib/simplicial_complex/simplex.rb +42 -0
- data/lib/simplicial_complex/vertex.rb +13 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e4dd604ab725c456c8c0bf34406bd425bc4b7a510ab7e4169fb278eae237209
|
4
|
+
data.tar.gz: 58595482625eba00fa6547d068c1b914d9a3b0c0b38e26d82f8d147da405801f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aec2acf720862645e1d88507db8365ef2a46a3e0eda3c4fbf869aeca73b44b4b442e83c6d27a1b356313de4ec5c9d082a16f3de68fe6af0f12dee77c57313489
|
7
|
+
data.tar.gz: 99d9c0d3d2e057302acf5c4ab1520f4835086b3d000d5ee2469b0c0840b90020ca807e81aee894ff0f87c0089102caa541f77b3de49de43946cb7bacec6f0d73
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module SimplicialComplex
|
2
|
+
class Complex
|
3
|
+
def initialize
|
4
|
+
@simplices = Array.new
|
5
|
+
end
|
6
|
+
|
7
|
+
# Adds a simplex to the complex
|
8
|
+
def add_simplex(simplex)
|
9
|
+
(0..simplex.dim).each do |d|
|
10
|
+
simplex.faces(d).each do |face|
|
11
|
+
@simplices << face unless @simplices.include?(face)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Removes a simplex from the complex
|
17
|
+
def remove_simplex(simplex)
|
18
|
+
@simplices.delete(simplex)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Computes the dimension of the complex
|
22
|
+
def dim
|
23
|
+
@simplices.map {|simplex| simplex.dim}.max
|
24
|
+
end
|
25
|
+
|
26
|
+
# Computes the simplices of certain dimension
|
27
|
+
def simplices(dim)
|
28
|
+
simplices = Array.new
|
29
|
+
@simplices.each do |simplex|
|
30
|
+
simplices << simplex if simplex.dim == dim
|
31
|
+
end
|
32
|
+
simplices
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Outputs the vertices
|
37
|
+
def vertices
|
38
|
+
simplices(0).map {|simplex| simplex.vertices[0]}
|
39
|
+
end
|
40
|
+
|
41
|
+
# Outputs the star of a vertex
|
42
|
+
def star(vertex)
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
# Computes the dim-Betti of the complex
|
47
|
+
def betti(dim)
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_json(*args)
|
52
|
+
{dim: dim, simplices: @simplices}.to_json(*args)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Concrete class for a Simplex
|
2
|
+
module SimplicialComplex
|
3
|
+
class Simplex
|
4
|
+
attr_reader :dim, :vertices
|
5
|
+
|
6
|
+
# Constructor method
|
7
|
+
def initialize(dim, vertices = nil)
|
8
|
+
@dim = dim
|
9
|
+
@vertices = vertices || Array.new(@dim + 1, Vertex.new(nil))
|
10
|
+
end
|
11
|
+
|
12
|
+
def face?(other)
|
13
|
+
@vertices.to_set <= other.vertices.to_set
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
@vertices.to_set == other.vertices.to_set
|
18
|
+
end
|
19
|
+
|
20
|
+
# Computes the faces of dimension dim
|
21
|
+
def faces(dim = @dim -1)
|
22
|
+
faces = Array.new
|
23
|
+
|
24
|
+
if dim < 0 || dim > @dim
|
25
|
+
puts 'Faces of this dimension do not exist.'
|
26
|
+
|
27
|
+
elsif dim == @dim
|
28
|
+
faces << self
|
29
|
+
|
30
|
+
else
|
31
|
+
@vertices.combination(dim+1) do |combination|
|
32
|
+
faces << Simplex.new(dim, combination)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
faces
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_json(*args)
|
39
|
+
{dim: @dim, vertices: @vertices}.to_json(*args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplicial_complex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sushovan Majhi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simplicial Complex
|
14
|
+
email: sushovan.majhi08@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/simplicial_complex.rb
|
20
|
+
- lib/simplicial_complex/complex.rb
|
21
|
+
- lib/simplicial_complex/simplex.rb
|
22
|
+
- lib/simplicial_complex/vertex.rb
|
23
|
+
homepage: http://rubygems.org/gems/simplicial_complex
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.7.6
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: This is a gem to manipulate simplicial complexes
|
47
|
+
test_files: []
|