Index: DCWoRMS/branches/coolemall/src/test/freqscaling/CB2_FCFS_Random_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/freqscaling/CB2_FCFS_Random_SP.java	(revision 1441)
+++ DCWoRMS/branches/coolemall/src/test/freqscaling/CB2_FCFS_Random_SP.java	(revision 1450)
@@ -190,205 +190,200 @@
 	
 	private void powerCap(ResourceManager resManager){
-		try {
-			for(ComputingResource compRes: resManager.getResourcesOfType(StandardResourceType.Rack)){
-				loadThresholds(compRes);
-
-				double powerConsumption = compRes.getPowerInterface().getRecentPowerUsage().getValue();
-				//System.out.println(compRes.getFullName() + " current: " + powerConsumption);
-				if(powerConsumption > MAX_THRESHOLD){
-					mode = compRes.getFullName();
-					ComputeBox1 cb1 = (ComputeBox1) compRes;
-					List<Processor> processors = cb1.getProcessors();
-					
-					double currentFrequencyLevel = 0;
-					if(currentFrequencyLevels.get(compRes.getFullName()) != null){
-						currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
-					} else {
-						currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency();
-					}
-					boolean overThreshold = true;
-					boolean canDoBetter = true;
-
-					while(overThreshold && canDoBetter){
-						//System.out.println(compRes.getFullName() + " - downgrading");
-						int procNumberWithoutChange = 0;
-						boolean improvement = false;
-						//System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel);
+		for(ComputingResource compRes: resManager.getResourcesOfType(StandardResourceType.Rack)){
+			loadThresholds(compRes);
+
+			double powerConsumption = compRes.getPowerInterface().getRecentPowerUsage().getValue();
+			//System.out.println(compRes.getFullName() + " current: " + powerConsumption);
+			if(powerConsumption > MAX_THRESHOLD){
+				mode = compRes.getFullName();
+				ComputeBox1 cb1 = (ComputeBox1) compRes;
+				List<Processor> processors = cb1.getProcessors();
+				
+				double currentFrequencyLevel = 0;
+				if(currentFrequencyLevels.get(compRes.getFullName()) != null){
+					currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
+				} else {
+					currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency();
+				}
+				boolean overThreshold = true;
+				boolean canDoBetter = true;
+
+				while(overThreshold && canDoBetter){
+					//System.out.println(compRes.getFullName() + " - downgrading");
+					int procNumberWithoutChange = 0;
+					boolean improvement = false;
+					//System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel);
+					for (Processor proc: processors){
+						PState currPState = proc.getPowerInterface().getPState();
+						//System.out.println(proc.getFullName() + " - checking");
+						if(currPState.getFrequency() <= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){
+							//System.out.println("operating same level");
+							procNumberWithoutChange++;
+							continue;
+						} 
+						if (proc.getFreeCores().size() == proc.getCores().size()){	
+							//System.out.println("free");
+							procNumberWithoutChange++;
+							continue;
+						} 
+		
+						double lowerFrequency = proc.getPowerInterface().getHighestPState().getFrequency();
+						for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){
+							PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName);
+							if(pState.getFrequency() > lowerFrequency && pState.getFrequency() < currPState.getFrequency()){
+								lowerFrequency = pState.getFrequency();
+							}
+						}
+						//System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency);
+						if(lowerFrequency < currentFrequencyLevel){
+							//System.out.println(compRes.getFullName() + " - changing current frequency level");
+							currentFrequencyLevels.put(compRes.getFullName(), lowerFrequency);
+							currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
+						}
+						
+						if(lowerFrequency != currPState.getFrequency()) {
+							//System.out.println(proc.getFullName() + " - lowering frequency");
+							proc.getPowerInterface().setFrequency(lowerFrequency);
+							Node n = proc.getNode();
+							for(Device device: n.getParent().getResourceCharacteristic().getDevices()){
+								
+								if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){
+									Fan fan = (Fan) device;
+
+									if(fan.getChilledResources().contains(n.getFullName())){
+										fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2"));
+									}
+								}
+							}
+							improvement = true;
+						}
+						if(lowerFrequency == proc.getPowerInterface().getHighestPState().getFrequency()){
+							canDoBetter = false;
+						} else {
+							canDoBetter = true;
+						}
+						if(compRes.getPowerInterface().getRecentPowerUsage().getValue() <= MAX_THRESHOLD){
+							overThreshold = false;
+							break;
+						}
+					}	
+					if(procNumberWithoutChange == processors.size() || improvement == false){
+						//System.out.println(compRes.getFullName() + " - failed to improve");
+						double nextFrequencyLevel = processors.get(0).getPowerInterface().getHighestPState().getFrequency();
 						for (Processor proc: processors){
-							PState currPState = proc.getPowerInterface().getPState();
-							//System.out.println(proc.getFullName() + " - checking");
-							if(currPState.getFrequency() <= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){
-								//System.out.println("operating same level");
-								procNumberWithoutChange++;
-								continue;
-							} 
-							if (proc.getFreeCores().size() == proc.getCores().size()){	
-								//System.out.println("free");
-								procNumberWithoutChange++;
-								continue;
-							} 
-			
-							double lowerFrequency = proc.getPowerInterface().getHighestPState().getFrequency();
 							for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){
 								PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName);
-								if(pState.getFrequency() > lowerFrequency && pState.getFrequency() < currPState.getFrequency()){
-									lowerFrequency = pState.getFrequency();
-								}
-							}
-							//System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency);
-							if(lowerFrequency < currentFrequencyLevel){
-								//System.out.println(compRes.getFullName() + " - changing current frequency level");
-								currentFrequencyLevels.put(compRes.getFullName(), lowerFrequency);
-								currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
-							}
-							
-							if(lowerFrequency != currPState.getFrequency()) {
-								//System.out.println(proc.getFullName() + " - lowering frequency");
-								proc.getPowerInterface().setFrequency(lowerFrequency);
-								Node n = proc.getNode();
-								for(Device device: n.getParent().getResourceCharacteristic().getDevices()){
-									
-									if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){
-										Fan fan = (Fan) device;
-
-										if(fan.getChilledResources().contains(n.getFullName())){
-											fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2"));
-										}
+								if(pState.getFrequency() > nextFrequencyLevel && pState.getFrequency() < currentFrequencyLevel){
+									nextFrequencyLevel = pState.getFrequency();
+								} 
+							}
+						}
+						//System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel);
+						currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel);
+						currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
+						if(currentFrequencyLevel == processors.get(0).getPowerInterface().getHighestPState().getFrequency()){
+							canDoBetter = false;
+						}
+						procNumberWithoutChange = 0;
+					}
+				}
+
+			} else if (powerConsumption < MIN_THRESHOLD) {
+				ComputeBox1 cb1 = (ComputeBox1) compRes;
+				List<Processor> processors = cb1.getProcessors();
+				
+				double currentFrequencyLevel = 0;
+				if(currentFrequencyLevels.get(compRes.getFullName()) != null){
+					currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
+				} else {
+					currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency();
+				}
+				boolean overThreshold = true;
+				boolean canDoBetter = true;
+
+				while(overThreshold && canDoBetter){
+					//System.out.println(compRes.getFullName() + " - downgrading");
+					int procNumberWithoutChange = 0;
+					boolean improvement = false;
+					//System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel);
+					for (Processor proc: processors){
+						PState currPState = proc.getPowerInterface().getPState();
+						//System.out.println(proc.getFullName() + " - checking");
+						if(currPState.getFrequency() >= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){
+							//System.out.println("operating same level");
+							procNumberWithoutChange++;
+							continue;
+						} 
+						if (proc.getFreeCores().size() == proc.getCores().size()){	
+							//System.out.println("free");
+							procNumberWithoutChange++;
+							continue;
+						} 
+		
+						double higherFrequency = proc.getPowerInterface().getLowestPState().getFrequency();
+						for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){
+							PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName);
+							if(pState.getFrequency() < higherFrequency && pState.getFrequency() > currPState.getFrequency()){
+								higherFrequency = pState.getFrequency();
+							}
+						}
+						//System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency);
+						if(higherFrequency > currentFrequencyLevel){
+							//System.out.println(compRes.getFullName() + " - changing current frequency level");
+							currentFrequencyLevels.put(compRes.getFullName(), higherFrequency);
+							currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
+						}
+						
+						if(higherFrequency != currPState.getFrequency()) {
+							//System.out.println(proc.getFullName() + " - lowering frequency");
+							proc.getPowerInterface().setFrequency(higherFrequency);
+							Node n = proc.getNode();
+							for(Device device: n.getParent().getResourceCharacteristic().getDevices()){
+								
+								if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){
+									Fan fan = (Fan) device;
+
+									if(fan.getChilledResources().contains(n.getFullName())){
+										fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2"));
 									}
 								}
-								improvement = true;
-							}
-							if(lowerFrequency == proc.getPowerInterface().getHighestPState().getFrequency()){
-								canDoBetter = false;
-							} else {
-								canDoBetter = true;
-							}
-							if(compRes.getPowerInterface().getRecentPowerUsage().getValue() <= MAX_THRESHOLD){
-								overThreshold = false;
-								break;
-							}
-						}	
-						if(procNumberWithoutChange == processors.size() || improvement == false){
-							//System.out.println(compRes.getFullName() + " - failed to improve");
-							double nextFrequencyLevel = processors.get(0).getPowerInterface().getHighestPState().getFrequency();
-							for (Processor proc: processors){
-								for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){
-									PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName);
-									if(pState.getFrequency() > nextFrequencyLevel && pState.getFrequency() < currentFrequencyLevel){
-										nextFrequencyLevel = pState.getFrequency();
-									} 
-								}
-							}
-							//System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel);
-							currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel);
-							currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
-							if(currentFrequencyLevel == processors.get(0).getPowerInterface().getHighestPState().getFrequency()){
-								canDoBetter = false;
-							}
-							procNumberWithoutChange = 0;
-						}
-					}
-
-				} else if (powerConsumption < MIN_THRESHOLD) {
-					ComputeBox1 cb1 = (ComputeBox1) compRes;
-					List<Processor> processors = cb1.getProcessors();
-					
-					double currentFrequencyLevel = 0;
-					if(currentFrequencyLevels.get(compRes.getFullName()) != null){
-						currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
-					} else {
-						currentFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency();
-					}
-					boolean overThreshold = true;
-					boolean canDoBetter = true;
-
-					while(overThreshold && canDoBetter){
-						//System.out.println(compRes.getFullName() + " - downgrading");
-						int procNumberWithoutChange = 0;
-						boolean improvement = false;
-						//System.out.println(compRes.getFullName() + "; currentFrequencyLevel: " + currentFrequencyLevel);
+							}
+							improvement = true;
+						}
+						if(higherFrequency == proc.getPowerInterface().getLowestPState().getFrequency()){
+							canDoBetter = false;
+						} else {
+							canDoBetter = true;
+						}
+						if(compRes.getPowerInterface().getRecentPowerUsage().getValue() >= MAX_THRESHOLD){
+							overThreshold = false;
+							break;
+						}
+					}
+					if(procNumberWithoutChange == processors.size() || improvement == false){
+						//System.out.println(compRes.getFullName() + " - failed to improve");
+						double nextFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency();
 						for (Processor proc: processors){
-							PState currPState = proc.getPowerInterface().getPState();
-							//System.out.println(proc.getFullName() + " - checking");
-							if(currPState.getFrequency() >= currentFrequencyLevel && proc.getFreeCores().size() != proc.getCores().size()){
-								//System.out.println("operating same level");
-								procNumberWithoutChange++;
-								continue;
-							} 
-							if (proc.getFreeCores().size() == proc.getCores().size()){	
-								//System.out.println("free");
-								procNumberWithoutChange++;
-								continue;
-							} 
-			
-							double higherFrequency = proc.getPowerInterface().getLowestPState().getFrequency();
 							for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){
 								PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName);
-								if(pState.getFrequency() < higherFrequency && pState.getFrequency() > currPState.getFrequency()){
-									higherFrequency = pState.getFrequency();
-								}
-							}
-							//System.out.println(proc.getFullName() + "; lower frequency: " + lowerFrequency);
-							if(higherFrequency > currentFrequencyLevel){
-								//System.out.println(compRes.getFullName() + " - changing current frequency level");
-								currentFrequencyLevels.put(compRes.getFullName(), higherFrequency);
-								currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
-							}
-							
-							if(higherFrequency != currPState.getFrequency()) {
-								//System.out.println(proc.getFullName() + " - lowering frequency");
-								proc.getPowerInterface().setFrequency(higherFrequency);
-								Node n = proc.getNode();
-								for(Device device: n.getParent().getResourceCharacteristic().getDevices()){
-									
-									if(device.getType().equals(StandardResourceType.Fan) || device.getType().equals(StandardResourceType.Inlet) | device.getType().equals(StandardResourceType.Outlet)){
-										Fan fan = (Fan) device;
-
-										if(fan.getChilledResources().contains(n.getFullName())){
-											fan.getAirflowInterface().setAirflowState(new CustomAirflowStateName("2"));
-										}
-									}
-								}
-								improvement = true;
-							}
-							if(higherFrequency == proc.getPowerInterface().getLowestPState().getFrequency()){
-								canDoBetter = false;
-							} else {
-								canDoBetter = true;
-							}
-							if(compRes.getPowerInterface().getRecentPowerUsage().getValue() >= MAX_THRESHOLD){
-								overThreshold = false;
-								break;
-							}
-						}
-						if(procNumberWithoutChange == processors.size() || improvement == false){
-							//System.out.println(compRes.getFullName() + " - failed to improve");
-							double nextFrequencyLevel = processors.get(0).getPowerInterface().getLowestPState().getFrequency();
-							for (Processor proc: processors){
-								for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){
-									PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName);
-									if(pState.getFrequency() < nextFrequencyLevel && pState.getFrequency() > currentFrequencyLevel){
-										nextFrequencyLevel = pState.getFrequency();
-									} 
-								}
-							}
-							//System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel);
-							currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel);
-							currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
-							if(currentFrequencyLevel == processors.get(0).getPowerInterface().getLowestPState().getFrequency()){
-								canDoBetter = false;
-							}
-							procNumberWithoutChange = 0;
-						}
-					}
-
-				}
-				mode = "";
-			}
-			
-		} catch (ResourceException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
+								if(pState.getFrequency() < nextFrequencyLevel && pState.getFrequency() > currentFrequencyLevel){
+									nextFrequencyLevel = pState.getFrequency();
+								} 
+							}
+						}
+						//System.out.println(compRes.getFullName() + "; nextFrequencyLevel: " + nextFrequencyLevel);
+						currentFrequencyLevels.put(compRes.getFullName(), nextFrequencyLevel);
+						currentFrequencyLevel = currentFrequencyLevels.get(compRes.getFullName());
+						if(currentFrequencyLevel == processors.get(0).getPowerInterface().getLowestPState().getFrequency()){
+							canDoBetter = false;
+						}
+						procNumberWithoutChange = 0;
+					}
+				}
+
+			}
+			mode = "";
+		}
+
 	}
 	
