In [1]:
from ipythonblocks import BlockGrid as bg
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
import random
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import Image


:0: FutureWarning: IPython widgets are experimental and may change in the future.

In [2]:
def array_city(x, p1, p2):
    p0 = 1-(p1+p2)
    p1 = 1-(p0+p2)
    p2 = 1-(p0+p1)
    grid = (np.random.choice([0, 1 , 2], size = (x, x), p = [p0, p1, p2]))
    return grid

In [3]:
def visualize(grid):
    g = bg(grid.shape[0], grid.shape[0])
    for row in range(g.height):
        for col in range(g.width):
            block = g[row,col]
            if grid[row,col] == 0:
                block.blue = 1000
                block.red = 1000
                block.green = 1000
            if grid[row,col] == 1:
                block.blue = 2000
                block.red = 0
                block.green = 0
            if grid[row,col] == 2:
                block.red = 2000
                block.green = 0
                block.blue = 0
    return g

In [4]:
def visualize_big(grid):
    g = bg(grid.shape[0], grid.shape[0],block_size = 5)
    for row in range(g.height):
        for col in range(g.width):
            block = g[row,col]
            if grid[row,col] == 0:
                block.blue = 1000
                block.red = 1000
                block.green = 1000
            if grid[row,col] == 1:
                block.blue = 2000
                block.red = 0
                block.green = 0
            if grid[row,col] == 2:
                block.red = 2000
                block.green = 0
                block.blue = 0
    return g

How does the amount of empty squares effect the number of loops required to reach satisfaction?

Example of high amount of empty squares


In [5]:
g = array_city(90,0.1,0.1)
visualize_big(g)


Out[5]:

Example of low amount of empty squares


In [7]:
g = array_city(90,0.45,0.45)
visualize_big(g)


Out[7]:

In [8]:
def empties(Positive,Inverse):
    print("Do you think the amount of empties has a positive or Inverse relationship with the amount of loops required grid to reach satisfaction?")
    if Positive == True:
        print ('Incorrect')
    if Inverse == True:
        print('Correct!')

In [9]:
interact(empties, Positive = False, Inverse = False);


Do you think the amount of empties has a positive or Inverse relationship with the amount of loops required grid to reach satisfaction?

In [10]:
#data
p0 = [0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8]
loops = [138,125,107,99,93,81,63,59,56,38,23,18,15,10,8]

In [11]:
#percent of empties in 40x40 grid at 20% satisfaction
plt.figure(figsize=(15,5))
plt.xlim(0.1, 0.8)
plt.plot(p0, loops)
plt.grid(True)
plt.xlabel('Percent of Empty Boxes')
plt.ylabel('Number of Loops')
plt.title('Empties vs. Loops');


How does the percent difference between red and blue effect ability to become satisfied?

Example of low difference between reds and blues


In [12]:
#Example of small difference
g = array_city(100,0.45,0.45)
visualize_big(g)


Out[12]:

Example of large difference between reds and blues


In [13]:
#Example of large difference
g = array_city(100,0.1,0.8)
visualize_big(g)


Out[13]:

In [14]:
def difference(Positive,Inverse):
    print("Do you think the difference between reds and blues has a positive or Inverse relationship with the amount of loops required grid to reach satisfaction?")
    if Positive == True:
        print ('Correct!')
    if Inverse == True:
        print('Incorrect')

In [15]:
interact(difference, Positive = False, Inverse = False);


Do you think the difference between reds and blues has a positive or Inverse relationship with the amount of loops required grid to reach satisfaction?

In [16]:
diff = [0.1,0.2,0.3,0.4,0.5,0.6,0.7]
loops = [51,55,58,90,92,93,95]

In [17]:
#difference between p1 and p2 in 40x40 grid at 20% satisfaction
plt.figure(figsize=(15,5))
plt.grid(True)
plt.plot(diff, loops)
plt.xlabel('Difference between reds and blues')
plt.ylabel('Number of Loops')
plt.title('Difference vs. Loops');


How does the size of the grid effect the speed of satisfaction?

Example of small grid


In [18]:
g = array_city(5,0.5,0.5)
visualize(g)


Out[18]:

Example of large grid


In [19]:
g = array_city(150,0.4,0.4)
visualize_big(g)


Out[19]:

In [20]:
def size(Positive,Inverse):
    print("Do you think grid size has a positive or inverse relationship with the amount of loops required grid to reach satisfaction?")
    if Positive == True:
        print ('Correct!')
    if Inverse == True:
        print('Incorrect')

In [21]:
interact(difference, Positive = False, Inverse = False);


Do you think the difference between reds and blues has a positive or Inverse relationship with the amount of loops required grid to reach satisfaction?

In [22]:
size = [10,20,30,40,50,60,70,80,90,100]
loops = [4,13,31,68,96,134,170,292,284,397]

In [23]:
#Size of grid
plt.figure(figsize=(15,5))
plt.grid(True)
plt.plot(size, loops)
plt.xlabel('Size of Grid')
plt.ylabel('Number of Loops')
plt.title('Size vs. Loops');


How does satisfaction value effect satisfaction speed?

Example of low satisfaction value


In [28]:
Image(filename = 'Low Sat.png')


Out[28]:

Example of high satisfaction value


In [29]:
Image(filename='High Sat.png')


Out[29]:

In [26]:
satisfaction = [0.1,0.2,0.3,0.4,0.5]
loops = [27,89,146,51,59]

In [27]:
#Satisfaction percent
plt.figure(figsize=(15,5))
plt.grid(True)
plt.plot(satisfaction, loops)
plt.xlabel('Satisfacton Percent')
plt.ylabel('Number of Loops')
plt.title('Satisfaction vs. Loops');