rubylabs 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/data/arrays/cars.txt +50 -0
- data/data/arrays/colors.txt +64 -0
- data/data/arrays/fruit.txt +45 -0
- data/data/arrays/wordlist.txt +210653 -0
- data/data/huffman/aafreq.txt +20 -0
- data/data/huffman/hacodes.txt +35 -0
- data/data/huffman/hafreq.txt +16 -0
- data/data/huffman/hvfreq.txt +5 -0
- data/data/spheres/fourbody.txt +6 -0
- data/data/spheres/solarsystem.txt +17 -0
- data/data/spheres/urey.txt +5 -0
- data/data/tsp/pac10.txt +55 -0
- data/data/tsp/test.txt +2 -0
- data/lib/tsplab.rb +68 -31
- metadata +14 -2
- data/data/solar.dat +0 -36501
@@ -0,0 +1,35 @@
|
|
1
|
+
# The binary numbers are Hawaiian words, encoded with a Huffman code based on the
|
2
|
+
# letter frequencies in hafreq.txt. The word next to a code is the English translation
|
3
|
+
# of the Hawaiian word -- after decoding a string of bits look for the word in a
|
4
|
+
# Hawaiian-English dictionary to see if the decoding is correct.
|
5
|
+
|
6
|
+
011010 rain
|
7
|
+
001010 sugarcane
|
8
|
+
0011111 carving
|
9
|
+
110011010 night
|
10
|
+
0011000110 duck
|
11
|
+
1100001010 chicken
|
12
|
+
1001110110 swordfish
|
13
|
+
111001101111 large
|
14
|
+
001010111010 leeward
|
15
|
+
110000100010110 island
|
16
|
+
1100001010111010 ocean
|
17
|
+
0001110101111101 octopus
|
18
|
+
0000101110101111 porch
|
19
|
+
1110110111101101 goose
|
20
|
+
0010110110000110 teacher
|
21
|
+
100000111101111111 royalty
|
22
|
+
00110000110001101111 beach
|
23
|
+
11000100001100000010 thankyou
|
24
|
+
11000100011011101111 wind
|
25
|
+
0001010100000010000110 friend
|
26
|
+
0011000110000111111000110 morning
|
27
|
+
0001100110011101000001111 happy
|
28
|
+
110001000110000111110011111 year
|
29
|
+
00010100111010001111111001110 hospitality
|
30
|
+
1100010000011110001111111101111 visitor
|
31
|
+
11000100010110100001111111101101 mother
|
32
|
+
00011000001000110000111110011111 pineapple
|
33
|
+
110001101111011010001011011101101 imp
|
34
|
+
0011011110011011000100001111111101101 daughter
|
35
|
+
000101101100001100001011011000011011100110001011011100110001011010110011011010011110 triggerfish
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Solar system data, downloaded from JPL, from ephemeris created for Jan 1, 1970
|
2
|
+
# Format for each line:
|
3
|
+
# name, mass, posx, posy, posz, velx, vely, velz, dia, color
|
4
|
+
# where mass is in grams; posx, posy, and posz are the 3d position vector (in meters)
|
5
|
+
# and velx, vely, and velz is the 3D velocity vector (m/sec). The last two items are
|
6
|
+
# for the visualization -- radius (in pixels) and color for drawing the body.
|
7
|
+
|
8
|
+
sun 1.9891E+30 0 0 0 0 0 0 10 #ffff00
|
9
|
+
mercury 3.302E+23 3.83713E+10 2.877025E+10 -1.175808E+09 -38787.67 41093.05 6918.461 3 #ffcc66
|
10
|
+
venus 4.8685E+24 -5.377313E+09 -1.085956E+11 -1.164748E+09 34741.48 -1865.747 -2031.506 5 #800080
|
11
|
+
earth 5.9736E+24 -2.700743E+10 1.446007E+11 9686451 -29770.44 -5568.042 0.3961261 5 #0000ff
|
12
|
+
mars 6.4185E+23 1.983825E+11 7.422924E+10 -3.334841E+09 -7557.626 24761.27 704.7457 4 #ff0000
|
13
|
+
jupiter 1.89813E+27 -7.496502E+11 -3.201711E+11 1.811155E+10 4982.522 -11417.83 -64.66531 7 #ffffbf
|
14
|
+
saturn 5.68319E+26 1.082806E+12 8.510841E+11 -5.793461E+10 -6487.118 7565.952 125.4422 6 #0080ff
|
15
|
+
uranus 8.68103E+25 -2.724616E+12 -2.894003E+11 3.428801E+10 671.3469 -7099.093 -35.04028 5 #008080
|
16
|
+
neptune 1.0241E+26 -2.328072E+12 -3.891086E+12 1.337436E+11 4633.961 -2767.423 -49.57268 5 #004080
|
17
|
+
pluto 1.314E+22 -4.551135E+12 3.175277E+11 1.282177E+12 635.998 -5762.115 440.8821 2 #dddddd
|
data/data/tsp/pac10.txt
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
% Driving distances (in minutes) between Pac-10 stadiums
|
2
|
+
|
3
|
+
Seattle Pullman 320
|
4
|
+
Seattle Corvallis 317
|
5
|
+
Seattle Eugene 338
|
6
|
+
Seattle Berkeley 863
|
7
|
+
Seattle Stanford 914
|
8
|
+
Seattle Pasadena 1190
|
9
|
+
Seattle Los_Angeles 1190
|
10
|
+
Seattle Tempe 1620
|
11
|
+
Seattle Tucson 1800
|
12
|
+
|
13
|
+
Pullman Corvallis 470
|
14
|
+
Pullman Eugene 492
|
15
|
+
Pullman Berkeley 1070
|
16
|
+
Pullman Stanford 1123
|
17
|
+
Pullman Pasadena 1437
|
18
|
+
Pullman Los_Angeles 1437
|
19
|
+
Pullman Tempe 1560
|
20
|
+
Pullman Tucson 1680
|
21
|
+
|
22
|
+
Corvallis Eugene 55
|
23
|
+
Corvallis Berkeley 572
|
24
|
+
Corvallis Stanford 624
|
25
|
+
Corvallis Pasadena 898
|
26
|
+
Corvallis Los_Angeles 899
|
27
|
+
Corvallis Tempe 1268
|
28
|
+
Corvallis Tucson 1379
|
29
|
+
|
30
|
+
Eugene Berkeley 526
|
31
|
+
Eugene Stanford 578
|
32
|
+
Eugene Pasadena 852
|
33
|
+
Eugene Los_Angeles 852
|
34
|
+
Eugene Tempe 1222
|
35
|
+
Eugene Tucson 1332
|
36
|
+
|
37
|
+
Berkeley Stanford 58
|
38
|
+
Berkeley Pasadena 369
|
39
|
+
Berkeley Los_Angeles 371
|
40
|
+
Berkeley Tempe 740
|
41
|
+
Berkeley Tucson 857
|
42
|
+
|
43
|
+
Stanford Pasadena 370
|
44
|
+
Stanford Los_Angeles 371
|
45
|
+
Stanford Tempe 740
|
46
|
+
Stanford Tucson 858
|
47
|
+
|
48
|
+
Pasadena Los_Angeles 16
|
49
|
+
Pasadena Tempe 373
|
50
|
+
Pasadena Tucson 483
|
51
|
+
|
52
|
+
Los_Angeles Tempe 375
|
53
|
+
Los_Angeles Tucson 486
|
54
|
+
|
55
|
+
Tempe Tucson 122
|
data/data/tsp/test.txt
ADDED
data/lib/tsplab.rb
CHANGED
@@ -48,43 +48,28 @@ city is assigned a one-letter key.
|
|
48
48
|
=end
|
49
49
|
|
50
50
|
def initialize(matrix)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@matrix = Hash.new
|
58
|
-
|
59
|
-
File.open(matrixfilename).each do |line|
|
60
|
-
next if line.chomp.length == 0
|
61
|
-
rec = line.split(/\t/)
|
62
|
-
i = getKey(rec[0])
|
63
|
-
j = getKey(rec[1])
|
64
|
-
dist = ((24 * getValue(rec[2]) + getValue(rec[3])) * 60) + getValue(rec[4])
|
65
|
-
assign(i,j,dist)
|
66
|
-
assign(j,i,dist)
|
67
|
-
end
|
68
|
-
|
69
|
-
@cities = @cities.invert # from now on a map from key to name string
|
70
|
-
|
71
|
-
errs = 0
|
72
|
-
(?A..@key-1).each do |i|
|
73
|
-
(i+1..@key-1).each do |j|
|
74
|
-
unless @matrix[i][j] && @matrix[j][i]
|
75
|
-
errs += 1
|
76
|
-
puts "CityList.new: missing distance between #{@cities[i]} and #{@cities[j]}"
|
77
|
-
end
|
78
|
-
end
|
51
|
+
if matrix.class == String || matrix.class == Symbol
|
52
|
+
read_file(matrix)
|
53
|
+
elsif matrix.class == Array
|
54
|
+
make_map(matrix)
|
55
|
+
else
|
56
|
+
raise "CityList: parameter must be a file name or array of points"
|
79
57
|
end
|
80
|
-
raise "CityList.new: errors in input file" if errs > 0
|
81
|
-
|
82
58
|
end
|
83
59
|
|
84
60
|
def inspect()
|
85
61
|
n = @matrix.length
|
86
62
|
return sprintf "TSPLab::CityList (%d x %d)", n, n-1
|
87
63
|
end
|
64
|
+
|
65
|
+
def dump
|
66
|
+
(?A..@key-1).each do |i|
|
67
|
+
(i+1..@key-1).each do |j|
|
68
|
+
printf "%s %s %d\n", @cities[i], @cities[j], @matrix[i][j]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
return true
|
72
|
+
end
|
88
73
|
|
89
74
|
def size()
|
90
75
|
return @key - ?A
|
@@ -116,6 +101,50 @@ city is assigned a one-letter key.
|
|
116
101
|
# get a time value from an input line, save a distance
|
117
102
|
|
118
103
|
private
|
104
|
+
|
105
|
+
def read_file(fn)
|
106
|
+
matrixfilename = fn.to_s + ".txt"
|
107
|
+
matrixfilename = File.join(@@dataDirectory, matrixfilename)
|
108
|
+
raise "Matrix not found: #{matrixfilename}" unless File.exists?(matrixfilename)
|
109
|
+
|
110
|
+
@key = ?A
|
111
|
+
@cities = Hash.new # initially a map from name string to one-letter key
|
112
|
+
@matrix = Hash.new
|
113
|
+
|
114
|
+
File.open(matrixfilename).each do |line|
|
115
|
+
next if line.chomp.length == 0
|
116
|
+
next if line[0] == ?%
|
117
|
+
rec = line.split
|
118
|
+
i = getKey(rec[0])
|
119
|
+
j = getKey(rec[1])
|
120
|
+
dist = rec[2].to_i
|
121
|
+
assign(i,j,dist)
|
122
|
+
assign(j,i,dist)
|
123
|
+
end
|
124
|
+
|
125
|
+
@cities = @cities.invert # from now on a map from key to name string
|
126
|
+
|
127
|
+
errs = 0
|
128
|
+
(?A..@key-1).each do |i|
|
129
|
+
(i+1..@key-1).each do |j|
|
130
|
+
unless @matrix[i][j] && @matrix[j][i]
|
131
|
+
errs += 1
|
132
|
+
puts "CityList.new: missing distance between #{@cities[i]} and #{@cities[j]}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
raise "CityList.new: errors in input file" if errs > 0
|
137
|
+
end
|
138
|
+
|
139
|
+
def make_map(a)
|
140
|
+
@key = ?A + a.length - 1
|
141
|
+
@cities = Hash.new
|
142
|
+
@matrix = Hash.new
|
143
|
+
for i in 0...a.length
|
144
|
+
for j in i...a.length
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
119
148
|
|
120
149
|
def getKey(s)
|
121
150
|
if @cities[s] == nil
|
@@ -387,7 +416,15 @@ inherited from a parent, and incremented whenever a mutation or crossover is app
|
|
387
416
|
|
388
417
|
return best
|
389
418
|
end
|
390
|
-
|
419
|
+
|
420
|
+
# Make a random set of n cities on a 1000 x 1000 grid
|
421
|
+
|
422
|
+
def random_cities(n)
|
423
|
+
a = Array.new
|
424
|
+
n.times { x = rand(1000); y = rand(1000); a << [x,y] }
|
425
|
+
return a
|
426
|
+
end
|
427
|
+
|
391
428
|
def checkout(matrix, filename = nil)
|
392
429
|
matrixfilename = matrix.to_s + ".txt"
|
393
430
|
matrixfilename = File.join(@@dataDirectory, matrixfilename)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubylabs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- conery
|
@@ -39,7 +39,15 @@ files:
|
|
39
39
|
- bin/statistics2-0.53/statistics2.rb
|
40
40
|
- bin/statistics2-0.53/t-inv.rb
|
41
41
|
- bin/statistics2.rb
|
42
|
+
- data/arrays/cars.txt
|
43
|
+
- data/arrays/colors.txt
|
44
|
+
- data/arrays/fruit.txt
|
45
|
+
- data/arrays/wordlist.txt
|
42
46
|
- data/eliza/doctor.txt
|
47
|
+
- data/huffman/aafreq.txt
|
48
|
+
- data/huffman/hacodes.txt
|
49
|
+
- data/huffman/hafreq.txt
|
50
|
+
- data/huffman/hvfreq.txt
|
43
51
|
- data/mars/chang1.txt
|
44
52
|
- data/mars/dwarf.txt
|
45
53
|
- data/mars/ferret.txt
|
@@ -53,7 +61,11 @@ files:
|
|
53
61
|
- data/mars/test_hello.txt
|
54
62
|
- data/mars/test_mult.txt
|
55
63
|
- data/mars/test_threads.txt
|
56
|
-
- data/
|
64
|
+
- data/spheres/fourbody.txt
|
65
|
+
- data/spheres/solarsystem.txt
|
66
|
+
- data/spheres/urey.txt
|
67
|
+
- data/tsp/pac10.txt
|
68
|
+
- data/tsp/test.txt
|
57
69
|
- lib/bitlab.rb
|
58
70
|
- lib/elizalab.rb
|
59
71
|
- lib/encryptionlab.rb
|