topology 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c25fec9db387d3d5dc8b098de24d8e426258de4
4
+ data.tar.gz: 23e7013a2523638fbe065ffcaf86614e98acff74
5
+ SHA512:
6
+ metadata.gz: f42eba565b1f0cd415c55a779c58cbb567c665389a7ebd29c63755cf5a3f8adbd7f6dd8a3af126798fc74f70b59aa85cd6c5f2073202ccf74416197e5f63edc4
7
+ data.tar.gz: dd46a88b6665e6cbf02870c1bec4342f9f6a0ab57825cf0acad26fe137e8d3b56599ee7d72653a3635d56451026aca27f0014ce8b46ecbd194664c75ead69da6
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry'
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 gogotanaka
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,33 @@
1
+ # Topology
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'topology'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install Topology
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ Topology.new Set[Set[1], Set[2]]
24
+ => #<Topology:0x007f8074132c60 @sos=#<Set: {#<Set: {1}>, #<Set: {2}>, #<Set: {1, 2}>, #<Set: {}>}>>
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/Topology/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
9
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "topology"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["gogotanaka"]
9
+ spec.email = ["mail@tanakakazuki.com"]
10
+ spec.summary = %q{topology.}
11
+ spec.description = %q{topology.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest"
23
+ end
@@ -0,0 +1,72 @@
1
+ require "pry"
2
+ require "set"
3
+ class Topology
4
+ attr_accessor :sos # Set of set
5
+
6
+ def initialize(set)
7
+ fail "sould be set of set" unless set.sos?
8
+ @sos = if set.top? set.flatten #TODO: set of set of set
9
+ set.flatten
10
+ else
11
+ set << set.flatten
12
+ set2 = set.dup
13
+ set3 = set.dup
14
+ set.each do |e|
15
+ set2.delete(e)
16
+ set2.each { |f| set3 << (e & f) }
17
+ end
18
+ set3
19
+ end
20
+ end
21
+
22
+ def top?(x)
23
+ @sos.top?(x)
24
+ end
25
+ end
26
+
27
+ class TopologySpace < Struct.new(:set, :top)
28
+ end
29
+
30
+ class Object
31
+ def set?
32
+ is_a?(Set)
33
+ end
34
+ end
35
+
36
+ class Set
37
+ def power
38
+ (0 .. 2 ** length - 1).map { |n|
39
+ select.with_index { |_, i| (n >> i) & 1 == 1 }.to_set
40
+ }.to_set
41
+ end
42
+
43
+ def sos?
44
+ all?(&:set?)
45
+ end
46
+
47
+ def top?(x)
48
+ sos? && subset?(x.power) && axiom1? && axiom2? && axiom3?(x)
49
+ end
50
+
51
+ def axiom1?
52
+ sos2 = dup
53
+ all? do |e|
54
+ sos2.delete(e)
55
+ sos2.all? { |f| _?(e | f) }
56
+ end
57
+ end
58
+
59
+ def axiom2?
60
+ sos2 = dup
61
+ all? do |e|
62
+ sos2.delete(e)
63
+ sos2.all? { |f| _?(e & f) }
64
+ end
65
+ end
66
+
67
+ def axiom3?(x)
68
+ _?(Set[]) && _?(x)
69
+ end
70
+
71
+ alias :_? :include?
72
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'topology'
3
+
4
+ require 'minitest/autorun'
@@ -0,0 +1,30 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestTopology < MiniTest::Unit::TestCase
4
+ def setup
5
+ @s2 = Set[1, 2]
6
+ @s3 = Set[1, 2, 3]
7
+ @top2 = @s2.power
8
+ @top = Topology.new Set[Set[2], Set[1]]
9
+ end
10
+
11
+ def test_power
12
+ assert_equal(@s2.power, Set[Set[], Set[1], Set[2], Set[1, 2]])
13
+ assert_equal(
14
+ @s3.power,
15
+ Set[Set[], Set[1], Set[2], Set[3], Set[1, 2], Set[2, 3], Set[3, 1], Set[1, 2, 3]]
16
+ )
17
+ end
18
+
19
+ def test_sos?
20
+ assert @s2.power.sos?
21
+ end
22
+
23
+ def test_top?
24
+ assert @top2.axiom1?
25
+ assert @top2.axiom2?
26
+ assert @top2.axiom3?(@s2)
27
+ assert @top2.top? @s2
28
+ assert @top.top? Set[1,2]
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: topology
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - gogotanaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: topology.
56
+ email:
57
+ - mail@tanakakazuki.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - Topology.gemspec
69
+ - lib/Topology.rb
70
+ - test/minitest_helper.rb
71
+ - test/test_Topology.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: topology.
96
+ test_files:
97
+ - test/minitest_helper.rb
98
+ - test/test_Topology.rb