/** Title: cloudsim toolkit * Description: cloudsim (cloud simulation) Toolkit for modeling and simulation of clouds * Licence: GPL-http://www.gnu.org/copyleft/gpl.html ** copyright (c) 2009-2010, the University of Melbourne, Australia */package Org. cloudid. cloudsim; import Java. util. arraylist; import Java. util. hashmap; import Java. util. iterator; import Java. util. list; import Java. util. map;/*** Space Shared Virtual Machine Scheduling Policy. PE cannot be shared * when no pe exists, the allocation will fail * vmschedulerspaceshared is a vmm allocation policy that * allocates one or more PE to a VM, and doesn' t allow sharing * of PES. if there is no free PES to the VM, allocation fails. * free PES are not allocated to VMS ** @ authorrodrigo n. calheiros * @ authoranton beloglazov * @ sincecloudsim toolkit 1.0 */public class vmschedulerspaceshared extends vmscheduler {/* * Map containing vm id and a vector of PES allocated to this VM. */private Map <string, list <PE> peallocationmap;/** the free PES vector. */private list <PE> freepes;/*** instantiates a new VM scheduler space shared. ** @ Param pelist the pelist */Public vmschedulerspaceshared (list <? Extends PE> pelist) {super (pelist); setpeallocationmap (New hashmap <string, list <PE> (); setfreepes (New arraylist <PE> ()); getfreepes (). addall (pelist);}/* (non-javadoc) * assign PES to VM * the value in mipshare indicates the MIPs to be allocated by a PE, the size of the mipshare list indicates the number of CPUs required * @ see Org. cloudid. cloudsim. vmscheduler # allocatepesforvm (Org. cloudid. cloudsim. VM, Java. util. list) */@ overridepublic Boolean allocatepesforvm (Vm, list <double> mipssha Re) {// if there is no enough free PES, failsif (getfreepes (). size () <mipsshare. size () {return false;} List <PE> selectedpes = new arraylist <PE> (); iterator <PE> peiterator = getfreepes (). iterator (); PE Pe = peiterator. next (); double totalmips = 0; For (double MIPS: mipsshare) {If (MIPs <= PE. getmips () {selectedpes. add (PE); If (! Peiterator. hasnext () {break;} Pe = peiterator. next (); totalmips + = MIPS ;}} if (mipsshare. size ()> selectedpes. size () {// The free PE does not return false;} getfreepes (). removeall (selectedpes); // remove getpeallocationmap () from the idle list (). put (VM. getuid (), selectedpes); // Add getmipsmap () to the allocated PE map (). put (VM. getuid (), mipsshare); // The MIPs of each PE are allocated to the MIPs map. setavailablemips (getavailablemips ()-totalmips); Return true ;} /* (non-javadoc) * reclaim vm pes * @ see Org. cloudid. cloudsim. vmscheduler # deallocatepesforvm (Org. cloudid. cloudsim. VM) * // @ overridepublic void deallocatepesforvm (Vm VM) {getfreepes (). addall (getpeallocationmap (). get (VM. getuid (); // Add the PE occupied by VM to getpeallocationmap () in the free PE list (). remove (VM. getuid (); // remove double totalmips = 0 from the allocated PE map; // update availablemipsfor (double MIPS: getmipsmap (). get (VM. getuid () {totalmips + = MIPS;} setavailablemips (getavailablemips () + totalmips); getmipsmap (). remove (VM. getuid (); // The MIPs map corresponding to the mountain size corresponds to this virtual machine part}/*** sets the PE allocation map. ** @ Param peallocationmap the PE allocation map */protected void setpeallocationmap (Map <string, list <PE> peallocationmap) {This. peallocationmap = peallocationmap;}/*** gets the PE allocation map. ** @ return the PE allocation map */protected Map <string, list <PE> getpeallocationmap () {return peallocationmap;}/*** sets the free PES vector. ** @ Param freepes the new free PES vector */protected void setfreepes (list <PE> freepes) {This. freepes = freepes;}/*** gets the free PES vector. ** @ return the free PES vector */protected list <PE> getfreepes () {return freepes ;}}