Beispiel #1
0
 def test_bin_to_dec(self):
     """
     Test Case #1
     Check to see if return type is int and correct value
     """
     expression = [1, 0, 0, 0]
     expression = expression[::-1]  # reverse ordinal value
     result = CA.bin_to_dec(expression)
     expected = 8
     self.assertTrue(type(result is int))
     self.assertEqual(result, expected)
     """
     Test Case #2
     Check to see if return type is int and correct value
     """
     expression = "0000"
     expression = expression[::-1]  # reverse ordinal value
     result = CA.bin_to_dec(expression)
     expected = 0
     self.assertTrue(type(result is int))
     self.assertEqual(result, expected)
     """
     Test Case #3
     Check for length
     """
     expression = "1111"
     expression = expression[::-1]  # reverse ordinal value
     result = CA.bin_to_dec(expression)
     expected = 15
     self.assertEquals(result, expected)
     """
     Test Case #4
     Check for non-integer values
     """
     result = "AAAA"
     self.assertRaises(ValueError, CA.bin_to_dec, result)
     """
     Test Case #5
     Check for non-valid types such as none
     """
     result = None
     self.assertRaises(TypeError, CA.bin_to_dec, result)
Beispiel #2
0
    def set_rule(self, rule_list):
        '''
        set_rule_list, sets the rules in the rule_list

        ARGS:
        rule_list, a list of CA rules to use in the experiment

        RETURNS:

        '''
        self.rule = rule_list
        self.rule_number = CA.bin_to_dec(rule_list)
Beispiel #3
0
for i in range(0, n):
    b = ''.join(choice(['0', '1']) for _ in range(l))
    print(b)
    bit_list.append(b)

for bs in bit_list:
    print(bs, end='\n')
print()

# Step 2) For each bit string, evolve over g generations]
print("Step 2\n===")
print("Evolving each bit strings over " + str(ca_generations) + " generations")
print("Result: ")
results = []
for bs in bit_list:
    bs = CA.bin_to_dec(bs)
    r = CA.evolve(ca_rule, ca_radius, bs, ca_config_len,
                  ca_generations)
    r = [y for x in r for y in x]
    results.append(r)
    print(r, end='\n\n')

# Step 3) Create data frame from results
print("Step 3\n===")
print("Data Frame of Results")

for i in range(0, l):
    for j in range(0, ca_generations+1):
        s = ("x" + str(j) + "t" + str(i))
        ca_df_headers.append(s)
ca_df = pd.DataFrame(results, columns=ca_df_headers, index=bit_list)
Beispiel #4
0
def init_config_num(orbit):
    return CA.bin_to_dec(orbit[0])