Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/SoftwarePhase.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/SoftwarePhase.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/SoftwarePhase.java	(revision 1334)
@@ -0,0 +1,55 @@
+package test.appProfConverter.dcworms;
+public class SoftwarePhase {
+	public String RefNode;
+	public Integer RefCores;
+	public Double RefFreq;
+	public Double RefUpload; // Network max upload speed
+	public Double RefDownload; // Network max download speed
+	public Double RefDiskBW; // Disk Bandwidth
+	public Double PM_Power;
+	public Double PM_Disk_IO;
+	public Double PM_Memory_RSS;
+	public Double PM_Download;
+	public Double PM_CPU_Usage;
+	public Integer PM_Threads;
+	public Double PM_Memory_Usage;
+	public Double PM_Upload;
+	public Integer Duration;
+
+	public SoftwarePhase(SoftwarePhase other) {
+		this.RefNode = other.RefNode;
+		this.RefCores = other.RefCores;
+		this.RefFreq = other.RefFreq;
+		this.RefUpload = other.RefUpload;
+		this.RefDownload = other.RefDownload;
+		this.RefDiskBW = other.RefDiskBW;
+		this.PM_Power = other.PM_Power;
+		this.PM_CPU_Usage = other.PM_CPU_Usage;
+		this.PM_Memory_RSS = other.PM_Memory_RSS;
+		this.PM_Memory_Usage = other.PM_Memory_Usage;
+		this.PM_Disk_IO = other.PM_Disk_IO;
+		this.PM_Download = other.PM_Download;
+		this.PM_Threads = other.PM_Threads;
+		this.PM_Upload = other.PM_Upload;
+		this.Duration = other.Duration;
+	}
+
+	public SoftwarePhase() {
+		this.RefNode = "";
+		this.RefCores = 1;
+		this.RefFreq = 0.0;
+		this.RefUpload = 0.0;
+		this.RefDownload = 0.0;
+		this.RefDiskBW = 0.0;
+		this.PM_Power = 0.0;
+		this.PM_CPU_Usage = 0.0;
+		this.PM_Memory_RSS = 0.0;
+		this.PM_Memory_Usage = 0.0;
+		this.PM_Disk_IO = 0.0;
+		this.PM_Download = 0.0;
+		this.PM_Upload = 0.0;
+		this.PM_Threads = 1;
+		this.Duration = 0;
+	}
+
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/SoftwareProfile.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/SoftwareProfile.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/SoftwareProfile.java	(revision 1334)
@@ -0,0 +1,74 @@
+package test.appProfConverter.dcworms;
+import schedframe.scheduling.tasks.phases.ResourceConsumption;
+import dcworms.schedframe.scheduling.Executable;
+
+public class SoftwareProfile {
+
+	public String taskId;
+	public SoftwarePhase[] phases;
+	
+	public SoftwareProfile(Executable executable) {
+		this.taskId = executable.getApplicationName();
+		
+		int nPhases = executable.getResourceConsumptionProfile().getResourceConsumptionList().size();
+		phases = new SoftwarePhase[nPhases];
+		
+
+		for (int i = 0; i < nPhases; i++) {
+			ResourceConsumption resConsumption = executable.getResourceConsumptionProfile().getResourceConsumptionList().get(i);
+			SoftwarePhase swPhase = new SoftwarePhase();
+
+			swPhase.Duration = (int) resConsumption.getDuration();
+			swPhase.RefNode = resConsumption.getReferenceHardware().get("name");
+			
+			try{
+				swPhase.RefCores = Integer.valueOf(resConsumption.getReferenceHardware().get("cpu_cores"));
+			} catch (Exception e){
+				
+			}
+			try{
+				swPhase.RefFreq = Double.valueOf(resConsumption.getReferenceHardware().get("cpu_maxfreq"));
+			} catch (Exception e){
+				
+			}
+
+			for (int b = 0; b < resConsumption.getBehaviourList().size(); b++) {
+				String name = resConsumption.getBehaviourList().get(b).getResouceName();
+				if (name.equals("PM_Power")) {
+					swPhase.PM_Power = resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+				if (name.equals("PM_Disk_IO")) {
+					swPhase.PM_Disk_IO = resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+				if (name.equals("PM_Memory_RSS")) {
+					swPhase.PM_Memory_RSS = resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+				if (name.equals("PM_Memory_Usage")) {
+					swPhase.PM_Memory_Usage = resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+				if (name.equals("PM_CPU_Usage")) {
+					swPhase.PM_CPU_Usage = resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+				if (name.equals("PM_Threads")) {
+					swPhase.PM_Threads = (int) resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+				if (name.equals("PM_Download")) {
+					swPhase.PM_Download = resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+				if (name.equals("PM_Upload")) {
+					swPhase.PM_Upload = resConsumption.getBehaviourList().get(b).getUtilization();
+				}
+			}
+
+			phases[i] = swPhase;
+		}
+		
+	}
+
+	public SoftwareProfile() {
+		this.taskId = null;
+		this.phases = null;
+	}
+
+
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/HardwareProfile.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/HardwareProfile.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/HardwareProfile.java	(revision 1334)
@@ -0,0 +1,113 @@
+package test.appProfConverter.dcworms;
+import java.util.HashMap;
+import java.util.Map;
+
+import schedframe.resources.computing.ComputingResource;
+import schedframe.resources.computing.Core;
+import schedframe.resources.computing.Node;
+import schedframe.resources.computing.profiles.energy.power.PState;
+import schedframe.resources.units.PEUnit;
+import schedframe.resources.units.ProcessingElements;
+import schedframe.resources.units.ResourceUnit;
+import schedframe.resources.units.ResourceUnitName;
+import schedframe.resources.units.StandardResourceUnitName;
+
+public class HardwareProfile {
+
+	public String componentId;
+	public Processor proc;
+	public Memory mem;
+	public Network net;
+
+	public HardwareProfile(Map<ResourceUnitName, ResourceUnit> resources) {
+		
+		PEUnit peUnit = (PEUnit) resources.get(StandardResourceUnitName.PE);
+		schedframe.resources.computing.Processor processor = null;
+		Node node = null;
+		int cores = 0;
+		if(peUnit instanceof ProcessingElements){
+			ProcessingElements pes = (ProcessingElements) peUnit;
+			for (ComputingResource compResource : pes) {
+				if(compResource instanceof Core) {
+					Core core = (Core) compResource;
+					processor = core.getProcessor();
+					node = processor.getNode();
+					cores = pes.getAmount();
+					break;
+				} else if (compResource instanceof schedframe.resources.computing.Processor) {
+					processor = (schedframe.resources.computing.Processor) compResource;
+					node = processor.getNode();
+					cores = processor.getCores().size();
+					break;
+				}
+			}
+		}
+		this.componentId = node.getResourceCharacteristic().getParameters().get("product").get(0).getContent();
+
+		double maxClockSpeed = Double.valueOf(processor.getResourceCharacteristic().getParameters().get("speed").get(0).getContent());
+		PhaseState pstates[] = new PhaseState[processor.getPowerInterface().getSupportedPStates().size()];
+		Map<Double, PhaseState> pstate_map = new HashMap<Double, PhaseState>();
+		int i = 0;
+		for (String pStateName: processor.getPowerInterface().getSupportedPStates().keySet()) {
+			PState pState =  processor.getPowerInterface().getSupportedPStates().get(pStateName);
+			PhaseState ps = new PhaseState(i, pState.getFrequency(), pState.getVoltage(), pState.getLoadPowerUsage().get(25.0), pState.getLoadPowerUsage().get(100.0));
+			pstates[i] = ps;
+			pstate_map.put(ps.frequency, ps);
+		}
+		this.proc = new Processor(maxClockSpeed, cores, pstates, pstate_map);
+		
+		int capacity = 0;
+		schedframe.resources.units.Memory memory;
+		try {
+			memory = (schedframe.resources.units.Memory) resources.get(StandardResourceUnitName.PE);
+			capacity = memory.getAmount();
+		} catch (Exception e) {
+			try {
+				memory = node.getMemory();
+				capacity = memory.getAmount();
+			} catch (NoSuchFieldException e2) {
+				// TODO Auto-generated catch block
+				e2.printStackTrace();
+			}
+		}
+		this.mem = new Memory(capacity);
+		
+		this.net = new Network(1000);
+		
+	}
+	
+	public HardwareProfile(Node node) {
+		
+		this.componentId = node.getResourceCharacteristic().getParameters().get("product").get(0).getContent();
+		
+		schedframe.resources.computing.Processor processor = node.getProcessors().get(0);
+		double maxClockSpeed = Double.valueOf(processor.getResourceCharacteristic().getParameters().get("speed").get(0).getContent());
+		int cores = processor.getCores().size();
+		PhaseState pstates[] = new PhaseState[processor.getPowerInterface().getSupportedPStates().size()];
+		Map<Double, PhaseState> pstate_map = new HashMap<Double, PhaseState>();
+		int i = 0;
+		for (String pStateName: processor.getPowerInterface().getSupportedPStates().keySet()) {
+			PState pState =  processor.getPowerInterface().getSupportedPStates().get(pStateName);
+			PhaseState ps = new PhaseState(i, pState.getFrequency(), pState.getVoltage(), pState.getLoadPowerUsage().get(25.0), pState.getLoadPowerUsage().get(100.0));
+			pstates[i] = ps;
+			pstate_map.put(ps.frequency, ps);
+		}
+		
+		this.proc = new Processor(maxClockSpeed, cores, pstates, pstate_map);
+		
+		int capacity = 0;
+		schedframe.resources.units.Memory memory;
+		try {
+			memory = node.getMemory();
+			capacity = memory.getAmount();
+		} catch (NoSuchFieldException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		this.mem = new Memory(capacity);
+		
+		this.net = new Network(1000);
+	}
+
+
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Processor.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Processor.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Processor.java	(revision 1334)
@@ -0,0 +1,19 @@
+package test.appProfConverter.dcworms;
+import java.util.Map;
+
+public class Processor {
+
+	public double maxClockSpeed;
+	public int cores;
+	public PhaseState pStates[];
+	public Map<Double, PhaseState> pStates_map;
+	
+	public Processor(double maxClockSpeed, int cores, PhaseState[] pStates, Map<Double, PhaseState> pStates_map) {
+		super();
+		this.maxClockSpeed = maxClockSpeed;
+		this.cores = cores;
+		this.pStates = pStates;
+		this.pStates_map = pStates_map;
+	}
+
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/PhaseState.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/PhaseState.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/PhaseState.java	(revision 1334)
@@ -0,0 +1,20 @@
+package test.appProfConverter.dcworms;
+
+public class PhaseState {
+
+	public int state;
+	public double frequency;
+	public double voltage;
+	public double powerUsageMin;
+	public double powerUsageMax;
+	
+	public PhaseState(int state, double frequency, double voltage, double powerUsageMin, double powerUsageMax) {
+		super();
+		this.state = state;
+		this.frequency = frequency;
+		this.voltage = voltage;
+		this.powerUsageMin = powerUsageMin;
+		this.powerUsageMax = powerUsageMax;
+	}
+
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/AppPowerEstimator.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/AppPowerEstimator.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/AppPowerEstimator.java	(revision 1334)
@@ -0,0 +1,14 @@
+package test.appProfConverter.dcworms;
+public class AppPowerEstimator {
+
+	public static Double PhasePower(SoftwarePhase phase, HardwareProfile hwProf) {
+		Double pow = 0.0;
+
+		PhaseState pstate = hwProf.proc.pStates_map.get(phase.RefFreq);
+
+		pow = (pstate.powerUsageMax - pstate.powerUsageMin)
+				* phase.PM_CPU_Usage;
+
+		return pow;
+	}
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Memory.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Memory.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Memory.java	(revision 1334)
@@ -0,0 +1,11 @@
+package test.appProfConverter.dcworms;
+
+public class Memory {
+
+	public int capacity;
+	
+	public Memory(int capacity) {
+		this.capacity = capacity;
+	}
+
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/AppProfileConverter.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/AppProfileConverter.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/AppProfileConverter.java	(revision 1334)
@@ -0,0 +1,75 @@
+package test.appProfConverter.dcworms;
+
+public class AppProfileConverter {
+	
+	public static SoftwareProfile convert(SoftwareProfile refSWProf,
+			HardwareProfile targetHWProf) {
+		SoftwareProfile newProf = new SoftwareProfile();
+
+		newProf.taskId = refSWProf.taskId;
+		newProf.phases = new SoftwarePhase[refSWProf.phases.length];
+		for (int i = 0; i < newProf.phases.length; i++) {
+			newProf.phases[i] = convertPhase(refSWProf.phases[i], targetHWProf);
+		}
+
+		return newProf;
+	}
+
+	private static SoftwarePhase convertPhase(SoftwarePhase refPhase,
+			HardwareProfile targetHW) {
+		SoftwarePhase newPhase;
+		double refCpuWork; // workload is constant in a phase
+		double loadCpu;
+		double t_cpu, t_nic, t_best;
+
+		newPhase = new SoftwarePhase(refPhase);
+		newPhase.RefNode = targetHW.componentId;
+		newPhase.RefFreq = targetHW.proc.maxClockSpeed;
+		newPhase.RefCores = targetHW.proc.cores;
+		newPhase.RefDownload = (double) targetHW.net.maxBandwidth;
+		newPhase.RefUpload = (double) targetHW.net.maxBandwidth;
+
+		refCpuWork = refPhase.RefFreq * refPhase.PM_CPU_Usage
+				* refPhase.Duration * refPhase.RefCores;
+
+		// Best CPU load and time duration
+		loadCpu = Math.min(1.0, refPhase.PM_CPU_Usage)
+				* Math.min(1.0,
+						((double) newPhase.PM_Threads / newPhase.RefCores));
+		System.out.println(loadCpu + ";" + refPhase.RefCores + ";" + refPhase.PM_CPU_Usage + ";" + newPhase.PM_Threads + ";" +newPhase.RefCores);
+		t_cpu = refCpuWork / (newPhase.RefCores * newPhase.RefFreq * loadCpu);
+
+		// Best network time duration
+		t_nic = Math.max((double) newPhase.PM_Upload / newPhase.RefUpload,
+				(double) newPhase.PM_Download / newPhase.RefDownload);
+
+		t_best = Math.max(t_cpu, t_nic);
+
+		// The duration in seconds will impact the load depending on the
+		// approximation error
+		newPhase.Duration = (int) Math.ceil(t_best);
+		// use t_best to debug
+		// newPhase.PM_CPU_Usage = refCpuWork
+		// / (newPhase.RefCores * newPhase.RefFreq * t_best);
+		newPhase.PM_CPU_Usage = refCpuWork
+				/ (newPhase.RefCores * newPhase.RefFreq * newPhase.Duration);
+
+		System.out
+				.printf("l0:%.2f\tl1:%.2f\td0:%d\td1:%d\tc0:%d\tc1:%d\tf0:%.2f\tf1:%.2f\tt0:%d\tt1:%d\n",
+						refPhase.PM_CPU_Usage, newPhase.PM_CPU_Usage,
+						refPhase.Duration, newPhase.Duration,
+						refPhase.RefCores, newPhase.RefCores, refPhase.RefFreq,
+						newPhase.RefFreq, refPhase.PM_Threads,
+						newPhase.PM_Threads);
+
+//		double newCpuWork = newPhase.RefFreq * newPhase.PM_CPU_Usage
+//				* newPhase.Duration * newPhase.RefCores;
+//		if (newCpuWork != refCpuWork) {
+//			System.out.printf("w0:%.2f\tw0:%.2f\n", refCpuWork, newCpuWork);
+//		}
+
+		newPhase.PM_Power = AppPowerEstimator.PhasePower(newPhase, targetHW);
+
+		return newPhase;
+	}
+}
Index: DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Network.java
===================================================================
--- DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Network.java	(revision 1334)
+++ DCWoRMS/branches/coolemall/src/test/appProfConverter/dcworms/Network.java	(revision 1334)
@@ -0,0 +1,11 @@
+package test.appProfConverter.dcworms;
+
+public class Network {
+
+	public int maxBandwidth;
+	
+	public Network(int maxBandwidth){
+		this.maxBandwidth = maxBandwidth;
+	}
+
+}
