tolatesry 6 éve
szülő
commit
1263f8694a
2 módosított fájl, 158 hozzáadás és 129 törlés
  1. 151 127
      src/classes/HolonBattery.java
  2. 7 2
      src/ui/controller/SimulationManager.java

+ 151 - 127
src/classes/HolonBattery.java

@@ -1,127 +1,151 @@
-package classes;
-
-public class HolonBattery extends AbstractCpsObject{
-	
-	private float inRatio;
-	private float outRatio;
-	private float capasity;
-	private float stateOfCharge;
-	public enum State{STANDBY, COLLECT, EMIT};
-	private State state;
-	/** Constructor for a unique ID.
-	 * @param ObjName
-	 */
-	public HolonBattery(String ObjName)
-	{
-		super(ObjName);
-		inRatio = 0;
-		outRatio = 0;
-		capasity = 0;
-		stateOfCharge = 0;
-		setState(State.STANDBY);
-	}
-	/** Constructor to Copy a Battery
-	 * @param obj Object to copy.
-	 */
-	public HolonBattery(AbstractCpsObject obj)
-	{
-		super(obj);
-		super.setName(obj.getName());
-		setInRatio(((HolonBattery) obj).getInRatio());
-		setOutRatio(((HolonBattery) obj).getOutRatio());
-		setCapasity(((HolonBattery) obj).getCapasity());
-		setStateOfCharge(((HolonBattery) obj).getStateOfCharge());
-		setState(State.STANDBY);
-	}
-	public float getStateOfCharge() {
-		return stateOfCharge;
-	}
-	public void setStateOfCharge(float stateOfCharge) {
-		if(stateOfCharge > capasity) //state of Charege can not more than the capacity
-		{
-			stateOfCharge = capasity;
-		}
-		else if(stateOfCharge < 0) // state of charge can not be a negativ value
-		{
-			stateOfCharge = 0;
-		}
-		this.stateOfCharge = stateOfCharge;
-	}
-	public float getCapasity() {
-	
-		return capasity;
-	}
-	public void setCapasity(float capasity) {	
-		if(capasity < 0) //capasity can not be negative
-		{
-			capasity = 0;
-		}
-		this.capasity = capasity;
-	}
-	public float getOutRatio() {
-		return outRatio;
-	}
-	public void setOutRatio(float outRatio) {
-		if(outRatio < 0) //
-		{
-			outRatio = 0;
-		}
-		this.outRatio = outRatio;
-	}
-	public float getInRatio() {
-			return inRatio;
-	}
-	//For Calculations
-	public float getIN()
-	{
-		if(getCapasity() - getStateOfCharge() < inRatio)
-			return getCapasity() - getStateOfCharge();
-		else
-			return inRatio;
-	}
-	public float getOUT()
-	{
-		if(getStateOfCharge() < outRatio)
-			return getStateOfCharge();
-		else
-			return outRatio;
-	}
-	public void setInRatio(float inRatio) {
-		if(inRatio < 0)
-		{
-			inRatio = 0;
-		}
-		this.inRatio = inRatio;
-	}
-	public State getState() {
-		return state;
-	}
-	public void setState(State state) {
-		this.state = state;
-	}
-
-	/**
-	 * @return The String that is over the Battery in the Canvas if COLLECT the
-	 *         input if EMIT the output of the Battery
-	 */
-	public String getCanvasBatteryString()
-	{
-		switch(getState())
-		{
-		case COLLECT:
-			return "-" + Float.toString(getIN());
-		case EMIT:
-			return "+" + Float.toString(getOUT());
-		case STANDBY:
-		default:
-			return "0";
-		}
-		
-	}
-	public String toString()
-	{
-		return "HolonBattery ID:" + this.getId() + " State:" + getState().name() 
-				+ " InRatio:" + getInRatio() + " OutRatio:" + getOutRatio() 
-				+ " Akku: " + getStateOfCharge() + "/" + getCapasity();
-	}
-}
+package classes;
+
+public class HolonBattery extends AbstractCpsObject{
+	
+	private float inRatio;
+	private float outRatio;
+	private float capasity;
+	private float stateOfCharge;
+	private float newStateOfCharge;
+	public enum State{STANDBY, COLLECT, EMIT};
+	private State state;
+	/** Constructor for a unique ID.
+	 * @param ObjName
+	 */
+	public HolonBattery(String ObjName)
+	{
+		super(ObjName);
+		inRatio = 0;
+		outRatio = 0;
+		capasity = 0;
+		stateOfCharge = 0;
+		newStateOfCharge = 0;
+		setState(State.STANDBY);
+	}
+	/** Constructor to Copy a Battery
+	 * @param obj Object to copy.
+	 */
+	public HolonBattery(AbstractCpsObject obj)
+	{
+		super(obj);
+		super.setName(obj.getName());
+		setInRatio(((HolonBattery) obj).getInRatio());
+		setOutRatio(((HolonBattery) obj).getOutRatio());
+		setCapasity(((HolonBattery) obj).getCapasity());
+		setStateOfCharge(((HolonBattery) obj).getStateOfCharge());
+		setNewStateOfCharge(((HolonBattery) obj).getStateOfCharge());
+		setState(State.STANDBY);
+	}
+	public float getStateOfCharge() {
+		return stateOfCharge;
+	}
+	public void setStateOfCharge(float stateOfCharge) {
+		if(stateOfCharge > capasity) //state of Charege can not more than the capacity
+		{
+			stateOfCharge = capasity;
+		}
+		else if(stateOfCharge < 0) // state of charge can not be a negativ value
+		{
+			stateOfCharge = 0;
+		}
+		this.stateOfCharge = stateOfCharge;
+	}
+	public float getCapasity() {
+	
+		return capasity;
+	}
+	public void setCapasity(float capasity) {	
+		if(capasity < 0) //capasity can not be negative
+		{
+			capasity = 0;
+		}
+		this.capasity = capasity;
+	}
+	public float getOutRatio() {
+		return outRatio;
+	}
+	public void setOutRatio(float outRatio) {
+		if(outRatio < 0) //
+		{
+			outRatio = 0;
+		}
+		this.outRatio = outRatio;
+	}
+	public float getInRatio() {
+			return inRatio;
+	}
+	//For Calculations
+	public float getIN()
+	{
+		if(getCapasity() - getStateOfCharge() < inRatio)
+			return getCapasity() - getStateOfCharge();
+		else
+			return inRatio;
+	}
+	public float getOUT()
+	{
+		if(getStateOfCharge() < outRatio)
+			return getStateOfCharge();
+		else
+			return outRatio;
+	}
+	public void setInRatio(float inRatio) {
+		if(inRatio < 0)
+		{
+			inRatio = 0;
+		}
+		this.inRatio = inRatio;
+	}
+	public State getState() {
+		return state;
+	}
+	public void setState(State state) {
+		this.state = state;
+	}
+
+	/**
+	 * @return The String that is over the Battery in the Canvas if COLLECT the
+	 *         input if EMIT the output of the Battery
+	 */
+	public String getCanvasBatteryString()
+	{
+		
+		switch(getState())
+		{
+		case COLLECT:
+			return "-" + Float.toString(getIN());
+		case EMIT:
+			return "+" + Float.toString(getOUT());
+		case STANDBY:
+		default:
+			return "0";
+		}
+		
+		/*
+		if(newStateOfCharge > stateOfCharge)
+		{
+			return "+" + Float.toString(newStateOfCharge - stateOfCharge);
+		}
+		else if (newStateOfCharge < stateOfCharge)
+		{
+			return Float.toString(newStateOfCharge - stateOfCharge); // '"-" +' not needed because negative
+		}else
+		{
+			return "0";
+		}
+		*/
+	}
+	public String toString()
+	{
+		return "HolonBattery ID:" + this.getId() + " State:" + getState().name() 
+				+ " InRatio:" + getInRatio() + " OutRatio:" + getOutRatio() 
+				+ " Akku: " + getStateOfCharge() + "/" + getCapasity()
+				+ " NewSOC: " + getNewStateOfCharge();
+	}
+	public float getNewStateOfCharge() {
+		return newStateOfCharge;
+	}
+	public void setNewStateOfCharge(float newStateOfCharge) {
+		this.newStateOfCharge = newStateOfCharge;
+	}
+}

