Example #1
0
            public MemoryBanks ReAllocate()
            {
                long highest  = -1;
                int  topIndex = -1;

                for (int n = 0; n < memory.Length; n++)
                {
                    if (memory[n] > highest)
                    {
                        highest  = memory[n];
                        topIndex = n;
                    }
                }

                long toAllocate = memory[topIndex];

                var newBank = new MemoryBanks(this.memory);

                newBank.memory[topIndex] = 0;
                var index = new ModNum(topIndex + 1, memory.Length);

                for (int n = 0; n < toAllocate; n++)
                {
                    newBank.memory[index.number]++;
                    index++;
                }
                return(newBank);
            }
Example #2
0
        public object GetResult2()
        {
            var seenStates   = new HashSet <MemoryBanks>();
            var currentState = new MemoryBanks(inputNums);

            int numRuns = 0;

            while (!seenStates.Contains(currentState))
            {
                seenStates.Add(currentState);
                currentState = currentState.ReAllocate();

                numRuns++;
            }

            var checkState = currentState;

            numRuns = 0;
            do
            {
                currentState = currentState.ReAllocate();
                numRuns++;
            } while (currentState != checkState);

            return(numRuns);
        }
Example #3
0
        public static void memoryParser(ManagementObjectSearcher searcher)
        {
            MemoryBanks myList = new MemoryBanks();

            foreach (ManagementObject queryObj in searcher.Get())
            {
                Memory currentItem = new Memory(queryObj);
                myList.banksList.Add(currentItem);
            }
            MemoryData.EventHandler(myList);
        }
        public void DistributeMemory(int targetIndex)
        {
            MemoryBankHistory.Add(MemoryBanks);

            var redistributed = MemoryBanks.ToArray();
            var blocks        = redistributed[targetIndex];

            redistributed[targetIndex++] = 0;

            while (blocks > 0)
            {
                if (targetIndex >= redistributed.Length)
                {
                    targetIndex = 0;
                }

                redistributed[targetIndex++]++;
                blocks--;
            }

            //var fullCycles = blocks / MemoryBanks.Length;
            //var additionalSteps = blocks % MemoryBanks.Length;

            //var redistributed = MemoryBanks.Select(b => b + fullCycles).ToArray();
            //redistributed[targetIndex] = fullCycles;

            //for (var i = 1; i <= additionalSteps; i++)
            //{
            //    if (targetIndex + i >= MemoryBanks.Length)
            //    {
            //        var adjustedIndex = targetIndex - MemoryBanks.Length + i;
            //        redistributed[adjustedIndex]++;
            //    }
            //    else
            //    {
            //        redistributed[targetIndex + i]++;
            //    }
            //}

            MemoryBanks = redistributed;
        }
        public int DetermineIndexOfHighestLoad()
        {
            var maxValue = MemoryBanks.Max();

            return(Array.IndexOf(MemoryBanks, maxValue));
        }
Example #6
0
 public void toDataGrid(MemoryBanks myList)
 {
     dataGrid1.ItemsSource = myList.banksList;
 }