Esempio n. 1
0
        /// <summary>
        /// Some try at randomizing the input grid.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="discrimination"></param>
        /// <returns></returns>
        public static Cell GenerateRandomCell(int x, int y, byte discrimination = 0)
        {
            //Cell randomCell = new Cell()
            //{
            //    R = (byte)randomGenerator.Next(0, 256),
            //    G = (byte)randomGenerator.Next(0, 256),
            //    B = (byte)randomGenerator.Next(0, 256)
            //};

            const int bufferSize = 32;

            byte[] buffer = new byte[bufferSize];
            randomGenerator.NextBytes(buffer);
            int randomIndex = randomGenerator.Next(bufferSize - 3);

            byte r, g, b;

            r = buffer[randomIndex];
            g = buffer[randomIndex + 1];
            b = buffer[randomIndex + 2];
            Cell randomCell = new Cell(new Point(x, y))
            {
                R = (r > discrimination ? (byte)(r - discrimination) : r),
                G = (g > discrimination ? (byte)(g - discrimination) : g),
                B = (b > discrimination ? (byte)(b - discrimination) : b)
            };

            return(randomCell);
        }
Esempio n. 2
0
 private int GenerateFormula(string fileName, int clauseNumberIndicator, bool randomClauseNumber = false)
 {
     using (StreamWriter file = new StreamWriter(fileName))
     {
         try
         {
             clauseNumberIndicator = clauseNumberIndicator == 0 ? _generator.Next(1, 2000001) : clauseNumberIndicator;
             var clauseNumber = randomClauseNumber ? _generator.Next(1, clauseNumberIndicator + 1) : clauseNumberIndicator;
             _clauseWriter.WriteProblemLine(file, clauseNumber, _generationModel.NoOfVariables);
             for (int i = 0; i < clauseNumber; i++)
             {
                 var randomLength          = _generationModel.LengthOfClauseType != LengthOfClauseTypeEnum.Fixed;
                 var clauseLengthIndicator = _generationModel.LengthOfClauseValue == 0 ? _generator.Next(1, 201) : _generationModel.LengthOfClauseValue;
                 var clause = GenerateClause(_generationModel.NoOfVariables, clauseLengthIndicator, randomLength);
                 _clauseWriter.WriteClause(file, clause);
             }
             return(1);
         }
         catch (Exception e)
         {
             return(0);
         }
     }
 }
        public static Cell Reproduction(int x, int y, Tuple <Cell, Cell> parents, AbstractGenerator randomGenerator = null)
        {
            if (randomGenerator == null)
            {
                randomGenerator = defaultGenerator;
            }

            byte TakeMax(byte d1, byte d2) => d1 > d2 ? d1 : d2;

            (Cell parentA, Cell parentB) = parents;
            int choice = randomGenerator.Next(3);

            Cell offspring = new Cell(new Point(x, y));

            switch (choice)
            {
            case 0:
            {
                offspring.R = TakeMax(parentA.R, parentB.R);
                offspring.G = TakeMax(parentA.G, parentB.G);
                offspring.B = TakeMax(parentA.B, parentB.B);

                return(offspring);
            }

            case 1:
            {
                offspring.R = TakeMax(parentA.B, parentB.B);
                offspring.G = TakeMax(parentA.R, parentB.R);
                offspring.B = TakeMax(parentA.G, parentB.G);

                return(offspring);
            }

            case 2:
            {
                offspring.R = TakeMax(parentA.G, parentB.G);
                offspring.G = TakeMax(parentA.B, parentB.B);
                offspring.B = TakeMax(parentA.R, parentB.R);

                return(offspring);
            }

            default:
                throw new Exception("BAD CHOICE");
            }
        }
Esempio n. 4
0
        public Source(ref ModelTime time,
                      AbstractGenerator aTypeGenerator,
                      AbstractGenerator bTypeGenerator)
        {
            _time           = time;
            _aTypeGenerator = aTypeGenerator;
            _bTypeGenerator = bTypeGenerator;

            NextAGenerationTime = new ModelTime()
            {
                Time = _time.Time + _aTypeGenerator.Next()
            };
            NextBGenerationTime = new ModelTime()
            {
                Time = _time.Time + _bTypeGenerator.Next()
            };
        }
Esempio n. 5
0
        public Transact Get()
        {
            Transact transact = null;

            if (NextAGenerationTime == _time)
            {
                NextAGenerationTime = new ModelTime()
                {
                    Time = _time.Time + _aTypeGenerator.Next()
                };
                transact = new Transact(++idCounter, TransactTypeEnum.Atype);
            }
            if (NextBGenerationTime == _time)
            {
                NextBGenerationTime = new ModelTime()
                {
                    Time = _time.Time + _bTypeGenerator.Next()
                };
                transact = new Transact(++idCounter, TransactTypeEnum.Btype);
            }

            transact?.AddLog(new TransactLog(_time, EventTypeEnum.Born));
            return(transact);
        }
Esempio n. 6
0
 public void Enter(Transact transact)
 {
     transact.AddLog(new TransactLog(_time, EventTypeEnum.EnterServer));
     IsFree           = false;
     _currentTransact = transact;
     NextReleaseTime  = new ModelTime()
     {
         Time = _time.Time + (_currentTransact.Type == TransactTypeEnum.Atype ? _aTypeGenerator.Next() : _bTypeGenerator.Next())
     };
 }