private Allocation mutate(Allocation alloc) { Allocation mutatedAlloc = alloc.Clone(); if (Rand.NextDouble() < MUTATION_RATE) { for (int _ = 0; _ < MUTATE_TASKS_COUNT; _++) { string taskId = ""; string originalProcId = ""; do { // Get a random task id int randOriginalProcIndex = Rand.Next(0, mutatedAlloc.ProcessorIds.Count); originalProcId = mutatedAlloc.ProcessorIds[randOriginalProcIndex]; Processor proc = mutatedAlloc.GetProcessor(originalProcId); taskId = proc.GetRandomTask(); } while (taskId == ""); // Assign the task id to another processor string newProcId; do { int randNewProcIndex = Rand.Next(0, mutatedAlloc.ProcessorIds.Count); newProcId = mutatedAlloc.ProcessorIds[randNewProcIndex]; } while (newProcId == originalProcId); mutatedAlloc.AssignTaskToProcessor(newProcId, taskId); mutatedAlloc.RemoveTask(originalProcId, taskId); } } return(mutatedAlloc); }
public void Allocation_GetReturn() { Allocation alloc = AllocationsTools.GetAllocation(); FXMarket fx = MarketTestTools.CreateMarket(); FXMarket fx2 = MarketTestTools.CreateMarket2(); alloc.Update(fx); Allocation alloc2 = (Allocation)alloc.Clone(); alloc2.Update(fx2); Assert.IsTrue(Math.Abs(1 / 1.1 * 0.05 - alloc2.GetReturn(alloc)) < Math.Pow(10, -6)); }