Ver código fonte

fix selecting which storage emits how much at each iteration

David Heck 5 anos atrás
pai
commit
59cacc50cd

+ 14 - 10
src/algo/StorageElement.java

@@ -34,7 +34,7 @@ public class StorageElement extends HolonElement {
 
 	public float getEnergyPerElement() {
 		switch (status) {
-		case STANDBY:
+			case STANDBY://TODO: switch wirklich notwendig?
 			return 0;
 		default:
 			return this.energyPerElement;
@@ -60,6 +60,9 @@ public class StorageElement extends HolonElement {
 	 *               by the storage
 	 * @return float how much energy was collected/emited
 	 */
+
+	//TODO: das beachtet nicht wie viel durch widerstand verloren geht
+
 	public float setStatusAndSetEnergy(Mode status, float energyWanted) {
 		this.status = status;
 		switch (status) {
@@ -119,19 +122,12 @@ public class StorageElement extends HolonElement {
 		return this.status;
 	}
 
-	public void chargeCalc(){
+	public void stateOfChargeCalculation(){
 		System.out.println("stateofcharge" + getId()+ "before:" + stateOfCharge + " with incomming " + status + " " + getEnergyPerElement() );
 		switch (status){
 			case COLLECT:
-				stateOfCharge = stateOfCharge - getEnergyPerElement();
-				break;
 			case EMIT:
-//				if(stateOfCharge - getEnergyPerElement() < 0){
-//
-//					stateOfCharge = 0;
-//				}else {
-					stateOfCharge = stateOfCharge - getEnergyPerElement();
-//				}
+				stateOfCharge = stateOfCharge - getEnergyPerElement();
 				break;
 			default:
 		}
@@ -169,6 +165,14 @@ public class StorageElement extends HolonElement {
 		return maxOutRatio;
 	}
 
+	public boolean storageChargeDepleted(){
+		if(stateOfCharge <= 0){
+			return true;
+		}else{
+			return false;
+		}
+	}
+
 	public enum Mode {
 		COLLECT, EMIT, STANDBY
 	}

+ 10 - 10
src/algo/StorageProductionController.java

@@ -1,7 +1,5 @@
 package algo;
 
-import classes.AbstractCpsObject;
-
 import java.util.ArrayList;
 
 public class StorageProductionController {
@@ -38,17 +36,19 @@ public class StorageProductionController {
         float energyLeftToEnabled = energyNeeded;
 
         if(currentStorageProduction() < energyNeeded){//TODO: das if muss ich nochmal ueberdenken
-        	energyLeftToEnabled = energyNeeded - currentStorageProduction();
-            //TODO: Problem: es wird abgezogen weil ja schon emitter aber wir wolle das ja erhoehen...
+//        	energyLeftToEnabled = energyNeeded - currentStorageProduction();
+            //DONE?: Problem: es wird abgezogen weil ja schon emitter aber wir wolle das ja erhoehen...
         	for (StorageElement se: storages) {
-                if (se.getStatus().equals(StorageElement.Mode.STANDBY)
-                || se.getStatus().equals(StorageElement.Mode.COLLECT)
-				|| (se.getStatus().equals(StorageElement.Mode.EMIT)
-						&& se.getEnergyPerElement() < se.getMaxOutRatio()
-						&& se.getEnergyPerElement() < se.getStateOfCharge())) {
+//                if (se.getStatus().equals(StorageElement.Mode.STANDBY)
+//                || se.getStatus().equals(StorageElement.Mode.COLLECT)
+//				|| (se.getStatus().equals(StorageElement.Mode.EMIT)
+//						&& se.getEnergyPerElement() < se.getMaxOutRatio()
+//						&& se.getEnergyPerElement() < se.getStateOfCharge())) {
                     // TODO: eventuell nach entfernung sortieren
+				if(!se.storageChargeDepleted()){
 					energyLeftToEnabled = energyLeftToEnabled - se.setStatusAndSetEnergy(StorageElement.Mode.EMIT, energyLeftToEnabled);
-                }
+				}
+//                }
 
                 if(energyLeftToEnabled <= 0){
                 	System.out.println("enabled energy from storage");

+ 6 - 6
src/algo/TestAlgo.java

@@ -287,12 +287,12 @@ public class TestAlgo implements AddOn {
 	 * @param curIteration
 	 */
 	private void blackstartMain(int curIteration) {
-//		try {
-//			Thread.sleep(1000);
-//		} catch (InterruptedException e) {
-//			// TODO Auto-generated catch block
-//			e.printStackTrace();
-//		}
+		try {
+			Thread.sleep(1000);
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 		control.getModel().setCurIteration(curIteration);
 		if (blackstartRunning()) {
 			if (!blackstartAlgo(curIteration)) {

+ 1 - 10
src/ui/controller/SimulationManager.java

@@ -2,9 +2,6 @@ package ui.controller;
 
 import algo.StorageElement;
 import classes.*;
-import classes.comparator.EnergyMinToMaxComparator;
-import classes.comparator.MinEnergyComparator;
-import classes.comparator.WeakestBattery;
 import ui.model.IntermediateCableWithState;
 import ui.model.DecoratedCable;
 import ui.model.DecoratedCable.CableState;
@@ -18,19 +15,13 @@ import ui.model.Model;
 import ui.model.Model.FairnessModel;
 import ui.model.VisualRepresentationalState;
 import ui.view.FlexiblePane;
-import ui.view.GUI;
-import ui.view.MyCanvas;
-import ui.view.Outliner;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 
-import javax.swing.JPanel;
-
 
 /**
  * Controller for Simulation.
@@ -131,7 +122,7 @@ public class SimulationManager {
 						.filter(ele -> ele != null)
 						.filter(ele -> (ele.getStatus().equals(StorageElement.Mode.EMIT)
 								|| (ele.getStatus().equals(StorageElement.Mode.COLLECT))))
-						.forEach(obj -> obj.chargeCalc());
+						.forEach(obj -> obj.stateOfChargeCalculation());
 
 				//find the cable with the energy supplied from his two connected objects are the biggest, from all cables that the network give more energy than the cablecapacity. 
 				IntermediateCableWithState cable = net.getEdgeList().stream().filter(aCable -> energyOnCables > aCable.getModel().getCapacity() && !aCable.getModel().isUnlimitedCapacity()).max((lhs,rhs) -> Float.compare(lhs.getEnergyFromConnetedAtTimestep(timestep, newFlexManager), rhs.getEnergyFromConnetedAtTimestep(timestep, newFlexManager))).orElse(null);