Commit 3c7f45bc authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

slicing

parent 3a9de335
......@@ -36,11 +36,11 @@ class Skython(object):
#'IFF',
]
INSTRUCTIONS3 = [
'LOCO_0', 'INS', 'LOCO_N', 'SWAB',
'SWAC', 'MULT', 'PUSH', 'INC',
'ADD', 'JNE', 'NAND', 'DIV',
'INS', 'SWAB',
'SWAC', 'PUSH', 'INC',
'ADD', 'NAND', 'DIV',
'NEG', 'XOR', 'LOCO_2', 'DEC', 'SWBC',
'PEEK', 'LAND', 'LOR', 'IFDO',
'PEEK', 'LOR', 'IFDO',
'IFF', 'NOT', 'EQ', 'LOCO_1', 'MOD',
]
ENABLED_FIB = [ 'SWAB', 'PUSH', 'INC', 'ADD', 'JNE', ]
......@@ -262,8 +262,8 @@ class Skython(object):
prog = self.make_program(bound)
total += 1
if total % (iterations/40) == 0:
print '.'
#if total % (iterations/40) == 0:
# print '.'
(output, r) = self.run_program(prog, step_limit=max_steps)
......@@ -292,24 +292,14 @@ class Skython(object):
def run(self, model_out, model_in=None, bound=50):
timeout = total = redundant = degen = 0
exact = 1
exact = 0
#lower_bound, upper_bound = 5, 15
if model_in is None:
model_in = []
#model_in = [1, 3, -5, 2, 20, 0, 6, 9, 7, -5]
#model_out = [4, -3, 20, 15, 2]
#model_out = [1, 1, 2, 3, 5, 8, 13]
#model_out = [0, 1, 2, 3, 4, 5]
#model_out = [1, 2, 4, 8, 16, 32]
#model_out = [1, 3, 9, 27, 81]
wins = 0
wins_needed = 1
wins_needed = 5
solutions = set()
time_start = time.time()
while (True):
......@@ -382,13 +372,34 @@ class Skython(object):
if __name__ == '__main__':
skyt = Skython()
EXPLORE = True
skyt.INSTRUCTIONS3 = [
'SWAB',
'PUSH', 'INC',
'ADD', 'DIV', 'MULT',
'NEG', 'XOR', 'LOCO_2', 'SWBC',
'PEEK',
'IFF', 'NOT', 'LOCO_1',
'JNE',
]
skyt.ENABLED_CODES = [skyt.OP_CODE[x] for x in skyt.INSTRUCTIONS3] # random.sample(range(30), random.randint(12, 26))
model_in = [1, 3, -5, 2, 20, 0, 6, 9, 7, -5]
model_out = [4, -3, 20, 15, 2]
#model_out = [1, 1, 2, 3, 5, 8, 13]
#model_out = [0, 1, 2, 3, 4, 5]
#model_out = [1, 2, 4, 8, 16, 32]
#model_in = []
#model_out = [1, 3, 9, 27, 81]
if EXPLORE:
iterations = 10**6
skyt.ENABLED_CODES = [skyt.OP_CODE[x] for x in skyt.INSTRUCTIONS3] # random.sample(range(30), random.randint(12, 26))
skyt.TRIM = 16
skyt.TRIM = 10
results, progs = skyt.explore(iterations=iterations, max_steps=256, bound=32)
inverted = {}
q = []
for k, v in results.items():
if v not in inverted:
inverted[v] = []
......@@ -397,6 +408,24 @@ if __name__ == '__main__':
for k in keys:
print "{:.5%}\n\t{}\n\n".format(1.0 * k / iterations, '\n\t'.join(inverted[k]))
print len(keys), len(results), [skyt.INSTRUCTIONS[x] for x in sorted(skyt.ENABLED_CODES)]
print "-" * 50
q = []
for i in range(30):
n = 0
sum_percent = 0.0
for k in keys:
if k < 100:
for pat in inverted[k]:
n += progs[pat][i] #progs[inverted[k]][i]
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, skyt.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q):
print r
print "-" * 50
q2 = []
for i in range(30):
n = 0
sum_percent = 0.0
......@@ -406,11 +435,28 @@ if __name__ == '__main__':
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
q2 += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, skyt.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q):
for p, r in sorted(q2):
print r
print "-" * 50
q3 = []
for i in range(30):
n = 0
sum_percent = 0.0
for k in keys:
if k > 10000:
for pat in inverted[k]:
n += progs[pat][i] #progs[inverted[k]][i]
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q3 += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, skyt.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q3):
print r
else:
print [skyt.INSTRUCTIONS[x] for x in sorted(skyt.ENABLED_CODES)]
#skyt.run(model_out=[1,2,3,3,4,5], model_in=[4,3,1,3,5,2], bound=30)
skyt.run(model_out=[19,23,37,37,42], model_in=[23,37,42,37,19], bound=35)
#skyt.run(model_out=[19,23,37,37,42], model_in=[23,37,42,37,19], bound=35)
skyt.run(model_out=model_out, model_in=model_in, bound=50)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment