Created
March 8, 2015 23:24
-
-
Save jogonba2/311be56dc9a6c6a13a6a to your computer and use it in GitHub Desktop.
Autómata celular unidimensional con conjunt de estados binario y condición de frontera periódica (CMC).
This file contains 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
(* Practica 2 Autómatas celulares *) | |
(* Ovexfl0w13 *) | |
(* Ejercicio AC unidimensional *) | |
SimulacionACDimensional[configInicial_List, enteroRegla_Integer, | |
t_Integer] := | |
Module[{reglaWolfram, configuraciones, d, i, configActual}, | |
reglaWolfram = GenerarReglaWolfram[enteroRegla]; | |
configActual = configInicial; | |
configuraciones = {ArrayPlot[{configActual}]}; | |
For[i = 1, i <= t, i++, | |
configActual = | |
CalcularSiguienteConfiguracion[configActual, reglaWolfram]; | |
AppendTo[configuraciones, ArrayPlot[{configActual}]] ]; | |
(* Simular *) | |
Return[ListAnimate[configuraciones]]; | |
]; | |
GenerarReglaWolfram[enteroRegla_Integer] := | |
Module[{enteroBinario, reglaWolfram, i}, | |
reglaWolfram = {}; | |
enteroBinario = Reverse[IntegerDigits[enteroRegla, 2, 8]]; | |
For[i = 1, i <= Length[enteroBinario], i++, | |
AppendTo[reglaWolfram, | |
AppendTo[IntegerDigits[i - 1, 2, 3], enteroBinario[[i]]]]; ]; | |
Return[reglaWolfram]; | |
]; | |
CalcularSiguienteConfiguracion[configActual_List, reglaWolfram_List] := | |
Module[{sigConfiguracion, d, actReglaWolfram, matchEstado}, | |
actReglaWolfram = {}; | |
sigConfiguracion = {}; | |
matchEstado = 0; | |
For[d = 1, d < Length[configActual], d++, | |
actReglaWolfram = {}; | |
AppendTo[actReglaWolfram, | |
configActual[[Mod[d - 2, Length[configActual]] + 1]]]; | |
AppendTo[actReglaWolfram, configActual[[d]]]; | |
AppendTo[actReglaWolfram, | |
configActual[[Mod[d + 1, Length[configActual] + 1]]]]; | |
AppendTo[actReglaWolfram, _]; | |
(* El valor de la celula sera el ultimo valor del cases *) | |
matchEstado = Cases[reglaWolfram, actReglaWolfram][[1]]; | |
AppendTo[sigConfiguracion, matchEstado[[Length[matchEstado]]]]; | |
]; | |
(* Calcular ultimo vecindario - | |
meter al bucle si se recalculan bien los indices - *) | |
actReglaWolfram = {}; | |
AppendTo[actReglaWolfram, configActual[[Length[configActual] - 1]]]; | |
AppendTo[actReglaWolfram, configActual[[Length[configActual]]]]; | |
AppendTo[actReglaWolfram, configActual[[1]]]; | |
AppendTo[actReglaWolfram, _]; | |
matchEstado = Cases[reglaWolfram, actReglaWolfram][[1]]; | |
AppendTo[sigConfiguracion, matchEstado[[Length[matchEstado]]]]; | |
Return[sigConfiguracion]; | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment