public void TaskEnergyConsumed()
        {
            // Arrange.
            Double referenceFrequency = 2.0;
            Double runtime            = 3.0;
            int    ram  = 2;
            Task   task = new Task(referenceFrequency, runtime, ram);

            string    name      = "Intel i5";
            Double    frequency = 1.8;
            Processor processor = new Processor(name, frequency, ram);

            Double        coefficientOne   = 10;
            Double        coefficientTwo   = 25;
            Double        coefficientThree = 24;
            ProcessorSpec spec             = new ProcessorSpec(name, coefficientOne, coefficientTwo, coefficientThree);

            processor.ProcSpec = spec;

            Double expectedEnergyConsumed = 37.99999;

            // Act.
            Double taskEnergy = task.EnergyConsumed(processor);

            // Assert.
            Assert.AreEqual(expectedEnergyConsumed, taskEnergy, 0.0001, "Correct Energy Consumed.");
        }
        public void AllocationEnergyConsumed()
        {
            // Arrange.
            Double referenceFrequency = 2.0;
            Double runtime            = 3.0;
            int    ram  = 2;
            Task   task = new Task(referenceFrequency, runtime, ram);

            string    name      = "Intel i5";
            Double    frequency = 1.8;
            Processor processor = new Processor(name, frequency, ram);

            Double        coefficientOne   = 10;
            Double        coefficientTwo   = 25;
            Double        coefficientThree = 24;
            ProcessorSpec spec             = new ProcessorSpec(name, coefficientOne, coefficientTwo, coefficientThree);

            processor.ProcSpec = spec;

            List <Task> tasks = new List <Task>();

            tasks.Add(task);
            List <Processor> processors = new List <Processor>();

            processors.Add(processor);
            Allocation allocation = new Allocation(referenceFrequency);

            int[] taskIds = { 0 };
            allocation.addAllocationSet(0, taskIds);

            Double expectedEnergyConsumed = 37.99999;

            // Act.
            Double allocationEnergy = allocation.computeAllocationEnergy(tasks, processors);

            // Assert.
            Assert.AreEqual(expectedEnergyConsumed, allocationEnergy, 0.0001, "Correct Allocation Energy Consumed.");
        }
        // Validate Allocations Event Handler
        private void AllocationsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Loop through Configuration Data & create TASK, PROCESSOR & PROCESSOR SPEC objects.
            foreach (string line in configurations)
            {
                string[] words = line.Split(seperators);
                // Set Program Data
                if (words.First() == "PROGRAM-DATA")
                {
                    programRuntime     = (float)Double.Parse(words[1]);
                    numberOfTasks      = Int32.Parse(words[2]);
                    numberOfProcessors = Int32.Parse(words[3]);
                }
                // Set Reference Frequency
                else if (words.First() == "REFERENCE-FREQUENCY")
                {
                    referenceFrequency = (float)Double.Parse(words[1]);
                }
                else if (words.First() == "TASK-RUNTIME-RAM")
                {
                    // Index of First Task's Runtime
                    int valueIndex = 1;
                    // Loop Number of Task Times.
                    for (int index = 0; index < numberOfTasks; index++)
                    {
                        Task task = new Task(referenceFrequency, Double.Parse(words[valueIndex]), Int32.Parse(words[valueIndex + 1]));
                        tasks.Add(task);
                        valueIndex += 2;
                    }
                }
                else if (words.First() == "PROCESSORS-FREQUENCIES-RAM")
                {
                    // Index of First Processor's Name
                    int valueIndex = 1;
                    // Loop Number of Processors Times
                    for (int index = 0; index < numberOfProcessors; index++)
                    {
                        Processor processor = new Processor(words[valueIndex], Double.Parse(words[valueIndex + 1]), Int32.Parse(words[valueIndex + 2]));
                        processors.Add(processor);
                        valueIndex += 3;
                    }
                }
                else if (words.First() == "PROCESSORS-COEFFICIENTS")
                {
                    // Index of First Processor Spec's Name
                    int valueIndex = 1;
                    // Loop Number of Processors Times
                    for (int index = 0; index < numberOfProcessors; index++)
                    {
                        ProcessorSpec spec = new ProcessorSpec(words[valueIndex], Double.Parse(words[valueIndex + 3]), Math.Abs(Double.Parse(words[valueIndex + 2])), Double.Parse(words[valueIndex + 1]));
                        // Loop Processors
                        foreach (Processor processor in processors)
                        {
                            // Find Correct Processor To Add Spec
                            if (processor.ProcessorName == spec.ProcessorName)
                            {
                                processor.ProcSpec = spec;
                            }
                        }
                        valueIndex += 4;
                    }
                }
            }

            // Allocation Model Object
            Allocation aAllocation = new Allocation(programRuntime);
            // Processor ID
            int processorId = 0;

            // Loop through Allocations Data to create Allocation objects.
            foreach (string line in allocations)
            {
                string[] words = line.Split(seperators);
                // Add Allocation Set Data to current Allocation.
                if (words.Length == numberOfTasks)
                {
                    List <int> taskIds = new List <int>();
                    for (int index = 0; index < words.Length; index++)
                    {
                        if (Int32.Parse(words[index]) == 1)
                        {
                            taskIds.Add(index);
                        }
                    }
                    aAllocation.addAllocationSet(processorId, taskIds.ToArray());
                    processorId++;
                }
                // Reset & Add New Allocation Object to List
                else
                {
                    aAllocation = new Allocation(programRuntime);
                    processorId = 0;
                    allocationsData.Add(aAllocation);
                }
            }

            // Print Allocation Energy
            outputTextBox.Text += Environment.NewLine;
            for (int index = 1; index <= allocationsData.Count; index++)
            {
                outputTextBox.Text += "Allocation ID - " + index + " - Energy = " + allocationsData[index - 1].computeAllocationEnergy(tasks, processors);
                outputTextBox.Text += Environment.NewLine;
            }
        }