cloudsim-plus-master/cloudsim-plus-master/cloudsim-plus/src/main/java/org/cloudbus/cloudsim/allocationpolicies/power/PowerVmAllocationPolicyMigrationAbstract.java
private void updateMigrationMapFromUnderloadedHosts(Set<PowerHostUtilizationHistory> overloadedHosts, final Map<Vm, Host> migrationMap) {
        final List<PowerHost> switchedOffHosts = getSwitchedOffHosts();

        // over-utilized hosts + hosts that are selected to migrate VMs to from over-utilized hosts
        final Set<Host> excludedHostsFromUnderloadSearch = new HashSet<>();
        excludedHostsFromUnderloadSearch.addAll(overloadedHosts);
        excludedHostsFromUnderloadSearch.addAll(switchedOffHosts);
        /*
        During the computation of the new placement for VMs
        the current VM placement is changed temporarily, before the actual migration of VMs.
        If VMs are being migrated from overloaded Hosts, they in fact already were removed
        from such Hosts and moved to destination ones.
        The target Host that maybe were shut down, might become underloaded too.
        This way, such Hosts are added to be ignored when
        looking for underloaded Hosts.
        See https://github.com/manoelcampos/cloudsim-plus/issues/94
         */
        excludedHostsFromUnderloadSearch.addAll(migrationMap.values());

        // over-utilized + under-utilized hosts
        final Set<PowerHost> excludedHostsForFindingNewVmPlacement = new HashSet<>();
        excludedHostsForFindingNewVmPlacement.addAll(overloadedHosts);
        excludedHostsForFindingNewVmPlacement.addAll(switchedOffHosts);

        final int numberOfHosts = getHostList().size();

        while (true) {
            if (numberOfHosts == excludedHostsFromUnderloadSearch.size()) {
                break;
            }

            final PowerHost underloadedHost = getUnderloadedHost(excludedHostsFromUnderloadSearch);
            if (underloadedHost == PowerHost.NULL) {
                break;
            }

            Log.printFormattedLine("%.2f: PowerVmAllocationPolicy: Underloaded hosts: %s", getDatacenter().getSimulation().clock(),  underloadedHost);

            excludedHostsFromUnderloadSearch.add(underloadedHost);
            excludedHostsForFindingNewVmPlacement.add(underloadedHost);

            List<? extends Vm> vmsToMigrateFromUnderloadedHost = getVmsToMigrateFromUnderUtilizedHost(underloadedHost);
            if (!vmsToMigrateFromUnderloadedHost.isEmpty()) {
                Log.printFormatted("\tVMs to be reallocated from the underloaded Host %d: ", underloadedHost.getId());
                printVmIds(vmsToMigrateFromUnderloadedHost);

                final Map<Vm, Host> newVmPlacement = getNewVmPlacementFromUnderloadedHost(
                        vmsToMigrateFromUnderloadedHost,
                        excludedHostsForFindingNewVmPlacement);

                excludedHostsFromUnderloadSearch.addAll(extractHostListFromMigrationMap(newVmPlacement));
                migrationMap.putAll(newVmPlacement);
                Log.printLine();
            }
        }
    }
/**
     * Updates the  map of VMs that will be migrated from under utilized hosts.
     *
     * @param overloadedHosts the List of over utilized hosts
     * @param migrationMap current migration map that will be updated
     */
