diff --git a/CO423_Project_2K18_IT_072_073.pdf b/CO423_Project_2K18_IT_072_073.pdf deleted file mode 100644 index 7aac76d..0000000 Binary files a/CO423_Project_2K18_IT_072_073.pdf and /dev/null differ diff --git a/LengthMatrix copy.txt b/LengthMatrix copy.txt new file mode 100644 index 0000000..c089c39 --- /dev/null +++ b/LengthMatrix copy.txt @@ -0,0 +1,30 @@ +288.69 288.69 288.69 288.69 288.69 +389.36 389.36 389.36 389.36 389.36 +97.92 97.92 97.92 97.92 97.92 +179.37 179.37 179.37 179.37 179.37 +197.86 197.86 197.86 197.86 197.86 +219.15 219.15 219.15 219.15 219.15 +322 322 322 322 322 +198 198 198 198 198 +456.36 456.36 456.36 456.36 456.36 +169.69 169.69 169.69 169.69 169.69 +62.44 62.44 62.44 62.44 62.44 +111.41 111.41 111.41 111.41 111.41 +311.62 311.62 311.62 311.62 311.62 +459.59 459.59 459.59 459.59 459.59 +471.76 471.76 471.76 471.76 471.76 +280.88 280.88 280.88 280.88 280.88 +590.20 590.20 590.20 590.20 590.20 +62.44 62.44 62.44 62.44 62.44 +111.41 111.41 111.41 111.41 111.41 +717.92 717.92 717.92 717.92 717.92 +200.66 200.66 200.66 200.66 200.66 +459.59 459.59 459.59 459.59 459.59 +102.83 102.83 102.83 102.83 102.83 +533.08 533.08 533.08 533.08 533.08 +671.33 671.33 671.33 671.33 671.33 +500.66 500.66 500.66 500.66 500.66 +136.11 136.11 136.11 136.11 136.11 +441.94 441.94 441.94 441.94 441.94 +168.68 168.68 168.68 168.68 168.68 +505.93 505.93 505.93 505.93 505.93 \ No newline at end of file diff --git a/LengthMatrixHetero.txt b/LengthMatrixHetero.txt new file mode 100644 index 0000000..95c43fe --- /dev/null +++ b/LengthMatrixHetero.txt @@ -0,0 +1,10 @@ +53.26 667.83 125.88 712.83 388.35 +81.92 269.33 109.71 328.33 155.07 +719.17 547.04 373.60 442.52 578.01 +408.90 231.28 300.43 305.72 726.50 +374.48 140.67 427.59 100.29 184.31 +280.68 505.28 611.43 443.82 355.33 +507.53 655.56 481.48 651.37 719.06 +135.66 611.43 414.17 499.46 401.28 +289.66 263.36 48.87 419.14 698.83 +137.55 254.64 504.53 290.09 168.43 diff --git a/jars/cloudsim-4.0.jar b/jars/cloudsim-4.0.jar new file mode 100644 index 0000000..80d99d1 Binary files /dev/null and b/jars/cloudsim-4.0.jar differ diff --git a/src/FCFS/FCFS_Scheduler.java b/src/FCFS/FCFS_Scheduler.java index 61c84c0..dc5bce5 100644 --- a/src/FCFS/FCFS_Scheduler.java +++ b/src/FCFS/FCFS_Scheduler.java @@ -3,11 +3,17 @@ import org.cloudbus.cloudsim.*; import org.cloudbus.cloudsim.core.CloudSim; import utils.*; + +import java.text.DecimalFormat; +import java.util.HashMap; import java.util.List; +import java.util.Map; + public class FCFS_Scheduler { +private static double[][] lengthMatrix; - public static double main(String[] args) { + public static double main(String[] args) { double finishtime = 0.0; Log.printLine("Starting FCFS Scheduler..."); @@ -31,6 +37,9 @@ public static double main(String[] args) { List newList = broker.getCloudletReceivedList(); finishtime = Commons.printCloudletList(newList, 1, null); + /***AddED EXTRA */ + printCloudletList(newList); + Log.printLine("FCFS Scheduler finished!"); } catch (Exception e) { e.printStackTrace(); @@ -42,4 +51,91 @@ public static double main(String[] args) { private static FCFS_DatacenterBroker createBroker(String name) throws Exception { return new FCFS_DatacenterBroker(name); } + + /******** ADDED EXTRA PART */ + private static void printCloudletList(List list) { + int size = list.size(); + Cloudlet cloudlet; + + String indent = " "; + Log.printLine(); + Log.printLine("========== OUTPUT =========="); + Log.printLine("VM ID" + indent + "Load Quality"+ indent + "Time"); + + DecimalFormat dft = new DecimalFormat("###.##"); + dft.setMinimumIntegerDigits(2); + + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + + // for (int i = 0; i < size; i++) { + // cloudlet = list.get(i); + // int taskId = i; // Assuming task ID starts from 0 + // int dataCenterId = cloudlet.getVmId() % Constants.NO_OF_DATACENTERS; + // double length = lengthMatrix[taskId][dataCenterId]; + + // Log.printLine(indent + dft.format(taskId) + indent + indent + dft.format(dataCenterId) + indent + indent + dft.format(length)); + // } + + // CODE TO CHECK UNDERLOADED/OVERLOADED SYSTEM + double tot_summation_time=0; + for(int i=0;i totalLengths = new HashMap<>(); + // First loop to calculate total lengths +for (int i = 0; i < size; i++) { + cloudlet = list.get(i); + int taskId = i; // Assuming task ID starts from 0 + int dataCenterId = cloudlet.getVmId() % Constants.NO_OF_DATACENTERS; + double length = lengthMatrix[taskId][dataCenterId]; + + // Update total length for the datacenter + totalLengths.put(dataCenterId, totalLengths.getOrDefault(dataCenterId, 0.0) + length); +} + // Second loop to print load quality using total lengths + for (Map.Entry entry : totalLengths.entrySet()) { + int dataCenterId = entry.getKey(); + double totalLengthForDatacenter = entry.getValue(); + String loadAns = ((totalLengthForDatacenter > y) ? "Overloaded" : (totalLengthForDatacenter < x) ? "Underloaded" : "Ok"); + System.out.println(dataCenterId + indent + loadAns + indent + totalLengthForDatacenter); + + } + + System.out.println("avg_sum_time "+ avg_sum_time); + System.out.printf(" \n Below are a, b, x, y "); + System.out.println(a + " "+ b + " " + x + " " + y); + // CODE FOR LOAD ENDS HERE + + + double makespan = calcMakespan(list); + Log.printLine("Makespan using FCFS: " + makespan); + } + + private static double calcMakespan(List list) { + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + double makespan = 0; + double[] dcWorkingTime = new double[Constants.NO_OF_DATACENTERS]; + + for (int i = 0; i < list.size(); i++) { + int dcId = list.get(i).getVmId() % Constants.NO_OF_DATACENTERS; + if (dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; + dcWorkingTime[dcId] += lengthMatrix[i][dcId]; + makespan = Math.max(makespan, dcWorkingTime[dcId]); + } + return makespan; + } + /**** */ + } + diff --git a/src/PSO/PSO.java b/src/PSO/PSO.java index 346560d..f5b375f 100644 --- a/src/PSO/PSO.java +++ b/src/PSO/PSO.java @@ -1,18 +1,22 @@ package PSO; import net.sourceforge.jswarm_pso.Swarm; +import net.sourceforge.jswarm_pso.Particle; +import utils.GenerateLengthMatrix; import utils.Constants; public class PSO { private static Swarm swarm; private static PSO_Particle[] particles; private static final PSO_FitnessFunction ff = new PSO_FitnessFunction(); + private static double[][] lengthMatrix; + private static final PSO_Particle pp = new PSO_Particle(); + public PSO() { initParticles(); } - public double[] run() { swarm = new Swarm(Constants.POPULATION_SIZE, new PSO_Particle(), ff); @@ -22,18 +26,24 @@ public double[] run() { swarm.setParticles(particles); swarm.setParticleUpdate(new PSO_ParticleUpdate(new PSO_Particle())); - for (int i = 0; i < 500; i++) { + for (int i = 0; i < 20; i++) { swarm.evolve(); - if (i % 10 == 0) { + // if (i % 10 == 0) { System.out.printf("Global best at iteration (%d): %f\n", i, swarm.getBestFitness()); - } + System.out.printf("Makespan at iteration (%d): %f\n" , i , ff.calcMakespan(swarm.getBestParticle().getBestPosition())); + printTaskAllocation(swarm.getBestParticle().getBestPosition()); + // printTaskAllocation( (PSO_Particle) swarm.getBestParticle()); + // System.out.println(pp.toString()); + + // } } System.out.println("\nThe best fitness value: " + swarm.getBestFitness() + "\nBest makespan: " + ff.calcMakespan(swarm.getBestParticle().getBestPosition())); System.out.println("The best solution is: "); PSO_Particle bestParticle = (PSO_Particle) swarm.getBestParticle(); - System.out.println(bestParticle.toString()); + System.out.println(bestParticle.toString() + "mkc"); + // printTaskAllocation(swarm.getBestParticle().getBestPosition()); return swarm.getBestPosition(); } @@ -48,4 +58,77 @@ public void printBestFitness() { System.out.println("\nBest fitness value: " + swarm.getBestFitness()+ "\nBest makespan: " + ff.calcMakespan(swarm.getBestParticle().getBestPosition())); } + + + private void printTaskAllocation(double[] position) { + System.out.println("Task Allocation:"); + for (int i = 0; i < Constants.NO_OF_DATACENTERS; i++) { + System.out.printf("Data Center %d: ", i); + int totalTaskSum = 0; + for (int j = 0; j < Constants.NO_OF_TASKS; j++) { + if ((int) position[j] == i) { + System.out.printf("%d ", j); + totalTaskSum += j; // Add the task number to the total sum + } + } + double totalLengthSum = calculateTotalLengthSum(position, i); + + // Machine State + double Total_Summation_Time = 0.0; + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + for(int k=0; k< lengthMatrix.length; k++){ + Total_Summation_Time += lengthMatrix[k][0]; + + } + + double Average_Summation_Time = Total_Summation_Time/Constants.NO_OF_VMS; + System.out.println(Average_Summation_Time); + double a = (Average_Summation_Time*25)/100; + double b = (Average_Summation_Time*60)/100; + double x = Average_Summation_Time-a; + double y = Average_Summation_Time+b; + System.out.println(a + " "+ b + " " + x + " " + y); + System.out.printf("(Task Sum: %d, Length Sum: %.2f)\n", totalTaskSum, totalLengthSum); + System.out.println("The tl is " + totalLengthSum); + if(totalLengthSum < (Average_Summation_Time-a)) System.out.println("UnderLoaded"); + else if(totalLengthSum > (Average_Summation_Time+b)) System.out.println("Overloaded"); + System.out.println("================================================================="); + } + } + + private double calculateTotalLengthSum(double[] position, int dataCenter) { + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + double totalLengthSum = 0; + for (int j = 0; j < Constants.NO_OF_TASKS; j++) { + if ((int) position[j] == dataCenter) { + totalLengthSum += lengthMatrix[j][dataCenter]; + } + } + return totalLengthSum; + } + + // private void printTaskAllocation(PSO_Particle particle) { + // System.out.println("Task Allocation:"); + // System.out.println(particle.toString()); + // } + + + // @Override + // public String toString() { + // String output = ""; + // for (int i = 0; i < Constants.NO_OF_DATACENTERS; i++) { + // String tasks = ""; + // int no_of_tasks = 0; + // for (int j = 0; j < Constants.NO_OF_TASKS; j++) { + // if (i == (int) swarm.getBestParticle().getPosition()[j]) { + // tasks += (tasks.isEmpty() ? "" : " ") + j; + // ++no_of_tasks; + // } + // } + // if (tasks.isEmpty()) output += "There is no tasks associated to Data Center " + i + "\n"; + // else + // output += "There are " + no_of_tasks + " tasks associated to Data Center " + i + " and they are " + tasks + "\n"; + // } + // return output; + // } } diff --git a/src/PSO/PSO_DatacenterBroker.java b/src/PSO/PSO_DatacenterBroker.java index 4394a74..0006725 100644 --- a/src/PSO/PSO_DatacenterBroker.java +++ b/src/PSO/PSO_DatacenterBroker.java @@ -7,6 +7,9 @@ import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.lists.VmList; +import utils.Constants; + +import java.util.Arrays; import java.util.List; public class PSO_DatacenterBroker extends DatacenterBroker { @@ -24,8 +27,14 @@ public void setMapping(double[] mapping) { private List assignCloudletsToVms(List cloudlist) { int idx = 0; for (Cloudlet cl : cloudlist) { - cl.setVmId((int) mapping[idx++]); + cl.setVmId((int) mapping[(idx++)]); + System.out.println("VM id to cloudlet is " + cl.getCloudletId() + " " + cl.getVmId()); } + + // Debug prints + System.out.println("Mapping array size: " + mapping.length); + System.out.println("Mapping array values: " + Arrays.toString(mapping)); + return cloudlist; } diff --git a/src/PSO/PSO_FitnessFunction.java b/src/PSO/PSO_FitnessFunction.java index 10a5793..4389e0e 100644 --- a/src/PSO/PSO_FitnessFunction.java +++ b/src/PSO/PSO_FitnessFunction.java @@ -15,7 +15,7 @@ public class PSO_FitnessFunction extends FitnessFunction { @Override public double evaluate(double[] position) { double alpha = 0.3; - return alpha * calcTotalTime(position) + (1 - alpha) * calcMakespan(position); + return calcMakespan(position); } private double calcTotalTime(double[] position) { @@ -24,6 +24,7 @@ private double calcTotalTime(double[] position) { int dcId = (int) position[i]; totalCost += lengthMatrix[i][dcId]; } + // System.out.println("totalCost "+ totalCost); return totalCost; } diff --git a/src/PSO/PSO_Particle.java b/src/PSO/PSO_Particle.java index 2118875..3572249 100644 --- a/src/PSO/PSO_Particle.java +++ b/src/PSO/PSO_Particle.java @@ -13,8 +13,13 @@ public class PSO_Particle extends Particle { for (int i = 0; i < Constants.NO_OF_TASKS; i++) { Random randObj = new Random(); - position[i] = randObj.nextInt(Constants.NO_OF_DATACENTERS); + position[i] = randObj.nextInt(Constants.NO_OF_DATACENTERS); // This line assigns a random position to the current task. + // The randObj.nextInt(Constants.NO_OF_DATACENTERS) method generates a random integer between + // 0 and Constants.NO_OF_DATACENTERS (exclusive). This random number is then stored + // in the position[i] array element. velocity[i] = Math.random(); + // This line assigns a random velocity to the current task. The Math.random() method generates a random double value between 0.0 and 1.0 (inclusive). + // This random number is then stored in the velocity[i] array element. } setPosition(position); setVelocity(velocity); diff --git a/src/RoundRobin/RoundRobin_Scheduler.java b/src/RoundRobin/RoundRobin_Scheduler.java index 0513533..5ee9cea 100644 --- a/src/RoundRobin/RoundRobin_Scheduler.java +++ b/src/RoundRobin/RoundRobin_Scheduler.java @@ -3,9 +3,14 @@ import org.cloudbus.cloudsim.*; import org.cloudbus.cloudsim.core.CloudSim; import utils.*; + +import java.text.DecimalFormat; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class RoundRobin_Scheduler { + private static double[][] lengthMatrix; public static double main(String[] args) { double finishtime = 0.0; @@ -29,7 +34,12 @@ public static double main(String[] args) { CloudSim.stopSimulation(); List newList = broker.getCloudletReceivedList(); + System.out.println(" size of new list is " + newList.size()); finishtime = Commons.printCloudletList(newList, 3, null); + + + /***AddED EXTRA */ + printCloudletList(newList); Log.printLine("Round Robin Scheduler finished!"); } catch (Exception e) { @@ -42,4 +52,90 @@ public static double main(String[] args) { private static RoundRobin_DatacenterBroker createBroker(String name) throws Exception { return new RoundRobin_DatacenterBroker(name); } + + + /******** ADDED EXTRA PART */ + private static void printCloudletList(List list) { + int size = list.size(); + Cloudlet cloudlet; + + String indent = " "; + Log.printLine(); + Log.printLine("========== OUTPUT =========="); + Log.printLine("VM ID" + indent + "Load Quality"+ indent + "Time"); + + DecimalFormat dft = new DecimalFormat("###.##"); + dft.setMinimumIntegerDigits(2); + + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + + // for (int i = 0; i < size; i++) { + // cloudlet = list.get(i); + // int taskId = i; // Assuming task ID starts from 0 + // int dataCenterId = cloudlet.getVmId() % Constants.NO_OF_DATACENTERS; + // double length = lengthMatrix[taskId][dataCenterId]; + + // Log.printLine(indent + dft.format(taskId) + indent + indent + dft.format(dataCenterId) + indent + indent + dft.format(length)); + // } + + // CODE TO CHECK UNDERLOADED/OVERLOADED SYSTEM + double tot_summation_time=0; + for(int i=0;i totalLengths = new HashMap<>(); + // First loop to calculate total lengths +for (int i = 0; i < size; i++) { + cloudlet = list.get(i); + int taskId = i; // Assuming task ID starts from 0 + int dataCenterId = cloudlet.getVmId() % Constants.NO_OF_DATACENTERS; + double length = lengthMatrix[taskId][dataCenterId]; + + // Update total length for the datacenter + totalLengths.put(dataCenterId, totalLengths.getOrDefault(dataCenterId, 0.0) + length); +} + // Second loop to print load quality using total lengths + for (Map.Entry entry : totalLengths.entrySet()) { + int dataCenterId = entry.getKey(); + double totalLengthForDatacenter = entry.getValue(); + String loadAns = ((totalLengthForDatacenter > y) ? "Overloaded" : (totalLengthForDatacenter < x) ? "Underloaded" : "Ok"); + System.out.println(dataCenterId + indent + loadAns + indent + totalLengthForDatacenter); + + } + + System.out.println("avg_sum_time "+ avg_sum_time); + System.out.printf(" \n Below are a, b, x, y "); + System.out.println(a + " "+ b + " " + x + " " + y); + // CODE FOR LOAD ENDS HERE + + + double makespan = calcMakespan(list); + Log.printLine("Makespan using RR: " + makespan); + } + + private static double calcMakespan(List list) { + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + double makespan = 0; + double[] dcWorkingTime = new double[Constants.NO_OF_DATACENTERS]; + + for (int i = 0; i < list.size(); i++) { + int dcId = list.get(i).getVmId() % Constants.NO_OF_DATACENTERS; + if (dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; + dcWorkingTime[dcId] += lengthMatrix[i][dcId]; + makespan = Math.max(makespan, dcWorkingTime[dcId]); + } + return makespan; + } + /**** */ } \ No newline at end of file diff --git a/src/SJF/SJF_Scheduler.java b/src/SJF/SJF_Scheduler.java index 8733a79..66dbe42 100644 --- a/src/SJF/SJF_Scheduler.java +++ b/src/SJF/SJF_Scheduler.java @@ -3,10 +3,16 @@ import org.cloudbus.cloudsim.*; import org.cloudbus.cloudsim.core.CloudSim; import utils.*; + +import java.text.DecimalFormat; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class SJF_Scheduler { + private static double[][] lengthMatrix; + public static double main(String[] args) { double finishtime = 0.0; Log.printLine("Starting SJF Scheduler..."); @@ -31,6 +37,10 @@ public static double main(String[] args) { List newList = broker.getCloudletReceivedList(); finishtime = Commons.printCloudletList(newList, 2, null); + /***AddED EXTRA */ + printCloudletList(newList); + + Log.printLine("SJF Scheduler finished!"); } catch (Exception e) { e.printStackTrace(); @@ -42,4 +52,91 @@ public static double main(String[] args) { private static SJF_DatacenterBroker createBroker(String name) throws Exception { return new SJF_DatacenterBroker(name); } + + + + /******** ADDED EXTRA PART */ +private static void printCloudletList(List list) { + int size = list.size(); + Cloudlet cloudlet; + + String indent = " "; + Log.printLine(); + Log.printLine("========== OUTPUT =========="); + Log.printLine("VM ID" + indent + "Load Quality"+ indent + "Time"); + + DecimalFormat dft = new DecimalFormat("###.##"); + dft.setMinimumIntegerDigits(2); + + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + + // for (int i = 0; i < size; i++) { + // cloudlet = list.get(i); + // int taskId = i; // Assuming task ID starts from 0 + // int dataCenterId = cloudlet.getVmId() % Constants.NO_OF_DATACENTERS; + // double length = lengthMatrix[taskId][dataCenterId]; + + // Log.printLine(indent + dft.format(taskId) + indent + indent + dft.format(dataCenterId) + indent + indent + dft.format(length)); + // } + + // CODE TO CHECK UNDERLOADED/OVERLOADED SYSTEM + double tot_summation_time=0; + for(int i=0;i totalLengths = new HashMap<>(); + // First loop to calculate total lengths +for (int i = 0; i < size; i++) { + cloudlet = list.get(i); + int taskId = i; // Assuming task ID starts from 0 + int dataCenterId = cloudlet.getVmId() % Constants.NO_OF_DATACENTERS; + double length = lengthMatrix[taskId][dataCenterId]; + + // Update total length for the datacenter + totalLengths.put(dataCenterId, totalLengths.getOrDefault(dataCenterId, 0.0) + length); +} + // Second loop to print load quality using total lengths + for (Map.Entry entry : totalLengths.entrySet()) { + int dataCenterId = entry.getKey(); + double totalLengthForDatacenter = entry.getValue(); + String loadAns = ((totalLengthForDatacenter > y) ? "Overloaded" : (totalLengthForDatacenter < x) ? "Underloaded" : "Ok"); + System.out.println(dataCenterId + indent + loadAns + indent + totalLengthForDatacenter); + + } + + System.out.println("avg_sum_time "+ avg_sum_time); + System.out.printf(" \n Below are a, b, x, y "); + System.out.println(a + " "+ b + " " + x + " " + y); + // CODE FOR LOAD ENDS HERE + + + double makespan = calcMakespan(list); + Log.printLine("Makespan using SJF: " + makespan); + } + + private static double calcMakespan(List list) { + lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + double makespan = 0; + double[] dcWorkingTime = new double[Constants.NO_OF_DATACENTERS]; + + for (int i = 0; i < list.size(); i++) { + int dcId = list.get(i).getVmId() % Constants.NO_OF_DATACENTERS; + if (dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; + dcWorkingTime[dcId] += lengthMatrix[i][dcId]; + makespan = Math.max(makespan, dcWorkingTime[dcId]); + } + return makespan; + } + /**** */ } diff --git a/src/Scheduler_Comparison.java b/src/Scheduler_Comparison.java index 411ec0c..a612b24 100644 --- a/src/Scheduler_Comparison.java +++ b/src/Scheduler_Comparison.java @@ -15,6 +15,14 @@ public static void main(String[] args) throws InterruptedException { SortedMap map = new TreeMap<>(); new GenerateLengthMatrix(); Commons.lengthMatrix = GenerateLengthMatrix.getlengthMatrix(); + // System.out.println("LINE -18"); + // for (int i = 0; i < Commons.lengthMatrix.length; i++) { + // for (int j = 0; j < Commons.lengthMatrix[i].length; j++) { + // System.out.print(Commons.lengthMatrix[i][j] + " "); + // } + // System.out.println(); // Move to the next line after printing each row + // } + map.put(FCFS_Scheduler.main(args), "First Come-First Serve"); System.out.println("==========================================="); TimeUnit.SECONDS.sleep(1); @@ -24,12 +32,12 @@ public static void main(String[] args) throws InterruptedException { map.put(RoundRobin_Scheduler.main(args), "Round Robin"); System.out.println("==========================================="); TimeUnit.SECONDS.sleep(1); + // map.put(ACO_Scheduler.main(args), "Ant Colony Optimisation"); + // System.out.println("==========================================="); + // TimeUnit.SECONDS.sleep(1); map.put(PSO_Scheduler.main(args), "Particle Swarm Optimisation"); System.out.println("==========================================="); TimeUnit.SECONDS.sleep(1); - map.put(ACO_Scheduler.main(args), "Ant Colony Optimisation"); - System.out.println("==========================================="); - TimeUnit.SECONDS.sleep(1); System.out.println("Sorted list of algorithms (criteria: earliest finish time)"); for(double i: map.keySet()){ System.out.printf("%s: %.2f%n", map.get(i), i); diff --git a/src/utils/Commons.java b/src/utils/Commons.java index 6d47269..9f4d1a9 100644 --- a/src/utils/Commons.java +++ b/src/utils/Commons.java @@ -6,6 +6,7 @@ import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; + import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Calendar; @@ -70,9 +71,10 @@ private static List createVMs(int userId, int vms) { Vm[] vm = new Vm[Constants.NO_OF_VMS]; for (int i = 0; i < vms; i++) { - vm[i] = new Vm(i, userId, Constants.VM_MIPS, Constants.VM_PES, Constants.VM_RAM, + int vmId = i + 2; // Adjust this logic based on your VM ID assignment + vm[i] = new Vm(vmId, userId, Constants.VM_MIPS, Constants.VM_PES, Constants.VM_RAM, Constants.VM_BANDWIDTH, Constants.VM_IMAGE_SIZE, - Constants.VMM_NAME, new CloudletSchedulerSpaceShared()); + Constants.VMM_NAME, new CloudletSchedulerSpaceShared() ); list.add(vm[i]); } @@ -85,7 +87,7 @@ private static List createCloudlets(int userId, int cloudlets, int cho UtilizationModel umf = new UtilizationModelFull(); Cloudlet[] cloudlet = new Cloudlet[cloudlets]; - + System.out.println(" cloudlet LIST lenght is "+ cloudlet.length); for (int i = 0; i < cloudlets; i++) { int dcId; if(choice == 4) @@ -93,23 +95,27 @@ private static List createCloudlets(int userId, int cloudlets, int cho else dcId = (int) (Math.random() * Constants.NO_OF_DATACENTERS); long length = (long) (1e3 * lengthMatrix[i][dcId]); - + // System.out.println(length); cloudlet[i] = new Cloudlet(i, length, Constants.TASK_PES, Constants.FILE_SIZE, Constants.OUTPUT_SIZE, umf, umf, umf); cloudlet[i].setUserId(userId); cloudlet[i].setVmId(dcId + 2); list.add(cloudlet[i]); } + System.out.println(" LIST lenght is "+ list.size()) ; return list; } public static void create_vms_and_cloudlets(int brokerId, int choice) { vmList = createVMs(brokerId, Constants.NO_OF_DATACENTERS); cloudletList = createCloudlets(brokerId, Constants.NO_OF_TASKS, choice); + System.out.println(" cloudlet LIST lenght is "+ cloudletList.size()); } public static double printCloudletList(List list, int choice, PSO PSOSchedulerInstance) { Cloudlet cloudlet; + System.out.println("LIST LENGTH IS " + list.size()); + Log.printLine(); Log.printLine("========== OUTPUT =========="); Log.printLine("Cloudlet ID\tSTATUS\t" + diff --git a/src/utils/Constants.java b/src/utils/Constants.java index 302e139..e2002cd 100644 --- a/src/utils/Constants.java +++ b/src/utils/Constants.java @@ -31,7 +31,7 @@ public class Constants { public static String VMM_NAME = "Topa"; //Cloudlet Parameters - public static int NO_OF_TASKS = 30; + public static int NO_OF_TASKS =30; public static long FILE_SIZE = 300; public static long OUTPUT_SIZE = 300; public static int TASK_PES = 1;