Pārlūkot izejas kodu

Add reactivePowerPerElement to HolonElement

Henrik Kunzelmann 3 gadi atpakaļ
vecāks
revīzija
6cdf7e0cf3

+ 13 - 1
src/classes/HolonElement.java

@@ -42,6 +42,8 @@ public class HolonElement implements LocalMode, GraphEditable{
     /** Currently used energy per element (- indicates consumation of energy, + indicates production of energy)*/
     @Expose
     private float energyPerElement;
+    @Expose
+    private float reactivePowerPerElement;
     /** Whether the gadget is active or not (currently uses/produces the energy in energyPerElement) */
     @Expose
     private boolean active;
@@ -276,6 +278,9 @@ public class HolonElement implements LocalMode, GraphEditable{
     	return amount * energyPerElement * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
     }
 
+    public float getReactivePowerAtTimestep(int timestep) {
+        return amount * reactivePowerPerElement * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
+    }
 
     /**
      * Get the Id of the selected HolonElement.
@@ -469,5 +474,12 @@ public class HolonElement implements LocalMode, GraphEditable{
 	public void setUseLocalPeriod(boolean state) {
 		this.isUsingLocalPeriod=state;
 	}
-	
+
+    public float getReactivePowerPerElement() {
+        return reactivePowerPerElement;
+    }
+
+    public void setReactivePowerPerElement(float reactivePowerPerElement) {
+        this.reactivePowerPerElement = reactivePowerPerElement;
+    }
 }

+ 5 - 0
src/classes/HolonObject.java

@@ -206,6 +206,11 @@ public class HolonObject extends AbstractCanvasObject {
     {
     	return getElements().stream().filter(element -> element.isActive()).map(element -> element.getEnergyAtTimeStep(timestep)).reduce(0.0f, (a, b) -> a + b);
     }
+
+    public float getReactiveEnergyAtTimeStep(int timestep)
+    {
+        return getElements().stream().filter(element -> element.isActive()).map(element -> element.getReactivePowerAtTimestep(timestep)).reduce(0.0f, (a, b) -> a + b);
+    }
     
     public float getEnergyAtTimeStepWithFlex(int timestep, FlexManager flexManager)
     {

+ 3 - 2
src/holeg/HolegGateway.java

@@ -23,13 +23,14 @@ public class HolegGateway {
         HashMap<AbstractCanvasObject, SimpleGridNode> canvasToGrid = new HashMap<>();
         for (HolonObject object : network.getHolonObjectList()) {
             double power = object.getEnergyAtTimeStep(iteration);
+            double reactivePower = object.getReactiveEnergyAtTimeStep(iteration);
             SimpleGridNode node;
 
             // Create house or generator
             if (power <= 0)
-                node = gridBuilder.addHouse(new ComplexNumber(-power, 0));
+                node = gridBuilder.addHouse(new ComplexNumber(-power, reactivePower));
             else
-                node = gridBuilder.addGenerator(new ComplexNumber(power, 0));
+                node = gridBuilder.addGenerator(new ComplexNumber(power, reactivePower));
             node.tag = object;
 
             // Find type by design

+ 2 - 2
src/ui/controller/UpdateController.java

@@ -80,7 +80,7 @@ public class UpdateController {
 				}
 			}
 			for (HolonElement e1 : elemList) {
-				Object[] temp2 = { e1.getObjName(), e1.getId(), e1.getEleName(), e1.getEnergyPerElement(),
+				Object[] temp2 = { e1.getObjName(), e1.getId(), e1.getEleName(), e1.getEnergyPerElement(), e1.getReactivePowerPerElement(),
 						controller.getSimManager().getActualFlexManager().isAFlexInUseOfHolonElement(e1), e1.getAmount(), e1.isActive()};
 				table.addRow(temp2);
 			}
@@ -94,7 +94,7 @@ public class UpdateController {
 				}
 				
 				for (HolonElement e1 : elemList) {
-					Object[] temp2 = { e1.getId(), e1.getEleName(), e1.getEnergyPerElement(),
+					Object[] temp2 = { e1.getId(), e1.getEleName(), e1.getEnergyPerElement(), e1.getReactivePowerPerElement(),
 							controller.getSimManager().getActualFlexManager().isAFlexInUseOfHolonElement(e1), e1.getAmount(), e1.isActive()};
 					table.addRow(temp2);
 				}

+ 20 - 13
src/ui/view/GUI.java

@@ -261,8 +261,8 @@ public class GUI implements CategoryListener {
 			"Reset Categories");
 	private final JMenu mnLanguage = new JMenu("Language");
 	private final String[] columnNamesMulti = { "Object", "Nr.", "Device",
-			"Energy", "Flexibility active", "Quantity", "Activated" };
-	private final String[] columnNamesSingle = { "Nr.", "Device", "Energy",
+			"Energy", "Power reactive", "Flexibility active", "Quantity", "Activated" };
+	private final String[] columnNamesSingle = { "Nr.", "Device", "Energy", "Power reactive",
 			"Flexibility active", "Quantity", "Activated" };
 	private final ArrayList<PropertyTable> tables = new ArrayList<>();
 	private final String[] comboBoxCat = { "Category", "Object", "Switch", "Battery" };
@@ -1436,24 +1436,26 @@ public class GUI implements CategoryListener {
 									}
 									// Energy Update
 									else if (selectedValueX == 3) {
-										System.out.println("selectedValueX == 3");
-										Float ftemp = Float
-												.parseFloat(newStuff);
+										Float ftemp = Float.parseFloat(newStuff);
 										eleTemp.setEnergyPerElement(ftemp);
 									}
-									// Flexibility
+									// ReactivePowerPerElement
 									else if (selectedValueX == 4) {
+										eleTemp.setReactivePowerPerElement(Float.parseFloat(newStuff));
+									}
+									// Flexibility
+									else if (selectedValueX == 5) {
 										Float ftemp = Float
 												.parseFloat(newStuff);
 										//TODO and here
 									}
 									// Amount of Elements update
-									else if (selectedValueX == 5) {
+									else if (selectedValueX == 6) {
 										Integer iTemp = Integer
 												.parseInt(newStuff);
 										eleTemp.setAmount(iTemp);
 									}
-									else if (selectedValueX == 6) {
+									else if (selectedValueX == 7) {
 										System.out.println("Test");
 									}
 								}
@@ -1518,8 +1520,11 @@ public class GUI implements CategoryListener {
 										Float ftemp = Float
 												.parseFloat(newStuff);
 										eleTemp.setEnergyPerElement(ftemp);
-									} // Flexibility
+									} // Reactive power
 									else if (selectedValueX == 3) {
+										eleTemp.setReactivePowerPerElement(Float.parseFloat(newStuff));
+									} // Flexibility
+									else if (selectedValueX == 4) {
 										Float ftemp = Float
 												.parseFloat(newStuff);
 										//TODO ---
@@ -1531,7 +1536,7 @@ public class GUI implements CategoryListener {
 										// be computed anew
 									}
 									// Amount of Elements update
-									else if (selectedValueX == 4) {
+									else if (selectedValueX == 5) {
 										Integer iTemp = Integer
 												.parseInt(newStuff);
 										eleTemp.setAmount(iTemp);
@@ -3095,13 +3100,15 @@ public class GUI implements CategoryListener {
 	private void updateElementTableAfterChange(HolonElement eleBTemp,
 			int selectedValueBY) {
 //		model.getSingleTable().setValueAt(false,
-//				selectedValueBY, 6);
+//				selectedValueBY, 7);
 		model.getSingleTable().setValueAt(eleBTemp.isActive(), selectedValueBY,
-				5);
+				6);
 		model.getSingleTable().setValueAt(eleBTemp.getAmount(),
-				selectedValueBY, 4);
+				selectedValueBY, 5);
 		model.getSingleTable().setValueAt(
 				controller.getSimManager().getActualFlexManager().isAFlexInUseOfHolonElement(eleBTemp),
+				selectedValueBY, 4);
+		model.getSingleTable().setValueAt(eleBTemp.getReactivePowerPerElement(),
 				selectedValueBY, 3);
 		model.getSingleTable().setValueAt(eleBTemp.getEnergyPerElement(),
 				selectedValueBY, 2);