-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomponents.py
More file actions
726 lines (620 loc) · 18.2 KB
/
components.py
File metadata and controls
726 lines (620 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
import unicodedata
class UnicodeIcons:
unicode_dictionary = {} # Dictionary of unicode characters and their names all ever used
other_icon_dictionary = {} # Dictionary of other icons and their names
# Maybe add fonts to dictionary that include that unicode character or icon for each unicode character/icon
# Should probably index by unicode character/other icon codepoint and return the names and font names
def __init__(self):
self.instance_set = self.addInstanceSet()
def addInstanceSet(self, instance_set={}):
#Dictionary that can have self defined display state names for unicode characters
#Returns a dictionary for each unicode character/icons used with an instance display state name
return instance_set #Idk
def addInstanceItem(self, name, instance_item):
self.unicode_dictionary[name] = instance_item
self.other_icon_dictionary[name] = instance_item
self.instance_set[name] = instance_item
def addUnicodeItem(self, name, unicode_char):
self.unicode_dictionary[name] = unicode_char
self.other_icon_dictionary[name] = unicode_char
def addIcon(self, name, icon):
self.unicode_dictionary[name] = icon
self.other_icon_dictionary[name] = icon
def returnAllIcons(self):
return self.unicode_dictionary
def increment_string(stri):
strings = ""
num = ""
inc = 0
for i in range(len(stri)):
if (stri[i].isdigit()):
num = num + stri[i]
else:
strings += stri[i]
if(num == ""):
print("No num found in: ", stri)
return strings
else:
inc = int(num) + 1
fin = strings + str(inc)
return fin
def make_prime(stri):
strings = ""
num = ""
for i in range(len(stri)):
if (stri[i].isdigit()):
num = num+ stri[i]
else:
strings += stri[i]
strings = strings + "'"
if(num == ""):
return strings
fin = strings + num
return fin
def check_is_prime(label):
if "'" in label:
return True
else: return False
def split_prime_label(label):
if "'" in label:
split_label = label.split("'")
split_label[1] = int(split_label[1])
print(split_label)
return split_label
def split_nonprime_label(label):
if "'" in label:
pass
else:
split_label = []
split_label.append(label[0])
split_label.append(label[1:])
if len(split_label) > 1:
split_label[1] = int(split_label[1])
print(split_label)
return split_label
def split_label_pnp(label):
split_label = []
if label == "S":
pass
elif "'" in label:
split_label = label.split("'")
split_label[1] = int(split_label[1])
else:
split_label.append(label[0])
split_num = label[1:]
split_label.append(int(split_num))
return split_label
def transition_to_forward(label):
new_label = "F" + label[1:]
return new_label
def transition_to_backward(label):
if not("B'" in label):
new_label = "B" + label[1:]
return new_label
def check_nums_same(labelA, labelB):
split_labelA = split_label_pnp(labelA)
split_labelB = split_label_pnp(labelB)
if split_labelA[1] == split_labelB[1]:
return True
else:
return False
def check_A_greater(labelA, labelB):
split_labelA = split_label_pnp(labelA)
split_labelB = split_label_pnp(labelB)
if split_labelA[1] > split_labelB[1]:
return True
else:
return False
def check_A_less(labelA, labelB):
split_labelA = split_label_pnp(labelA)
split_labelB = split_label_pnp(labelB)
if split_labelA[1] < split_labelB[1]:
return True
else:
return False
# States Tests
def states_test_14(states):
#Hard Coded for N = 14
st = []
st.append("S")
st.append("B0")
st.append("B'0")
st.append("F0")
# 1s
st.append("B1")
st.append("F1")
st.append("F'1")
# 2s
st.append("B2")
st.append("F2")
st.append("F'2")
# 3's
st.append("B3")
# Rs
st.append("R3")
st.append("R'3")
st.append("R2")
st.append("R'2")
st.append("R'0")
passes = []
missing = st.copy()
failures = []
for i in range(len(states)):
if states[i] in st:
passes.append(states[i])
missing.remove(states[i])
elif not(states[i] in st):
failures.append(states[i])
print("Number Passed: ", len(passes), "Out of: ", len(st))
for p in passes:
print("Passed: ", p)
print("Number Failed: ", len(failures), "Out of: ", len(st))
for p in failures:
print("Failed: ", p)
print("Number Missing: ", len(missing), "Out of: ", len(st))
for p in missing:
print("Missing: ", p)
def states_test_27(states):
#Hard Coded for N = 27
st = []
st.append("S")
st.append("B0")
st.append("B'0")
st.append("F0")
# 1s
st.append("B1")
st.append("F1")
st.append("F'1")
# 2s
st.append("B2")
st.append("F2")
st.append("F'2")
# 3's
st.append("B3")
st.append("F3")
st.append("F'3")
# 4's
st.append("B4")
# Rs
st.append("R4")
st.append("R'4")
st.append("R3")
st.append("R'3")
st.append("R1")
st.append("R'1")
passes = []
missing = st.copy()
failures = []
for i in range(len(states)):
if states[i] in st:
passes.append(states[i])
missing.remove(states[i])
elif not(states[i] in st):
failures.append(states[i])
print("Number Passed: ", len(passes), "Out of: ", len(st))
for p in passes:
print("Passed: ", p)
print("Number Failed: ", len(failures), "Out of: ", len(st))
for p in failures:
print("Failed: ", p)
print("Number Missing: ", len(missing), "Out of: ", len(st))
for p in missing:
print("Missing: ", p)
def affinities_test_14(aff_dict):
#Hard Coded for N = 14
st = []
rs = []
pr = []
npr = []
# S and 0s
st.append("S")
st.append("B0")
npr.append("B0")
st.append("B'0")
pr.append("B'0")
st.append("F0")
npr.append("F0")
# 1s
st.append("B1")
npr.append("B1")
st.append("F1")
npr.append("F1")
st.append("F'1")
pr.append("F'1")
# 2s
st.append("B2")
npr.append("B2")
st.append("F2")
npr.append("F2")
st.append("F'2")
pr.append("F'2")
# 3's
st.append("B3")
npr.append("B3")
# Rs
st.append("R3")
npr.append("R3")
st.append("R'3")
pr.append("R'3")
st.append("R2")
npr.append("R2")
st.append("R'2")
pr.append("R'2")
st.append("R'0")
pr.append("R'0")
rs.append("R3")
rs.append("R'3")
rs.append("R2")
rs.append("R'2")
rs.append("R'0")
#Affs
correct_affs = [[], [], [], [], []]
aff_copy = aff_dict.copy()
# Seed Affinities
for n in npr:
if n == "R2":
pass
else:
correct_affs[0].append(("S", n))
correct_affs[0].sort()
print("Correct Seed Affinities: ")
print(correct_affs[0])
print("Current Seed Affinities: ")
saffs = []
for i in aff_copy:
if i[0] == "S":
saffs.append(i)
print(saffs)
# Attachments to self
for n in npr:
if n[1] == "0":
pass
elif n[1] == "1":
pass
else:
correct_affs[1].append((n, n))
print("Correct Self Attachment Affinities: ")
print(correct_affs[1])
print("Current Self Attachment Affinities: ")
saffs = []
for i in aff_copy:
if i[0] == i[1]:
saffs.append(i)
print(saffs)
# Attachments to prime self
for n in npr:
if n[1] == "0":
pass
elif n[0] == "B":
pass
else:
l2 = make_prime(n)
correct_affs[2].append((n, l2))
print("Correct Self Prime Attachment Affinities: ")
print(correct_affs[2])
print("Current Self Prime Attachment Affinities: ")
spaffs = []
for i in aff_copy:
if "'" not in i[0]:
pv = i[0][0] + "'" + i[0][1:]
if pv == i[1]:
spaffs.append(i)
print(spaffs)
# Attachments to b0 f0
for n in pr:
if n == "B'0" or n == "R'0":
pass
else:
correct_affs[3].append((n, "B0"))
correct_affs[3].append((n, "F0"))
print("Correct Prime b0 f0 Affinities: ")
print(correct_affs[3])
print("Current Prime b0 f0 Affinities: ")
saffs = []
for i in aff_copy:
if i[0] in pr:
if i[1][1:] == "0" or i[1][1:] == "1":
saffs.append(i)
print(saffs)
# Test List
all_affs =[("S", "B0"), ("S", "B1"), ("S", "B2"), ("S", "B3"),
("S", "F0"), ("S", "F1"), ("S", "F2"),
("S", "R3"),
("F0", "B0"),
("F'1", "B0"), ("F'2", "B0"), ("R'3", "B0"), ("R'2", "B0"),
("F'1", "F0"), ("F'2", "F0"), ("R'3", "F0"), ("R'2", "R'0"),
("F0", "B'0"), ("F1", "B'0"), ("F2", "B'0"), ("R2", "B'0"), ("R3", "B'0"),
("F'1", "B1"), ("F'2", "B1"), ("R'3", "B1"),
("F'2", "F1"), ("R'3", "F1"),
("F'2", "B2"), ("R'3", "B2"),
("R'3", "R2"), ("F2", "B3"),
("F2", "F2"), ("B3", "B3"), ("B2", "B2"), ("F2", "F'2"), ("R2", "R2"), ("R3", "R3"),
("B1", "B'0"), ("F1", "F'1"), ("B2", "B1"), ("F1", "B2"), ("F2", "B2"),("F2", "B1"), ("B3", "B2"), ("R3", "B3"), ("R3", "B2"), ("R3", "B1"), ("R3", "R'3"), ("R2", "B2"), ("R2", "B1"), ("R2", "R'2")]
passes = []
missing = all_affs.copy()
failures = []
all_affs.sort()
j = 0
for i in aff_copy:
if i in all_affs:
passes.append(i)
missing.remove(i)
else:
failures.append(i)
for i in missing:
if i in failures:
failures.remove(i)
print("All affinities test:")
print("Number Passed: ", len(passes), "Out of: ", len(all_affs))
passes.sort()
for p in passes:
print("Passed: ", p)
print("Number Failed: ", len(failures), "Out of: ", len(all_affs))
failures.sort()
for p in failures:
print("Failed: ", p)
print("Number Missing: ", len(missing), "Out of: ", len(all_affs))
missing.sort()
for p in missing:
print("Missing: ", p)
def affinities_test_17(aff_dict):
st = []
pr = []
npr = []
# S and 0s
st.append("S")
st.append("B0")
npr.append("B0")
st.append("B'0")
pr.append("B'0")
st.append("F0")
npr.append("F0")
# 1s
st.append("B1")
npr.append("B1")
st.append("F1")
npr.append("F1")
st.append("F'1")
pr.append("F'1")
# 2s
st.append("B2")
npr.append("B2")
st.append("F2")
npr.append("F2")
st.append("F'2")
pr.append("F'2")
# 3's
st.append("B3")
npr.append("B3")
st.append("F3")
npr.append("F3")
st.append("F'3")
pr.append("F'3")
# 4's
st.append("B4")
npr.append("B4")
# Reseed
st.append("R4")
npr.append("R4")
st.append("R'4")
pr.append("R'4")
all_affs =[("S", "B0"), ("S", "B1"), ("S", "B2"), ("S", "B3"), ("S", "B4"),
# S forward
("S", "F0"), ("S", "F1"), ("S", "F2"), ("S", "F3"),
# F0 B0
("F0", "B0"),
# F' to B0
("F'1", "B0"), ("F'2", "B0"), ("F'3", "B0"),
# F' to F0
("F'1", "F0"), ("F'2", "F0"), ("F'3", "F0"),
#Fs to B'0
("F0", "B'0"), ("F1", "B'0"), ("F2", "B'0"), ("F3", "B'0"),
# B1 to B'0
("B1", "B'0"),
# F' to B1
("F'1", "B1"), ("F'2", "B1"), ("F'3", "B1"),
#Fs to B1
("F2", "B1"), ("F3", "B1"),
# F' to F1
("F'2", "F1"), ("F'3", "F1"), ("F'3", "F2"),
#F1 to F'1
# F' to B2
("F'2", "B2"), ("F'3", "B2"),
# F' to B3
("F'3", "B3"),
# Attach to self
("F2", "F2"), ("F3", "F3"), ("B4", "B4"), ("B3", "B3"), ("B2", "B2"),
# Attach to prime self
("F3", "F'3"), ("F2", "F'2"), ("F1", "F'1"),
# F to larger B
("F2", "B3"), ("F3", "B4"), ("F1", "B2"),
# B to smaller B
("B4","B3"), ("B3", "B2"), ("B2", "B1"),
# F to smaller B
("F3", "B2"),
# F to equal B
("F2", "B2"), ("F3", "B3"),
# Reseed affinities
("S", "R4"), ("R4", "R'4"), ("R4", "R4"), ("R4", "B4"), ("R4", "B3"), ("R4", "B2"), ("R4", "B1"), ("R4", "B'0")
]
aff_copy = aff_dict.copy()
passes = []
missing = all_affs.copy()
failures = []
all_affs.sort()
j = 0
for i in aff_copy:
if i in all_affs:
passes.append(i)
missing.remove(i)
else:
failures.append(i)
for i in missing:
if i in failures:
failures.remove(i)
print("All affinities test:")
print("Number Passed: ", len(passes), "Out of: ", len(all_affs))
passes.sort()
for p in passes:
print("Passed: ", p)
print("Number Failed: ", len(failures), "Out of: ", len(all_affs))
failures.sort()
for p in failures:
print("Failed: ", p)
print("Number Missing: ", len(missing), "Out of: ", len(all_affs))
missing.sort()
for p in missing:
print("Missing: ", p)
# Test affinities for line of len 9
def affinities_test_9(aff_dict):
st = []
pr = []
npr = []
rs = []
# S and 0s
st.append("S")
st.append("B0")
npr.append("B0")
st.append("B'0")
pr.append("B'0")
st.append("F0")
npr.append("F0")
# 1s
st.append("B1")
npr.append("B1")
st.append("F1")
npr.append("F1")
st.append("F'1")
pr.append("F'1")
# 2s
st.append("B2")
npr.append("B2")
st.append("F2")
npr.append("F2")
st.append("F'2")
pr.append("F'2")
# 3's
st.append("B3")
npr.append("B3")
# Reseed
rs.append("R3")
rs.append("R'3")
all_affs =[("S", "B0"), ("S", "B1"), ("S", "B2"), ("S", "B3"),
# S forward
("S", "F0"), ("S", "F1"), ("S", "F2"), ("S", "R3"),
# F0 B0
("F0", "B0"),
# F' to B0
("F'1", "B0"), ("F'2", "B0"),
# F' to F0
("F'1", "F0"), ("F'2", "F0"),
#Fs to B'0
("F0", "B'0"), ("F1", "B'0"), ("F2", "B'0"), ("R3", "B'0"),
# B1 to B'0
("B1", "B'0"),
# F' to B1
("F'1", "B1"), ("F'2", "B1"),
#Fs to B1
("F2", "B1"), ("R3", "B1"),
# F' to F1
("F'2", "F1"),
# F' to B2
("F'2", "B2"),
# F' to B3
("F'3", "B3"),
# Attach to self
("F2", "F2"), ("B3", "B3"), ("B2", "B2"), ("R3", "R3"),
# Attach to prime self
("F2", "F'2"), ("F1", "F'1"), ("R3", "R'3"),
# F to larger B
("F2", "B3"), ("F1", "B2"),
# B to smaller B
("B3", "B2"), ("B2", "B1"),
# F to smaller B
("R3", "B2"),
# FR to equal B
("F2", "B2"), ("R3", "B3"),
]
aff_copy = aff_dict.copy()
passes = []
missing = all_affs.copy()
failures = []
all_affs.sort()
j = 0
for i in all_affs:
if i in aff_copy:
passes.append(i)
missing.remove(i)
else:
failures.append(i)
for i in missing:
if i in failures:
failures.remove(i)
print("All affinities test:")
print("Number Passed: ", len(passes), "Out of: ", len(all_affs))
passes.sort()
for p in passes:
print("Passed: ", p)
print("Number Failed: ", len(failures), "Out of: ", len(all_affs))
failures.sort()
for p in failures:
print("Failed: ", p)
print("Number Missing: ", len(missing), "Out of: ", len(all_affs))
missing.sort()
for p in missing:
print("Missing: ", p)
def transition_rules_check_14(trans_dict):
all_transitions = {
("S", "B0"):("S", "F0"),
("S", "B1"):("S", "F1"),
("S", "B2"):("S", "F2"),
("S", "B3"):("S", "R3"),
("F0", "B0"):("F0", "B'0"),
("F0", "B'0"):("B1", "B'0"),
("F1", "B'0"):("F1", "F'1"),
("F2", "B'0"):("F2", "F'2"),
("R3", "B'0"):("R3", "R'3"),
("R2", "B'0"):("R2", "R'2"),
("F2", "B2"):("F2", "F2"),
("F'1", "B1"):("B2", "B1"),
("F'2", "B2"):("B3", "B2"),
("F1", "B2"):("B2", "B2"),
("F2", "B3"):("B3", "B3"),
("F'1", "B0"):("F'1", "F0"),
("F'2", "B0"):("F'2", "F0"),
("F'2", "B1"):("F'2", "F1"),
("R'3", "B0"):("R'3", "F0"),
("R'3", "B1"):("R'3", "F1"),
("R'3", "B2"):("R'3", "R2"),
("R'2", "B0"):("R'2", "R'0"),
("R3", "B1"):("R3", "R3"),
("R3", "B2"):("R3", "R3"),
("R3", "B3"):("R3", "R3"),
("R2", "B2"):("R2", "R2"),
("R2", "B1"):("R2", "R2"),
("F2", "B1"):("F2", "F2"),
}
trans_copy = trans_dict.copy()
passes = {}
missing = all_transitions.copy()
failures = {}
j = 0
for key in trans_copy:
if key in all_transitions and (trans_copy[key] == all_transitions[key]):
passes[key] = trans_copy[key]
missing.pop(key)
else:
failures[key] = trans_copy[key]
for key in missing:
if key in failures:
failures.pop(key)
print("All transitions test:")
print("Number Passed: ", len(passes), "Out of: ", len(all_transitions))
for p in passes:
print("Passed: ", p)
print("Number Failed: ", len(failures), "Out of: ", len(all_transitions))
for p in failures:
print("Failed: ", p)
print("Number Missing: ", len(missing), "Out of: ", len(all_transitions))
for p in missing:
print("Missing: ", p)