Exemplo n.º 1
0
        public TPDict(List <int[, ]> input_samples, List <int> sizes, WarpOptions warp = null, BorderOptions borders = null)
        {
            Tuple <Dictionary <int, PatternCounts>, Dictionary <int, PatternList>, Dictionary <int, BorderPatternList> > temp =
                Helper.CalculateTilePatternProbabilities(input_samples, sizes, warp, borders);

            this._q_counts        = temp.Item1;
            this._patterns        = temp.Item2;
            this._border_patterns = temp.Item3;
        }
Exemplo n.º 2
0
 public EvolutionStrategy()
 {
     this._random      = new Random();
     this._tpdict      = null;
     this._chromosomes = null;
     this._tp_size     = 2;
     this._iteration   = 0;
     this._warp        = null;
     this._borders     = null;
 }
Exemplo n.º 3
0
        public void InitializePatternDictionary(List <int[, ]> input_samples, int tp_size, WarpOptions warp, BorderOptions borders)
        {
            List <int> sizes = new List <int>();

            for (int i = 1; i <= tp_size; i++)
            {
                sizes.Add(i);
            }
            this._tpdict  = new TPDict(input_samples, sizes, warp, borders);
            this._tp_size = tp_size;
            this._warp    = warp;
            this._borders = borders;
        }
Exemplo n.º 4
0
        public static Tuple <Dictionary <int, PatternCounts>, Dictionary <int, PatternList>, Dictionary <int, BorderPatternList> > CalculateTilePatternProbabilities(List <int[, ]> maps, List <int> tp_sizes, WarpOptions warp = null, BorderOptions borders = null)
        {
            Dictionary <int, PatternCounts>     p               = new Dictionary <int, PatternCounts>();
            Dictionary <int, PatternList>       patterns        = new Dictionary <int, PatternList>();
            Dictionary <int, BorderPatternList> border_patterns = new Dictionary <int, BorderPatternList>();

            foreach (int size in tp_sizes)
            {
                p[size]               = new PatternCounts();
                patterns[size]        = new PatternList();
                border_patterns[size] = new BorderPatternList();
                for (int i = 0; i < maps.Count; i++)
                {
                    int[,] map = maps[i];
                    int ySize = size;
                    if (warp != null && warp["y"])
                    {
                        ySize = 1;
                    }
                    for (int y = 0; y < map.GetLength(0) - ySize + 1; y++)
                    {
                        int xSize = size;
                        if (warp != null && warp["x"])
                        {
                            xSize = 1;
                        }
                        for (int x = 0; x < map.GetLength(1) - xSize + 1; x++)
                        {
                            Pattern pattern = CalculateTilePattern(map, x, y, size);

                            p[size].Add(pattern);

                            if (borders != null)
                            {
                                bool temp_border = false;
                                if (borders["top"] && y == 0)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("top", pattern);
                                }
                                if (borders["bot"] && y == map.GetLength(0) - size)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("bot", pattern);
                                }
                                if (borders["left"] && x == 0)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("left", pattern);
                                }
                                if (borders["right"] && x == map.GetLength(1) - size)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("right", pattern);
                                }
                                if (!temp_border)
                                {
                                    patterns[size].Add(pattern);
                                }
                            }
                            else
                            {
                                patterns[size].Add(pattern);
                            }
                        }
                    }
                }
            }
            return(Tuple.Create(p, patterns, border_patterns));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initialize the pattern dictionary that is used during generation
 /// only call that function when you want to change any aspect of the patterns
 /// </summary>
 /// <param name="input_samples">the input integer matrix that the algorithm sample from</param>
 /// <param name="tp_size">the size of the tile patterns used in generation larger than 1</param>
 /// <param name="warp">an object that allow the patterns to sample by wrapping across the edges</param>
 /// <param name="borders">an object that allow the edges to be similar to the edges from the input_samples</param>
 public void InitializePatternDictionary(List <int[, ]> input_samples, int tp_size, WarpOptions warp = null, BorderOptions borders = null)
 {
     if (tp_size <= 1)
     {
         tp_size = 2;
     }
     this._es.InitializePatternDictionary(input_samples, tp_size, warp, borders);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Run the algorithm for a fixed amount of iterations.
 /// This function doesn't need anything to be called before hand.
 /// You can call step to enhance the generation after that function is done
 /// </summary>
 /// <param name="input_samples">the input integer matrix that the algorithm sample from</param>
 /// <param name="tp_size">the size of the tile patterns used in generation larger than 1</param>
 /// <param name="width">the width of the generated map</param>
 /// <param name="height">the height of the generated map</param>
 /// <param name="iterations">the number of iterations that the algorithm should do before finishing</param>
 /// <param name="warp">an object that allow the patterns to sample by wrapping across the edges</param>
 /// <param name="borders">an object that allow the edges to be similar to the edges from the input_samples</param>
 /// <param name="pop_size">the number of generated map at once (having more maps in parallel) helps find good solution faster</param>
 /// <param name="inter_weight">the Asymmetric weight defined from Lucas and Volz work. It balances between having the input_sample have at least one of each pattern in the generated image or vice versa.</param>
 /// <param name="mut_times">the maximum number of modifications the algorithm is allowed to do in one step</param>
 /// <param name="noise">noise value to push the algorithm away from certain arrays and embrace some new noise</param>
 /// <returns>The best generated map so far</returns>
 public int[,] Generate(List <int[, ]> input_samples, int tp_size, int width, int height, int iterations = 10000, WarpOptions warp = null, BorderOptions borders = null, int pop_size = 1, double inter_weight = 0.5, int mut_times = 1, double noise = 0)
 {
     this.InitializePatternDictionary(input_samples, tp_size, warp, borders);
     this.InitializeGeneration(width, height, pop_size);
     while (this.GetIteration() < iterations)
     {
         this.Step(inter_weight, mut_times, noise);
     }
     return(this.GetMap());
 }