├── .idea ├── libraries │ └── jars.xml ├── misc.xml ├── modules.xml └── workspace.xml ├── CommunicationTimeMatrix.txt ├── ExecutionTimeMatrix.txt ├── README.md ├── cloudlets.txt ├── desktop.ini ├── out └── production │ └── trunk │ ├── ACO │ ├── ACO$position.class │ ├── ACO.class │ ├── ACODatacenterBroker.class │ ├── ACO_Scheduler.class │ ├── Ant$position.class │ └── Ant.class │ ├── FCFS │ ├── FCFSDatacenterBroker.class │ └── FCFS_Scheduler.class │ ├── PSO │ ├── PSO.class │ ├── PSODatacenterBroker.class │ ├── PSO_Scheduler.class │ ├── SchedulerFitnessFunction.class │ ├── SchedulerParticle.class │ └── SchedulerParticleUpdate.class │ ├── RoundRobin │ ├── RoundRobinDatacenterBroker.class │ └── RoundRobinScheduler.class │ ├── SAWPSO │ ├── SAWPSO.class │ ├── SAWPSODatacenterBroker.class │ ├── SAWPSO_Scheduler.class │ ├── SchedulerFitnessFunction.class │ ├── SchedulerParticle.class │ └── SchedulerParticleUpdate.class │ ├── SJF │ ├── SJFDatacenterBroker.class │ └── SJF_Scheduler.class │ ├── net │ └── sourceforge │ │ └── jswarm_pso │ │ ├── FitnessFunction.class │ │ ├── Gpr.class │ │ ├── Particle.class │ │ ├── ParticleUpdate.class │ │ ├── ParticleUpdateFullyRandom.class │ │ ├── ParticleUpdateRandomByParticle.class │ │ ├── ParticleUpdateRepulsive.class │ │ ├── ParticleUpdateSimple.class │ │ ├── Swarm.class │ │ ├── SwarmRepulsive.class │ │ ├── VariablesUpdate.class │ │ ├── alpine │ │ ├── Example.class │ │ ├── ExampleRepulsive.class │ │ ├── MyFitnessFunction.class │ │ └── MyParticle.class │ │ ├── example_1 │ │ ├── Example.class │ │ ├── MyFitnessFunction.class │ │ └── MyParticle.class │ │ ├── example_2 │ │ ├── DrawingArea.class │ │ ├── Example.class │ │ ├── MyFitnessFunction.class │ │ ├── MyParticle.class │ │ ├── SwarmShow2D.class │ │ └── SwarmThread.class │ │ ├── rosenbrock │ │ ├── Example.class │ │ ├── MyFitnessFunction.class │ │ └── MyParticle.class │ │ ├── rosenbrock_30 │ │ ├── Example.class │ │ ├── MyFitnessFunction.class │ │ └── MyParticle.class │ │ ├── schaffer │ │ ├── Example.class │ │ ├── MyFitnessFunction.class │ │ └── MyParticle.class │ │ └── sphere │ │ ├── Example.class │ │ ├── MyFitnessFunction.class │ │ └── MyParticle.class │ └── utils │ ├── Calculator.class │ ├── Constants.class │ ├── DatacenterCreator.class │ └── GenerateMatrices.class └── trunk ├── .gitignore ├── README.md ├── cloudsim-task-scheduling.iml ├── jars └── cloudsim-3.0.3.jar ├── src ├── ACO │ ├── ACO.java │ ├── ACODatacenterBroker.java │ ├── ACOFitnessFunction.java │ ├── ACO_Scheduler.java │ └── Ant.java ├── FCFS │ ├── FCFSDatacenterBroker.java │ └── FCFS_Scheduler.java ├── PSO │ ├── PSO.java │ ├── PSODatacenterBroker.java │ ├── PSO_Scheduler.java │ ├── SchedulerFitnessFunction.java │ ├── SchedulerParticle.java │ └── SchedulerParticleUpdate.java ├── RoundRobin │ ├── RoundRobinDatacenterBroker.java │ └── RoundRobinScheduler.java ├── SAPSO │ ├── SAPSO.java │ ├── SAPSODatacenterBroker.java │ ├── SAPSO_Scheduler.java │ ├── SchedulerFitnessFunction.java │ ├── SchedulerParticle.java │ └── SchedulerParticleUpdate.java ├── SAWPSO │ ├── SAWPSO.java │ ├── SAWPSODatacenterBroker.java │ ├── SAWPSO_Scheduler.java │ ├── SAWPSO_SchedulerTestOne.java │ ├── SchedulerFitnessFunction.java │ ├── SchedulerParticle.java │ └── SchedulerParticleUpdate.java ├── SJF │ ├── SJFDatacenterBroker.java │ └── SJF_Scheduler.java ├── net │ └── sourceforge │ │ └── jswarm_pso │ │ ├── FitnessFunction.class │ │ ├── FitnessFunction.java │ │ ├── Gpr.class │ │ ├── Gpr.java │ │ ├── Particle.class │ │ ├── Particle.java │ │ ├── ParticleUpdate.class │ │ ├── ParticleUpdate.java │ │ ├── ParticleUpdateFullyRandom.class │ │ ├── ParticleUpdateFullyRandom.java │ │ ├── ParticleUpdateRandomByParticle.class │ │ ├── ParticleUpdateRandomByParticle.java │ │ ├── ParticleUpdateRepulsive.class │ │ ├── ParticleUpdateRepulsive.java │ │ ├── ParticleUpdateSimple.class │ │ ├── ParticleUpdateSimple.java │ │ ├── Swarm.class │ │ ├── Swarm.java │ │ ├── SwarmRepulsive.class │ │ ├── SwarmRepulsive.java │ │ ├── VariablesUpdate.class │ │ ├── VariablesUpdate.java │ │ ├── alpine │ │ ├── Example.class │ │ ├── Example.java │ │ ├── ExampleRepulsive.class │ │ ├── ExampleRepulsive.java │ │ ├── MyFitnessFunction.class │ │ ├── MyFitnessFunction.java │ │ ├── MyParticle.class │ │ └── MyParticle.java │ │ ├── example_1 │ │ ├── Example.class │ │ ├── Example.java │ │ ├── MyFitnessFunction.class │ │ ├── MyFitnessFunction.java │ │ ├── MyParticle.class │ │ └── MyParticle.java │ │ ├── example_2 │ │ ├── DrawingArea.class │ │ ├── DrawingArea.java │ │ ├── Example.class │ │ ├── Example.java │ │ ├── MyFitnessFunction.class │ │ ├── MyFitnessFunction.java │ │ ├── MyParticle.class │ │ ├── MyParticle.java │ │ ├── SwarmShow2D.class │ │ ├── SwarmShow2D.java │ │ ├── SwarmThread.class │ │ └── SwarmThread.java │ │ ├── rosenbrock │ │ ├── Example.class │ │ ├── Example.java │ │ ├── MyFitnessFunction.class │ │ ├── MyFitnessFunction.java │ │ ├── MyParticle.class │ │ └── MyParticle.java │ │ ├── rosenbrock_30 │ │ ├── Example.class │ │ ├── Example.java │ │ ├── MyFitnessFunction.class │ │ ├── MyFitnessFunction.java │ │ ├── MyParticle.class │ │ └── MyParticle.java │ │ ├── schaffer │ │ ├── Example.class │ │ ├── Example.java │ │ ├── MyFitnessFunction.class │ │ ├── MyFitnessFunction.java │ │ ├── MyParticle.class │ │ └── MyParticle.java │ │ └── sphere │ │ ├── Example.class │ │ ├── Example.java │ │ ├── MyFitnessFunction.class │ │ ├── MyFitnessFunction.java │ │ ├── MyParticle.class │ │ └── MyParticle.java └── utils │ ├── Calculator.java │ ├── ChaosStrategy.java │ ├── ChaosTest.java │ ├── Constants.java │ ├── DatacenterCreator.java │ └── GenerateMatrices.java └── trunk.iml /.idea/libraries/jars.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cloudsim-task-scheduling 2 | extended algorithms for task scheduling 3 | 4 | 使用IntelliJ IDEA可以直接打开 5 | -------------------------------------------------------------------------------- /desktop.ini: -------------------------------------------------------------------------------- 1 | [ViewState] 2 | Mode= 3 | Vid= 4 | FolderType=Generic 5 | -------------------------------------------------------------------------------- /out/production/trunk/ACO/ACO$position.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/ACO/ACO$position.class -------------------------------------------------------------------------------- /out/production/trunk/ACO/ACO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/ACO/ACO.class -------------------------------------------------------------------------------- /out/production/trunk/ACO/ACODatacenterBroker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/ACO/ACODatacenterBroker.class -------------------------------------------------------------------------------- /out/production/trunk/ACO/ACO_Scheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/ACO/ACO_Scheduler.class -------------------------------------------------------------------------------- /out/production/trunk/ACO/Ant$position.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/ACO/Ant$position.class -------------------------------------------------------------------------------- /out/production/trunk/ACO/Ant.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/ACO/Ant.class -------------------------------------------------------------------------------- /out/production/trunk/FCFS/FCFSDatacenterBroker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/FCFS/FCFSDatacenterBroker.class -------------------------------------------------------------------------------- /out/production/trunk/FCFS/FCFS_Scheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/FCFS/FCFS_Scheduler.class -------------------------------------------------------------------------------- /out/production/trunk/PSO/PSO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/PSO/PSO.class -------------------------------------------------------------------------------- /out/production/trunk/PSO/PSODatacenterBroker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/PSO/PSODatacenterBroker.class -------------------------------------------------------------------------------- /out/production/trunk/PSO/PSO_Scheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/PSO/PSO_Scheduler.class -------------------------------------------------------------------------------- /out/production/trunk/PSO/SchedulerFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/PSO/SchedulerFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/PSO/SchedulerParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/PSO/SchedulerParticle.class -------------------------------------------------------------------------------- /out/production/trunk/PSO/SchedulerParticleUpdate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/PSO/SchedulerParticleUpdate.class -------------------------------------------------------------------------------- /out/production/trunk/RoundRobin/RoundRobinDatacenterBroker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/RoundRobin/RoundRobinDatacenterBroker.class -------------------------------------------------------------------------------- /out/production/trunk/RoundRobin/RoundRobinScheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/RoundRobin/RoundRobinScheduler.class -------------------------------------------------------------------------------- /out/production/trunk/SAWPSO/SAWPSO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SAWPSO/SAWPSO.class -------------------------------------------------------------------------------- /out/production/trunk/SAWPSO/SAWPSODatacenterBroker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SAWPSO/SAWPSODatacenterBroker.class -------------------------------------------------------------------------------- /out/production/trunk/SAWPSO/SAWPSO_Scheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SAWPSO/SAWPSO_Scheduler.class -------------------------------------------------------------------------------- /out/production/trunk/SAWPSO/SchedulerFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SAWPSO/SchedulerFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/SAWPSO/SchedulerParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SAWPSO/SchedulerParticle.class -------------------------------------------------------------------------------- /out/production/trunk/SAWPSO/SchedulerParticleUpdate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SAWPSO/SchedulerParticleUpdate.class -------------------------------------------------------------------------------- /out/production/trunk/SJF/SJFDatacenterBroker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SJF/SJFDatacenterBroker.class -------------------------------------------------------------------------------- /out/production/trunk/SJF/SJF_Scheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/SJF/SJF_Scheduler.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/FitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/FitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/Gpr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/Gpr.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/Particle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/Particle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdate.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateFullyRandom.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateFullyRandom.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateRandomByParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateRandomByParticle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateRepulsive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateRepulsive.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateSimple.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/ParticleUpdateSimple.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/Swarm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/Swarm.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/SwarmRepulsive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/SwarmRepulsive.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/VariablesUpdate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/VariablesUpdate.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/alpine/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/alpine/Example.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/alpine/ExampleRepulsive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/alpine/ExampleRepulsive.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/alpine/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/alpine/MyFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/alpine/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/alpine/MyParticle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_1/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_1/Example.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_1/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_1/MyFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_1/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_1/MyParticle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_2/DrawingArea.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_2/DrawingArea.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_2/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_2/Example.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_2/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_2/MyFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_2/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_2/MyParticle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_2/SwarmShow2D.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_2/SwarmShow2D.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/example_2/SwarmThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/example_2/SwarmThread.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock/Example.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock/MyFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock/MyParticle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock_30/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock_30/Example.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock_30/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock_30/MyFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock_30/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/rosenbrock_30/MyParticle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/schaffer/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/schaffer/Example.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/schaffer/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/schaffer/MyFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/schaffer/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/schaffer/MyParticle.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/sphere/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/sphere/Example.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/sphere/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/sphere/MyFitnessFunction.class -------------------------------------------------------------------------------- /out/production/trunk/net/sourceforge/jswarm_pso/sphere/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/net/sourceforge/jswarm_pso/sphere/MyParticle.class -------------------------------------------------------------------------------- /out/production/trunk/utils/Calculator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/utils/Calculator.class -------------------------------------------------------------------------------- /out/production/trunk/utils/Constants.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/utils/Constants.class -------------------------------------------------------------------------------- /out/production/trunk/utils/DatacenterCreator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/utils/DatacenterCreator.class -------------------------------------------------------------------------------- /out/production/trunk/utils/GenerateMatrices.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/out/production/trunk/utils/GenerateMatrices.class -------------------------------------------------------------------------------- /trunk/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | out/ 3 | *.txt 4 | -------------------------------------------------------------------------------- /trunk/README.md: -------------------------------------------------------------------------------- 1 | # CloudSim Task Allocation and Scheduling 2 | 3 | * Particle Swarm Optimization `PSO.PSO_Scheduler` 4 | * Round Robin Algorithm `RoundRobin.RoundRobinScheduler` 5 | * Shortest Job First `SJF.SJF_Scheduler` 6 | * First Come First Serve `FCFS.FCFS_Scheduler` 7 | * Self adaptive weight PSO `SAWPSO.SAWPSO_Scheduler` 8 | * Ant Colony Optimization `ACO.ACO_Scheduler` 9 | -------------------------------------------------------------------------------- /trunk/cloudsim-task-scheduling.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /trunk/jars/cloudsim-3.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/jars/cloudsim-3.0.3.jar -------------------------------------------------------------------------------- /trunk/src/ACO/ACO.java: -------------------------------------------------------------------------------- 1 | package ACO; 2 | 3 | import java.util.*; 4 | import org.cloudbus.cloudsim.Cloudlet; 5 | import org.cloudbus.cloudsim.Vm; 6 | 7 | /** 8 | * 蚁群优化算法,用来求解任务分配给虚拟机达到时间最短的问题 9 | * @author Gavrila 10 | */ 11 | public class ACO { 12 | public class position{ 13 | public int vm; 14 | public int task; 15 | public position(int a, int b){ 16 | vm = a; 17 | task = b; 18 | } 19 | } 20 | private List ants;//定义蚂蚁群 21 | private int antcount;//蚂蚁的数量 22 | private int Q = 100; 23 | private double[][] pheromone;//信息素矩阵 24 | private double[][] Delta;//总的信息素增量 25 | private int VMs;//虚拟机数量 26 | private int tasks;//任务个数 27 | public position[] bestTour;//最佳解 28 | private double bestLength;//最优解的长度(时间的大小) 29 | private List cloudletList; 30 | private List vmList; 31 | /** 32 | * 初始化矩阵 33 | * @param antNum 为系统要用到蚂蚁的数量 34 | */ 35 | public void init(int antNum, List list1, List list2){ 36 | //cloudletList = new ArrayList; 37 | cloudletList = list1; 38 | vmList = list2; 39 | antcount = antNum; 40 | ants = new ArrayList(); 41 | VMs = vmList.size(); 42 | tasks = cloudletList.size(); 43 | pheromone = new double[VMs][tasks]; 44 | Delta = new double[VMs][tasks]; 45 | bestLength = 1000000; 46 | //初始化信息素矩阵 47 | for(int i=0; i cloudletList, List vmList) 26 | //public void run(int maxgen) 27 | public void RunACO(int antcount, int maxgen){ 28 | long time = System.currentTimeMillis(); 29 | ACO aco; 30 | aco = new ACO(); 31 | aco.init(antcount, cloudletList, vmList); 32 | aco.run(maxgen); 33 | aco.ReportResult(); 34 | double[] bestposition = new double[Constants.NO_OF_TASKS]; 35 | for (int i = 0; i < cloudletList.size(); i++) { 36 | cloudletList.get(aco.bestTour[i].task).setVmId(aco.bestTour[i].vm); 37 | bestposition[i] = aco.bestTour[i].vm; 38 | } 39 | ACOFitnessFunction ff = new ACOFitnessFunction(); 40 | System.out.println("best totalcost:"+ff.calcTotalTime(bestposition)); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /trunk/src/ACO/ACOFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package ACO; 2 | 3 | import utils.Constants; 4 | import utils.GenerateMatrices; 5 | 6 | public class ACOFitnessFunction { 7 | 8 | private static double[][] execMatrix, commMatrix; 9 | 10 | public ACOFitnessFunction() 11 | { 12 | commMatrix = GenerateMatrices.getCommMatrix(); 13 | execMatrix = GenerateMatrices.getExecMatrix(); 14 | } 15 | 16 | public double evaluate(double[] position) { 17 | double alpha = 0.3; 18 | return alpha * calcTotalTime(position) + (1 - alpha) * calcMakespan(position); 19 | // return calcMakespan(position); 20 | } 21 | 22 | public double calcTotalTime(double[] position) { 23 | double totalCost = 0; 24 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 25 | int dcId = (int) position[i]; 26 | totalCost += execMatrix[i][dcId] + commMatrix[i][dcId]; 27 | } 28 | return totalCost; 29 | } 30 | 31 | public double calcMakespan(double[] position) { 32 | double makespan = 0; 33 | double[] dcWorkingTime = new double[Constants.NO_OF_VMS]; 34 | 35 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 36 | int dcId = (int) position[i]; 37 | if(dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; 38 | dcWorkingTime[dcId] += execMatrix[i][dcId] + commMatrix[i][dcId]; 39 | makespan = Math.max(makespan, dcWorkingTime[dcId]); 40 | } 41 | return makespan; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /trunk/src/ACO/ACO_Scheduler.java: -------------------------------------------------------------------------------- 1 | package ACO; 2 | 3 | import PSO.PSODatacenterBroker; 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.core.CloudSim; 6 | import utils.Constants; 7 | import utils.DatacenterCreator; 8 | import utils.GenerateMatrices; 9 | 10 | import java.io.BufferedReader; 11 | import java.io.FileInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStreamReader; 14 | import java.text.DecimalFormat; 15 | import java.util.*; 16 | 17 | public class ACO_Scheduler 18 | { 19 | private static List cloudletList = new LinkedList<>(); 20 | private static List vmList; 21 | // private static Datacenter[] datacenter; 22 | private static Datacenter datacenter; 23 | private static ACO ACOSchedularInstance; 24 | private static double mapping[]; 25 | private static double[][] commMatrix; 26 | private static double[][] execMatrix; 27 | 28 | public static void main(String[] args) 29 | { 30 | Log.printLine("Starting ACO Scheduler..."); 31 | 32 | // new GenerateMatrices(); 33 | // commMatrix = GenerateMatrices.getCommMatrix(); 34 | // execMatrix = GenerateMatrices.getExecMatrix(); 35 | // ACOSchedularInstance = new ACO(); 36 | // mapping = ACOSchedularInstance.run(); 37 | 38 | try { 39 | String filePath = "D:\\github\\cloudsim-package\\modules\\cloudsim-examples\\src\\main\\java\\org\\cloudbus\\cloudsim\\examples\\cloudlets.txt"; 40 | int num_user = 1; // number of grid users 41 | Calendar calendar = Calendar.getInstance(); 42 | boolean trace_flag = false; // mean trace events 43 | 44 | CloudSim.init(num_user, calendar, trace_flag); 45 | 46 | // Second step: Create Datacenter 47 | datacenter = DatacenterCreator.createDatacenter("DataCenter_"+1, Constants.NO_OF_VMS); 48 | 49 | //Third step: Create Broker 50 | ACODatacenterBroker broker = createBroker("Broker_0"); 51 | int brokerId = broker.getId(); 52 | 53 | //Fourth step: Create VMs and Cloudlets and send them to broker 54 | vmList = createVM(brokerId, Constants.NO_OF_VMS); 55 | // cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 56 | createTasks(brokerId,filePath,Constants.NO_OF_TASKS); 57 | GenerateMatrices GM = new GenerateMatrices(vmList); 58 | commMatrix = GM.getcommMatrix(); 59 | execMatrix = GM.getexecMatrix(); 60 | broker.submitVmList(vmList); 61 | // broker.setMapping(mapping); 62 | broker.submitCloudletList(cloudletList); 63 | 64 | broker.RunACO(5, 2); 65 | // Fifth step: Starts the simulation 66 | CloudSim.startSimulation(); 67 | 68 | List newList = broker.getCloudletReceivedList(); 69 | 70 | CloudSim.stopSimulation(); 71 | 72 | // printCloudletList(newList); 73 | PrintResults(newList); 74 | Log.printLine(ACO_Scheduler.class.getName() + " finished!"); 75 | } catch (Exception e) { 76 | e.printStackTrace(); 77 | Log.printLine("The simulation has been terminated due to an unexpected error"); 78 | } 79 | 80 | } 81 | 82 | private static List createVM(int userId, int vms) { 83 | //Creates a container to store VMs. This list is passed to the broker later 84 | LinkedList list = new LinkedList(); 85 | 86 | //VM Parameters 87 | long size = 10000; //image size (MB) 88 | int ram = 512; //vm memory (MB) 89 | int mips = 500; 90 | long bw = 1000; 91 | int pesNumber = 1; //number of cpus 92 | String vmm = "Xen"; //VMM name 93 | 94 | //create VMs 95 | Vm[] vm = new Vm[vms]; 96 | 97 | for (int i = 0; i < vms; i++) { 98 | vm[i] = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared()); 99 | list.add(vm[i]); 100 | } 101 | 102 | return list; 103 | } 104 | 105 | protected static void createTasks(int brokerId,String filePath, int taskNum) 106 | { 107 | try 108 | { 109 | @SuppressWarnings("resource") 110 | BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(filePath))); 111 | String data = null; 112 | int index = 0; 113 | 114 | //cloudlet properties. 115 | int pesNumber = 1; 116 | long fileSize = 1000; 117 | long outputSize = 1000; 118 | UtilizationModel utilizationModel = new UtilizationModelFull(); 119 | 120 | while ((data = br.readLine()) != null) 121 | { 122 | System.out.println(data); 123 | String[] taskLength=data.split("\t");//tasklength[i]是任务执行的耗费(指令数量) 124 | for(int j=0;j<20;j++){ 125 | Cloudlet task=new Cloudlet(index+j, (long) Double.parseDouble(taskLength[j]), pesNumber, fileSize, 126 | outputSize, utilizationModel, utilizationModel, 127 | utilizationModel); 128 | task.setUserId(brokerId); 129 | cloudletList.add(task); 130 | if(cloudletList.size()==taskNum) 131 | { 132 | br.close(); 133 | return; 134 | } 135 | } 136 | //20 cloudlets each line in the file cloudlets.txt. 137 | index+=20; 138 | } 139 | } 140 | catch (IOException e) 141 | { 142 | e.printStackTrace(); 143 | } 144 | } 145 | 146 | private static ACODatacenterBroker createBroker(String name) throws Exception { 147 | return new ACODatacenterBroker(name); 148 | } 149 | 150 | private static double PrintResults(List list) 151 | { 152 | int size = list.size(); 153 | Cloudlet cloudlet; 154 | 155 | String indent = " "; 156 | Log.printLine(); 157 | Log.printLine("================ Execution Result =================="); 158 | Log.printLine("No."+indent +"Cloudlet ID" + indent + "STATUS" + indent 159 | + "Data center ID" + indent + "VM ID" + indent+"VM mips"+ indent +"CloudletLength"+indent+ "Time" 160 | + indent + "Start Time" + indent + "Finish Time"); 161 | double mxFinishTime = 0; 162 | DecimalFormat dft = new DecimalFormat("###.##"); 163 | for (int i = 0; i < size; i++) 164 | { 165 | cloudlet = list.get(i); 166 | Log.print(i+1+indent+indent + cloudlet.getCloudletId() + indent + indent); 167 | 168 | if (cloudlet.getStatus()== Cloudlet.SUCCESS) 169 | { 170 | Log.print("SUCCESS"); 171 | 172 | Log.printLine(indent +indent + indent + cloudlet.getResourceId() 173 | + indent + indent + indent + cloudlet.getVmId() 174 | + indent + indent + getVmById(cloudlet.getVmId()).getMips() 175 | + indent + indent + cloudlet.getCloudletLength() 176 | + indent + indent+ indent + indent 177 | + dft.format(cloudlet.getActualCPUTime()) + indent 178 | + indent + dft.format(cloudlet.getExecStartTime()) 179 | + indent + indent 180 | + dft.format(cloudlet.getFinishTime())); 181 | } 182 | mxFinishTime = Math.max(mxFinishTime, cloudlet.getFinishTime()); 183 | } 184 | Log.printLine("================ Execution Result Ends here =================="); 185 | Log.printLine(mxFinishTime); 186 | return mxFinishTime; 187 | } 188 | 189 | public static Vm getVmById(int vmId) 190 | { 191 | for(Vm v:vmList) 192 | { 193 | if(v.getId()==vmId) 194 | return v; 195 | } 196 | return null; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /trunk/src/ACO/Ant.java: -------------------------------------------------------------------------------- 1 | package ACO; 2 | 3 | import java.util.*; 4 | 5 | import org.cloudbus.cloudsim.Cloudlet; 6 | import org.cloudbus.cloudsim.Vm; 7 | import utils.Calculator; 8 | /** 9 | *蚂蚁类 10 | *@author Gavrila 11 | */ 12 | public class Ant{ 13 | public class position{ 14 | public int vm; 15 | public int task; 16 | public position(int a, int b){ 17 | vm = a; 18 | task = b; 19 | } 20 | } 21 | public double[][] delta;//每个节点增加的信息素 22 | public int Q = 100; 23 | public List tour;//蚂蚁获得的路径(解,任务分配给虚拟机的分法) 24 | public double tourLength;//蚂蚁获得的路径长度(分配好后,总的花费时间) 25 | public long[] TL_task;//每个虚拟机的任务总量 26 | public List tabu;//禁忌表 27 | private int VMs;//城市的个数(相当于虚拟机的个数) 28 | private int tasks;//任务个数 29 | private List cloudletList; //云任务列表 30 | private List vmList; //虚拟机列表 31 | /** 32 | *随机分配蚂蚁到某个节点中,同时完成蚂蚁包含字段的初试化工作 33 | *@param list1 任务列表 34 | *@param list2 虚拟机列表 35 | */ 36 | public void RandomSelectVM(List list1, List list2){ 37 | cloudletList = list1; 38 | vmList = list2; 39 | VMs = vmList.size(); 40 | tasks = cloudletList.size(); 41 | delta = new double[VMs][tasks]; 42 | TL_task = new long[VMs]; 43 | for(int i=0; i(); 45 | tour=new ArrayList(); 46 | 47 | //随机选择蚂蚁的位置 48 | int firstVM = (int)(VMs*Math.random()); 49 | int firstExecute = (int)(tasks*Math.random()); 50 | tour.add(new position(firstVM, firstExecute)); 51 | tabu.add(new Integer(firstExecute)); 52 | TL_task[firstVM] += cloudletList.get(firstExecute).getCloudletLength(); 53 | } 54 | /** 55 | * calculate the expected execution time and transfer time of the task on vm 56 | * @param vm 虚拟机序号 57 | * @param task 任务序号 58 | */ 59 | public double Dij(int vm, int task){ 60 | double d; 61 | double s = TL_task[vm]; 62 | double s1 = vmList.get(vm).getMips(); 63 | double s2 = cloudletList.get(task).getCloudletLength(); 64 | double s3 = vmList.get(vm).getBw(); 65 | double r1 = Calculator.div(TL_task[vm],vmList.get(vm).getMips(),1); 66 | double r2 = Calculator.div(cloudletList.get(task).getCloudletLength(),vmList.get(vm).getBw(),1); 67 | //d = TL_task[vm]/vmList.get(vm).getMips() + cloudletList.get(task).getCloudletLength()/vmList.get(vm).getBw(); 68 | d = r1+r2; 69 | return d; 70 | } 71 | /** 72 | * 选择下一个节点 73 | * @param pheromone 全局的信息素信息 74 | */ 75 | public void SelectNextVM(double[][] pheromone){ 76 | double[][] p;//每个节点被选中的概率 77 | p = new double[VMs][tasks]; 78 | double alpha = 1.0; 79 | double beta = 1.0; 80 | double sum = 0;//分母 81 | //计算公式中的分母部分 82 | for(int i=0; i=selectp){ 108 | selectVM = i; 109 | selectTask = j; 110 | flag=false; 111 | break; 112 | } 113 | } 114 | } 115 | if (selectVM==-1 | selectTask == -1) 116 | System.out.println("选择下一个虚拟机没有成功!"); 117 | tabu.add(new Integer(selectTask)); 118 | tour.add(new position(selectVM, selectTask)); 119 | TL_task[selectVM] += cloudletList.get(selectTask).getCloudletLength(); 120 | } 121 | 122 | 123 | 124 | public void CalTourLength(){ 125 | System.out.println(); 126 | double[] max; 127 | max = new double[VMs]; 128 | for(int i=0; itourLength)tourLength = max[i]; 134 | System.out.println("第"+i+"台虚拟机的执行时间:"+max[i]); 135 | } 136 | return; 137 | } 138 | /** 139 | * 计算信息素增量矩阵 140 | */ 141 | public void CalDelta(){ 142 | for(int i=0; i clist = new ArrayList(); 28 | 29 | for (Cloudlet cloudlet : getCloudletSubmittedList()) { 30 | clist.add(cloudlet); 31 | } 32 | 33 | setCloudletReceivedList(clist); 34 | } 35 | 36 | @Override 37 | protected void processCloudletReturn(SimEvent ev) { 38 | Cloudlet cloudlet = (Cloudlet) ev.getData(); 39 | getCloudletReceivedList().add(cloudlet); 40 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + cloudlet.getCloudletId() 41 | + " received"); 42 | cloudletsSubmitted--; 43 | if (getCloudletList().size() == 0 && cloudletsSubmitted == 0) { 44 | scheduleTaskstoVms(); 45 | cloudletExecution(cloudlet); 46 | } 47 | } 48 | 49 | 50 | protected void cloudletExecution(Cloudlet cloudlet) { 51 | 52 | if (getCloudletList().size() == 0 && cloudletsSubmitted == 0) { // all cloudlets executed 53 | Log.printLine(CloudSim.clock() + ": " + getName() + ": All Cloudlets executed. Finishing..."); 54 | clearDatacenters(); 55 | finishExecution(); 56 | } else { // some cloudlets haven't finished yet 57 | if (getCloudletList().size() > 0 && cloudletsSubmitted == 0) { 58 | // all the cloudlets sent finished. It means that some bount 59 | // cloudlet is waiting its VM be created 60 | clearDatacenters(); 61 | createVmsInDatacenter(0); 62 | } 63 | 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /trunk/src/FCFS/FCFS_Scheduler.java: -------------------------------------------------------------------------------- 1 | package FCFS; 2 | 3 | 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.core.CloudSim; 6 | import utils.Constants; 7 | import utils.DatacenterCreator; 8 | import utils.GenerateMatrices; 9 | 10 | import java.text.DecimalFormat; 11 | import java.util.Calendar; 12 | import java.util.LinkedList; 13 | import java.util.List; 14 | import java.util.Random; 15 | 16 | public class FCFS_Scheduler { 17 | 18 | private static List cloudletList; 19 | private static List vmList; 20 | private static Datacenter datacenter; 21 | private static double[][] commMatrix; 22 | private static double[][] execMatrix; 23 | 24 | private static List createVM(int userId, int vms) { 25 | //Creates a container to store VMs. This list is passed to the broker later 26 | LinkedList list = new LinkedList(); 27 | 28 | //VM Parameters 29 | long size = 10000; //image size (MB) 30 | int ram = 512; //vm memory (MB) 31 | int mips = 1000; 32 | long bw = 1000; 33 | int pesNumber = 1; //number of cpus 34 | String vmm = "Xen"; //VMM name 35 | 36 | //create VMs 37 | Vm[] vm = new Vm[vms]; 38 | 39 | for (int i = 0; i < vms; i++) { 40 | vm[i] = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared()); 41 | list.add(vm[i]); 42 | } 43 | 44 | return list; 45 | } 46 | 47 | private static List createCloudlet(int userId, int cloudlets, int idShift) { 48 | // Creates a container to store Cloudlets 49 | LinkedList list = new LinkedList(); 50 | 51 | //cloudlet parameters 52 | long fileSize = 300; 53 | long outputSize = 300; 54 | int pesNumber = 1; 55 | UtilizationModel utilizationModel = new UtilizationModelFull(); 56 | 57 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 58 | 59 | for (int i = 0; i < cloudlets; i++) { 60 | // int dcId = (int) (Math.random() * Constants.NO_OF_VMS); 61 | Random rd = new Random(); 62 | int dcId = rd.nextInt(Constants.NO_OF_VMS); 63 | long length = (long) (1e3 * (commMatrix[i][dcId] + execMatrix[i][dcId])); 64 | cloudlet[i] = new Cloudlet(idShift + i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); 65 | // setting the owner of these Cloudlets 66 | cloudlet[i].setUserId(userId); 67 | // cloudlet[i].setVmId(dcId + 2); 68 | cloudlet[i].setVmId(dcId); 69 | list.add(cloudlet[i]); 70 | } 71 | return list; 72 | } 73 | 74 | public static void main(String[] args) { 75 | Log.printLine("Starting FCFS Scheduler..."); 76 | 77 | new GenerateMatrices(); 78 | execMatrix = GenerateMatrices.getExecMatrix(); 79 | commMatrix = GenerateMatrices.getCommMatrix(); 80 | 81 | try { 82 | int num_user = 1; // number of grid users 83 | Calendar calendar = Calendar.getInstance(); 84 | boolean trace_flag = false; // mean trace events 85 | 86 | CloudSim.init(num_user, calendar, trace_flag); 87 | 88 | // Second step: Create Datacenters 89 | // datacenter = new Datacenter[Constants.NO_OF_DATA_CENTERS]; 90 | // for (int i = 0; i < Constants.NO_OF_DATA_CENTERS; i++) { 91 | // datacenter[i] = DatacenterCreator.createDatacenter("Datacenter_" + i); 92 | // } 93 | 94 | datacenter = DatacenterCreator.createDatacenter("Datacenter_", Constants.NO_OF_VMS); 95 | //Third step: Create Broker 96 | FCFSDatacenterBroker broker = createBroker("Broker_0"); 97 | int brokerId = broker.getId(); 98 | 99 | //Fourth step: Create VMs and Cloudlets and send them to broker 100 | vmList = createVM(brokerId, Constants.NO_OF_VMS); 101 | cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 102 | 103 | broker.submitVmList(vmList); 104 | broker.submitCloudletList(cloudletList); 105 | 106 | // Fifth step: Starts the simulation 107 | CloudSim.startSimulation(); 108 | 109 | // Final step: Print results when simulation is over 110 | List newList = broker.getCloudletReceivedList(); 111 | //newList.addAll(globalBroker.getBroker().getCloudletReceivedList()); 112 | 113 | CloudSim.stopSimulation(); 114 | 115 | printCloudletList(newList); 116 | 117 | Log.printLine(FCFS_Scheduler.class.getName() + " finished!"); 118 | } catch (Exception e) { 119 | e.printStackTrace(); 120 | Log.printLine("The simulation has been terminated due to an unexpected error"); 121 | } 122 | } 123 | 124 | private static FCFSDatacenterBroker createBroker(String name) throws Exception { 125 | return new FCFSDatacenterBroker(name); 126 | } 127 | 128 | /** 129 | * Prints the Cloudlet objects 130 | * 131 | * @param list list of Cloudlets 132 | */ 133 | private static void printCloudletList(List list) { 134 | int size = list.size(); 135 | Cloudlet cloudlet; 136 | 137 | String indent = " "; 138 | Log.printLine(); 139 | Log.printLine("========== OUTPUT =========="); 140 | Log.printLine("Cloudlet ID" + indent + "STATUS" + 141 | indent + "Data center ID" + 142 | indent + "VM ID" + 143 | indent + indent + "Time" + 144 | indent + "Start Time" + 145 | indent + "Finish Time"); 146 | 147 | DecimalFormat dft = new DecimalFormat("###.##"); 148 | dft.setMinimumIntegerDigits(2); 149 | for (int i = 0; i < size; i++) { 150 | cloudlet = list.get(i); 151 | Log.print(indent + dft.format(cloudlet.getCloudletId()) + indent + indent); 152 | 153 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) { 154 | Log.print("SUCCESS"); 155 | 156 | Log.printLine(indent + indent + dft.format(cloudlet.getResourceId()) + 157 | indent + indent + indent + dft.format(cloudlet.getVmId()) + 158 | indent + indent + dft.format(cloudlet.getActualCPUTime()) + 159 | indent + indent + dft.format(cloudlet.getExecStartTime()) + 160 | indent + indent + indent + dft.format(cloudlet.getFinishTime())); 161 | } 162 | } 163 | double makespan = calcMakespan(list); 164 | Log.printLine("Makespan using FCFS: " + makespan); 165 | } 166 | 167 | private static double calcMakespan(List list) { 168 | double makespan = 0; 169 | double[] dcWorkingTime = new double[Constants.NO_OF_VMS]; 170 | 171 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 172 | int dcId = list.get(i).getVmId() % Constants.NO_OF_VMS; 173 | if (dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; 174 | dcWorkingTime[dcId] += execMatrix[i][dcId] + commMatrix[i][dcId]; 175 | makespan = Math.max(makespan, dcWorkingTime[dcId]); 176 | } 177 | return makespan; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /trunk/src/PSO/PSO.java: -------------------------------------------------------------------------------- 1 | package PSO; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | import utils.Constants; 5 | 6 | public class PSO { 7 | private static Swarm swarm; 8 | private static SchedulerParticle particles[]; 9 | private static SchedulerFitnessFunction ff = new SchedulerFitnessFunction(); 10 | 11 | public PSO() { 12 | initParticles(); 13 | } 14 | 15 | 16 | public double[] run() { 17 | swarm = new Swarm(Constants.POPULATION_SIZE, new SchedulerParticle(), ff); 18 | 19 | swarm.setMinPosition(0); 20 | swarm.setMaxPosition(Constants.NO_OF_VMS - 1); 21 | swarm.setMaxMinVelocity(0.5); 22 | swarm.setParticles(particles); 23 | swarm.setParticleUpdate(new SchedulerParticleUpdate(new SchedulerParticle())); 24 | 25 | for (int i = 0; i < Constants.NO_OF_Iterations; i++) { 26 | swarm.evolve(); 27 | if (i % 10 == 0) { 28 | System.out.printf("Gloabl best at iteration (%d): %f\n", i, swarm.getBestFitness()); 29 | } 30 | // swarm.setInertia(); 31 | } 32 | System.out.println("\nThe best fitness value: " + swarm.getBestFitness() + "\nBest makespan: " + ff.calcMakespan(swarm.getBestParticle().getBestPosition())); 33 | 34 | System.out.println("The best solution is: "); 35 | SchedulerParticle bestParticle = (SchedulerParticle) swarm.getBestParticle(); 36 | System.out.println(bestParticle.toString()); 37 | 38 | return swarm.getBestPosition(); 39 | } 40 | 41 | private static void initParticles() { 42 | particles = new SchedulerParticle[Constants.POPULATION_SIZE]; 43 | for (int i = 0; i < Constants.POPULATION_SIZE; ++i) 44 | particles[i] = new SchedulerParticle(); 45 | } 46 | 47 | public void printBestFitness() { 48 | System.out.println("\nBest fitness value: " + swarm.getBestFitness() + 49 | "\nBest makespan: " + ff.calcMakespan(swarm.getBestParticle().getBestPosition())); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /trunk/src/PSO/PSODatacenterBroker.java: -------------------------------------------------------------------------------- 1 | package PSO; 2 | 3 | 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.core.CloudSim; 6 | import org.cloudbus.cloudsim.core.CloudSimTags; 7 | import org.cloudbus.cloudsim.core.SimEvent; 8 | import org.cloudbus.cloudsim.lists.VmList; 9 | 10 | import java.util.List; 11 | 12 | public class PSODatacenterBroker extends DatacenterBroker { 13 | 14 | private double[] mapping; 15 | 16 | PSODatacenterBroker(String name) throws Exception { 17 | super(name); 18 | } 19 | 20 | public void setMapping(double[] mapping) { 21 | this.mapping = mapping; 22 | } 23 | 24 | private List assignCloudletsToVms(List cloudlist) { 25 | int idx = 0; 26 | for (Cloudlet cl : cloudlist) { 27 | cl.setVmId((int) mapping[idx++]); 28 | } 29 | return cloudlist; 30 | } 31 | 32 | @Override 33 | protected void submitCloudlets() { 34 | List tasks = assignCloudletsToVms(getCloudletList()); 35 | int vmIndex = 0; 36 | for (Cloudlet cloudlet : tasks) { 37 | Vm vm; 38 | // if user didn't bind this cloudlet and it has not been executed yet 39 | if (cloudlet.getVmId() == -1) { 40 | vm = getVmsCreatedList().get(vmIndex); 41 | } else { // submit to the specific vm 42 | vm = VmList.getById(getVmsCreatedList(), cloudlet.getVmId()); 43 | if (vm == null) { // vm was not created 44 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Postponing execution of cloudlet " 45 | + cloudlet.getCloudletId() + ": bount VM not available"); 46 | continue; 47 | } 48 | } 49 | 50 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Sending cloudlet " 51 | + cloudlet.getCloudletId() + " to VM #" + vm.getId()); 52 | cloudlet.setVmId(vm.getId()); 53 | sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.CLOUDLET_SUBMIT, cloudlet); 54 | cloudletsSubmitted++; 55 | vmIndex = (vmIndex + 1) % getVmsCreatedList().size(); 56 | getCloudletSubmittedList().add(cloudlet); 57 | } 58 | } 59 | 60 | @Override 61 | protected void processResourceCharacteristics(SimEvent ev) { 62 | DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData(); 63 | getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics); 64 | 65 | if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) { 66 | distributeRequestsForNewVmsAcrossDatacenters(); 67 | } 68 | } 69 | 70 | protected void distributeRequestsForNewVmsAcrossDatacenters() { 71 | int numberOfVmsAllocated = 0; 72 | int i = 0; 73 | 74 | final List availableDatacenters = getDatacenterIdsList(); 75 | 76 | for (Vm vm : getVmList()) { 77 | int datacenterId = availableDatacenters.get(i++ % availableDatacenters.size()); 78 | String datacenterName = CloudSim.getEntityName(datacenterId); 79 | 80 | if (!getVmsToDatacentersMap().containsKey(vm.getId())) { 81 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Trying to Create VM #" + vm.getId() + " in " + datacenterName); 82 | sendNow(datacenterId, CloudSimTags.VM_CREATE_ACK, vm); 83 | numberOfVmsAllocated++; 84 | } 85 | } 86 | 87 | setVmsRequested(numberOfVmsAllocated); 88 | setVmsAcks(0); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /trunk/src/PSO/SchedulerFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package PSO; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | import sun.misc.VM; 5 | import utils.Constants; 6 | import utils.GenerateMatrices; 7 | 8 | public class SchedulerFitnessFunction extends FitnessFunction { 9 | private static double[][] execMatrix, commMatrix; 10 | 11 | SchedulerFitnessFunction() { 12 | super(false); 13 | commMatrix = GenerateMatrices.getCommMatrix(); 14 | execMatrix = GenerateMatrices.getExecMatrix(); 15 | } 16 | 17 | @Override 18 | public double evaluate(double[] position) { 19 | double alpha = 0.3; 20 | return alpha * calcTotalTime(position) + (1 - alpha) * calcMakespan(position); 21 | // return calcMakespan(position); 22 | } 23 | 24 | private double calcTotalTime(double[] position) { 25 | double totalCost = 0; 26 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 27 | int dcId = (int) position[i]; 28 | totalCost += execMatrix[i][dcId] + commMatrix[i][dcId]; 29 | } 30 | return totalCost; 31 | } 32 | 33 | public double calcMakespan(double[] position) { 34 | double makespan = 0; 35 | double[] dcWorkingTime = new double[Constants.NO_OF_VMS]; 36 | 37 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 38 | int dcId = (int) position[i]; 39 | if(dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; 40 | dcWorkingTime[dcId] += execMatrix[i][dcId] + commMatrix[i][dcId]; 41 | makespan = Math.max(makespan, dcWorkingTime[dcId]); 42 | } 43 | return makespan; 44 | } 45 | 46 | public double calcLoadCost(double[] position) 47 | { 48 | double utilization = 0.0; 49 | for(int i =0;i availableDatacenters = getDatacenterIdsList(); 39 | 40 | for (Vm vm : getVmList()) { 41 | int datacenterId = availableDatacenters.get(i++ % availableDatacenters.size()); 42 | String datacenterName = CloudSim.getEntityName(datacenterId); 43 | 44 | if (!getVmsToDatacentersMap().containsKey(vm.getId())) { 45 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Trying to Create VM #" + vm.getId() + " in " + datacenterName); 46 | sendNow(datacenterId, CloudSimTags.VM_CREATE_ACK, vm); 47 | numberOfVmsAllocated++; 48 | } 49 | } 50 | 51 | setVmsRequested(numberOfVmsAllocated); 52 | setVmsAcks(0); 53 | } 54 | } -------------------------------------------------------------------------------- /trunk/src/RoundRobin/RoundRobinScheduler.java: -------------------------------------------------------------------------------- 1 | package RoundRobin; 2 | 3 | import org.cloudbus.cloudsim.*; 4 | import org.cloudbus.cloudsim.core.CloudSim; 5 | import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; 6 | import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; 7 | import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; 8 | import utils.Constants; 9 | import utils.DatacenterCreator; 10 | import utils.GenerateMatrices; 11 | 12 | import java.text.DecimalFormat; 13 | import java.util.ArrayList; 14 | import java.util.Calendar; 15 | import java.util.LinkedList; 16 | import java.util.List; 17 | 18 | 19 | public class RoundRobinScheduler { 20 | 21 | private static List cloudletList; 22 | private static List vmList; 23 | private static Datacenter[] datacenter; 24 | private static double[][] commMatrix; 25 | private static double[][] execMatrix; 26 | 27 | private static List createVM(int userId, int vms) { 28 | //Creates a container to store VMs. This list is passed to the broker later 29 | LinkedList list = new LinkedList(); 30 | 31 | //VM Parameters 32 | long size = 10000; //image size (MB) 33 | int ram = 512; //vm memory (MB) 34 | int mips = 250; 35 | long bw = 1000; 36 | int pesNumber = 1; //number of cpus 37 | String vmm = "Xen"; //VMM name 38 | 39 | //create VMs 40 | Vm[] vm = new Vm[vms]; 41 | 42 | for (int i = 0; i < vms; i++) { 43 | vm[i] = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared()); 44 | list.add(vm[i]); 45 | } 46 | 47 | return list; 48 | } 49 | 50 | private static List createCloudlet(int userId, int cloudlets, int idShift) { 51 | // Creates a container to store Cloudlets 52 | LinkedList list = new LinkedList(); 53 | 54 | //cloudlet parameters 55 | long fileSize = 300; 56 | long outputSize = 300; 57 | int pesNumber = 1; 58 | UtilizationModel utilizationModel = new UtilizationModelFull(); 59 | 60 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 61 | 62 | for (int i = 0; i < cloudlets; i++) { 63 | int dcId = (int) (Math.random() * Constants.NO_OF_DATA_CENTERS); 64 | long length = (long) (1e3 * (commMatrix[i][dcId] + execMatrix[i][dcId])); 65 | cloudlet[i] = new Cloudlet(idShift + i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); 66 | // setting the owner of these Cloudlets 67 | cloudlet[i].setUserId(userId); 68 | cloudlet[i].setVmId(dcId + 2); 69 | list.add(cloudlet[i]); 70 | } 71 | return list; 72 | } 73 | 74 | public static void main(String[] args) { 75 | Log.printLine("Starting Round Robin Scheduler..."); 76 | 77 | new GenerateMatrices(); 78 | execMatrix = GenerateMatrices.getExecMatrix(); 79 | commMatrix = GenerateMatrices.getCommMatrix(); 80 | 81 | try { 82 | int num_user = 1; // number of grid users 83 | Calendar calendar = Calendar.getInstance(); 84 | boolean trace_flag = false; // mean trace events 85 | 86 | CloudSim.init(num_user, calendar, trace_flag); 87 | 88 | // Second step: Create Datacenters 89 | datacenter = new Datacenter[Constants.NO_OF_DATA_CENTERS]; 90 | for (int i = 0; i < Constants.NO_OF_DATA_CENTERS; i++) { 91 | datacenter[i] = DatacenterCreator.createDatacenter("Datacenter_" + i); 92 | } 93 | 94 | //Third step: Create Broker 95 | RoundRobinDatacenterBroker broker = createBroker("Broker_0"); 96 | int brokerId = broker.getId(); 97 | 98 | //Fourth step: Create VMs and Cloudlets and send them to broker 99 | vmList = createVM(brokerId, Constants.NO_OF_VMS); 100 | cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 101 | 102 | broker.submitVmList(vmList); 103 | broker.submitCloudletList(cloudletList); 104 | 105 | // Fifth step: Starts the simulation 106 | CloudSim.startSimulation(); 107 | 108 | // Final step: Print results when simulation is over 109 | List newList = broker.getCloudletReceivedList(); 110 | //newList.addAll(globalBroker.getBroker().getCloudletReceivedList()); 111 | 112 | CloudSim.stopSimulation(); 113 | 114 | printCloudletList(newList); 115 | 116 | Log.printLine(RoundRobinScheduler.class.getName() + " finished!"); 117 | } catch (Exception e) { 118 | e.printStackTrace(); 119 | Log.printLine("The simulation has been terminated due to an unexpected error"); 120 | } 121 | } 122 | 123 | private static RoundRobinDatacenterBroker createBroker(String name) throws Exception { 124 | return new RoundRobinDatacenterBroker(name); 125 | } 126 | 127 | /** 128 | * Prints the Cloudlet objects 129 | * 130 | * @param list list of Cloudlets 131 | */ 132 | private static void printCloudletList(List list) { 133 | int size = list.size(); 134 | Cloudlet cloudlet; 135 | 136 | String indent = " "; 137 | Log.printLine(); 138 | Log.printLine("========== OUTPUT =========="); 139 | Log.printLine("Cloudlet ID" + indent + "STATUS" + 140 | indent + "Data center ID" + 141 | indent + "VM ID" + 142 | indent + indent + "Time" + 143 | indent + "Start Time" + 144 | indent + "Finish Time"); 145 | 146 | DecimalFormat dft = new DecimalFormat("###.##"); 147 | dft.setMinimumIntegerDigits(2); 148 | for (int i = 0; i < size; i++) { 149 | cloudlet = list.get(i); 150 | Log.print(indent + dft.format(cloudlet.getCloudletId()) + indent + indent); 151 | 152 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) { 153 | Log.print("SUCCESS"); 154 | 155 | Log.printLine(indent + indent + dft.format(cloudlet.getResourceId()) + 156 | indent + indent + indent + dft.format(cloudlet.getVmId()) + 157 | indent + indent + dft.format(cloudlet.getActualCPUTime()) + 158 | indent + indent + dft.format(cloudlet.getExecStartTime()) + 159 | indent + indent + indent + dft.format(cloudlet.getFinishTime())); 160 | } 161 | } 162 | double makespan = calcMakespan(list); 163 | Log.printLine("Makespan using RR: " + makespan); 164 | } 165 | 166 | private static double calcMakespan(List list) { 167 | double makespan = 0; 168 | double[] dcWorkingTime = new double[Constants.NO_OF_DATA_CENTERS]; 169 | 170 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 171 | int dcId = list.get(i).getVmId() % Constants.NO_OF_DATA_CENTERS; 172 | if (dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; 173 | dcWorkingTime[dcId] += execMatrix[i][dcId] + commMatrix[i][dcId]; 174 | makespan = Math.max(makespan, dcWorkingTime[dcId]); 175 | } 176 | return makespan; 177 | } 178 | } -------------------------------------------------------------------------------- /trunk/src/SAPSO/SAPSO.java: -------------------------------------------------------------------------------- 1 | package SAPSO; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | import utils.Constants; 5 | 6 | public class SAPSO { 7 | private static Swarm swarm; 8 | private static SchedulerParticle particles[]; 9 | private static SchedulerFitnessFunction ff = new SchedulerFitnessFunction(); 10 | 11 | public SAPSO() { 12 | initParticles(); 13 | } 14 | 15 | 16 | public double[] run() { 17 | swarm = new Swarm(Constants.POPULATION_SIZE, new SchedulerParticle(), ff); 18 | 19 | swarm.setMinPosition(0); 20 | swarm.setMaxPosition(Constants.NO_OF_VMS - 1); 21 | swarm.setMaxMinVelocity(0.5); 22 | swarm.setParticles(particles); 23 | swarm.setParticleUpdate(new SchedulerParticleUpdate(new SchedulerParticle())); 24 | 25 | for (int i = 0; i < Constants.NO_OF_Iterations; i++) { 26 | swarm.evolve(); 27 | if (i % 10 == 0) { 28 | System.out.printf("Gloabl best at iteration (%d): %f\n", i, swarm.getBestFitness()); 29 | } 30 | double w = GetWeightBySAStrategy(swarm.getInertia(),i); 31 | // swarm.setInertia(w); 32 | } 33 | System.out.println("\nThe best fitness value: " + swarm.getBestFitness() + "\nBest makespan: " + ff.calcMakespan(swarm.getBestParticle().getBestPosition())); 34 | System.out.println("The best totalcost:"+ff.calcTotalTime(swarm.getBestParticle().getPosition())); 35 | System.out.println("The best solution is: "); 36 | SchedulerParticle bestParticle = (SchedulerParticle) swarm.getBestParticle(); 37 | System.out.println(bestParticle.toString()); 38 | 39 | return swarm.getBestPosition(); 40 | } 41 | 42 | private double GetWeightBySAStrategy(double w,int iter) 43 | { 44 | double value = 0.0; 45 | // 使用模拟退火的策略 46 | return value; 47 | } 48 | 49 | private static void initParticles() { 50 | particles = new SchedulerParticle[Constants.POPULATION_SIZE]; 51 | for (int i = 0; i < Constants.POPULATION_SIZE; ++i) 52 | particles[i] = new SchedulerParticle(); 53 | } 54 | 55 | public void printBestFitness() { 56 | System.out.println("\nBest fitness value: " + swarm.getBestFitness() + 57 | "\nBest makespan: " + ff.calcMakespan(swarm.getBestParticle().getBestPosition())); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /trunk/src/SAPSO/SAPSODatacenterBroker.java: -------------------------------------------------------------------------------- 1 | package SAPSO; 2 | 3 | 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.core.CloudSim; 6 | import org.cloudbus.cloudsim.core.CloudSimTags; 7 | import org.cloudbus.cloudsim.core.SimEvent; 8 | import org.cloudbus.cloudsim.lists.VmList; 9 | 10 | import java.util.List; 11 | 12 | public class SAPSODatacenterBroker extends DatacenterBroker { 13 | 14 | private double[] mapping; 15 | 16 | SAPSODatacenterBroker(String name) throws Exception { 17 | super(name); 18 | } 19 | 20 | public void setMapping(double[] mapping) { 21 | this.mapping = mapping; 22 | } 23 | 24 | private List assignCloudletsToVms(List cloudlist) { 25 | int idx = 0; 26 | for (Cloudlet cl : cloudlist) { 27 | cl.setVmId((int) mapping[idx++]); 28 | } 29 | return cloudlist; 30 | } 31 | 32 | @Override 33 | protected void submitCloudlets() { 34 | List tasks = assignCloudletsToVms(getCloudletList()); 35 | int vmIndex = 0; 36 | for (Cloudlet cloudlet : tasks) { 37 | Vm vm; 38 | // if user didn't bind this cloudlet and it has not been executed yet 39 | if (cloudlet.getVmId() == -1) { 40 | vm = getVmsCreatedList().get(vmIndex); 41 | } else { // submit to the specific vm 42 | vm = VmList.getById(getVmsCreatedList(), cloudlet.getVmId()); 43 | if (vm == null) { // vm was not created 44 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Postponing execution of cloudlet " 45 | + cloudlet.getCloudletId() + ": bount VM not available"); 46 | continue; 47 | } 48 | } 49 | 50 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Sending cloudlet " 51 | + cloudlet.getCloudletId() + " to VM #" + vm.getId()); 52 | cloudlet.setVmId(vm.getId()); 53 | sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.CLOUDLET_SUBMIT, cloudlet); 54 | cloudletsSubmitted++; 55 | vmIndex = (vmIndex + 1) % getVmsCreatedList().size(); 56 | getCloudletSubmittedList().add(cloudlet); 57 | } 58 | } 59 | 60 | @Override 61 | protected void processResourceCharacteristics(SimEvent ev) { 62 | DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData(); 63 | getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics); 64 | 65 | if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) { 66 | distributeRequestsForNewVmsAcrossDatacenters(); 67 | } 68 | } 69 | 70 | protected void distributeRequestsForNewVmsAcrossDatacenters() { 71 | int numberOfVmsAllocated = 0; 72 | int i = 0; 73 | 74 | final List availableDatacenters = getDatacenterIdsList(); 75 | 76 | for (Vm vm : getVmList()) { 77 | int datacenterId = availableDatacenters.get(i++ % availableDatacenters.size()); 78 | String datacenterName = CloudSim.getEntityName(datacenterId); 79 | 80 | if (!getVmsToDatacentersMap().containsKey(vm.getId())) { 81 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Trying to Create VM #" + vm.getId() + " in " + datacenterName); 82 | sendNow(datacenterId, CloudSimTags.VM_CREATE_ACK, vm); 83 | numberOfVmsAllocated++; 84 | } 85 | } 86 | 87 | setVmsRequested(numberOfVmsAllocated); 88 | setVmsAcks(0); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /trunk/src/SAPSO/SAPSO_Scheduler.java: -------------------------------------------------------------------------------- 1 | package SAPSO; 2 | 3 | import org.cloudbus.cloudsim.*; 4 | import org.cloudbus.cloudsim.core.CloudSim; 5 | import utils.Constants; 6 | import utils.DatacenterCreator; 7 | import utils.GenerateMatrices; 8 | 9 | import java.io.BufferedReader; 10 | import java.io.FileInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStreamReader; 13 | import java.text.DecimalFormat; 14 | import java.util.*; 15 | 16 | public class SAPSO_Scheduler { 17 | 18 | private static List cloudletList = new LinkedList<>(); 19 | private static List vmList; 20 | // private static Datacenter[] datacenter; 21 | private static Datacenter datacenter; 22 | private static SAPSO SAPSOSchedularInstance; 23 | private static double mapping[]; 24 | private static double[][] commMatrix; 25 | private static double[][] execMatrix; 26 | 27 | private static List createVM(int userId, int vms) { 28 | //Creates a container to store VMs. This list is passed to the broker later 29 | LinkedList list = new LinkedList(); 30 | 31 | //VM Parameters 32 | long size = 10000; //image size (MB) 33 | int ram = 512; //vm memory (MB) 34 | int mips = 800; 35 | long bw = 1000; 36 | int pesNumber = 1; //number of cpus 37 | String vmm = "Xen"; //VMM name 38 | 39 | //create VMs 40 | Vm[] vm = new Vm[vms]; 41 | 42 | for (int i = 0; i < vms; i++) { 43 | vm[i] = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared()); 44 | list.add(vm[i]); 45 | } 46 | 47 | return list; 48 | } 49 | 50 | private static List createCloudlet(int userId, int cloudlets, int idShift) { 51 | LinkedList list = new LinkedList(); 52 | 53 | //cloudlet parameters 54 | long fileSize = 300; 55 | long outputSize = 300; 56 | int pesNumber = 1; 57 | UtilizationModel utilizationModel = new UtilizationModelFull(); 58 | 59 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 60 | 61 | for (int i = 0; i < cloudlets; i++) { 62 | int dcId = (int) (mapping[i]); 63 | // long length = (long) (1e3 * (commMatrix[i][dcId] + execMatrix[i][dcId])); 64 | long length = (long)(execMatrix[i][dcId]*1e3); 65 | cloudlet[i] = new Cloudlet(idShift + i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); 66 | cloudlet[i].setUserId(userId); 67 | list.add(cloudlet[i]); 68 | } 69 | 70 | return list; 71 | } 72 | 73 | public static void main(String[] args) { 74 | Log.printLine("Starting SA-PSO Scheduler..."); 75 | 76 | try { 77 | int num_user = 1; // number of grid users 78 | Calendar calendar = Calendar.getInstance(); 79 | boolean trace_flag = false; // mean trace events 80 | 81 | CloudSim.init(num_user, calendar, trace_flag); 82 | 83 | // Second step: Create Datacenters 84 | // datacenter = new Datacenter[Constants.NO_OF_DATA_CENTERS]; 85 | // for (int i = 0; i < Constants.NO_OF_DATA_CENTERS; i++) { 86 | // datacenter[i] = DatacenterCreator.createDatacenter("Datacenter_" + i); 87 | // } 88 | datacenter = DatacenterCreator.createDatacenter("DataCenter_"+1,Constants.NO_OF_VMS); 89 | 90 | //Third step: Create Broker 91 | SAPSODatacenterBroker broker = createBroker("Broker_0"); 92 | int brokerId = broker.getId(); 93 | 94 | //Fourth step: Create VMs and Cloudlets and send them to broker 95 | vmList = createVM(brokerId, Constants.NO_OF_VMS); 96 | 97 | GenerateMatrices GM = new GenerateMatrices(vmList); 98 | commMatrix = GM.getcommMatrix(); 99 | execMatrix = GM.getexecMatrix(); 100 | SAPSOSchedularInstance = new SAPSO(); 101 | mapping = SAPSOSchedularInstance.run(); 102 | cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 103 | 104 | // cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 105 | // mapping our dcIds to cloudsim dcIds 106 | HashSet dcIds = new HashSet<>(); 107 | HashMap hm = new HashMap<>(); 108 | for (Vm dc : vmList) { 109 | if (!dcIds.contains(dc.getId())) 110 | dcIds.add(dc.getId()); 111 | } 112 | Iterator it = dcIds.iterator(); 113 | for (int i = 0; i < mapping.length; i++) { 114 | if (hm.containsKey((int) mapping[i])) continue; 115 | hm.put((int) mapping[i], it.next()); 116 | } 117 | for (int i = 0; i < mapping.length; i++) 118 | mapping[i] = hm.containsKey((int) mapping[i]) ? hm.get((int) mapping[i]) : mapping[i]; 119 | 120 | broker.submitVmList(vmList); 121 | broker.setMapping(mapping); 122 | broker.submitCloudletList(cloudletList); 123 | 124 | 125 | // Fifth step: Starts the simulation 126 | CloudSim.startSimulation(); 127 | 128 | List newList = broker.getCloudletReceivedList(); 129 | 130 | CloudSim.stopSimulation(); 131 | 132 | // printCloudletList(newList); 133 | PrintResults(newList); 134 | Log.printLine(SAPSO_Scheduler.class.getName() + " finished!"); 135 | } catch (Exception e) { 136 | e.printStackTrace(); 137 | Log.printLine("The simulation has been terminated due to an unexpected error"); 138 | } 139 | } 140 | 141 | private static SAPSODatacenterBroker createBroker(String name) throws Exception { 142 | return new SAPSODatacenterBroker(name); 143 | } 144 | 145 | /** 146 | * Prints the Cloudlet objects 147 | * 148 | * @param list list of Cloudlets 149 | */ 150 | private static void printCloudletList(List list) { 151 | int size = list.size(); 152 | Cloudlet cloudlet; 153 | 154 | String indent = " "; 155 | Log.printLine(); 156 | Log.printLine("========== OUTPUT =========="); 157 | Log.printLine("Cloudlet ID" + indent + "STATUS" + 158 | indent + "Data center ID" + 159 | indent + "VM ID" + 160 | indent + indent + "Time" + 161 | indent + "Start Time" + 162 | indent + "Finish Time"); 163 | 164 | double mxFinishTime = 0; 165 | DecimalFormat dft = new DecimalFormat("###.##"); 166 | dft.setMinimumIntegerDigits(2); 167 | for (int i = 0; i < size; i++) { 168 | cloudlet = list.get(i); 169 | Log.print(indent + dft.format(cloudlet.getCloudletId()) + indent + indent); 170 | 171 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) { 172 | Log.print("SUCCESS"); 173 | Log.printLine(indent + indent + dft.format(cloudlet.getResourceId()) + 174 | indent + indent + indent + dft.format(cloudlet.getVmId()) + 175 | indent + indent + dft.format(cloudlet.getActualCPUTime()) + 176 | indent + indent + dft.format(cloudlet.getExecStartTime()) + 177 | indent + indent + indent + dft.format(cloudlet.getFinishTime())); 178 | } 179 | mxFinishTime = Math.max(mxFinishTime, cloudlet.getFinishTime()); 180 | } 181 | Log.printLine(mxFinishTime); 182 | SAPSOSchedularInstance.printBestFitness(); 183 | } 184 | 185 | private static double PrintResults(List list) 186 | { 187 | int size = list.size(); 188 | Cloudlet cloudlet; 189 | 190 | String indent = " "; 191 | Log.printLine(); 192 | Log.printLine("================ Execution Result =================="); 193 | Log.printLine("No."+indent +"Cloudlet ID" + indent + "STATUS" + indent 194 | + "Data center ID" + indent + "VM ID" + indent+"VM mips"+ indent +"CloudletLength"+indent+ "Time" 195 | + indent + "Start Time" + indent + "Finish Time"); 196 | double mxFinishTime = 0; 197 | DecimalFormat dft = new DecimalFormat("###.##"); 198 | for (int i = 0; i < size; i++) 199 | { 200 | cloudlet = list.get(i); 201 | Log.print(i+1+indent+indent + cloudlet.getCloudletId() + indent + indent); 202 | 203 | if (cloudlet.getStatus()== Cloudlet.SUCCESS) 204 | { 205 | Log.print("SUCCESS"); 206 | 207 | Log.printLine(indent +indent + indent + cloudlet.getResourceId() 208 | + indent + indent + indent + cloudlet.getVmId() 209 | + indent + indent + getVmById(cloudlet.getVmId()).getMips() 210 | + indent + indent + cloudlet.getCloudletLength() 211 | + indent + indent+ indent + indent 212 | + dft.format(cloudlet.getActualCPUTime()) + indent 213 | + indent + dft.format(cloudlet.getExecStartTime()) 214 | + indent + indent 215 | + dft.format(cloudlet.getFinishTime())); 216 | } 217 | mxFinishTime = Math.max(mxFinishTime, cloudlet.getFinishTime()); 218 | } 219 | Log.printLine("================ Execution Result Ends here =================="); 220 | Log.printLine(mxFinishTime); 221 | return mxFinishTime; 222 | } 223 | 224 | public static Vm getVmById(int vmId) 225 | { 226 | for(Vm v:vmList) 227 | { 228 | if(v.getId()==vmId) 229 | return v; 230 | } 231 | return null; 232 | } 233 | } -------------------------------------------------------------------------------- /trunk/src/SAPSO/SchedulerFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package SAPSO; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | import sun.misc.VM; 5 | import utils.Constants; 6 | import utils.GenerateMatrices; 7 | 8 | public class SchedulerFitnessFunction extends FitnessFunction { 9 | private static double[][] execMatrix, commMatrix; 10 | 11 | SchedulerFitnessFunction() { 12 | super(false); 13 | commMatrix = GenerateMatrices.getCommMatrix(); 14 | execMatrix = GenerateMatrices.getExecMatrix(); 15 | } 16 | 17 | @Override 18 | public double evaluate(double[] position) { 19 | double alpha = 0.3; 20 | return alpha * calcTotalTime(position) + (1 - alpha) * calcMakespan(position); 21 | // return calcMakespan(position); 22 | } 23 | 24 | public double calcTotalTime(double[] position) { 25 | double totalCost = 0; 26 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 27 | int dcId = (int) position[i]; 28 | totalCost += execMatrix[i][dcId] + commMatrix[i][dcId]; 29 | } 30 | return totalCost; 31 | } 32 | 33 | public double calcMakespan(double[] position) { 34 | double makespan = 0; 35 | double[] dcWorkingTime = new double[Constants.NO_OF_VMS]; 36 | 37 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 38 | int dcId = (int) position[i]; 39 | if(dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; 40 | dcWorkingTime[dcId] += execMatrix[i][dcId] + commMatrix[i][dcId]; 41 | makespan = Math.max(makespan, dcWorkingTime[dcId]); 42 | } 43 | return makespan; 44 | } 45 | 46 | public double calcLoadCost(double[] position) 47 | { 48 | double utilization = 0.0; 49 | for(int i =0;i=value) 107 | { 108 | AcceptNewPosition(position, fitness); 109 | } 110 | } 111 | T= Calculator.mul(a, T); 112 | } 113 | 114 | 115 | private double GenerateValueUnderCurrentT() 116 | { 117 | Random rd = new Random(); 118 | double value = rd.nextDouble(); 119 | return value; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /trunk/src/SAPSO/SchedulerParticleUpdate.java: -------------------------------------------------------------------------------- 1 | package SAPSO; 2 | 3 | import net.sourceforge.jswarm_pso.Particle; 4 | import net.sourceforge.jswarm_pso.ParticleUpdate; 5 | import net.sourceforge.jswarm_pso.Swarm; 6 | import utils.Constants; 7 | 8 | public class SchedulerParticleUpdate extends ParticleUpdate { 9 | private static final double W = 0.9; 10 | private static final double C = 2.0; 11 | 12 | SchedulerParticleUpdate(Particle particle) { 13 | super(particle); 14 | } 15 | 16 | @Override 17 | public void update(Swarm swarm, Particle particle) { 18 | double[] v = particle.getVelocity(); 19 | double[] x = particle.getPosition(); 20 | double[] pbest = particle.getBestPosition(); 21 | double[] gbest = swarm.getBestPosition(); 22 | 23 | for (int i = 0; i < Constants.NO_OF_TASKS; ++i) { 24 | v[i] = W * v[i] + C * Math.random() * (pbest[i] - x[i]) + C * Math.random() * (gbest[i] - x[i]); 25 | x[i] = (int) (x[i] + v[i]); 26 | } 27 | 28 | particle.InitMutation(); 29 | } 30 | } -------------------------------------------------------------------------------- /trunk/src/SAWPSO/SAWPSO.java: -------------------------------------------------------------------------------- 1 | package SAWPSO; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | import utils.Calculator; 5 | import utils.Constants; 6 | 7 | public class SAWPSO { 8 | private static Swarm swarm; 9 | private static SchedulerParticle particles[]; 10 | private static SchedulerFitnessFunction ff = new SchedulerFitnessFunction(); 11 | 12 | public SAWPSO() { 13 | initParticles(); 14 | } 15 | 16 | /** 17 | * 算法主流程 18 | * @return 返回粒子群全局最优位置的粒子位置,即位置向量,即最优解 19 | */ 20 | public double[] run() { 21 | swarm = new Swarm(Constants.POPULATION_SIZE, new SchedulerParticle(), ff); 22 | double w_max = 0.9; 23 | double w_min = 0.5; 24 | swarm.setInertia(0.9); 25 | swarm.setMinPosition(0); 26 | swarm.setMaxPosition(Constants.NO_OF_VMS - 1); 27 | swarm.setMaxMinVelocity(0.5); 28 | swarm.setParticles(particles); 29 | swarm.setParticleUpdate(new SchedulerParticleUpdate(new SchedulerParticle())); 30 | for (int i = 0; i < Constants.NO_OF_Iterations; i++) { 31 | double w = swarm.getInertia();//获取当前惯性权值 32 | swarm.evolve();//算法正式的计算流程 33 | if (i % 10 == 0) { 34 | System.out.printf("Gloabl best at iteration (%d): %f\n", i+1, swarm.getBestFitness()); 35 | } 36 | w = CalSOW(w_max, w_min, i, w); 37 | swarm.setInertia(w);//设置惯性权值 38 | } 39 | System.out.println("\nThe best fitness value: " + swarm.getBestFitness() + "\nBest makespan: " + ff.calcMakespan(swarm.getBestParticle().getBestPosition())); 40 | System.out.println("The best totalcost:"+ff.calcTotalTime(swarm.getBestParticle().getPosition())); 41 | System.out.println("The best solution is: "); 42 | SchedulerParticle bestParticle = (SchedulerParticle) swarm.getBestParticle(); 43 | System.out.println(bestParticle.toString()); 44 | 45 | return swarm.getBestPosition(); 46 | } 47 | 48 | /** 49 | * 根据迭代的次数计算自组织方式的惯性权重 50 | * @param w_max 权重上限 51 | * @param w_min 权重下限 52 | * @param i 当前迭代循环的中间变量 一般从0开始 53 | * @param w 惯性权重 54 | * @return 返回计算后的惯性权重值 55 | */ 56 | private double CalSOW(double w_max, double w_min, int i, double w) { 57 | double iter = i+1;//当前迭代的次数 58 | double ret = Calculator.div(iter, Constants.NO_OF_Iterations); 59 | if(iter>=1&iter<=Constants.NO_OF_Iterations/2) 60 | { 61 | w= -Math.pow(ret,2.0)+w_max; 62 | } 63 | if(iter<=Constants.NO_OF_Iterations&&iter>Constants.NO_OF_Iterations/2) 64 | { 65 | w= -Math.pow(ret-1.0,2.0)+w_min; 66 | } 67 | if(w>w_max) 68 | { 69 | w = w_max; 70 | } 71 | if(w assignCloudletsToVms(List cloudlist) { 25 | int idx = 0; 26 | for (Cloudlet cl : cloudlist) { 27 | cl.setVmId((int) mapping[idx++]); 28 | } 29 | return cloudlist; 30 | } 31 | 32 | @Override 33 | protected void submitCloudlets() { 34 | List tasks = assignCloudletsToVms(getCloudletList()); 35 | int vmIndex = 0; 36 | for (Cloudlet cloudlet : tasks) { 37 | Vm vm; 38 | // if user didn't bind this cloudlet and it has not been executed yet 39 | if (cloudlet.getVmId() == -1) { 40 | vm = getVmsCreatedList().get(vmIndex); 41 | } else { // submit to the specific vm 42 | vm = VmList.getById(getVmsCreatedList(), cloudlet.getVmId()); 43 | if (vm == null) { // vm was not created 44 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Postponing execution of cloudlet " 45 | + cloudlet.getCloudletId() + ": bount VM not available"); 46 | continue; 47 | } 48 | } 49 | 50 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Sending cloudlet " 51 | + cloudlet.getCloudletId() + " to VM #" + vm.getId()); 52 | cloudlet.setVmId(vm.getId()); 53 | sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.CLOUDLET_SUBMIT, cloudlet); 54 | cloudletsSubmitted++; 55 | vmIndex = (vmIndex + 1) % getVmsCreatedList().size(); 56 | getCloudletSubmittedList().add(cloudlet); 57 | } 58 | } 59 | 60 | @Override 61 | protected void processResourceCharacteristics(SimEvent ev) { 62 | DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData(); 63 | getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics); 64 | 65 | if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) { 66 | distributeRequestsForNewVmsAcrossDatacenters(); 67 | } 68 | } 69 | 70 | protected void distributeRequestsForNewVmsAcrossDatacenters() { 71 | int numberOfVmsAllocated = 0; 72 | int i = 0; 73 | 74 | final List availableDatacenters = getDatacenterIdsList(); 75 | 76 | for (Vm vm : getVmList()) { 77 | int datacenterId = availableDatacenters.get(i++ % availableDatacenters.size()); 78 | String datacenterName = CloudSim.getEntityName(datacenterId); 79 | 80 | if (!getVmsToDatacentersMap().containsKey(vm.getId())) { 81 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Trying to Create VM #" + vm.getId() + " in " + datacenterName); 82 | sendNow(datacenterId, CloudSimTags.VM_CREATE_ACK, vm); 83 | numberOfVmsAllocated++; 84 | } 85 | } 86 | 87 | setVmsRequested(numberOfVmsAllocated); 88 | setVmsAcks(0); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /trunk/src/SAWPSO/SAWPSO_SchedulerTestOne.java: -------------------------------------------------------------------------------- 1 | package SAWPSO; 2 | 3 | 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.core.CloudSim; 6 | import utils.Constants; 7 | import utils.DatacenterCreator; 8 | import utils.GenerateMatrices; 9 | 10 | import java.io.BufferedReader; 11 | import java.io.FileInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStreamReader; 14 | import java.text.DecimalFormat; 15 | import java.util.*; 16 | 17 | public class SAWPSO_SchedulerTestOne { 18 | 19 | private static List cloudletList = new LinkedList<>(); 20 | private static List vmList; 21 | // private static Datacenter[] datacenter; 22 | private static Datacenter datacenter; 23 | private static SAWPSO SAWPSOSchedularInstance; 24 | private static double mapping[]; 25 | private static double[][] commMatrix; 26 | private static double[][] execMatrix; 27 | 28 | private static List createVM(int userId, int vms) { 29 | //Creates a container to store VMs. This list is passed to the broker later 30 | LinkedList list = new LinkedList(); 31 | 32 | //VM Parameters 33 | long size = 10000; //image size (MB) 34 | int ram = 512; //vm memory (MB) 35 | int mips = 1000; 36 | long bw = 1000; 37 | int pesNumber = 1; //number of cpus 38 | String vmm = "Xen"; //VMM name 39 | 40 | //create VMs 41 | Vm[] vm = new Vm[vms]; 42 | 43 | for (int i = 0; i < vms; i++) { 44 | vm[i] = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared()); 45 | list.add(vm[i]); 46 | } 47 | 48 | return list; 49 | } 50 | 51 | private static List createCloudlet(int userId, int cloudlets, int idShift) { 52 | LinkedList list = new LinkedList(); 53 | 54 | //cloudlet parameters 55 | long fileSize = 300; 56 | long outputSize = 300; 57 | int pesNumber = 1; 58 | UtilizationModel utilizationModel = new UtilizationModelFull(); 59 | 60 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 61 | 62 | for (int i = 0; i < cloudlets; i++) { 63 | int dcId = (int) (mapping[i]); 64 | // long length = (long) (1e3 * (commMatrix[i][dcId] + execMatrix[i][dcId])); 65 | long length = (long)(execMatrix[i][dcId]*1e3); 66 | cloudlet[i] = new Cloudlet(idShift + i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); 67 | cloudlet[i].setUserId(userId); 68 | list.add(cloudlet[i]); 69 | } 70 | 71 | return list; 72 | } 73 | 74 | public static void main(String[] args) { 75 | Log.printLine("Starting C-M-SOWPSO Scheduler..."); 76 | 77 | 78 | try { 79 | int num_user = 1; // number of grid users 80 | Calendar calendar = Calendar.getInstance(); 81 | boolean trace_flag = false; // mean trace events 82 | 83 | CloudSim.init(num_user, calendar, trace_flag); 84 | 85 | // Second step: Create Datacenters 86 | datacenter = DatacenterCreator.createDatacenter("DataCenter_"+1,Constants.NO_OF_VMS); 87 | 88 | //Third step: Create Broker 89 | SAWPSODatacenterBroker broker = createBroker("Broker_0"); 90 | int brokerId = broker.getId(); 91 | 92 | //Fourth step: Create VMs and Cloudlets and send them to broker 93 | vmList = createVM(brokerId, Constants.NO_OF_VMS); 94 | // cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 95 | 96 | GenerateMatrices GM = new GenerateMatrices(vmList); 97 | commMatrix = GM.getcommMatrix(); 98 | execMatrix = GM.getexecMatrix(); 99 | SAWPSOSchedularInstance = new SAWPSO(); 100 | mapping = SAWPSOSchedularInstance.run(); 101 | cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 102 | 103 | // mapping our dcIds to cloudsim dcIds 104 | HashSet dcIds = new HashSet<>(); 105 | HashMap hm = new HashMap<>(); 106 | for (Vm dc : vmList) { 107 | if (!dcIds.contains(dc.getId())) 108 | dcIds.add(dc.getId()); 109 | } 110 | Iterator it = dcIds.iterator(); 111 | for (int i = 0; i < mapping.length; i++) { 112 | if (hm.containsKey((int) mapping[i])) continue; 113 | hm.put((int) mapping[i], it.next()); 114 | } 115 | for (int i = 0; i < mapping.length; i++) 116 | mapping[i] = hm.containsKey((int) mapping[i]) ? hm.get((int) mapping[i]) : mapping[i]; 117 | 118 | broker.submitVmList(vmList); 119 | broker.setMapping(mapping); 120 | broker.submitCloudletList(cloudletList); 121 | 122 | 123 | // Fifth step: Starts the simulation 124 | CloudSim.startSimulation(); 125 | 126 | List newList = broker.getCloudletReceivedList(); 127 | 128 | CloudSim.stopSimulation(); 129 | 130 | // printCloudletList(newList); 131 | PrintResults(newList); 132 | Log.printLine(SAWPSO_Scheduler.class.getName() + " finished!"); 133 | } catch (Exception e) { 134 | e.printStackTrace(); 135 | Log.printLine("The simulation has been terminated due to an unexpected error"); 136 | } 137 | } 138 | 139 | private static SAWPSODatacenterBroker createBroker(String name) throws Exception { 140 | return new SAWPSODatacenterBroker(name); 141 | } 142 | 143 | private static double PrintResults(List list) 144 | { 145 | int size = list.size(); 146 | Cloudlet cloudlet; 147 | 148 | String indent = " "; 149 | Log.printLine(); 150 | Log.printLine("================ Execution Result =================="); 151 | Log.printLine("No."+indent +"Cloudlet ID" + indent + "STATUS" + indent 152 | + "Data center ID" + indent + "VM ID" + indent+"VM mips"+ indent +"CloudletLength"+indent+ "Time" 153 | + indent + "Start Time" + indent + "Finish Time"); 154 | double mxFinishTime = 0; 155 | DecimalFormat dft = new DecimalFormat("###.##"); 156 | for (int i = 0; i < size; i++) 157 | { 158 | cloudlet = list.get(i); 159 | Log.print(i+1+indent+indent + cloudlet.getCloudletId() + indent + indent); 160 | 161 | if (cloudlet.getStatus()== Cloudlet.SUCCESS) 162 | { 163 | Log.print("SUCCESS"); 164 | 165 | Log.printLine(indent +indent + indent + cloudlet.getResourceId() 166 | + indent + indent + indent + cloudlet.getVmId() 167 | + indent + indent + getVmById(cloudlet.getVmId()).getMips() 168 | + indent + indent + cloudlet.getCloudletLength() 169 | + indent + indent+ indent + indent 170 | + dft.format(cloudlet.getActualCPUTime()) + indent 171 | + indent + dft.format(cloudlet.getExecStartTime()) 172 | + indent + indent 173 | + dft.format(cloudlet.getFinishTime())); 174 | } 175 | mxFinishTime = Math.max(mxFinishTime, cloudlet.getFinishTime()); 176 | } 177 | Log.printLine("================ Execution Result Ends here =================="); 178 | Log.printLine(mxFinishTime); 179 | return mxFinishTime; 180 | } 181 | 182 | public static Vm getVmById(int vmId) 183 | { 184 | for(Vm v:vmList) 185 | { 186 | if(v.getId()==vmId) 187 | return v; 188 | } 189 | return null; 190 | } 191 | } -------------------------------------------------------------------------------- /trunk/src/SAWPSO/SchedulerFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package SAWPSO; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | import sun.misc.VM; 5 | import utils.Constants; 6 | import utils.GenerateMatrices; 7 | 8 | public class SchedulerFitnessFunction extends FitnessFunction { 9 | private static double[][] execMatrix, commMatrix; 10 | 11 | SchedulerFitnessFunction() { 12 | super(false); 13 | commMatrix = GenerateMatrices.getCommMatrix(); 14 | execMatrix = GenerateMatrices.getExecMatrix(); 15 | } 16 | 17 | @Override 18 | public double evaluate(double[] position) { 19 | double alpha = 0.3; 20 | return alpha * calcTotalTime(position) + (1 - alpha) * calcMakespan(position); 21 | // return calcMakespan(position); 22 | // return calcTotalTime(position); 23 | } 24 | 25 | //任务完成成本 26 | public double calcTotalTime(double[] position) { 27 | double totalCost = 0; 28 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 29 | int dcId = (int) position[i]; 30 | totalCost += execMatrix[i][dcId] + commMatrix[i][dcId]; 31 | } 32 | return totalCost; 33 | } 34 | //最大完成时间 35 | public double calcMakespan(double[] position) { 36 | double makespan = 0; 37 | double[] dcWorkingTime = new double[Constants.NO_OF_VMS]; 38 | 39 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 40 | int dcId = (int) position[i]; 41 | if(dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; 42 | dcWorkingTime[dcId] += execMatrix[i][dcId] + commMatrix[i][dcId]; 43 | makespan = Math.max(makespan, dcWorkingTime[dcId]); 44 | } 45 | return makespan; 46 | } 47 | 48 | public double calcEC(double[] position) 49 | { 50 | double Consumption = 0.0; 51 | for(int i =0;i=10)//粒子连续10次判断都不活跃 进入变异环节 62 | { 63 | count=0; 64 | //启动变异策略 65 | System.out.println("go particle mutation!"); 66 | ChaosStrategy instance = ChaosStrategy.getInstance(); 67 | instance.CalChaos(); 68 | 69 | double[] new_vel = new double[Constants.NO_OF_TASKS]; 70 | double[] new_pos = new double[Constants.NO_OF_TASKS]; 71 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 72 | //混沌映射方式生成变异粒子的速度和位置 73 | new_pos[i] = instance.PLM(1,instance.getChaosValue())*Constants.NO_OF_VMS; 74 | new_vel[i] = instance.LM(1,instance.getChaosValue()); 75 | } 76 | setPosition(new_pos); 77 | setVelocity(new_vel); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /trunk/src/SAWPSO/SchedulerParticleUpdate.java: -------------------------------------------------------------------------------- 1 | package SAWPSO; 2 | 3 | import net.sourceforge.jswarm_pso.Particle; 4 | import net.sourceforge.jswarm_pso.ParticleUpdate; 5 | import net.sourceforge.jswarm_pso.Swarm; 6 | import utils.Constants; 7 | 8 | public class SchedulerParticleUpdate extends ParticleUpdate { 9 | private double W = 0.9; 10 | private static final double C = 2.0; 11 | SchedulerParticleUpdate(Particle particle) { 12 | super(particle); 13 | } 14 | 15 | @Override 16 | public void update(Swarm swarm, Particle particle) { 17 | double[] v = particle.getVelocity(); 18 | double[] x = particle.getPosition(); 19 | double[] pbest = particle.getBestPosition(); 20 | double[] gbest = swarm.getBestPosition(); 21 | W = swarm.getInertia(); 22 | for (int i = 0; i < Constants.NO_OF_TASKS; ++i) { 23 | v[i] = W * v[i] + C * Math.random() * (pbest[i] - x[i]) + C * Math.random() * (gbest[i] - x[i]); 24 | x[i] = (int) (x[i] + v[i]); 25 | } 26 | 27 | if(SAWPSO_Scheduler.class.getName()=="SAWPSO.SAWPSO_Scheduler") 28 | { 29 | particle.InitMutation(); 30 | } 31 | if(SAWPSO_SchedulerTestOne.class.getName()=="SAWPSO.SAWPSO_SchedulerTestOne") 32 | { 33 | particle.InitMutation(); 34 | } 35 | } 36 | 37 | 38 | } -------------------------------------------------------------------------------- /trunk/src/SJF/SJFDatacenterBroker.java: -------------------------------------------------------------------------------- 1 | package SJF; 2 | 3 | 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.core.CloudSim; 6 | import org.cloudbus.cloudsim.core.CloudSimTags; 7 | import org.cloudbus.cloudsim.core.SimEvent; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class SJFDatacenterBroker extends DatacenterBroker { 13 | 14 | SJFDatacenterBroker(String name) throws Exception { 15 | super(name); 16 | } 17 | 18 | public void scheduleTaskstoVms() { 19 | int reqTasks = cloudletList.size(); 20 | int reqVms = vmList.size(); 21 | Vm vm = vmList.get(0); 22 | 23 | for (int i = 0; i < reqTasks; i++) { 24 | bindCloudletToVm(i, (i % reqVms)); 25 | System.out.println("Task" + cloudletList.get(i).getCloudletId() + " is bound with VM" + vmList.get(i % reqVms).getId()); 26 | } 27 | 28 | //System.out.println("reqTasks: "+ reqTasks); 29 | 30 | ArrayList list = new ArrayList(); 31 | for (Cloudlet cloudlet : getCloudletReceivedList()) { 32 | list.add(cloudlet); 33 | } 34 | 35 | //setCloudletReceivedList(null); 36 | 37 | Cloudlet[] list2 = list.toArray(new Cloudlet[list.size()]); 38 | 39 | //System.out.println("size :"+list.size()); 40 | 41 | Cloudlet temp = null; 42 | 43 | int n = list.size(); 44 | 45 | for (int i = 0; i < n; i++) { 46 | for (int j = 1; j < (n - i); j++) { 47 | if (list2[j - 1].getCloudletLength() / (vm.getMips() * vm.getNumberOfPes()) > list2[j].getCloudletLength() / (vm.getMips() * vm.getNumberOfPes())) { 48 | //swap the elements! 49 | //swap(list2[j-1], list2[j]); 50 | temp = list2[j - 1]; 51 | list2[j - 1] = list2[j]; 52 | list2[j] = temp; 53 | } 54 | // printNumbers(list2); 55 | } 56 | } 57 | 58 | ArrayList list3 = new ArrayList(); 59 | 60 | for (int i = 0; i < list2.length; i++) { 61 | list3.add(list2[i]); 62 | } 63 | //printNumbers(list); 64 | 65 | setCloudletReceivedList(list); 66 | 67 | //System.out.println("\n\tSJFS Broker Schedules\n"); 68 | //System.out.println("\n"); 69 | } 70 | 71 | public void printNumber(Cloudlet[] list) { 72 | for (int i = 0; i < list.length; i++) { 73 | System.out.print(" " + list[i].getCloudletId()); 74 | System.out.println(list[i].getCloudletStatusString()); 75 | } 76 | System.out.println(); 77 | } 78 | 79 | public void printNumbers(ArrayList list) { 80 | for (int i = 0; i < list.size(); i++) { 81 | System.out.print(" " + list.get(i).getCloudletId()); 82 | } 83 | System.out.println(); 84 | } 85 | 86 | @Override 87 | protected void processCloudletReturn(SimEvent ev) { 88 | Cloudlet cloudlet = (Cloudlet) ev.getData(); 89 | getCloudletReceivedList().add(cloudlet); 90 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + cloudlet.getCloudletId() 91 | + " received"); 92 | cloudletsSubmitted--; 93 | if (getCloudletList().size() == 0 && cloudletsSubmitted == 0) { 94 | scheduleTaskstoVms(); 95 | cloudletExecution(cloudlet); 96 | } 97 | } 98 | 99 | protected void cloudletExecution(Cloudlet cloudlet) { 100 | 101 | if (getCloudletList().size() == 0 && cloudletsSubmitted == 0) { // all cloudlets executed 102 | Log.printLine(CloudSim.clock() + ": " + getName() + ": All Cloudlets executed. Finishing..."); 103 | clearDatacenters(); 104 | finishExecution(); 105 | } else { // some cloudlets haven't finished yet 106 | if (getCloudletList().size() > 0 && cloudletsSubmitted == 0) { 107 | // all the cloudlets sent finished. It means that some bount 108 | // cloudlet is waiting its VM be created 109 | clearDatacenters(); 110 | createVmsInDatacenter(0); 111 | } 112 | } 113 | } 114 | 115 | @Override 116 | protected void processResourceCharacteristics(SimEvent ev) { 117 | DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData(); 118 | getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics); 119 | 120 | if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) { 121 | distributeRequestsForNewVmsAcrossDatacenters(); 122 | } 123 | } 124 | 125 | protected void distributeRequestsForNewVmsAcrossDatacenters() { 126 | int numberOfVmsAllocated = 0; 127 | int i = 0; 128 | 129 | final List availableDatacenters = getDatacenterIdsList(); 130 | 131 | for (Vm vm : getVmList()) { 132 | int datacenterId = availableDatacenters.get(i++ % availableDatacenters.size()); 133 | String datacenterName = CloudSim.getEntityName(datacenterId); 134 | 135 | if (!getVmsToDatacentersMap().containsKey(vm.getId())) { 136 | Log.printLine(CloudSim.clock() + ": " + getName() + ": Trying to Create VM #" + vm.getId() + " in " + datacenterName); 137 | sendNow(datacenterId, CloudSimTags.VM_CREATE_ACK, vm); 138 | numberOfVmsAllocated++; 139 | } 140 | } 141 | 142 | setVmsRequested(numberOfVmsAllocated); 143 | setVmsAcks(0); 144 | } 145 | } -------------------------------------------------------------------------------- /trunk/src/SJF/SJF_Scheduler.java: -------------------------------------------------------------------------------- 1 | package SJF; 2 | 3 | 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.core.CloudSim; 6 | import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; 7 | import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; 8 | import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; 9 | import utils.Constants; 10 | import utils.DatacenterCreator; 11 | import utils.GenerateMatrices; 12 | 13 | import java.text.DecimalFormat; 14 | import java.util.ArrayList; 15 | import java.util.Calendar; 16 | import java.util.LinkedList; 17 | import java.util.List; 18 | 19 | public class SJF_Scheduler { 20 | 21 | private static List cloudletList; 22 | private static List vmList; 23 | private static Datacenter[] datacenter; 24 | private static double[][] commMatrix; 25 | private static double[][] execMatrix; 26 | 27 | private static List createVM(int userId, int vms) { 28 | //Creates a container to store VMs. This list is passed to the broker later 29 | LinkedList list = new LinkedList(); 30 | 31 | //VM Parameters 32 | long size = 10000; //image size (MB) 33 | int ram = 512; //vm memory (MB) 34 | int mips = 250; 35 | long bw = 1000; 36 | int pesNumber = 1; //number of cpus 37 | String vmm = "Xen"; //VMM name 38 | 39 | //create VMs 40 | Vm[] vm = new Vm[vms]; 41 | 42 | for (int i = 0; i < vms; i++) { 43 | vm[i] = new Vm(datacenter[i].getId(), userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared()); 44 | list.add(vm[i]); 45 | } 46 | 47 | return list; 48 | } 49 | 50 | private static List createCloudlet(int userId, int cloudlets, int idShift) { 51 | // Creates a container to store Cloudlets 52 | LinkedList list = new LinkedList(); 53 | 54 | //cloudlet parameters 55 | long fileSize = 300; 56 | long outputSize = 300; 57 | int pesNumber = 1; 58 | UtilizationModel utilizationModel = new UtilizationModelFull(); 59 | 60 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 61 | 62 | for (int i = 0; i < cloudlets; i++) { 63 | int dcId = (int) (Math.random() * Constants.NO_OF_DATA_CENTERS); 64 | long length = (long) (1e3 * (commMatrix[i][dcId] + execMatrix[i][dcId])); 65 | cloudlet[i] = new Cloudlet(idShift + i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); 66 | // setting the owner of these Cloudlets 67 | cloudlet[i].setUserId(userId); 68 | cloudlet[i].setVmId(dcId + 2); 69 | list.add(cloudlet[i]); 70 | } 71 | return list; 72 | } 73 | 74 | public static void main(String[] args) { 75 | Log.printLine("Starting SJF Scheduler..."); 76 | 77 | new GenerateMatrices(); 78 | execMatrix = GenerateMatrices.getExecMatrix(); 79 | commMatrix = GenerateMatrices.getCommMatrix(); 80 | 81 | try { 82 | int num_user = 1; // number of grid users 83 | Calendar calendar = Calendar.getInstance(); 84 | boolean trace_flag = false; // mean trace events 85 | 86 | CloudSim.init(num_user, calendar, trace_flag); 87 | 88 | // Second step: Create Datacenters 89 | datacenter = new Datacenter[Constants.NO_OF_DATA_CENTERS]; 90 | for (int i = 0; i < Constants.NO_OF_DATA_CENTERS; i++) { 91 | datacenter[i] = DatacenterCreator.createDatacenter("Datacenter_" + i); 92 | } 93 | 94 | //Third step: Create Broker 95 | SJFDatacenterBroker broker = createBroker("Broker_0"); 96 | int brokerId = broker.getId(); 97 | 98 | //Fourth step: Create VMs and Cloudlets and send them to broker 99 | vmList = createVM(brokerId, Constants.NO_OF_DATA_CENTERS); 100 | cloudletList = createCloudlet(brokerId, Constants.NO_OF_TASKS, 0); 101 | 102 | broker.submitVmList(vmList); 103 | broker.submitCloudletList(cloudletList); 104 | 105 | // Fifth step: Starts the simulation 106 | CloudSim.startSimulation(); 107 | 108 | // Final step: Print results when simulation is over 109 | List newList = broker.getCloudletReceivedList(); 110 | //newList.addAll(globalBroker.getBroker().getCloudletReceivedList()); 111 | 112 | CloudSim.stopSimulation(); 113 | 114 | printCloudletList(newList); 115 | 116 | Log.printLine(SJF_Scheduler.class.getName() + " finished!"); 117 | } catch (Exception e) { 118 | e.printStackTrace(); 119 | Log.printLine("The simulation has been terminated due to an unexpected error"); 120 | } 121 | } 122 | 123 | private static SJFDatacenterBroker createBroker(String name) throws Exception { 124 | return new SJFDatacenterBroker(name); 125 | } 126 | 127 | /** 128 | * Prints the Cloudlet objects 129 | * 130 | * @param list list of Cloudlets 131 | */ 132 | private static void printCloudletList(List list) { 133 | int size = list.size(); 134 | Cloudlet cloudlet; 135 | 136 | String indent = " "; 137 | Log.printLine(); 138 | Log.printLine("========== OUTPUT =========="); 139 | Log.printLine("Cloudlet ID" + indent + "STATUS" + 140 | indent + "Data center ID" + 141 | indent + "VM ID" + 142 | indent + indent + "Time" + 143 | indent + "Start Time" + 144 | indent + "Finish Time"); 145 | 146 | DecimalFormat dft = new DecimalFormat("###.##"); 147 | dft.setMinimumIntegerDigits(2); 148 | for (int i = 0; i < size; i++) { 149 | cloudlet = list.get(i); 150 | Log.print(indent + dft.format(cloudlet.getCloudletId()) + indent + indent); 151 | 152 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) { 153 | Log.print("SUCCESS"); 154 | 155 | Log.printLine(indent + indent + dft.format(cloudlet.getResourceId()) + 156 | indent + indent + indent + dft.format(cloudlet.getVmId()) + 157 | indent + indent + dft.format(cloudlet.getActualCPUTime()) + 158 | indent + indent + dft.format(cloudlet.getExecStartTime()) + 159 | indent + indent + indent + dft.format(cloudlet.getFinishTime())); 160 | } 161 | } 162 | double makespan = calcMakespan(list); 163 | Log.printLine("Makespan using SJF: " + makespan); 164 | } 165 | 166 | private static double calcMakespan(List list) { 167 | double makespan = 0; 168 | double[] dcWorkingTime = new double[Constants.NO_OF_DATA_CENTERS]; 169 | 170 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 171 | int dcId = list.get(i).getVmId() % Constants.NO_OF_DATA_CENTERS; 172 | if (dcWorkingTime[dcId] != 0) --dcWorkingTime[dcId]; 173 | dcWorkingTime[dcId] += execMatrix[i][dcId] + commMatrix[i][dcId]; 174 | makespan = Math.max(makespan, dcWorkingTime[dcId]); 175 | } 176 | return makespan; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/FitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/FitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/FitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | 4 | /** 5 | * Base Fitness Function 6 | * @author Pablo Cingolani 7 | */ 8 | public abstract class FitnessFunction { 9 | 10 | /** Should this funtion be maximized or minimized */ 11 | boolean maximize; 12 | 13 | //------------------------------------------------------------------------- 14 | // Constructors 15 | //------------------------------------------------------------------------- 16 | 17 | /** Default constructor */ 18 | public FitnessFunction() { 19 | this.maximize = true; // Default: Maximize 20 | } 21 | 22 | /** 23 | * Constructor 24 | * @param maximize : Should we try to maximize or minimize this funtion? 25 | */ 26 | public FitnessFunction(boolean maximize) { 27 | this.maximize = maximize; 28 | } 29 | 30 | //------------------------------------------------------------------------- 31 | // Methods 32 | //------------------------------------------------------------------------- 33 | 34 | /** 35 | * Evaluates a particles at a given position 36 | * NOTE: You should write your own method! 37 | * 38 | * @param position : Particle's position 39 | * @return Fitness function for a particle 40 | */ 41 | public abstract double evaluate(double position[]); 42 | 43 | /** 44 | * Evaluates a particles fitness 45 | * @param particle : Particle to evaluate 46 | * @return Fitness function for a particle 47 | */ 48 | public double evaluate(Particle particle) { 49 | double position[] = particle.getPosition(); 50 | double fit = evaluate(position); 51 | particle.setFitness(fit,maximize); 52 | return fit; 53 | } 54 | 55 | /** Are we maximizing this fitness funtion? */ 56 | public boolean isMaximize() { 57 | return maximize; 58 | } 59 | 60 | public void setMaximize(boolean maximize) { 61 | this.maximize = maximize; 62 | } 63 | } -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/Gpr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/Gpr.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/Gpr.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | /** 4 | * General pupose rutines 5 | * @author Pablo Cingolani 6 | */ 7 | public class Gpr { 8 | 9 | /** Only print this number of warnings */ 10 | public static int MAX_NUMBER_OF_WARNINGS = 5; 11 | 12 | /** Print warning only N times */ 13 | public static int warnCount = 0; 14 | 15 | /** 16 | * Prints a debug message (prints class name, method and line number) 17 | * @param b : Boolean to print 18 | */ 19 | public static void debug(boolean b) { 20 | debug(new Boolean(b), 1); 21 | } 22 | 23 | /** 24 | * Prits a debug message (prints class name, method and line number) 25 | * @param debug : Only prints message if debug=true 26 | * @param i : int to print 27 | */ 28 | public static void debug(boolean debug, int i) { 29 | if( debug ) debug(new Integer(i), 1); 30 | } 31 | 32 | /** 33 | * Prits a debug message (prints class name, method and line number) 34 | * @param debug : Only prints message if debug=true 35 | * @param obj : Object to print 36 | */ 37 | public static void debug(boolean debug, Object obj) { 38 | if( debug ) debug(obj, 1); 39 | } 40 | 41 | /** 42 | * Prints a debug message (prints class name, method and line number) 43 | * @param d : double to print 44 | */ 45 | public static void debug(double d) { 46 | debug(Double.toString(d), 1); 47 | } 48 | 49 | /** 50 | * Prints a debug message (prints class name, method and line number) 51 | * @param i : int to print 52 | */ 53 | public static void debug(int i) { 54 | debug(new Integer(i), 1); 55 | } 56 | 57 | /** 58 | * Prits a debug message (prints class name, method and line number) 59 | * @param currentDebugLevel : Debug level being used 60 | * @param thisMessageLevel : Only prints message if thisMessageLevel >= currentDebugLevel 61 | * @param obj : Object to print 62 | */ 63 | public static void debug(int currentDebugLevel, int thisMessageLevel, Object obj) { 64 | if( currentDebugLevel >= thisMessageLevel ) debug(obj, 1); 65 | } 66 | 67 | /** 68 | * Prits a debug message (prints class name, method and line number) 69 | * @param obj : Object to print 70 | */ 71 | public static void debug(Object obj) { 72 | debug(obj, 1, true); 73 | } 74 | 75 | /** 76 | * Prits a debug message (prints class name, method and line number) 77 | * @param obj : Object to print 78 | * @param offset : Offset N lines from stacktrace 79 | */ 80 | public static void debug(Object obj, int offset) { 81 | debug(obj, offset, true); 82 | } 83 | 84 | /** 85 | * Prits a debug message (prints class name, method and line number) 86 | * @param obj : Object to print 87 | * @param offset : Offset N lines from stacktrace 88 | * @param newLine : Print a newline char at the end ('\n') 89 | */ 90 | public static void debug(Object obj, int offset, boolean newLine) { 91 | StackTraceElement ste = new Exception().getStackTrace()[1 + offset]; 92 | String steStr = ste.getClassName(); 93 | int ind = steStr.lastIndexOf('.'); 94 | steStr = steStr.substring(ind + 1); 95 | steStr += "." + ste.getMethodName() + "(" + ste.getLineNumber() + "):\t" + (obj == null ? null : obj.toString()); 96 | if( newLine ) System.err.println(steStr); 97 | else System.err.print(steStr); 98 | } 99 | 100 | /** 101 | * Print a warning message (only a few of them) 102 | * @param warning 103 | */ 104 | public static void warn(String warning) { 105 | if( warnCount < MAX_NUMBER_OF_WARNINGS ) { 106 | warnCount++; 107 | Gpr.debug(warning, 2); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/Particle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/Particle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/ParticleUpdate.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdate.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | /** 4 | * Particle update strategy 5 | * 6 | * Every Swarm.evolve() itereation the following methods are called 7 | * - begin(Swarm) : Once at the begining of each iteration 8 | * - update(Swarm,Particle) : Once for each particle 9 | * - end(Swarm) : Once at the end of each iteration 10 | * 11 | * @author Pablo Cingolani 12 | */ 13 | public abstract class ParticleUpdate { 14 | 15 | /** 16 | * Constructor 17 | * @param particle : Sample of particles that will be updated later 18 | */ 19 | public ParticleUpdate(Particle particle) { 20 | } 21 | 22 | /** 23 | * This method is called at the begining of each iteration 24 | * Initialize random vectors use for local and global updates (rlocal[] and rother[]) 25 | */ 26 | public void begin(Swarm swarm) { 27 | } 28 | 29 | /** Update particle's velocity and position */ 30 | public abstract void update(Swarm swarm, Particle particle); 31 | 32 | /** This method is called at the end of each iteration */ 33 | public void end(Swarm swarm) { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateFullyRandom.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateFullyRandom.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateFullyRandom.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | /** 4 | * Particle update: Fully random approach 5 | * Note that rlocal and rother are randomly choosen for each particle and for each dimention 6 | * 7 | * @author Pablo Cingolani 8 | */ 9 | public class ParticleUpdateFullyRandom extends ParticleUpdate { 10 | 11 | /** 12 | * Constructor 13 | * @param particle : Sample of particles that will be updated later 14 | */ 15 | public ParticleUpdateFullyRandom(Particle particle) { 16 | super(particle); 17 | } 18 | 19 | /** Update particle's velocity and position */ 20 | public void update(Swarm swarm, Particle particle) { 21 | double position[] = particle.getPosition(); 22 | double velocity[] = particle.getVelocity(); 23 | double globalBestPosition[] = swarm.getBestPosition(); 24 | double particleBestPosition[] = particle.getBestPosition(); 25 | 26 | // Update velocity and position 27 | for( int i = 0; i < position.length; i++ ) { 28 | // Update position 29 | position[i] = position[i] + velocity[i]; 30 | 31 | // Update velocity 32 | velocity[i] = swarm.getInertia() * velocity[i] // Inertia 33 | + Math.random() * swarm.getParticleIncrement() * (particleBestPosition[i] - position[i]) // Local best 34 | + Math.random() * swarm.getGlobalIncrement() * (globalBestPosition[i] - position[i]); // Global best 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateRandomByParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateRandomByParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateRandomByParticle.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | /** 4 | * Particle update: Each particle selects an rlocal and rother 5 | * independently from other particles' values 6 | * 7 | * @author Pablo Cingolani 8 | */ 9 | public class ParticleUpdateRandomByParticle extends ParticleUpdate { 10 | 11 | /** 12 | * Constructor 13 | * @param particle : Sample of particles that will be updated later 14 | */ 15 | public ParticleUpdateRandomByParticle(Particle particle) { 16 | super(particle); 17 | } 18 | 19 | /** Update particle's velocity and position */ 20 | public void update(Swarm swarm, Particle particle) { 21 | double position[] = particle.getPosition(); 22 | double velocity[] = particle.getVelocity(); 23 | double globalBestPosition[] = swarm.getBestPosition(); 24 | double particleBestPosition[] = particle.getBestPosition(); 25 | 26 | double rlocal = Math.random(); 27 | double rglobal = Math.random(); 28 | 29 | // Update velocity and position 30 | for( int i = 0; i < position.length; i++ ) { 31 | // Update position 32 | position[i] = position[i] + velocity[i]; 33 | 34 | // Update velocity 35 | velocity[i] = swarm.getInertia() * velocity[i] // Inertia 36 | + rlocal * swarm.getParticleIncrement() * (particleBestPosition[i] - position[i]) // Local best 37 | + rglobal * swarm.getGlobalIncrement() * (globalBestPosition[i] - position[i]); // Global best 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateRepulsive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateRepulsive.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateRepulsive.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | /** 4 | * Particle update strategy 5 | * Warning: It's designed to be used with SwarmRepulsive swarms 6 | * 7 | * @author Pablo Cingolani 8 | */ 9 | public class ParticleUpdateRepulsive extends ParticleUpdate { 10 | 11 | /** Random vector for local update */ 12 | double rlocal[]; 13 | /** Random vector for global update */ 14 | double rother[]; 15 | /** Random factor for random velocity update */ 16 | double randRand; 17 | 18 | /** 19 | * Constructor 20 | * @param particle : Sample of particles that will be updated later 21 | */ 22 | public ParticleUpdateRepulsive(Particle particle) { 23 | super(particle); 24 | rlocal = new double[particle.getDimention()]; 25 | rother = new double[particle.getDimention()]; 26 | } 27 | 28 | /** 29 | * This method is called at the begining of each iteration 30 | * Initialize random vectors use for local and global updates (rlocal[] and rother[]) 31 | */ 32 | public void begin(Swarm swarm) { 33 | randRand = Math.random();// Random factor for random velocity 34 | 35 | int i,dim = swarm.getSampleParticle().getDimention(); 36 | for( i=0 ; i < dim ; i++ ) { 37 | rlocal[i] = Math.random(); 38 | rother[i] = Math.random(); 39 | } 40 | } 41 | 42 | /** 43 | * Update particle's position and velocity using repulsive algorithm 44 | */ 45 | public void update(Swarm swarm, Particle particle) { 46 | double position[] = particle.getPosition(); 47 | double velocity[] = particle.getVelocity(); 48 | double particleBestPosition[] = particle.getBestPosition(); 49 | double maxVelocity[] = swarm.getMaxVelocity(); 50 | double minVelocity[] = swarm.getMinVelocity(); 51 | SwarmRepulsive swarmRepulsive = (SwarmRepulsive)swarm; 52 | 53 | // Randomly select other particle 54 | int randOtherParticle = (int) (Math.random() * swarm.size()); 55 | double otherParticleBestPosition[] = swarm.getParticle(randOtherParticle).getBestPosition(); 56 | 57 | // Update velocity and position 58 | for( int i = 0; i < position.length; i++ ) { 59 | // Update position 60 | position[i] = position[i] + velocity[i]; 61 | 62 | // Create a random velocity (one on every dimention) 63 | double randVelocity = velocity[i] = (maxVelocity[i] - minVelocity[i]) * Math.random() + minVelocity[i]; 64 | 65 | // Update velocity 66 | velocity[i] = swarmRepulsive.getInertia() * velocity[i] // Inertia 67 | + rlocal[i] * swarmRepulsive.getParticleIncrement() * (particleBestPosition[i] - position[i]) // Local best 68 | + rother[i] * swarmRepulsive.getOtherParticleIncrement() * (otherParticleBestPosition[i] - position[i]) // other Particle Best Position 69 | + randRand * swarmRepulsive.getRandomIncrement() * randVelocity; // Random velocity 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateSimple.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateSimple.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/ParticleUpdateSimple.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | /** 4 | * Particle update strategy 5 | * 6 | * Every Swarm.evolve() itereation the following methods are called 7 | * - begin(Swarm) : Once at the begining of each iteration 8 | * - update(Swarm,Particle) : Once for each particle 9 | * - end(Swarm) : Once at the end of each iteration 10 | * 11 | * @author Pablo Cingolani 12 | */ 13 | public class ParticleUpdateSimple extends ParticleUpdate { 14 | 15 | /** Random vector for local update */ 16 | double rlocal[]; 17 | /** Random vector for global update */ 18 | double rglobal[]; 19 | 20 | /** 21 | * Constructor 22 | * @param particle : Sample of particles that will be updated later 23 | */ 24 | public ParticleUpdateSimple(Particle particle) { 25 | super(particle); 26 | rlocal = new double[particle.getDimention()]; 27 | rglobal = new double[particle.getDimention()]; 28 | } 29 | 30 | /** 31 | * This method is called at the begining of each iteration 32 | * Initialize random vectors use for local and global updates (rlocal[] and rother[]) 33 | */ 34 | public void begin(Swarm swarm) { 35 | int i,dim = swarm.getSampleParticle().getDimention(); 36 | for( i=0 ; i < dim ; i++ ) { 37 | rlocal[i] = Math.random(); 38 | rglobal[i] = Math.random(); 39 | } 40 | } 41 | 42 | /** Update particle's velocity and position */ 43 | public void update(Swarm swarm, Particle particle) { 44 | double position[] = particle.getPosition(); 45 | double velocity[] = particle.getVelocity(); 46 | double globalBestPosition[] = swarm.getBestPosition(); 47 | double particleBestPosition[] = particle.getBestPosition(); 48 | 49 | // Update velocity and position 50 | for( int i = 0; i < position.length; i++ ) { 51 | // Update velocity 52 | velocity[i] = swarm.getInertia() * velocity[i] // Inertia 53 | + rlocal[i] * swarm.getParticleIncrement() * (particleBestPosition[i] - position[i]) // Local best 54 | + rglobal[i] * swarm.getGlobalIncrement() * (globalBestPosition[i] - position[i]); // Global best 55 | // Update position 56 | position[i] += velocity[i]; 57 | } 58 | } 59 | 60 | /** This method is called at the end of each iteration */ 61 | public void end(Swarm swarm) { 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/Swarm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/Swarm.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/SwarmRepulsive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/SwarmRepulsive.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/SwarmRepulsive.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | /** 4 | * A swarm of repulsive particles 5 | * @author Pablo Cingolani 6 | */ 7 | public class SwarmRepulsive extends Swarm { 8 | 9 | public static double DEFAULT_OTHER_PARTICLE_INCREMENT = 0.9; 10 | public static double DEFAULT_RANDOM_INCREMENT = 0.1; 11 | 12 | /** Other particle increment */ 13 | double otherParticleIncrement; 14 | /** Random increment */ 15 | double randomIncrement; 16 | 17 | /** 18 | * Create a Swarm and set default values 19 | * @param numberOfParticles : Number of particles in this swarm (should be greater than 0). 20 | * If unsure about this parameter, try Swarm.DEFAULT_NUMBER_OF_PARTICLES or greater 21 | * @param sampleParticle : A particle that is a sample to build all other particles 22 | * @param fitnessFunction : Fitness function used to evaluate each particle 23 | */ 24 | public SwarmRepulsive(int numberOfParticles, Particle sampleParticle, FitnessFunction fitnessFunction) { 25 | super(numberOfParticles, sampleParticle, fitnessFunction); 26 | 27 | this.otherParticleIncrement = DEFAULT_OTHER_PARTICLE_INCREMENT; 28 | this.randomIncrement = DEFAULT_RANDOM_INCREMENT; 29 | 30 | // Set up particle update strategy (default: ParticleUpdateRepulsive) 31 | this.particleUpdate = new ParticleUpdateRepulsive(sampleParticle); 32 | } 33 | 34 | public double getOtherParticleIncrement() { 35 | return otherParticleIncrement; 36 | } 37 | 38 | public double getRandomIncrement() { 39 | return randomIncrement; 40 | } 41 | 42 | public void setOtherParticleIncrement(double otherParticleIncrement) { 43 | this.otherParticleIncrement = otherParticleIncrement; 44 | } 45 | 46 | public void setRandomIncrement(double randomIncrement) { 47 | this.randomIncrement = randomIncrement; 48 | } 49 | } -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/VariablesUpdate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/VariablesUpdate.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/VariablesUpdate.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso; 2 | 3 | 4 | /** 5 | * Swarm variables update 6 | * Every Swarm.evolve() iteration, update() is called 7 | * @author Pablo Cingolani 8 | */ 9 | public class VariablesUpdate { 10 | 11 | /** 12 | * Default constructor 13 | */ 14 | public VariablesUpdate() { 15 | super(); 16 | } 17 | 18 | /** 19 | * Update Swarm parameters here 20 | * @param swarm : Swarm to update 21 | */ 22 | public void update(Swarm swarm) { 23 | //// Nothing updated in this case (build your own VariablesUpdate class) 24 | //// e.g. (exponential update): 25 | // swarm.setInertia( 0.99 * swarm.getInertia() ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/alpine/Example.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/Example.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.alpine; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | 5 | /** 6 | * Maximize Alpine function, http://clerc.maurice.free.fr/pso/Alpine/Alpine_Function.htm 7 | * 8 | * f( x1 , x2 ) = sin( x2 ) * sin( x2 ) * Sqrt( x1 * x2 ) 9 | * 10 | * Solution should be: [x1, x2] = [ 7.917 , 7.917 ] where f() is 7.8856 (NOT 2.88 as the page says) 11 | * 12 | * @author Alvaro Jaramillo Duque 13 | */ 14 | public class Example { 15 | 16 | //------------------------------------------------------------------------- 17 | // Main 18 | //------------------------------------------------------------------------- 19 | public static void main(String[] args) { 20 | System.out.println("Begin: Example alpine\n"); 21 | 22 | // Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function) 23 | Swarm swarm = new Swarm(Swarm.DEFAULT_NUMBER_OF_PARTICLES, new MyParticle(), new MyFitnessFunction()); 24 | 25 | // Set position (and velocity) constraints. I.e.: where to look for solutions 26 | swarm.setInertia(0.95); 27 | swarm.setMaxPosition(10); // This should be 10, not 100 as your code said.... 28 | swarm.setMinPosition(0); 29 | swarm.setMaxMinVelocity(0.1); 30 | 31 | int numberOfIterations = 10000; 32 | 33 | // Optimize (and time it) 34 | for( int i = 0; i < numberOfIterations; i++ ) 35 | swarm.evolve(); 36 | 37 | // Print en results 38 | System.out.println(swarm.toStringStats()); 39 | System.out.println("Particle "+ swarm.getBestParticleIndex()); 40 | System.out.println("Particle "+ swarm.getParticle(swarm.getBestParticleIndex()).toString()); 41 | System.out.println("End: Example alpine"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/ExampleRepulsive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/alpine/ExampleRepulsive.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/ExampleRepulsive.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/alpine/ExampleRepulsive.java -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/alpine/MyFitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/MyFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.alpine; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | 5 | /** 6 | * Maximize Alpine function, http://clerc.maurice.free.fr/pso/Alpine/Alpine_Function.htm 7 | * 8 | * f( x1 , x2 ) = sin( x2 ) * sin( x2 ) * Sqrt( x1 * x2 ) 9 | * 10 | * @author Alvaro Jaramillo Duque 11 | */ 12 | public class MyFitnessFunction extends FitnessFunction { 13 | 14 | //------------------------------------------------------------------------- 15 | // Methods 16 | //------------------------------------------------------------------------- 17 | 18 | /** 19 | * Evaluates a particles at a given position 20 | * @param position : Particle's position 21 | * @return Fitness function for a particle 22 | */ 23 | public double evaluate(double position[]) { 24 | double x1 = position[0]; 25 | double x2 = position[1]; 26 | return Math.sin(x1) * Math.sin(x2) * Math.sqrt(x1 * x2); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/alpine/MyParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/alpine/MyParticle.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.alpine; 2 | 3 | import net.sourceforge.jswarm_pso.Particle; 4 | 5 | /** 6 | * Simple particle 7 | * @author Alvaro Jaramillo Duque 8 | */ 9 | public class MyParticle extends Particle { 10 | 11 | /** Default constructor */ 12 | public MyParticle() { 13 | super(2); // Create a 2-dimentional particle 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_1/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_1/Example.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_1/Example.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_1; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | import net.sourceforge.jswarm_pso.example_2.SwarmShow2D; 5 | 6 | /** 7 | * An extremely simple swarm optimization example 8 | * 9 | * Maximize function 10 | * f( x1 , x2 ) = 1 - Sqrt( ( x1 - 1/2 )^2 + ( x2 - 1/2 )^2 ) 11 | * Solution is (obviously): [ 1/2 , 1/2 ] 12 | * 13 | * @author Pablo Cingolani 14 | */ 15 | public class Example { 16 | 17 | //------------------------------------------------------------------------- 18 | // Main 19 | //------------------------------------------------------------------------- 20 | public static void main(String[] args) { 21 | System.out.println("Begin: Example 1\n"); 22 | 23 | // Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function) 24 | Swarm swarm = new Swarm(Swarm.DEFAULT_NUMBER_OF_PARTICLES, new MyParticle(), new MyFitnessFunction()); 25 | 26 | // Set position (and velocity) constraints. I.e.: where to look for solutions 27 | swarm.setInertia(0.95); 28 | swarm.setMaxPosition(1); 29 | swarm.setMinPosition(0); 30 | swarm.setMaxMinVelocity(0.1); 31 | 32 | int numberOfIterations = 100; 33 | boolean showGraphics = false; 34 | 35 | if( showGraphics ) { 36 | int displayEvery = numberOfIterations / 100 + 1; 37 | SwarmShow2D ss2d = new SwarmShow2D(swarm, numberOfIterations, displayEvery, true); 38 | ss2d.run(); 39 | } else { 40 | // Optimize (and time it) 41 | for( int i = 0; i < numberOfIterations; i++ ) 42 | swarm.evolve(); 43 | } 44 | 45 | // Print en results 46 | System.out.println(swarm.toStringStats()); 47 | System.out.println("End: Example 1"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_1/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_1/MyFitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_1/MyFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_1; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | 5 | /** 6 | * Sample Fitness function 7 | * f( x1 , x2 ) = 1 - Sqrt( ( x1 - 1/2 )^2 + ( x2 - 1/2 )^2 ) 8 | * 9 | * @author Pablo Cingolani 10 | */ 11 | public class MyFitnessFunction extends FitnessFunction { 12 | //------------------------------------------------------------------------- 13 | // Methods 14 | //------------------------------------------------------------------------- 15 | 16 | /** 17 | * Evaluates a particles at a given position 18 | * @param position : Particle's position 19 | * @return Fitness function for a particle 20 | */ 21 | public double evaluate(double position[]) { 22 | double sum = 0; 23 | double s = position[0] - 0.5; 24 | sum += s * s; 25 | s = position[1] - 0.5; 26 | sum += s * s; 27 | return (1 - Math.sqrt(sum)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_1/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_1/MyParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_1/MyParticle.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_1; 2 | 3 | import net.sourceforge.jswarm_pso.Particle; 4 | 5 | /** 6 | * Simple particle example 7 | * @author Pablo Cingolani 8 | */ 9 | public class MyParticle extends Particle { 10 | 11 | /** Default constructor */ 12 | public MyParticle() { 13 | super(2); // Create a 2-dimentional particle 14 | } 15 | } -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/DrawingArea.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_2/DrawingArea.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/DrawingArea.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_2; 2 | 3 | import java.awt.Color; 4 | import java.awt.Dimension; 5 | import java.awt.Graphics; 6 | 7 | import javax.swing.JComponent; 8 | 9 | /** 10 | * A drawing area 11 | * 12 | * @author pcingola@users.sourceforge.net 13 | */ 14 | public class DrawingArea extends JComponent { 15 | 16 | protected SwarmShow2D controller; 17 | protected Dimension preferredSize; 18 | 19 | //------------------------------------------------------------------------- 20 | // Constructor 21 | //------------------------------------------------------------------------- 22 | 23 | public DrawingArea(SwarmShow2D controller) { 24 | this.controller = controller; 25 | setBackground(Color.WHITE); 26 | setOpaque(true); 27 | } 28 | 29 | //------------------------------------------------------------------------- 30 | // Methods 31 | //------------------------------------------------------------------------- 32 | 33 | /** Clear screen */ 34 | public void clear() { 35 | paintComponent(this.getGraphics()); 36 | } 37 | 38 | /** Get dimention */ 39 | public Dimension getPreferredSize() { 40 | return controller.getPreferredSize(); 41 | } 42 | 43 | /** Paint */ 44 | protected void paintComponent(Graphics g) { 45 | // Paint background if we're opaque. 46 | if( isOpaque() ) { 47 | g.setColor(getBackground()); 48 | g.fillRect(0, 0, getWidth(), getHeight()); 49 | } 50 | } 51 | 52 | /** Run a swarm */ 53 | protected void runSwarm() { 54 | Thread thread = new SwarmThread(controller); 55 | try { 56 | thread.join(); 57 | } catch(InterruptedException e) { 58 | ; 59 | } // It's OK to interrupt this process 60 | } 61 | 62 | /** Show swarm's points */ 63 | protected void showSwarm() { 64 | controller.getSwarm().show(getGraphics(), getForeground(), getWidth(), getHeight(), controller.getShowDimention0(), controller.getShowDimention1(), controller.isShowVelocity()); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_2/Example.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/Example.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_2; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | 5 | /** 6 | * An extremely simple swarm optimization example 7 | * Minimize Rastrigin's function 8 | * f( x1 , x2 ) = 20.0 + (x1 * x1) + (x2 * x2) - 10.0 * (Math.cos(2 * Math.PI * x1) + Math.cos(2 * Math.PI * x2)); 9 | * Solution is (obviously): [ 0, 0 ] 10 | * 11 | * @author Pablo Cingolani 12 | */ 13 | public class Example { 14 | 15 | public static void main(String[] args) { 16 | System.out.println("Example of Particle Swarm Optimization: Optimizing Rastrijin's funtion"); 17 | 18 | // Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function) 19 | Swarm swarm = new Swarm(Swarm.DEFAULT_NUMBER_OF_PARTICLES, new MyParticle(), new MyFitnessFunction()); 20 | 21 | // Tune swarm's update parameters (if needed) 22 | swarm.setInertia(0.95); 23 | swarm.setParticleIncrement(0.8); 24 | swarm.setGlobalIncrement(0.8); 25 | 26 | // Set position (and velocity) constraints. I.e.: where to look for solutions 27 | swarm.setMaxPosition(100); 28 | swarm.setMinPosition(-100); 29 | 30 | // Show a 2D graph 31 | int numberOfIterations = 5000; 32 | int displayEvery = numberOfIterations / 100 + 1; 33 | SwarmShow2D ss2d = new SwarmShow2D(swarm, numberOfIterations, displayEvery, true); 34 | ss2d.run(); 35 | 36 | // Show best position 37 | double bestPosition[] = ss2d.getSwarm().getBestPosition(); 38 | System.out.println("Best position: [" + bestPosition[0] + ", " + bestPosition[1] + " ]\nBest fitness: " + ss2d.getSwarm().getBestFitness() + "\nKnown Solution: [0.0, 0.0]"); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_2/MyFitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/MyFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_2; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | 5 | /** 6 | * Sample Fitness function (Rastrigin's function) 7 | * f( x1 , x2 ) = 20.0 + (x1 * x1) + (x2 * x2) - 10.0 * (Math.cos(2 * Math.PI * x1) + Math.cos(2 * Math.PI * x2)); 8 | * 9 | * @author Pablo Cingolani 10 | */ 11 | public class MyFitnessFunction extends FitnessFunction { 12 | 13 | //------------------------------------------------------------------------- 14 | // Constructors 15 | //------------------------------------------------------------------------- 16 | 17 | /** Default constructor */ 18 | public MyFitnessFunction() { 19 | super(false); // Minimize this function 20 | } 21 | 22 | //------------------------------------------------------------------------- 23 | // Methods 24 | //------------------------------------------------------------------------- 25 | 26 | /** 27 | * Evaluates a particles at a given position 28 | * @param position : Particle's position 29 | * @return Fitness function for a particle 30 | */ 31 | public double evaluate(double position[]) { 32 | double x1 = position[0]; 33 | double x2 = position[1]; 34 | return 20.0 + (x1 * x1) + (x2 * x2) - 10.0 * (Math.cos(2 * Math.PI * x1) + Math.cos(2 * Math.PI * x2)); 35 | } 36 | } -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_2/MyParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/MyParticle.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_2; 2 | 3 | import net.sourceforge.jswarm_pso.Particle; 4 | 5 | /** 6 | * Simple particle example 7 | * @author Pablo Cingolani 8 | */ 9 | public class MyParticle extends Particle { 10 | 11 | /** Number of dimentions for this particle */ 12 | public static int NUMBER_OF_DIMENTIONS = 2; 13 | 14 | /** Totally useless, just to see how an example with local data works */ 15 | double particleData; 16 | 17 | //------------------------------------------------------------------------- 18 | // Constructor/s 19 | //------------------------------------------------------------------------- 20 | 21 | /** 22 | * Default constructor 23 | */ 24 | public MyParticle() { 25 | super(NUMBER_OF_DIMENTIONS); // Create a 2-dimentional particle 26 | particleData = Math.random(); // Add some custom 'local' data 27 | } 28 | 29 | //------------------------------------------------------------------------- 30 | // Methods 31 | //------------------------------------------------------------------------- 32 | 33 | /** Convert to string() */ 34 | public String toString() { 35 | String str = super.toString(); 36 | return str + "\tParticle's data: " + particleData + "\n"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/SwarmShow2D.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_2/SwarmShow2D.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/SwarmShow2D.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_2; 2 | 3 | import java.awt.Container; 4 | import java.awt.Dimension; 5 | import java.awt.GridBagConstraints; 6 | import java.awt.GridBagLayout; 7 | import java.awt.event.ActionEvent; 8 | import java.awt.event.ActionListener; 9 | 10 | import javax.swing.JFrame; 11 | import javax.swing.JLabel; 12 | 13 | import net.sourceforge.jswarm_pso.Gpr; 14 | import net.sourceforge.jswarm_pso.Swarm; 15 | 16 | /** 17 | * An extremely simple swarm optimization example 18 | * 19 | * Maximize function 20 | * f( x1 , x2 ) = 1 - Sqrt( ( x1 - 3/4 )^2 + ( x2 - 1/4 )^2 ) 21 | * Solution is (obviously): [ 3/4 , 1/4 ] 22 | * 23 | * @author Pablo Cingolani 24 | */ 25 | public class SwarmShow2D implements ActionListener, Runnable { 26 | 27 | /** Refresh display every 'displayRefresh' number of iterations */ 28 | int displayRefresh; 29 | /** Drawing area */ 30 | DrawingArea drawingArea; 31 | /** Frame containing drawing area */ 32 | JFrame frame; 33 | /** Message text */ 34 | JLabel message; 35 | /** Number of iterations */ 36 | int numberOfIterations; 37 | /** Prefered drawing area's dimention */ 38 | Dimension preferredSize; 39 | /** Dimentions to show in graph */ 40 | int showDimention0, showDimention1; 41 | /** Show velocities in graph? */ 42 | boolean showVelocity; 43 | /** Swarm optimizer */ 44 | Swarm swarm; 45 | 46 | //------------------------------------------------------------------------- 47 | // Methods 48 | //------------------------------------------------------------------------- 49 | 50 | /** 51 | * Create a new SwarmShow2D Object 52 | * @param swarm : Swram to optimize 53 | * @param numberOfIterations : Number of iterations 54 | * @param displayRefresh : Refresh display every N iterations 55 | * @param showVelocity : Show velocity lines 56 | */ 57 | public SwarmShow2D(Swarm swarm, int numberOfIterations, int displayRefresh, boolean showVelocity) { 58 | // Initialize 59 | this.swarm = swarm; 60 | this.numberOfIterations = numberOfIterations; 61 | this.showVelocity = showVelocity; 62 | this.displayRefresh = displayRefresh; 63 | showDimention0 = 0; // Default dimntions to show 64 | showDimention1 = 1; 65 | } 66 | 67 | //------------------------------------------------------------------------- 68 | // Methods 69 | //------------------------------------------------------------------------- 70 | 71 | /** 72 | * Action dispatcher 73 | */ 74 | public void actionPerformed(ActionEvent e) { 75 | Gpr.debug("actionPerformed: ActionCommand = " + e.getActionCommand()); 76 | } 77 | 78 | /** 79 | * Builds User Interface 80 | * @param container 81 | */ 82 | private void buildUserInterface(Container container) { 83 | int rowNum = 0; 84 | 85 | preferredSize = new Dimension(800, 600); 86 | 87 | container.setLayout(new GridBagLayout()); 88 | GridBagConstraints gbc = new GridBagConstraints(); 89 | gbc.fill = GridBagConstraints.BOTH; 90 | 91 | gbc.weightx = 1; 92 | gbc.weighty = 1; 93 | 94 | // Add an area to draw 95 | drawingArea = new DrawingArea(this); 96 | gbc.gridx = 0; 97 | gbc.gridy = rowNum; 98 | gbc.gridwidth = 10; 99 | gbc.gridheight = 4; 100 | container.add(drawingArea, gbc); 101 | rowNum += 10; 102 | 103 | gbc.fill = GridBagConstraints.BOTH; 104 | gbc.weightx = 0; 105 | gbc.weighty = 0; 106 | 107 | // Add a 'message' label 108 | message = new JLabel(); //, drawingArea, JLabel.LEFT ); 109 | message.setText("Ok"); 110 | gbc.gridx = 0; 111 | gbc.gridy = rowNum++; 112 | gbc.gridwidth = 4; 113 | gbc.gridheight = 1; 114 | container.add(message, gbc); 115 | } 116 | 117 | public void clear() { 118 | drawingArea.clear(); 119 | } 120 | 121 | public int getDisplayRefresh() { 122 | return displayRefresh; 123 | } 124 | 125 | public int getNumberOfIterations() { 126 | return numberOfIterations; 127 | } 128 | 129 | public Dimension getPreferredSize() { 130 | return preferredSize; 131 | } 132 | 133 | public int getShowDimention0() { 134 | return showDimention0; 135 | } 136 | 137 | public int getShowDimention1() { 138 | return showDimention1; 139 | } 140 | 141 | public Swarm getSwarm() { 142 | return swarm; 143 | } 144 | 145 | public boolean isShowVelocity() { 146 | return showVelocity; 147 | } 148 | 149 | /** Run swarm */ 150 | public void run() { 151 | //--- 152 | // Create and show graphics user interface 153 | //--- 154 | JFrame.setDefaultLookAndFeelDecorated(true); 155 | 156 | // Create and set up the window. 157 | frame = new JFrame("Swarm"); 158 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 159 | 160 | // Set up the content pane. 161 | this.buildUserInterface(frame.getContentPane()); 162 | 163 | // Display the window. 164 | frame.pack(); 165 | frame.setVisible(true); 166 | 167 | this.drawingArea.runSwarm(); 168 | } 169 | 170 | public void setDisplayRefresh(int displayRefresh) { 171 | this.displayRefresh = displayRefresh; 172 | } 173 | 174 | public void setMessage(String text) { 175 | message.setText(text); 176 | } 177 | 178 | public void setNumberOfIterations(int numberOfIterations) { 179 | this.numberOfIterations = numberOfIterations; 180 | } 181 | 182 | public void setPreferredSize(Dimension preferredSize) { 183 | this.preferredSize = preferredSize; 184 | } 185 | 186 | public void setShowDimention0(int showDimention0) { 187 | this.showDimention0 = showDimention0; 188 | } 189 | 190 | public void setShowDimention1(int showDimention1) { 191 | this.showDimention1 = showDimention1; 192 | } 193 | 194 | public void setShowVelocity(boolean showVelocity) { 195 | this.showVelocity = showVelocity; 196 | } 197 | 198 | public void setSwarm(Swarm swarm) { 199 | this.swarm = swarm; 200 | } 201 | 202 | public void showSwarm() { 203 | drawingArea.showSwarm(); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/SwarmThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/example_2/SwarmThread.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/example_2/SwarmThread.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.example_2; 2 | 3 | /** 4 | * A thread that runs in background while calculating kohonen's learning algorithm 5 | * @author pcingola@users.sourceforge.net 6 | */ 7 | public class SwarmThread extends Thread { 8 | 9 | /** Controller */ 10 | SwarmShow2D controller; 11 | 12 | //------------------------------------------------------------------------- 13 | // Constructor 14 | //------------------------------------------------------------------------- 15 | 16 | public SwarmThread(SwarmShow2D controller) { 17 | super("SwarmThread"); 18 | this.controller = controller; 19 | start(); 20 | } 21 | 22 | //------------------------------------------------------------------------- 23 | // Methods 24 | //------------------------------------------------------------------------- 25 | 26 | /** Run */ 27 | public void run() { 28 | for( int i = 0; i < controller.getNumberOfIterations(); i++ ) { 29 | // Show something every displayStep iterations 30 | if( (i % controller.getDisplayRefresh()) == 0 ) { 31 | controller.setMessage("Iteration: " + i + " Best fitness: " + controller.getSwarm().getBestFitness() + " "); 32 | controller.clear(); 33 | controller.showSwarm(); 34 | } 35 | 36 | // Evolve swarm 37 | controller.getSwarm().evolve(); 38 | } 39 | controller.setMessage("Finished: Best fitness: " + controller.getSwarm().getBestFitness() + " "); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/rosenbrock/Example.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock/Example.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.rosenbrock; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | 5 | /** 6 | * Minize Rosenbrock function. http://mathworld.wolfram.com/RosenbrockFunction.html 7 | * 8 | * General form 9 | * 10 | * f( x1 , x2 ) = (1 - x_1)^2 + 100 (x_2 - x_1^2)^2 11 | * 12 | * @author Alvaro Jaramillo Duque 13 | */ 14 | public class Example { 15 | 16 | //------------------------------------------------------------------------- 17 | // Main 18 | //------------------------------------------------------------------------- 19 | public static void main(String[] args) { 20 | System.out.println("Begin: Example Rosenbrock\n"); 21 | 22 | // Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function) 23 | Swarm swarm = new Swarm(Swarm.DEFAULT_NUMBER_OF_PARTICLES, new MyParticle(), new MyFitnessFunction()); 24 | 25 | // Set position (and velocity) constraints. I.e.: where to look for solutions 26 | swarm.setInertia(0.99); // Tuned up intertia (just a little) 27 | swarm.setMaxPosition(30); 28 | swarm.setMinPosition(0); 29 | swarm.setMaxMinVelocity(0.1); 30 | 31 | int numberOfIterations = 10000; // Added some more iterations 32 | 33 | // Optimize (and time it) 34 | for( int i = 0; i < numberOfIterations; i++ ) 35 | swarm.evolve(); 36 | 37 | // Print en results 38 | System.out.println(swarm.toStringStats()); 39 | System.out.println("End: Example Rosenbrock"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/rosenbrock/MyFitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock/MyFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.rosenbrock; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | 5 | /** 6 | * Minize Rosenbrock function. http://mathworld.wolfram.com/RosenbrockFunction.html 7 | * 8 | * General form 9 | * 10 | * f( x1 , x2 ) = Sum i=1 to n ; 100*(x(i+1) - xi^2)^2 + (1 - xi)^2 11 | * 12 | * @author Alvaro Jaramillo Duque 13 | */ 14 | public class MyFitnessFunction extends FitnessFunction { 15 | 16 | /** Default constructor */ 17 | public MyFitnessFunction() { 18 | super(false); // Minimize this function 19 | } 20 | 21 | //------------------------------------------------------------------------- 22 | // Methods 23 | //------------------------------------------------------------------------- 24 | 25 | /** 26 | * Evaluates a particles at a given position 27 | * @param position : Particle's position 28 | * @return Fitness function for a particle 29 | */ 30 | public double evaluate(double position[]) { 31 | double x1 = position[0]; 32 | double x2 = position[1]; 33 | return (100 * Math.pow((x2 - Math.pow(x1, 2)), 2) + Math.pow((1 - x1), 2)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/rosenbrock/MyParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock/MyParticle.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/rosenbrock/MyParticle.java -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/Example.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/Example.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.rosenbrock_30; 2 | 3 | import net.sourceforge.jswarm_pso.SwarmRepulsive; 4 | 5 | /** 6 | * Minize Rosenbrock function. http://mathworld.wolfram.com/RosenbrockFunction.html 7 | * 8 | * General form 9 | * 10 | * f( x1 , x2 ) = \sum_{i=1}^{n} { 100 (x_{i+1} - x_i^2)^2 + (1 - x_i)^2 } 11 | * 12 | * @author Alvaro Jaramillo Duque 13 | */ 14 | public class Example { 15 | 16 | //------------------------------------------------------------------------- 17 | // Main 18 | //------------------------------------------------------------------------- 19 | public static void main(String[] args) { 20 | System.out.println("Begin: Example Rosenbrock 30\n"); 21 | 22 | // Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function) 23 | SwarmRepulsive swarm = new SwarmRepulsive(100, new MyParticle(), new MyFitnessFunction()); 24 | swarm.setOtherParticleIncrement(0.1); 25 | swarm.setRandomIncrement(0.1); 26 | 27 | // Set position (and velocity) constraints. I.e.: where to look for solutions 28 | swarm.setInertia(0.9); 29 | swarm.setGlobalIncrement(0.1); 30 | swarm.setParticleIncrement(0.1); 31 | 32 | swarm.setMaxPosition(30); 33 | swarm.setMinPosition(0); 34 | swarm.setMaxMinVelocity(0.1); 35 | 36 | int numberOfIterations = 50000; 37 | 38 | for( int i = 0; i < numberOfIterations; i++ ) { 39 | swarm.evolve(); 40 | if( i % 1000 == 0 ) System.out.println("Iteration: " + i + "\tParticle: " + swarm.getParticle(swarm.getBestParticleIndex()).toString()); 41 | } 42 | 43 | // Print en results 44 | System.out.println(swarm.toStringStats()); 45 | // System.out.println(swarm); 46 | System.out.println("End: Example Rosenbrock 30"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/MyFitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/MyFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.rosenbrock_30; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | 5 | /** 6 | * Minize Rosenbrock function. http://mathworld.wolfram.com/RosenbrockFunction.html 7 | * 8 | * General form 9 | * 10 | * f( x1 , x2 ) = \sum_{i=1}^{n} { 100 (x_{i+1} - x_i^2)^2 + (1 - x_i)^2 } 11 | * 12 | * @author �lvaro Jaramillo Duque 13 | */ 14 | public class MyFitnessFunction extends FitnessFunction { 15 | 16 | /** Default constructor */ 17 | public MyFitnessFunction() { 18 | super(false); // Minimize this function 19 | } 20 | 21 | //------------------------------------------------------------------------- 22 | // Methods 23 | //------------------------------------------------------------------------- 24 | 25 | /** 26 | * Evaluates a particles at a given position 27 | * @param position : Particle's position 28 | * @return Fitness function for a particle 29 | */ 30 | public double evaluate(double position[]) { 31 | double f = 0; 32 | for( int i = 0; i < (position.length - 1); i++ ) { 33 | double p1 = position[i] * position[i]; // x_i^2 34 | double p2 = (1 - position[i]); // ( 1 - x_i ) 35 | p2 *= p2; // ( 1 - x_i )^2 36 | double p3 = position[i + 1] - p1; // ( x_{i+1} - x_i^2 ) 37 | p3 *= p3; // ( x_{i+1} - x_i^2 )^2 38 | 39 | f += 100 * p3 + p2; // 100 ( x_{i+1} - x_i^2 )^2 + ( 1 - x_i )^2 40 | } 41 | return f; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/MyParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/rosenbrock_30/MyParticle.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.rosenbrock_30; 2 | 3 | import net.sourceforge.jswarm_pso.Particle; 4 | 5 | /** 6 | * Simple particle 7 | * @author Alvaro Jaramillo Duque 8 | */ 9 | public class MyParticle extends Particle { 10 | 11 | /** Default constructor */ 12 | public MyParticle() { 13 | super(30); // Create a 30-dimentional particle 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/schaffer/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/schaffer/Example.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/schaffer/Example.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.schaffer; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | 5 | /** 6 | * An extremely simple swarm optimization example 7 | * 8 | * Minimizar schaffer function 9 | * 10 | * f( x1 , x2 ) = 0.5 + ( sin( Sqrt( x1^2 + x2^2 ))^2 - 0.5 ) / (1 + 0.001 * ( x1^2 * x2^2 ))^2 11 | * 12 | * @author Alvaro Jaramillo Duque 13 | */ 14 | public class Example { 15 | 16 | //------------------------------------------------------------------------- 17 | // Main 18 | //------------------------------------------------------------------------- 19 | public static void main(String[] args) { 20 | System.out.println("Begin: Example schaffer\n"); 21 | 22 | // Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function) 23 | Swarm swarm = new Swarm(Swarm.DEFAULT_NUMBER_OF_PARTICLES, new MyParticle(), new MyFitnessFunction()); 24 | 25 | // Set position (and velocity) constraints. I.e.: where to look for solutions 26 | swarm.setInertia(0.95); 27 | swarm.setGlobalIncrement(0.1); 28 | swarm.setParticleIncrement(0.1); 29 | 30 | swarm.setMaxPosition(50); 31 | swarm.setMinPosition(-50); 32 | swarm.setMaxMinVelocity(0.1); 33 | 34 | int numberOfIterations = 10000; 35 | 36 | // Optimize (and time it) 37 | for( int i = 0; i < numberOfIterations; i++ ) { 38 | swarm.evolve(); 39 | if( i % 1000 == 0 ) System.out.println("Iteration: " + i + "\tParticle: " + swarm.getParticle(swarm.getBestParticleIndex()).toString()); 40 | } 41 | 42 | // Print en results 43 | System.out.println(swarm.toStringStats()); 44 | System.out.println("End: Example schaffer"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/schaffer/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/schaffer/MyFitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/schaffer/MyFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.schaffer; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | 5 | /** 6 | * Minimize schaffer function 7 | * 8 | * f( x1 , x2 ) = 0.5 + ( sin( Sqrt( x1^2 + x2^2 ))^2 - 0.5 ) / (1 + 0.001 * ( x1^2 * x2^2 ))^2 9 | * 10 | * @author Alvaro Jaramillo Duque 11 | */ 12 | public class MyFitnessFunction extends FitnessFunction { 13 | 14 | /** Default constructor */ 15 | public MyFitnessFunction() { 16 | super(false); // Minimize this function 17 | } 18 | 19 | //------------------------------------------------------------------------- 20 | // Methods 21 | //------------------------------------------------------------------------- 22 | 23 | /** 24 | * Evaluates a particles at a given position 25 | * @param position : Particle's position 26 | * @return Fitness function for a particle 27 | */ 28 | public double evaluate(double position[]) { 29 | double x1 = position[0]; 30 | double x2 = position[1]; 31 | double sum = x1 * x1 + x2 * x2; 32 | 33 | return 0.5 + (Math.pow(Math.sin(Math.sqrt(sum)), 2) - 0.5) / Math.pow(1 + 0.001 * sum, 2); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/schaffer/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/schaffer/MyParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/schaffer/MyParticle.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.schaffer; 2 | 3 | import net.sourceforge.jswarm_pso.Particle; 4 | 5 | /** 6 | * Simple particle 7 | * @author Alvaro Jaramillo Duque 8 | */ 9 | public class MyParticle extends Particle { 10 | 11 | /** Default constructor */ 12 | public MyParticle() { 13 | super(2); // Create a 2-dimentional particle 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/sphere/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/sphere/Example.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/sphere/Example.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.sphere; 2 | 3 | import net.sourceforge.jswarm_pso.Swarm; 4 | 5 | /** 6 | * Minimize sphere function 7 | * 8 | * f( x ) = \sum_{i=1}^{n} { (x_i-1)^2 } 9 | * 10 | * @author Alvaro Jaramillo Duque 11 | */ 12 | public class Example { 13 | 14 | //------------------------------------------------------------------------- 15 | // Main 16 | //------------------------------------------------------------------------- 17 | 18 | public static void main(String[] args) { 19 | System.out.println("Begin: Example sphere\n"); 20 | 21 | // Create a swarm (using 'MyParticle' as sample particle and 'MyFitnessFunction' as finess function) 22 | Swarm swarm = new Swarm(Swarm.DEFAULT_NUMBER_OF_PARTICLES, new MyParticle(), new MyFitnessFunction()); 23 | 24 | // Set position (and velocity) constraints. I.e.: where to look for solutions 25 | swarm.setInertia(0.99); 26 | swarm.setMaxPosition(100); 27 | swarm.setMinPosition(0); 28 | swarm.setMaxMinVelocity(0.1); 29 | 30 | int numberOfIterations = 10000; 31 | 32 | // Optimize (and time it) 33 | for( int i = 0; i < numberOfIterations; i++ ) { 34 | swarm.evolve(); 35 | if( i % 1000 == 0 ) System.out.println("Iteration: " + i + "\tParticle: " + swarm.getParticle(swarm.getBestParticleIndex()).toString()); 36 | } 37 | 38 | // Print en results 39 | System.out.println(swarm.toStringStats()); 40 | System.out.println("End: Example sphere"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/sphere/MyFitnessFunction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/sphere/MyFitnessFunction.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/sphere/MyFitnessFunction.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jswarm_pso.sphere; 2 | 3 | import net.sourceforge.jswarm_pso.FitnessFunction; 4 | 5 | /** 6 | * Minimize sphere function 7 | * 8 | * f( x ) = \sum_{i=1}^{n} { (x_i-1)^2 } 9 | * 10 | * @author Alvaro Jaramillo Duque 11 | */ 12 | public class MyFitnessFunction extends FitnessFunction { 13 | 14 | /** Default constructor */ 15 | public MyFitnessFunction() { 16 | super(false); // Minimize this function 17 | } 18 | 19 | //------------------------------------------------------------------------- 20 | // Methods 21 | //------------------------------------------------------------------------- 22 | 23 | /** 24 | * Evaluates a particles at a given position 25 | * @param position : Particle's position 26 | * @return Fitness function for a particle 27 | */ 28 | public double evaluate(double position[]) { 29 | double f = 0; 30 | for( int i = 0; i < (position.length - 1); i++ ) 31 | f += position[i] * position[i]; 32 | return f; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/sphere/MyParticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/sphere/MyParticle.class -------------------------------------------------------------------------------- /trunk/src/net/sourceforge/jswarm_pso/sphere/MyParticle.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/James2356/cloudsim-task-scheduling/55ca9efc84f2989ec461ab6f762cf3865695eeec/trunk/src/net/sourceforge/jswarm_pso/sphere/MyParticle.java -------------------------------------------------------------------------------- /trunk/src/utils/Calculator.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | import java.io.BufferedWriter; 3 | import java.io.FileOutputStream; 4 | import java.io.IOException; 5 | import java.io.OutputStreamWriter; 6 | import java.math.BigDecimal; 7 | public class Calculator 8 | { 9 | //默认除法运算精度 10 | private static final int DEF_DIV_SCALE = 10; 11 | //构造器私有化,让这个类不能实例化 12 | private Calculator(){} 13 | //提供精确的加法运算 14 | public static double add(double v1, double v2) 15 | { 16 | BigDecimal b1 = BigDecimal.valueOf(v1); 17 | BigDecimal b2 = BigDecimal.valueOf(v2); 18 | return b1.add(b2).doubleValue(); 19 | } 20 | //精确的减法运算 21 | public static double sub(double v1, double v2) 22 | { 23 | BigDecimal b1 = BigDecimal.valueOf(v1); 24 | BigDecimal b2 = BigDecimal.valueOf(v2); 25 | return b1.subtract(b2).doubleValue(); 26 | } 27 | //精确的乘法运算 28 | public static double mul(double v1, double v2) 29 | { 30 | BigDecimal b1 = BigDecimal.valueOf(v1); 31 | BigDecimal b2 = BigDecimal.valueOf(v2); 32 | return b1.multiply(b2).doubleValue(); 33 | } 34 | //提供(相对)精确的除法运算,当发生除不尽的情况时 35 | //精确到小数点后10位的数字四舍五入 36 | public static double div(double v1, double v2) 37 | { 38 | BigDecimal b1 = BigDecimal.valueOf(v1); 39 | BigDecimal b2 = BigDecimal.valueOf(v2); 40 | return b1.divide(b2, DEF_DIV_SCALE, BigDecimal.ROUND_HALF_UP).doubleValue(); 41 | } 42 | 43 | public static double div(double d1,double d2,int len) {// 进行除法运算 44 | BigDecimal b1 = new BigDecimal(d1); 45 | BigDecimal b2 = new BigDecimal(d2); 46 | return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP).doubleValue(); 47 | } 48 | 49 | public static void LogResult(String file, String conent) { 50 | BufferedWriter out = null; 51 | try { 52 | out = new BufferedWriter(new OutputStreamWriter( 53 | new FileOutputStream(file, true)));// true,进行追加写。 54 | out.write(conent+"\r\n"); 55 | 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | } finally { 59 | try { 60 | out.close(); 61 | } catch (IOException e) { 62 | e.printStackTrace(); 63 | } 64 | } 65 | } 66 | // public static void main(String[] args) 67 | // { 68 | // System.out.println("0.05 + 0.01 = " + Caculator.add(0.05, 0.01)); 69 | // System.out.println("1.0 - 0.42 = " + Caculator.sub(1.0, 0.42)); 70 | // System.out.println("4.015*100 = " + Caculator.mul(4.015, 100)); 71 | // System.out.println("123.3/100 = " + Caculator.div(123.3, 100)); 72 | // } 73 | } 74 | -------------------------------------------------------------------------------- /trunk/src/utils/ChaosStrategy.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.util.Random; 4 | 5 | public class ChaosStrategy 6 | { 7 | //使用静态内部类实现 本人使用的目前最优单例模式线程安全实现 8 | 9 | /** 可以看到使用这种方式我们没有显式的进行任何同步操作,那他是如何保证线程安全呢? 10 | * 和饿汉模式一样,是靠JVM保证类的静态成员只能被加载一次的特点, 11 | * 这样就从JVM层面保证了只会有一个实例对象。 12 | * 那么问题来了,这种方式和饿汉模式又有什么区别呢?不也是立即加载么? 13 | * 实则不然,加载一个类时,其内部类不会同时被加载。 14 | * 一个类被加载,当且仅当其某个静态成员(静态域、构造器、静态方法等)被调用时发生。 15 | * */ 16 | private ChaosStrategy() 17 | { 18 | chaosvalue = 0.0; 19 | u=3.9999;//完全混沌状态 20 | } 21 | 22 | private double u; 23 | 24 | private static class ChaosStrategyInner 25 | { 26 | private static ChaosStrategy instance= new ChaosStrategy(); 27 | } 28 | 29 | public static ChaosStrategy getInstance() 30 | { 31 | try { 32 | Thread.sleep(1000); 33 | } catch (InterruptedException e) { 34 | e.printStackTrace(); 35 | } 36 | return ChaosStrategyInner.instance; 37 | } 38 | 39 | private double chaosvalue; 40 | public double getChaosValue() 41 | { 42 | return chaosvalue; 43 | } 44 | 45 | public void setChaosValue(double value) 46 | { 47 | this.chaosvalue = value; 48 | } 49 | 50 | //计算拜托初始值影响,迭代500次,得到混沌状态值,基于Logistic映射产生 51 | public void CalChaos() 52 | { 53 | Random rd = new Random(); 54 | double chaosvalue = LM(500,rd.nextDouble()); 55 | setChaosValue(chaosvalue); 56 | } 57 | 58 | public double LM(int n,double x0) 59 | { 60 | double result = x0;//迭代的初始值 61 | for(int i=0;i=0.0&&result<=0.5) 75 | result = Calculator.mul(Calculator.mul(Calculator.sub(0.5, result), result), u); 76 | if(result>=0.5&&result<=1.0) 77 | result = 1.0-Calculator.mul(Calculator.mul(Calculator.sub(1.0, result), Calculator.sub(result,0.5)), u); 78 | } 79 | setChaosValue(result); 80 | return result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /trunk/src/utils/ChaosTest.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | public class ChaosTest { 4 | 5 | private static ChaosStrategy instance = ChaosStrategy.getInstance(); 6 | 7 | public static void main(String[] args) { 8 | instance.CalChaos(); 9 | for (int i = 0; i < 500; i++) { 10 | double result = instance.LM(1, instance.getChaosValue()); 11 | System.out.println(result); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /trunk/src/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | public class Constants { 4 | public static final int NO_OF_TASKS = 400; // number of Cloudlets任务数量; 5 | public static final int NO_OF_DATA_CENTERS = 1; // number of Datacenters数据中心个数; 6 | public static final int POPULATION_SIZE = 50; // Number of Particles.粒子群规模(粒子个数) 7 | public static final int NO_OF_VMS = 40;//虚拟机个数 8 | public static final int NO_OF_Iterations=50;//迭代次数 9 | } 10 | -------------------------------------------------------------------------------- /trunk/src/utils/DatacenterCreator.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | 4 | import org.cloudbus.cloudsim.*; 5 | import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; 6 | import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; 7 | import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; 8 | 9 | import java.util.ArrayList; 10 | import java.util.LinkedList; 11 | import java.util.List; 12 | 13 | public class DatacenterCreator { 14 | 15 | public static Datacenter createDatacenter(String name) { 16 | 17 | // Here are the steps needed to create a PowerDatacenter: 18 | // 1. We need to create a list to store one or more Machines 19 | List hostList = new ArrayList(); 20 | 21 | // 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should 22 | // create a list to store these PEs before creating a Machine. 23 | List peList = new ArrayList(); 24 | 25 | int mips = 1000; 26 | 27 | // 3. Create PEs and add these into the list. 28 | peList.add(new Pe(0, new PeProvisionerSimple(mips))); 29 | 30 | //4. Create Hosts with its id and list of PEs and add them to the list of machines 31 | int hostId = 0; 32 | int ram = 2048; //host memory (MB) 33 | long storage = 1000000; //host storage 34 | int bw = 10000; 35 | 36 | hostList.add( 37 | new Host( 38 | hostId, 39 | new RamProvisionerSimple(ram), 40 | new BwProvisionerSimple(bw), 41 | storage, 42 | peList, 43 | new VmSchedulerTimeShared(peList) 44 | ) 45 | ); // This is our first machine 46 | 47 | 48 | // 5. Create a DatacenterCharacteristics object that stores the 49 | // properties of a data center: architecture, OS, list of 50 | // Machines, allocation policy: time- or space-shared, time zone 51 | // and its price (G$/Pe time unit). 52 | String arch = "x86"; // system architecture 53 | String os = "Linux"; // operating system 54 | String vmm = "Xen"; 55 | double time_zone = 10.0; // time zone this resource located 56 | double cost = 3.0; // the cost of using processing in this resource 57 | double costPerMem = 0.05; // the cost of using memory in this resource 58 | double costPerStorage = 0.1; // the cost of using storage in this resource 59 | double costPerBw = 0.1; // the cost of using bw in this resource 60 | LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now 61 | 62 | DatacenterCharacteristics characteristics = new DatacenterCharacteristics( 63 | arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw); 64 | 65 | 66 | // 6. Finally, we need to create a PowerDatacenter object. 67 | Datacenter datacenter = null; 68 | try { 69 | datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0); 70 | } catch (Exception e) { 71 | e.printStackTrace(); 72 | } 73 | return datacenter; 74 | } 75 | 76 | public static Datacenter createDatacenter(String name,int PeNum) 77 | { 78 | List hostList = new ArrayList(); 79 | List peList = new ArrayList(); 80 | int mips = 2000; 81 | for(int i=0;i storageList = new LinkedList(); //we are not adding SAN devices by now 116 | 117 | DatacenterCharacteristics characteristics = new DatacenterCharacteristics( 118 | arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw); 119 | 120 | 121 | // 6. Finally, we need to create a PowerDatacenter object. 122 | Datacenter datacenter = null; 123 | try { 124 | datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0); 125 | } catch (Exception e) { 126 | e.printStackTrace(); 127 | } 128 | return datacenter; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /trunk/src/utils/GenerateMatrices.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import org.cloudbus.cloudsim.Vm; 4 | import org.cloudbus.cloudsim.lists.VmList; 5 | 6 | import java.io.*; 7 | import java.util.List; 8 | import java.util.Random; 9 | 10 | public class GenerateMatrices { 11 | private static double[][] commMatrix, execMatrix;//传输转移消耗矩阵,执行时间矩阵 12 | private File commFile = new File("CommunicationTimeMatrix.txt"); 13 | private File execFile = new File("ExecutionTimeMatrix.txt"); 14 | private String filePath = "D:\\github\\cloudsim-package\\modules\\cloudsim-examples\\src\\main\\java\\org\\cloudbus\\cloudsim\\examples\\cloudlets.txt"; 15 | 16 | public GenerateMatrices() { 17 | commMatrix = new double[Constants.NO_OF_TASKS][Constants.NO_OF_VMS]; 18 | execMatrix = new double[Constants.NO_OF_TASKS][Constants.NO_OF_VMS]; 19 | try { 20 | if (commFile.exists() && execFile.exists()) { 21 | readCostMatrix(); 22 | } else { 23 | initCostMatrix(); 24 | } 25 | } catch (IOException e) { 26 | e.printStackTrace(); 27 | } 28 | } 29 | 30 | //基于已有虚拟机列表的各矩阵初始化 31 | public GenerateMatrices(List vmlist){ 32 | this.vmlist = vmlist; 33 | 34 | 35 | commMatrix = new double[Constants.NO_OF_TASKS][Constants.NO_OF_VMS]; 36 | execMatrix = new double[Constants.NO_OF_TASKS][Constants.NO_OF_VMS]; 37 | try { 38 | if (commFile.exists() && execFile.exists()) { 39 | readCostMatrix(); 40 | } else { 41 | initCostMatrix(filePath); 42 | } 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | 48 | private void initCostMatrix() throws IOException { 49 | System.out.println("Initializing new Matrices..."); 50 | BufferedWriter commBufferedWriter = new BufferedWriter(new FileWriter(commFile)); 51 | BufferedWriter execBufferedWriter = new BufferedWriter(new FileWriter(execFile)); 52 | 53 | for (int i = 0; i < Constants.NO_OF_TASKS; i++) { 54 | for (int j = 0; j < Constants.NO_OF_VMS; j++) { 55 | commMatrix[i][j] = Math.random() * 600 + 20; 56 | execMatrix[i][j] = Math.random() * 500 + 10; 57 | commBufferedWriter.write(String.valueOf(commMatrix[i][j]) + ' '); 58 | execBufferedWriter.write(String.valueOf(execMatrix[i][j]) + ' '); 59 | } 60 | commBufferedWriter.write('\n'); 61 | execBufferedWriter.write('\n'); 62 | } 63 | commBufferedWriter.close(); 64 | execBufferedWriter.close(); 65 | } 66 | 67 | private void readCostMatrix() throws IOException { 68 | System.out.println("Reading the Matrices..."); 69 | BufferedReader commBufferedReader = new BufferedReader(new FileReader(commFile)); 70 | 71 | int i = 0, j = 0; 72 | do { 73 | String line = commBufferedReader.readLine(); 74 | for (String num : line.split(" ")) { 75 | commMatrix[i][j++] = new Double(num); 76 | } 77 | ++i; 78 | j = 0; 79 | } while (commBufferedReader.ready()); 80 | 81 | 82 | BufferedReader execBufferedReader = new BufferedReader(new FileReader(execFile)); 83 | 84 | i = j = 0; 85 | do { 86 | String line = execBufferedReader.readLine(); 87 | for (String num : line.split(" ")) { 88 | execMatrix[i][j++] = new Double(num); 89 | } 90 | ++i; 91 | j = 0; 92 | } while (execBufferedReader.ready()); 93 | } 94 | 95 | public static double[][] getCommMatrix() { 96 | return commMatrix; 97 | } 98 | 99 | public static double[][] getExecMatrix() { 100 | return execMatrix; 101 | } 102 | 103 | //一般public方法 104 | public double[][] getcommMatrix() { 105 | return commMatrix; 106 | } 107 | 108 | public double[][] getexecMatrix(){ 109 | return execMatrix; 110 | } 111 | 112 | //基于样本生成任务初始化矩阵的方法 113 | private void initCostMatrix(String filePath) throws IOException 114 | { 115 | @SuppressWarnings("resource") 116 | BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(filePath))); 117 | String data = null; 118 | int index=0; 119 | double[] LengthGroup = new double[Constants.NO_OF_TASKS]; 120 | while ((data = br.readLine()) != null) 121 | { 122 | System.out.println(data); 123 | String[] taskLength=data.split("\t");//tasklength[i]是任务执行的耗费(指令数量) 124 | for(int j=0;j vmlist; 160 | public void SetVmList(List vmlist) 161 | { 162 | this.vmlist = vmlist; 163 | } 164 | 165 | public List GetVmList() 166 | { 167 | return vmlist; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /trunk/trunk.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | --------------------------------------------------------------------------------