+ 7 - 2
src/ui/controller/SimulationManager.java

@@ -155,12 +155,14 @@ public class SimulationManager {
 					if(currentProduction >= energyToCollect)
 					{
 						//TODO: change StateofCharge soc = soc + energyToCollect
+						hB.setNewStateOfCharge(hB.getStateOfCharge() + energyToCollect);
 						currentProduction -= energyToCollect;
 					}else
 					{
 						//TODO: change StateofCharge soc = soc + currentProduction
+						hB.setNewStateOfCharge(hB.getStateOfCharge() + currentProduction);
 						currentProduction = 0;
-						break; //because no more energy
+						//no break must be calculatet for all break; //because no more energy
 					}
 					System.out.println(hB.toString() + " currentProduction: "+ currentProduction);
 				}
@@ -197,12 +199,14 @@ public class SimulationManager {
 						if(maxEnergyAvailable >= -neededEnergyFromBattery)
 						{
 							//TODO: change StateofCharge soc = soc - -neededEnergyFromBattery
+							hB.setNewStateOfCharge(hB.getStateOfCharge() - -neededEnergyFromBattery);
 							currentProduction += -neededEnergyFromBattery;
-							break; //When a energy can supply the last needed energy break;
+							//no break must be calculatet for all beabreak; //When a energy can supply the last needed energy break;
 						}
 						else
 						{
 							//TODO: change StateofCharge soc = soc - maxEnergyAvailable
+							hB.setNewStateOfCharge(hB.getStateOfCharge() - maxEnergyAvailable);
 							currentProduction += maxEnergyAvailable;
 						}
 					}
@@ -225,6 +229,7 @@ public class SimulationManager {
 					{
 						float maxEnergyAvailable = hB.getOUT(); //energy is positiv
 						//TODO: change StateofCharge soc = soc - maxEnergyAvailable
+						hB.setNewStateOfCharge(hB.getStateOfCharge() - maxEnergyAvailable);
 						currentProduction += maxEnergyAvailable;
 					}
 					calculation(x, singleSubNet, production, consumption, energySurplus, currentProduction,