This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getMappedStartingPosition(startingPosition): | |
| """ | |
| maps original starting positions to starting positions on the condensed matrix | |
| """ | |
| mappingDictionary = { | |
| 0:3, | |
| 1:0, | |
| 2:1, | |
| 3:0, | |
| 4:2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NEIGHBORS_MAP = { | |
| 1: (6, 8), | |
| 2: (7, 9), | |
| 3: (4, 8), | |
| 4: (3, 9, 0), | |
| 5: tuple(), # 5 has no neighbors | |
| 6: (1, 7, 0), | |
| 7: (2, 6), | |
| 8: (1, 3), | |
| 9: (2, 4), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def getMatrix(matrix, turns): | |
| newMatrix = np.identity(matrix.shape[0]) | |
| for i in range(turns): | |
| newMatrix = newMatrix*matrix | |
| return newMatrix | |
| def getPossibilities(startingPosition, turns): | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> matrix | |
| matrix([[ 2., 0., 1., 0., 0., 0., 1., 0., 0., 1.], | |
| [ 0., 2., 0., 1., 0., 1., 0., 0., 0., 0.], | |
| [ 1., 0., 2., 0., 0., 0., 0., 0., 1., 1.], | |
| [ 0., 1., 0., 3., 0., 1., 0., 1., 0., 0.], | |
| [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], | |
| [ 0., 1., 0., 1., 0., 3., 0., 1., 0., 0.], | |
| [ 1., 0., 0., 0., 0., 0., 2., 0., 1., 1.], | |
| [ 0., 0., 0., 1., 0., 1., 0., 2., 0., 0.], | |
| [ 0., 0., 1., 0., 0., 0., 1., 0., 2., 1.], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> import numpy as np | |
| >>> def getMatrix(matrix, turns): | |
| ... newMatrix = np.identity(matrix.shape[0]) | |
| ... for i in range(turns): | |
| ... newMatrix = newMatrix*matrix | |
| ... return newMatrix | |
| >>> twoTurnMatrix = getMatrix(transitionMatrix,2) | |
| >>> twoTurnMatrix | |
| matrix([ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> nextState = nextState * transitionMatrix | |
| >>> nextState | |
| matrix([[1, 2, 0, 1, 0, 0, 0, 1, 0, 0]]) | |
| >>> np.sum(nextState) | |
| 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| transitionMatrix = np.matrix([[0, 0, 0, 0, 1, 0, 1, 0, 0, 0], | |
| [0, 0, 0, 0, 0, 0, 1, 0, 1, 0], | |
| [0, 0, 0, 0, 0, 0, 0, 1, 0, 1], | |
| [0, 0, 0, 0, 1, 0, 0, 0, 1, 0], | |
| [1, 0, 0, 1, 0, 0, 0, 0, 0, 1], | |
| [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
| [1, 1, 0, 0, 0, 0, 0, 1, 0, 0], | |
| [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], | |
| [0, 1, 0, 1, 0, 0, 0, 0, 0, 0], | |
| [0, 0, 1, 0, 1, 0, 0, 0, 0, 0]], dtype=object) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> stateVector | |
| matrix([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> transitionMatrix = np.matrix( | |
| [[0, 0, 0, 0, 1, 0, 1, 0, 0, 0], | |
| [0, 0, 0, 0, 0, 0, 1, 0, 1, 0], | |
| [0, 0, 0, 0, 0, 0, 0, 1, 0, 1], | |
| [0, 0, 0, 0, 1, 0, 0, 0, 1, 0], | |
| [1, 0, 0, 1, 0, 0, 0, 0, 0, 1], | |
| [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
| [1, 1, 0, 0, 0, 0, 0, 1, 0, 0], | |
| [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], | |
| [0, 1, 0, 1, 0, 0, 0, 0, 0, 0], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| So, I started off by visualizing the network map | |
| 1 - 6 - 7 | |
| | | | | |
| 8 0 2 | |
| | | | | |
| 3 - 4 - 9 | |
| 5 |