Browse Source

various fixes + distance to plant now in elements

David Heck 4 years ago
parent
commit
5a8aca1f2c

+ 1 - 0
src/algo/StorageProductionController.java

@@ -61,6 +61,7 @@ public class StorageProductionController {
 //        }
 	}
 
+	//TODO: redo algorithm to actually us it right...
 	public void disableStorageProduction(float energyNotNeeded) {
 		if(energyNotNeeded == -1) {
 			for (StorageElement se : storages) {

+ 33 - 20
src/algo/TestAlgo.java

@@ -2,13 +2,11 @@ package algo;
 
 import java.awt.*;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 
 import javax.swing.*;
 
-import algo.StorageElement.Mode;
 import api.AddOn;
 import classes.*;
 import ui.controller.Control;
@@ -33,6 +31,7 @@ public class TestAlgo implements AddOn {
 	private TextField powerplantMaxOutputTextfield;
 	private TextField blackstartStartTimeTextfield;
 	private TextField simulationDurationTextfield;
+	private TextField storageStartCharge;
 
 	private int blackstartSuccessTime;
 	private int blackstartStartTime;
@@ -116,6 +115,14 @@ public class TestAlgo implements AddOn {
 		powerplantMaxOutputLabel.setBounds(185, 110, 300, 20);
 		parameterPanel.add(powerplantMaxOutputLabel);
 
+		storageStartCharge = new TextField("10000");
+		storageStartCharge.setBounds(10, 135, 170, 20);
+		parameterPanel.add(storageStartCharge);
+
+		JLabel storageStartChargeLabel = new JLabel("Storage charge at start");
+		storageStartChargeLabel.setBounds(185, 135, 300, 20);
+		parameterPanel.add(storageStartChargeLabel);
+
 //		JButton selectGroupNodeButton = new JButton("Select GroupNode");
 //		selectGroupNodeButton.setEnabled(false);
 //		selectGroupNodeButton.setBounds(10, 25, 165, 20);
@@ -236,7 +243,7 @@ public class TestAlgo implements AddOn {
 				println("No Power Plant in Model");
 				return;
 			}
-			calcResistance();
+			setDistanceToCalcResistance();
 			blackstartRunningCounter = 0;
 			deactivateBlackstart();
 			control.getModel().setCurIteration(0);
@@ -246,10 +253,7 @@ public class TestAlgo implements AddOn {
 			setPowerplantProduction(0);
 			enableAllConsumers();
 			SPC.disableStorageProduction(-1); //disable all storage production
-			for (StorageElement se :
-					getStorageElements()) {
-				se.setStateOfCharge(10000);
-			}
+
 //			StorageElement ele = new StorageElement("Storage", 1, 0, control.getModel());
 //			ele.setStatusAndSetEnergy(Mode.EMIT, 5000);
 //			
@@ -270,6 +274,10 @@ public class TestAlgo implements AddOn {
 			powerplantMaxOutput = Float.parseFloat(powerplantMaxOutputTextfield.getText());
 			blackstartStartTime = Integer.parseInt(blackstartStartTimeTextfield.getText());
 			control.getModel().setIterations(Integer.parseInt(simulationDurationTextfield.getText()));
+			for (StorageElement se :
+					getStorageElements()) {
+				se.setStateOfCharge(Integer.parseInt(storageStartCharge.getText()));
+			}
 
 			updateVisual();
 			if (blackstartStartTime + blackstartSuccessTime > control.getModel().getIterations() - 1) {
@@ -305,6 +313,7 @@ public class TestAlgo implements AddOn {
 				blackstartRunningCounter++;
 				if (blackstartRunningCounter == blackstartSuccessTime) {
 					// blackstart was successfull for the needed iterations
+					SPC.disableStorageProduction(-1);
 					deactivateBlackstart();
 					enableAllConsumers();
 					updateVisual();
@@ -330,7 +339,8 @@ public class TestAlgo implements AddOn {
 
 	/**
 	 * TODO:HOLEG UNTERVERSORGUNG CHECKEN
-	 * 
+	 * TODO: storage laden
+	 *
 	 * @param curIteration
 	 * @return true or false depending on whether the blackstart was successful for
 	 *         this iteration
@@ -394,7 +404,7 @@ public class TestAlgo implements AddOn {
 		return storageElements;
 	}
 
-	private void calcResistance() {
+	private void setDistanceToCalcResistance() {
 
 		if (powerPlant != null) {
 //			println("Powerplant Energy @"+powerPlant.getEnergyAtTimeStep(1));
@@ -435,8 +445,9 @@ public class TestAlgo implements AddOn {
 //			println("Distance to " + currentObject.getId() + ": " + distance);
 //			((HolonObject) currentObject).addElement(new StorageElement("Storage", 1, 0, control.getModel()));
 			for (HolonElement ele : ((HolonObject) currentObject).getElements()) {
-				if (ele.getEleName() == "Solar Panels") {
-					ele.setEnergyPerElement(5000);// TODO: das wollen wir ja so nicht
+				ele.setDistance(distance);
+				if (ele.getEleName() == "Solar Panels") {// TODO: das wollen wir ja so nicht
+					ele.setEnergyPerElement(5000);
 //					println("Energy: " + ele.getEnergyPerElement());
 					// set how much energy is left after resistance22
 					ele.setEnergyPerElement(calcEnergyAfterResistance(ele.getEnergyPerElement(), distance));// TODO: das
@@ -446,10 +457,20 @@ public class TestAlgo implements AddOn {
 																											// nicht
 //					println("Energy after resistance: " + ele.getEnergyPerElement());
 				}
+//				println(ele.getId() + " distance to pp " + ele.getDistance());
 			}
+
 		}
 	}
 
+	private double calcEdgeLength(CpsEdge edge) {
+		Position aPos = edge.getA().getPosition();
+		Position bPos = edge.getB().getPosition();
+		double xDiff = Math.abs(aPos.x - bPos.x);
+		double yDiff = Math.abs(aPos.y - bPos.y);
+		return Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
+	}
+
 	private float calcEnergyAfterResistance(float currentEnergy, double distance) {
 		// 230v kupfer 30mm durchmesser
 		int volatage = 230;
@@ -461,14 +482,6 @@ public class TestAlgo implements AddOn {
 		return (float) (1 - (cableResistance / (cableResistance + blackstartResistance))) * currentEnergy;
 	}
 
-	private double calcEdgeLength(CpsEdge edge) {
-		Position aPos = edge.getA().getPosition();
-		Position bPos = edge.getB().getPosition();
-		double xDiff = Math.abs(aPos.x - bPos.x);
-		double yDiff = Math.abs(aPos.y - bPos.y);
-		return Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
-	}
-
 	private void disableConsumers() {
 		// TODO: disableBatteryLoading? will ich das wirklich?
 		// SPC.disableStorageProduction();
@@ -524,7 +537,7 @@ public class TestAlgo implements AddOn {
 				if (!ele.isActive() && ele.isConsumer()) {
 					ele.setActive(true);
 				}
-			}
+			}//TODO: storage?
 		}
 	}
 

+ 13 - 0
src/classes/HolonElement.java

@@ -24,6 +24,10 @@ import java.util.ListIterator;
  */
 public class HolonElement implements LocalMode, GraphEditable{
 
+
+    @Expose
+    private double distance;
+
     /** Points of new TestGraph 
      * Represent the Graph 
      * the X component from a Point is period from 0..1
@@ -449,6 +453,15 @@ public class HolonElement implements LocalMode, GraphEditable{
 		return bezier;
 		
 	}
+
+    public double getDistance() {
+        return distance;
+    }
+
+    public void setDistance(double distance){
+        this.distance = distance;
+    }
+
 	//interfaces.LocalMode
 	@Override
 	public void setLocalPeriod(int period) {

+ 1 - 4
src/classes/HolonObject.java

@@ -6,7 +6,7 @@ import ui.controller.FlexManager;
 
 import java.util.ArrayList;
 
-
+
 
 /**
  * The class HolonObject represents any Object on the system which capability of
@@ -298,9 +298,6 @@ public class HolonObject extends AbstractCpsObject {
         this.totalFlex = totalFlex;
     }
 
-
-
-
     /**
      * If the user track any HolonObject the tracking information will be
      * updated. (If the HolonObject enters into the untracked state, the array