/* * public bool IsSystemCoherent() * { * List<Device> devices = new List<Device>(); * devices.Add(Devices[0]); * * for (int i = 0; i < devices.Count; i++) * { * for (int j = 0; j < devices[i].AvailableDevices(Device.AvailableDevicesSearchingMode.AllDevicesAsNodes).Count; j++) * { * if (!devices.Contains(devices[i].AvailableDevices(Device.AvailableDevicesSearchingMode.AllDevicesAsNodes)[j])) * { * devices.Add(devices[i].AvailableDevices(Device.AvailableDevicesSearchingMode.AllDevicesAsNodes)[j]); * } * } * } * * if(devices.Intersect(Devices) == Devices) * { * return true; * } * else * { * return false; * } * * } */ public void BalanceLoad(Option arg, PhysicalMachine root) //reassigns 1 task from random nearest machine to root machine { foreach (PhysicalMachine el in root.AvailableDevices(Device.AvailableDevicesSearchingMode.AllNearestMachines)) { int ELload; switch (arg) { case Option.Speed: ELload = ((PhysicalMachine)el).GetLoadSpeed(); if (ELload > root.GetLoadSpeed()) { int index = rnd.Next(0, el.VirtualMachines.Count); root.AssignTask(el.VirtualMachines[index].CurrentTask, el); el.VirtualMachines[index].CurrentTask = null; } break; case Option.Memory: ELload = ((PhysicalMachine)el).GetLoadMemory(); if (ELload > root.GetLoadMemory()) { root.AssignTask(el.TaskQueue.Last(), el); } break; } } }
private void buttonOK_Click(object sender, EventArgs e) { try { uint memoryPhM = Convert.ToUInt32(textBoxMemory.Text); uint speedPhM = Convert.ToUInt32(textBoxSpeed.Text); uint countPhM = Convert.ToUInt32(textBoxCount.Text); if (!((Form1)this.Tag).edit) { Figure fig = new Figure(((Form1)this.Tag).X, ((Form1)this.Tag).Y, ((Form1)this.Tag).sizeW, ((Form1)this.Tag).sizeH); ((Form1)this.Tag).graphics.FillRectangle(((Form1)this.Tag).brushPhM, ((Form1)this.Tag).X, ((Form1)this.Tag).Y, ((Form1)this.Tag).sizeW, ((Form1)this.Tag).sizeH); ((Form1)this.Tag).figures.Add(fig); ((Form1)this.Tag).groundBox.Image = ((Form1)this.Tag).bmp; PhysicalMachine physical = new PhysicalMachine((int)speedPhM, (int)memoryPhM, (int)countPhM, fig); Controller.getInstance().Devices.Add(physical); Controller.getInstance().Machines.Add(physical); } this.Close(); } catch (Exception) { MessageBox.Show("Некоректний ввід", "ERROR :("); } }
public override void AssignTask(DTTask dTTask, PhysicalMachine Donor) { if (AvailableMemory >= dTTask.MemoryConsumption) { TaskQueue.Add(dTTask); AvailableMemory -= dTTask.MemoryConsumption; Donor.TaskQueue.Remove(dTTask); } //else //{ // throw new Exception("Not enough memory for new task"); //} }
/* * public override void AssignTasks(List<DTTask> dTTasks, PhysicalMachine Donor) * { * throw new NotSupportedException("This class doesn`t support this method"); * } */ public void CreateTask() //creates task and give it to a random nearest machine { int TargetIndex = rnd.Next(0, AvailableDevices(AvailableDevicesSearchingMode.AllNearestMachines).Count); PhysicalMachine TargetMachine = (PhysicalMachine)AvailableDevices(AvailableDevicesSearchingMode.AllNearestMachines)[TargetIndex]; DTTask task; switch (Mode) { case GenerationMode.Random: task = new DTTask(rnd.Next(VolumeMinGenerationBound, VolumeMaxGenerationBound), rnd.Next(MemConsumptionMinGenerationBound, MemConsumptionMaxGenerationBound)); if (task.MemoryConsumption <= TargetMachine.AvailableMemory) { TargetMachine.TaskQueue.Add(task); TargetMachine.AvailableMemory -= task.MemoryConsumption; } break; case GenerationMode.Defined: task = new DTTask(TaskVolume, TaskMemoryConsumption); if (task.MemoryConsumption <= TargetMachine.AvailableMemory) { TargetMachine.TaskQueue.Add(task); TargetMachine.AvailableMemory -= task.MemoryConsumption; } break; case GenerationMode.Manual: break; } }
public VirtualMachine(PhysicalMachine host, int speed) { Host = host; Speed = speed; CurrentTask = null; }
public override void AssignTask(DTTask dTTask, PhysicalMachine Donor) { throw new NotSupportedException("This class doesn`t support this method"); }
} //memory - how much tasks it can store abstract public void AssignTask(DTTask dTTask, PhysicalMachine Donor);