Index: /DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java	(revision 1207)
+++ /DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java	(revision 1298)
@@ -5,6 +5,4 @@
 import eduni.simjava.Sim_event;
 import eduni.simjava.Sim_system;
-import gridsim.Accumulator;
-import gridsim.ResourceCalendar;
 import gridsim.dcworms.DCWormsTags;
 import gridsim.dcworms.filter.ExecTaskFilter;
@@ -31,4 +29,5 @@
 import schedframe.events.scheduling.TaskRequestedTimeExpiredEvent;
 import schedframe.exceptions.ResourceException;
+import schedframe.resources.StandardResourceType;
 import schedframe.resources.computing.ComputingResource;
 import schedframe.resources.computing.profiles.energy.EnergyEvent;
@@ -54,5 +53,4 @@
 import schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin;
 import schedframe.scheduling.plugin.grid.ModuleListImpl;
-import schedframe.scheduling.plugin.grid.ModuleType;
 import schedframe.scheduling.policy.AbstractManagementSystem;
 import schedframe.scheduling.queue.TaskQueueList;
@@ -64,4 +62,5 @@
 import schedframe.scheduling.tasks.WorkloadUnit;
 import simulator.DCWormsConstants;
+import simulator.stats.GSSAccumulator;
 import simulator.utils.DoubleMath;
 
@@ -71,6 +70,4 @@
 
 	protected double lastUpdateTime;
-
-	protected Accumulator accTotalLoad;
 
 	public LocalManagementSystem(String providerId, String entityName, SchedulingPlugin schedPlugin,
@@ -85,12 +82,8 @@
 		this.schedulingPlugin =  schedPlugin;
 		this.moduleList = new ModuleListImpl(1);
-		
-		this.accTotalLoad = new Accumulator();
 	}
 
 	public void init(Scheduler sched, ManagedResources managedResources) {
 		super.init(sched, managedResources);
-		double load = 0;
-		accTotalLoad.add(load);
 	}
 
@@ -135,5 +128,5 @@
 				sendFinishedWorkloadUnit(execTask);
 				log.debug(execTask.getJobId() + "_" + execTask.getId() + " finished execution on " + new DateTime());
-				log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad(jobRegistry.getRunningTasks().size()));
+				log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad());
 				if (pluginSupportsEvent(tag)) {
 					SchedulingEvent event = new TaskFinishedEvent(execTask.getJobId(), execTask.getId());
@@ -178,4 +171,12 @@
 			execTask = (ExecTask) ev.get_data();
 			updateTaskExecution(execTask, SchedulingEventType.RESOURCE_STATE_CHANGED);
+			break;
+			
+		case DCWormsTags.POWER_LIMIT_EXCEEDED:
+			if (pluginSupportsEvent(tag)) {
+				SchedulingEvent event = new SchedulingEvent(SchedulingEventType.POWER_LIMIT_EXCEEDED);
+				schedulingPlugin.schedule(event,
+						queues,  getJobRegistry(), getResourceManager(), moduleList);
+			}
 			break;
 		}
@@ -263,5 +264,5 @@
 		}
 
-		log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad(jobRegistry.getRunningTasks().size()));
+		log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad());
 		
 		PEUnit peUnit = (PEUnit)choosenResources.get(StandardResourceUnitName.PE);
@@ -323,10 +324,10 @@
 			ExecTask task = iter.next();
 			Executable exec = (Executable)task;
-			exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / exec.getEstimatedDuration()));
-			UsedResourcesList usedResourcesList = exec.getUsedResources();
-			PEUnit peUnit = (PEUnit)usedResourcesList.getLast().getResourceUnits()
-					.get(StandardResourceUnitName.PE);
-			double load = getMIShare(timeSpan, peUnit);
-			addTotalLoad(load);
+			if( exec.getUsedResources().size() > 1){	 
+				exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / exec.getEstimatedDuration() * (1.0 - exec.getCompletionPercentage()/100.0)));
+			}
+			else {
+				exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / exec.getEstimatedDuration()));
+			}
 		}
 	}
@@ -357,23 +358,6 @@
 		}
 	}
-	
-	private double getMIShare(double timeSpan, PEUnit pes) {
-		double localLoad;
-		ResourceCalendar resCalendar = (ResourceCalendar) moduleList.getModule(ModuleType.RESOURCE_CALENDAR);
-		if (resCalendar == null)
-			localLoad = 0;
-		else
-			// 1 - localLoad_ = available MI share percentage
-			localLoad = resCalendar.getCurrentLoad();
-
-		int speed = pes.getSpeed();
-		int cnt = pes.getAmount();
-
-		double totalMI = speed * cnt * timeSpan * (1 - localLoad);
-		return totalMI;
-	}
 
 	protected void updateProcessingTimes(Sim_event ev) {
-		updateProcessingProgress();
 		for (ExecTask execTask : jobRegistry.getRunningTasks()) {
 			Executable exec = (Executable)execTask;
@@ -385,5 +369,5 @@
 
 			if(DoubleMath.subtract((lastTimeStamp + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration)) == 0.0){
-				return;
+				continue;
 			}
 
@@ -438,35 +422,19 @@
 	}	
 
-	public double calculateTotalLoad(int size) {
-		// background load, defined during initialization
-		double load;
-		ResourceCalendar resCalendar = (ResourceCalendar) moduleList.getModule(ModuleType.RESOURCE_CALENDAR);
-		if (resCalendar == null)
-			load = 0;
-		else
-			load = resCalendar.getCurrentLoad();
-
-		int numberOfPE = 0;
+	public double calculateTotalLoad() {
+
+		GSSAccumulator loadAcc = new GSSAccumulator();
 		try {
-			for(ResourceUnit resUnit : getResourceManager().getPE()){
-				numberOfPE = numberOfPE + resUnit.getAmount();
-			}
-		} catch (Exception e) {
-			numberOfPE = 1;
-		}
-		double tasksPerPE = (double) size / numberOfPE;
-		load += Math.min(1.0 - load, tasksPerPE);
-
-		return load;
-	}
-
-	public Accumulator getTotalLoad() {
-		return accTotalLoad;
-	}
-
-	protected void addTotalLoad(double load) {
-		accTotalLoad.add(load);
-	}
-	
+			for(ComputingResource compRes: getResourceManager().getResourcesOfType(StandardResourceType.Node)){
+				loadAcc.add(compRes.getLoadInterface().getRecentUtilization().getValue());				
+			}
+		} catch (ResourceException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+		return loadAcc.getMean();
+	}
+
 	private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(String resourceName,
 			ExecTask task) {