Updates the  map of VMs that will be migrated from under utilized hosts.
@param overloadedHosts the List of over utilized hosts
@param migrationMap current migration map that will be updated
Updates the map of VMs that will be migrated from under utilized hosts . @param overloadedHosts the List of over utilized hosts @param migrationMap current migration map that will be updated
private void updateMigrationMapFromUnderloadedHosts(Set<PowerHostUtilizationHistory> overloadedHosts, final Map<Vm, Host> migrationMap) {
        final List<PowerHost> switchedOffHosts = getSwitchedOffHosts();
        final Set<Host> excludedHostsFromUnderloadSearch = new HashSet<>();
        excludedHostsFromUnderloadSearch.addAll(overloadedHosts);
        excludedHostsFromUnderloadSearch.addAll(switchedOffHosts);
        /*
        During the computation of the new placement for VMs
        the current VM placement is changed temporarily, before the actual migration of VMs.
        If VMs are being migrated from overloaded Hosts, they in fact already were removed
        from such Hosts and moved to destination ones.
        The target Host that maybe were shut down, might become underloaded too.
        This way, such Hosts are added to be ignored when
        looking for underloaded Hosts.
        See https://github.com/manoelcampos/cloudsim-plus/issues/94
         */
        excludedHostsFromUnderloadSearch.addAll(migrationMap.values());
        final Set<PowerHost> excludedHostsForFindingNewVmPlacement = new HashSet<>();
        excludedHostsForFindingNewVmPlacement.addAll(overloadedHosts);
        excludedHostsForFindingNewVmPlacement.addAll(switchedOffHosts);
        final int numberOfHosts = getHostList().size();
        while (true) {
            if (numberOfHosts == excludedHostsFromUnderloadSearch.size()) {
                break;
            }
            final PowerHost underloadedHost = getUnderloadedHost(excludedHostsFromUnderloadSearch);
            if (underloadedHost == PowerHost.NULL) {
                break;
            }
            Log.printFormattedLine("%.2f: PowerVmAllocationPolicy: Underloaded hosts: %s", getDatacenter().getSimulation().clock(),  underloadedHost);
            excludedHostsFromUnderloadSearch.add(underloadedHost);
            excludedHostsForFindingNewVmPlacement.add(underloadedHost);
            List<? extends Vm> vmsToMigrateFromUnderloadedHost = getVmsToMigrateFromUnderUtilizedHost(underloadedHost);
            if (!vmsToMigrateFromUnderloadedHost.isEmpty()) {
                Log.printFormatted("\tVMs to be reallocated from the underloaded Host %d: ", underloadedHost.getId());
                printVmIds(vmsToMigrateFromUnderloadedHost);
                final Map<Vm, Host> newVmPlacement = getNewVmPlacementFromUnderloadedHost(
                        vmsToMigrateFromUnderloadedHost,
                        excludedHostsForFindingNewVmPlacement);
                excludedHostsFromUnderloadSearch.addAll(extractHostListFromMigrationMap(newVmPlacement));
                migrationMap.putAll(newVmPlacement);
                Log.printLine();
            }
        }
    }
private void updateMigrationMapFromUnderloadedHosts ( Set < PowerHostUtilizationHistory > overloadedHosts , final Map < Vm , Host > migrationMap ) { final List < PowerHost > switchedOffHosts = getSwitchedOffHosts ( ) ; final Set < Host > excludedHostsFromUnderloadSearch = new HashSet < > ( ) ; excludedHostsFromUnderloadSearch . addAll ( overloadedHosts ) ; excludedHostsFromUnderloadSearch . addAll ( switchedOffHosts ) ; /*
        During the computation of the new placement for VMs
        the current VM placement is changed temporarily, before the actual migration of VMs.
        If VMs are being migrated from overloaded Hosts, they in fact already were removed
        from such Hosts and moved to destination ones.
        The target Host that maybe were shut down, might become underloaded too.
        This way, such Hosts are added to be ignored when
        looking for underloaded Hosts.
        See https://github.com/manoelcampos/cloudsim-plus/issues/94
         */ excludedHostsFromUnderloadSearch . addAll ( migrationMap . values ( ) ) ; final Set < PowerHost > excludedHostsForFindingNewVmPlacement = new HashSet < > ( ) ; excludedHostsForFindingNewVmPlacement . addAll ( overloadedHosts ) ; excludedHostsForFindingNewVmPlacement . addAll ( switchedOffHosts ) ; final int numberOfHosts = getHostList ( ) . size ( ) ; while ( true ) { if ( numberOfHosts == excludedHostsFromUnderloadSearch . size ( ) ) { break ; } final PowerHost underloadedHost = getUnderloadedHost ( excludedHostsFromUnderloadSearch ) ; if ( underloadedHost == PowerHost . NULL ) { break ; } Log . printFormattedLine ( "%.2f: PowerVmAllocationPolicy: Underloaded hosts: %s" , getDatacenter ( ) . getSimulation ( ) . clock ( ) , underloadedHost ) ; excludedHostsFromUnderloadSearch . add ( underloadedHost ) ; excludedHostsForFindingNewVmPlacement . add ( underloadedHost ) ; List < ? extends Vm > vmsToMigrateFromUnderloadedHost = getVmsToMigrateFromUnderUtilizedHost ( underloadedHost ) ; if ( ! vmsToMigrateFromUnderloadedHost . isEmpty ( ) ) { Log . printFormatted ( "\tVMs to be reallocated from the underloaded Host %d: " , underloadedHost . getId ( ) ) ; printVmIds ( vmsToMigrateFromUnderloadedHost ) ; final Map < Vm , Host > newVmPlacement = getNewVmPlacementFromUnderloadedHost ( vmsToMigrateFromUnderloadedHost , excludedHostsForFindingNewVmPlacement ) ; excludedHostsFromUnderloadSearch . addAll ( extractHostListFromMigrationMap ( newVmPlacement ) ) ; migrationMap . putAll ( newVmPlacement ) ; Log . printLine ( ) ; } } }
Updates the  map of VMs that will be migrated from under utilized hosts.
Updates the map of VMs that will be migrated from under utilized hosts .
// over-utilized hosts + hosts that are selected to migrate VMs to from over-utilized hosts // over-utilized + under-utilized hosts