-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDirectCombine.py
More file actions
128 lines (108 loc) · 6.1 KB
/
Copy pathDirectCombine.py
File metadata and controls
128 lines (108 loc) · 6.1 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
from UniversalClasses import State, AffinityRule, TransitionRule, System
def main(currentSystem, secondSystem, symbol=None):
# Does the new state in secondSystem already exist in currentSystem?
state_duplicated = False
# Does the new rule in secondSystem alread exist in currentSystem?
rule_duplicated = False
if(symbol == None):
symbol = input("Enter the symbol marker for System #2: ")
# Gather currentSystem's lists
current_CompleteStateSet = currentSystem.returnStates()
current_InitialStateSet = currentSystem.returnInitialStates()
current_SeedStateSet = currentSystem.returnSeedStates()
current_VerticalAffinityRules = currentSystem.returnVerticalAffinityList()
current_HorizontalAffinityRules = currentSystem.returnHorizontalAffinityList()
current_VerticalTransitionRules = currentSystem.returnVerticalTransitionList()
current_HorizontalTransitionRules = currentSystem.returnHorizontalTransitionList()
current_temp = currentSystem.returnTemp()
# Gather secondSystem's lists
second_CompleteStateSet = secondSystem.returnStates()
second_InitialStateSet = secondSystem.returnInitialStates()
second_SeedStateSet = secondSystem.returnSeedStates()
second_VerticalAffinityRules = secondSystem.returnVerticalAffinityList()
second_HorizontalAffinityRules = secondSystem.returnHorizontalAffinityList()
second_VerticalTransitionRules = secondSystem.returnVerticalTransitionList()
second_HorizontalTransitionRules = secondSystem.returnHorizontalTransitionList()
# Attach secondSystem's All States (with symbol marker) to currentSystem
# All States
for new_state in second_CompleteStateSet:
second_label = new_state.returnLabel() + symbol
second_color = new_state.returnColor()
for original_state in current_CompleteStateSet:
if(original_state.returnLabel() == second_label):
state_duplicated = True
break
if(not state_duplicated):
tempState = State(second_label, second_color)
current_CompleteStateSet.append(tempState)
state_duplicated = False
# Initial States
for new_state in second_InitialStateSet:
second_label = new_state.returnLabel() + symbol
second_color = new_state.returnColor()
for original_state in current_InitialStateSet:
if(original_state.returnLabel() == second_label):
state_duplicated = True
break
if(not state_duplicated):
tempState = State(second_label, second_color)
current_InitialStateSet.append(tempState)
state_duplicated = False
# Ignoring secondSystem's seed list because currentSystem has priority
# Vertical Transitions
for new_rule in second_VerticalTransitionRules:
second_label1 = new_rule.returnLabel1() + symbol
second_label2 = new_rule.returnLabel2() + symbol
second_label1Final = new_rule.returnLabel1Final() + symbol
second_label2Final = new_rule.returnLabel2Final() + symbol
for original_rule in current_VerticalTransitionRules:
if(original_rule.returnLabel1() == second_label1 and original_rule.returnLabel2() == second_label2 and original_rule.returnLabel1Final() == second_label1Final and original_rule.returnLabel2Final() == second_label2Final):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = TransitionRule(
second_label1, second_label2, second_label1Final, second_label2Final, "v")
current_VerticalTransitionRules.append(tempRule)
rule_duplicated = False
# Horizontal Transitions
for new_rule in second_HorizontalTransitionRules:
second_label1 = new_rule.returnLabel1() + symbol
second_label2 = new_rule.returnLabel2() + symbol
second_label1Final = new_rule.returnLabel1Final() + symbol
second_label2Final = new_rule.returnLabel2Final() + symbol
for original_rule in current_HorizontalTransitionRules:
if(original_rule.returnLabel1() == second_label1 and original_rule.returnLabel2() == second_label2 and original_rule.returnLabel1Final() == second_label1Final and original_rule.returnLabel2Final() == second_label2Final):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = TransitionRule(
second_label1, second_label2, second_label1Final, second_label2Final, "h")
current_HorizontalTransitionRules.append(tempRule)
rule_duplicated = False
# Vertical Affinities
for new_rule in second_VerticalAffinityRules:
second_label1 = new_rule.returnLabel1() + symbol
second_label2 = new_rule.returnLabel2() + symbol
second_strength = new_rule.returnStr()
for original_rule in current_VerticalAffinityRules:
if(original_rule.returnLabel1() == second_label1 and original_rule.returnLabel2() == second_label2):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = AffinityRule(
second_label1, second_label2, "v", second_strength)
current_VerticalAffinityRules.append(tempRule)
# Horizontal Affinities
for new_rule in second_HorizontalAffinityRules:
second_label1 = new_rule.returnLabel1() + symbol
second_label2 = new_rule.returnLabel2() + symbol
second_strength = new_rule.returnStr()
for original_rule in current_HorizontalAffinityRules:
if(original_rule.returnLabel1() == second_label1 and original_rule.returnLabel2() == second_label2):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = AffinityRule(
second_label1, second_label2, "h", second_strength)
current_HorizontalAffinityRules.append(tempRule)
return System(current_temp, current_CompleteStateSet, current_InitialStateSet, current_SeedStateSet, current_VerticalAffinityRules, current_HorizontalAffinityRules, current_VerticalTransitionRules, current_HorizontalTransitionRules)