controlAlgorithm.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. package blackstart;
  2. import java.awt.*;
  3. import java.util.ArrayList;
  4. import java.util.LinkedList;
  5. import java.util.List;
  6. import javax.swing.*;
  7. import api.AddOn;
  8. import classes.*;
  9. import ui.controller.Control;
  10. public class controlAlgorithm implements AddOn {
  11. private boolean cancel = false;
  12. // Gui Part:
  13. private Control control;
  14. private JTextArea textArea;
  15. private JPanel content = new JPanel();
  16. // ProgressBar
  17. private JProgressBar progressBar = new JProgressBar();
  18. private long startTime;
  19. private Thread runThread;
  20. // Blackstart Resistance in Watt
  21. private HolonObject powerPlant;
  22. private TextField blackstartResistanceTextfield;
  23. private TextField blackstartSuccessTimeTextfield;
  24. private TextField powerplantMaxOutputTextfield;
  25. private TextField blackstartStartTimeTextfield;
  26. private TextField simulationDurationTextfield;
  27. private TextField storageStartCharge;
  28. private TextField waitBetweenIterations;
  29. private int blackstartSuccessTime;
  30. private int blackstartStartTime;
  31. private int blackstartRunningCounter;
  32. private float powerplantMaxOutput;
  33. private List<HolonObject> renewableProducers;
  34. private List<HolonObject> consumers;
  35. private StorageProductionController SPC;
  36. public static void main(String[] args) {
  37. JFrame newFrame = new JFrame("exampleWindow");
  38. controlAlgorithm instance = new controlAlgorithm();
  39. newFrame.setContentPane(instance.getPanel());
  40. newFrame.pack();
  41. newFrame.setVisible(true);
  42. newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  43. }
  44. public controlAlgorithm() {
  45. content.setLayout(new BorderLayout());
  46. textArea = new JTextArea();
  47. textArea.setEditable(false);
  48. JScrollPane scrollPane = new JScrollPane(textArea);
  49. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, createOptionPanel(), scrollPane);
  50. splitPane.setResizeWeight(0.0);
  51. content.add(splitPane, BorderLayout.CENTER);
  52. content.setPreferredSize(new Dimension(800, 800));
  53. }
  54. public JPanel createOptionPanel() {
  55. JPanel optionPanel = new JPanel(new BorderLayout());
  56. JScrollPane scrollPane = new JScrollPane(createParameterPanel());
  57. scrollPane.setBorder(BorderFactory.createTitledBorder("Parameter"));
  58. optionPanel.add(scrollPane, BorderLayout.CENTER);
  59. optionPanel.add(createButtonPanel(), BorderLayout.PAGE_END);
  60. return optionPanel;
  61. }
  62. private Component createParameterPanel() {
  63. JPanel parameterPanel = new JPanel(null);
  64. parameterPanel.setPreferredSize(new Dimension(510, 300));
  65. blackstartResistanceTextfield = new TextField("5000000");
  66. blackstartResistanceTextfield.setBounds(10, 10, 170, 20);
  67. parameterPanel.add(blackstartResistanceTextfield);
  68. JLabel blackstartResistanceLabel = new JLabel("Blackstart resistance in Watt");
  69. blackstartResistanceLabel.setBounds(185, 10, 300, 20);
  70. parameterPanel.add(blackstartResistanceLabel);
  71. blackstartSuccessTimeTextfield = new TextField("30");
  72. blackstartSuccessTimeTextfield.setBounds(10, 35, 170, 20);
  73. parameterPanel.add(blackstartSuccessTimeTextfield);
  74. JLabel blackstartSuccessTimeLabel = new JLabel("Time for successfull blackstart in minutes(iterations)");
  75. blackstartSuccessTimeLabel.setBounds(185, 35, 300, 20);
  76. parameterPanel.add(blackstartSuccessTimeLabel);
  77. blackstartStartTimeTextfield = new TextField("15");
  78. blackstartStartTimeTextfield.setBounds(10, 60, 170, 20);
  79. parameterPanel.add(blackstartStartTimeTextfield);
  80. JLabel blackstartStartTimeLabel = new JLabel("Starttime for the blackstart");
  81. blackstartStartTimeLabel.setBounds(185, 60, 300, 20);
  82. parameterPanel.add(blackstartStartTimeLabel);
  83. simulationDurationTextfield = new TextField("500");// TODO:!
  84. simulationDurationTextfield.setBounds(10, 85, 170, 20);
  85. parameterPanel.add(simulationDurationTextfield);
  86. JLabel simulationDurationLabel = new JLabel("How long should the simulation run?");
  87. simulationDurationLabel.setBounds(185, 85, 300, 20);
  88. parameterPanel.add(simulationDurationLabel);
  89. powerplantMaxOutputTextfield = new TextField("40000000");
  90. powerplantMaxOutputTextfield.setBounds(10, 110, 170, 20);
  91. parameterPanel.add(powerplantMaxOutputTextfield);
  92. JLabel powerplantMaxOutputLabel = new JLabel("Powerplant Output afer Blackstart");
  93. powerplantMaxOutputLabel.setBounds(185, 110, 300, 20);
  94. parameterPanel.add(powerplantMaxOutputLabel);
  95. storageStartCharge = new TextField("10000");
  96. storageStartCharge.setBounds(10, 135, 170, 20);
  97. parameterPanel.add(storageStartCharge);
  98. JLabel storageStartChargeLabel = new JLabel("Storage charge at start");
  99. storageStartChargeLabel.setBounds(185, 135, 300, 20);
  100. parameterPanel.add(storageStartChargeLabel);
  101. waitBetweenIterations = new TextField("0");
  102. waitBetweenIterations.setBounds(10, 205, 170, 20);
  103. parameterPanel.add(waitBetweenIterations);
  104. JLabel waitBetweenIterationsLabel = new JLabel("Wait time between iterations");
  105. waitBetweenIterationsLabel.setBounds(185, 205, 300, 20);
  106. parameterPanel.add(waitBetweenIterationsLabel);
  107. // JButton selectGroupNodeButton = new JButton("Select GroupNode");
  108. // selectGroupNodeButton.setEnabled(false);
  109. // selectGroupNodeButton.setBounds(10, 25, 165, 20);
  110. // selectGroupNodeButton.addActionListener(actionEvent -> selectGroupNode());
  111. // borderPanel.add(selectGroupNodeButton);
  112. // JCheckBox useGroupNodeCheckBox = new JCheckBox();
  113. // useGroupNodeCheckBox.setSelected(false);
  114. // useGroupNodeCheckBox.setBounds(155, 1, 25, 20);
  115. // useGroupNodeCheckBox.addActionListener(actionEvent -> {
  116. // useGroupNode = useGroupNodeCheckBox.isSelected();
  117. // selectGroupNodeButton.setEnabled(useGroupNode);
  118. // });
  119. // borderPanel.add(useGroupNodeCheckBox);
  120. return parameterPanel;
  121. }
  122. public JPanel createButtonPanel() {
  123. JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  124. JButton cancelButton = new JButton("Cancel Run");
  125. cancelButton.addActionListener(actionEvent -> cancel());
  126. buttonPanel.add(cancelButton);
  127. JButton clearButton = new JButton("Clear Console");
  128. clearButton.addActionListener(actionEvent -> clear());
  129. buttonPanel.add(clearButton);
  130. JButton resetButton = new JButton("Reset");
  131. resetButton.setToolTipText("Resets the State to before the Algorithm has runed.");
  132. resetButton.addActionListener(actionEvent -> reset());
  133. buttonPanel.add(resetButton);
  134. JButton runButton = new JButton("Run");
  135. runButton.addActionListener(actionEvent -> {
  136. Runnable task = () -> run();
  137. runThread = new Thread(task);
  138. runThread.start();
  139. });
  140. buttonPanel.add(runButton);
  141. return buttonPanel;
  142. }
  143. private void cancel() {
  144. if (runThread.isAlive()) {
  145. println("");
  146. println("Cancel run.");
  147. cancel = true;
  148. progressBar.setValue(0);
  149. } else {
  150. println("Nothing to cancel.");
  151. }
  152. }
  153. private void run() {
  154. cancel = false;
  155. disableGuiInput(true);
  156. startTimer();
  157. initAlgo();
  158. if (cancel) {
  159. reset();
  160. disableGuiInput(false);
  161. return;
  162. }
  163. printElapsedTime();
  164. disableGuiInput(false);
  165. }
  166. private void reset() {
  167. println("RESET DOES NOTHING platzhalter");
  168. }
  169. private void disableGuiInput(boolean bool) {
  170. control.guiDisable(bool);
  171. }
  172. @Override
  173. public JPanel getPanel() {
  174. return content;
  175. }
  176. @Override
  177. public void setController(Control control) {
  178. this.control = control;
  179. }
  180. private void clear() {
  181. textArea.setText("");
  182. }
  183. private void print(String message) {
  184. textArea.append(message);
  185. }
  186. private void println(String message) {
  187. textArea.append(message + "\n");
  188. }
  189. private void startTimer() {
  190. startTime = System.currentTimeMillis();
  191. }
  192. private void printElapsedTime() {
  193. long elapsedMilliSeconds = System.currentTimeMillis() - startTime;
  194. println("Execution Time of Algo in Milliseconds:" + elapsedMilliSeconds);
  195. }
  196. ///////////////////////////////////////////////////////////////////////////////////
  197. /**
  198. *
  199. */
  200. private void initAlgo() {
  201. try {
  202. // init
  203. // SPC = new StorageProductionController(getStorageElements());// DANGER DONT GIVE NULL
  204. control.getModel().setStorageProductionController();
  205. SPC = control.getModel().getStorageProductionController();
  206. renewableProducers = getRenewableProducers();
  207. consumers = getConsumers();
  208. powerPlant = getPowerPlant();// DANGER DONT GIVE NULL
  209. if(powerPlant == null){
  210. println("No Power Plant in Model");
  211. return;
  212. }
  213. setDistanceToCalcResistance();
  214. blackstartRunningCounter = 0;
  215. deactivateBlackstart();
  216. control.getModel().setCurIteration(0);
  217. // prepare model
  218. /////////
  219. setPowerplantProduction(0);
  220. enableAllConsumers();
  221. SPC.disableStorageProduction(-1); //disable all storage production
  222. // StorageElement ele = new StorageElement("Storage", 1, 0, control.getModel());
  223. // ele.setStatusAndSetEnergy(Mode.EMIT, 5000);
  224. //
  225. // System.out.println(""+ele.getEnergyPerElement());
  226. // powerPlant.addElement(ele);
  227. // for (HolonElement elem : powerPlant.getElements()) {
  228. // if(elem instanceof StorageElement) {
  229. // println("boom");
  230. // }
  231. // }
  232. // TODO: prios?
  233. /////////
  234. // Get parameters from textfields
  235. setPowerPlantBlackstartResistance(-Float.parseFloat(blackstartResistanceTextfield.getText()));
  236. blackstartSuccessTime = Integer.parseInt(blackstartSuccessTimeTextfield.getText());
  237. powerplantMaxOutput = Float.parseFloat(powerplantMaxOutputTextfield.getText());
  238. blackstartStartTime = Integer.parseInt(blackstartStartTimeTextfield.getText());
  239. control.getModel().setIterations(Integer.parseInt(simulationDurationTextfield.getText()));
  240. for (StorageElement se :
  241. control.getModel().getStorageElements()) {
  242. se.setStateOfCharge(Integer.parseInt(storageStartCharge.getText()));
  243. }
  244. updateVisual();
  245. if (blackstartStartTime + blackstartSuccessTime > control.getModel().getIterations() - 1) {
  246. println("No Time for the blackstart, use working numbers");
  247. } else {
  248. blackstartMain(control.getModel().getCurIteration());
  249. }
  250. } catch (NumberFormatException e) {
  251. println("Worng Input, only numbers please");
  252. }
  253. }
  254. /**
  255. *
  256. * @param curIteration
  257. */
  258. private void blackstartMain(int curIteration) {
  259. try {
  260. Thread.sleep(Integer.parseInt(waitBetweenIterations.getText()));
  261. } catch (InterruptedException e) {
  262. // TODO Auto-generated catch block
  263. e.printStackTrace();
  264. }
  265. control.getModel().setCurIteration(curIteration);
  266. if (blackstartRunning()) {
  267. if (!blackstartAlgo(curIteration)) {
  268. // blackstart for this iteration was not successfull
  269. deactivateBlackstart();
  270. updateVisual();
  271. println("Simulation of blackstart failed in Iteration: " + curIteration);
  272. } else {
  273. // blackstart for this iteration was successfull
  274. blackstartRunningCounter++;
  275. if (blackstartRunningCounter == blackstartSuccessTime) {
  276. // blackstart was successfull for the needed iterations
  277. SPC.disableStorageProduction(-1);
  278. deactivateBlackstart();
  279. enableAllConsumers();
  280. updateVisual();
  281. println("Simulation of blackstart Successfull in Iteration: " + curIteration);
  282. } else {
  283. // blackstart not finished yet
  284. updateVisual();
  285. blackstartMain(curIteration + 1);
  286. }
  287. }
  288. } else {
  289. // blackstart has not started yet
  290. if (curIteration == blackstartStartTime) {
  291. activateBlackstart();
  292. disableConsumers();
  293. blackstartMain(curIteration);
  294. } else {
  295. updateVisual();
  296. blackstartMain(curIteration + 1);
  297. }
  298. }
  299. }
  300. /**
  301. * TODO:HOLEG UNTERVERSORGUNG CHECKEN
  302. * TODO: storage laden
  303. * TODO: run houses / elements from storage storage entladen
  304. * TODO: storage im GUI hinzufuegen
  305. * TODO: prios fuer elemente anschalten
  306. *
  307. * @param curIteration
  308. * @return true or false depending on whether the blackstart was successful for
  309. * this iteration
  310. */
  311. private boolean blackstartAlgo(int curIteration) {
  312. if (currentRenewableProduction() < getPowerPlantBlackstartResistance()) {
  313. // renewable energy production is not sufficient for the blackstart
  314. if (SPC.currentPossibleStorageProduction() >= getPowerPlantBlackstartResistance()
  315. - currentRenewableProduction()) {// is there currently enough power available from storage?
  316. SPC.disableStorageProduction(-1);// emergency fix
  317. SPC.enableStorageProduction(getPowerPlantBlackstartResistance() - currentRenewableProduction());
  318. rampUpPowerplant();
  319. enableConsumers(getPowerplantProduction());
  320. return true;
  321. } else {
  322. // blackstart has failed
  323. SPC.disableStorageProduction(-1);//TODO:disable all
  324. println("Not enough storage energy available");
  325. return false;
  326. }
  327. } else {
  328. //TODO: disable storage?
  329. // renewable energy production is sufficient for the blackstart
  330. rampUpPowerplant();
  331. enableConsumers(
  332. currentRenewableProduction() - getPowerPlantBlackstartResistance() + getPowerplantProduction());
  333. return true;
  334. }
  335. }
  336. private HolonObject getPowerPlant() {
  337. for (AbstractCpsObject cps : control.getModel().getAllHolonObjectsOnCanvas()) {
  338. // geht nur wenn nur ein power plant vorhanden ist
  339. if (cps instanceof HolonObject) {
  340. if (cps.getObjName().equals("Power Plant")) {
  341. return (HolonObject) cps;
  342. }
  343. }
  344. }
  345. return null;
  346. }
  347. private void setDistanceToCalcResistance() {
  348. if (powerPlant != null) {
  349. // println("Powerplant Energy @"+powerPlant.getEnergyAtTimeStep(1));
  350. // println("" + getPowerplantProduction());
  351. // travers
  352. if (powerPlant.getConnectedTo().size() > 0) {
  353. for (CpsEdge edge : powerPlant.getConnectedTo()) {
  354. // println(edge.toString());
  355. if (powerPlant.getId() == edge.getA().getId()) {
  356. traversEdges(edge.getB(), powerPlant, calcEdgeLength(edge));
  357. } else {
  358. traversEdges(edge.getA(), powerPlant, calcEdgeLength(edge));
  359. }
  360. }
  361. } else {
  362. println("Nothing connected to powerplant");
  363. }
  364. } else {
  365. println("No powerplant connected");
  366. }
  367. }
  368. private void traversEdges(AbstractCpsObject currentObject, AbstractCpsObject last, double distance) {
  369. if (currentObject.getConnectedTo().size() > 1) { // recursive call for all edges
  370. for (CpsEdge edge : currentObject.getConnectedTo()) {
  371. if (currentObject.getId() == edge.getA().getId()) { // look at which way the edge points
  372. if (last.getId() != edge.getB().getId()) {
  373. traversEdges(edge.getB(), currentObject, distance + calcEdgeLength(edge));
  374. }
  375. } else {
  376. if (last.getId() != edge.getA().getId()) {
  377. traversEdges(edge.getA(), currentObject, distance + calcEdgeLength(edge));
  378. }
  379. }
  380. }
  381. } else { // at leaf
  382. // println("Distance to " + currentObject.getId() + ": " + distance);
  383. // ((HolonObject) currentObject).addElement(new StorageElement("Storage", 1, 0, control.getModel()));
  384. for (HolonElement ele : ((HolonObject) currentObject).getElements()) {
  385. ele.setDistance(distance);
  386. if (ele.getEleName() == "Solar Panels") {// TODO: das wollen wir ja so nicht
  387. ele.setEnergyPerElement(5000);
  388. // println("Energy: " + ele.getEnergyPerElement());
  389. // set how much energy is left after resistance22
  390. ele.setEnergyPerElement(calcEnergyAfterResistance(ele.getEnergyPerElement(), distance));// TODO: das
  391. // wollen
  392. // wir ja so
  393. // auch
  394. // nicht
  395. // println("Energy after resistance: " + ele.getEnergyPerElement());
  396. }
  397. // println(ele.getId() + " distance to pp " + ele.getDistance());
  398. }
  399. }
  400. }
  401. private double calcEdgeLength(CpsEdge edge) {
  402. Position aPos = edge.getA().getPosition();
  403. Position bPos = edge.getB().getPosition();
  404. double xDiff = Math.abs(aPos.x - bPos.x);
  405. double yDiff = Math.abs(aPos.y - bPos.y);
  406. return Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
  407. }
  408. private float calcEnergyAfterResistance(float currentEnergy, double distance) {
  409. // 230v kupfer 30mm durchmesser
  410. int volatage = 230;
  411. int diameter = 30;
  412. // kupfer
  413. double specificMaterialResistance = 0.017;
  414. double blackstartResistance = Math.pow(volatage, 2) / getPowerPlantBlackstartResistance();
  415. double cableResistance = specificMaterialResistance * (distance / (0.25 * Math.PI * Math.pow(diameter, 2)));
  416. return (float) (1 - (cableResistance / (cableResistance + blackstartResistance))) * currentEnergy;
  417. }
  418. private void disableConsumers() {
  419. // TODO: disableBatteryLoading? will ich das wirklich?
  420. // SPC.disableStorageProduction();
  421. for (HolonObject consumer : consumers) {
  422. for (HolonElement ele : consumer.getElements()) {
  423. if (ele.isActive() && ele.isConsumer()) {
  424. ele.setActive(false);
  425. }
  426. }
  427. }
  428. }
  429. private void enableConsumers(float energyAvailable) {
  430. println("currenctrenewable: " + currentRenewableProduction());
  431. println("currenctpossiblestorage: " + SPC.currentPossibleStorageProduction());
  432. println("blackstart resi: " + getPowerPlantBlackstartResistance());
  433. println("current pp production: " + getPowerplantProduction());
  434. println("energy available for consumers" + energyAvailable);
  435. // Damit wir immer die gleiche ausgangslage haben //TODO: wirklich?
  436. disableConsumers();
  437. // TODO: das ganze lieber mit prirotaeten
  438. for (HolonObject consumer : consumers) {
  439. for (HolonElement ele : consumer.getElements()) {
  440. if (energyAvailable > 0
  441. && energyAvailable - Math.abs(ele.getEnergyPerElement() * ele.getAmount()) >= 0) {
  442. if (!ele.isActive()) {
  443. ele.setActive(true);
  444. energyAvailable = energyAvailable - Math.abs(ele.getEnergyPerElement() * ele.getAmount());// +
  445. // since
  446. // its
  447. // negative
  448. // System.out.println("Element " + ele.getId() + " was enabled Energy left: "+ energyAvailable);
  449. }
  450. } else {
  451. return;
  452. }
  453. }
  454. }
  455. // if (!SPC.batteriesFull()) {
  456. // // TODO: load unused batteries
  457. // } else {
  458. //
  459. // }
  460. }
  461. private void enableAllConsumers() {
  462. for (HolonObject consumer : consumers) {
  463. for (HolonElement ele : consumer.getElements()) {
  464. if (!ele.isActive() && ele.isConsumer()) {
  465. ele.setActive(true);
  466. }
  467. }//TODO: storage?
  468. }
  469. }
  470. private float currentRenewableProduction() {
  471. float production = 0;
  472. for (HolonObject house : renewableProducers) {
  473. for (HolonElement ele : house.getElements()) {
  474. if (ele.getEleName().equals("Solar Panels")) {// TODO: hier muss noch mehr dazu
  475. production = production + ele.getEnergyAtTimeStep(control.getModel().getCurIteration());
  476. }
  477. }
  478. }
  479. return production;
  480. }
  481. private void rampUpPowerplant() {
  482. for (HolonElement ele : powerPlant.getElements()) {
  483. if (ele.getEleName().equals("Power")) {
  484. ele.setEnergyPerElement(ele.getEnergyPerElement() + powerplantMaxOutput / blackstartSuccessTime);
  485. }
  486. }
  487. }
  488. private float getPowerplantProduction() {
  489. float totalProduction = 0;
  490. for (HolonElement ele : powerPlant.getElements()) {
  491. if (ele.getEleName().equals("Power")) {
  492. totalProduction = ele.getEnergyPerElement();
  493. }
  494. }
  495. return totalProduction;
  496. }
  497. private float setPowerplantProduction(float power) {
  498. float totalProduction = 0;
  499. for (HolonElement ele : powerPlant.getElements()) {
  500. if (ele.getEleName().equals("Power")) {
  501. ele.setEnergyPerElement(power);
  502. }
  503. }
  504. return totalProduction;
  505. }
  506. private float getPowerPlantBlackstartResistance() {
  507. for (HolonElement ele : powerPlant.getElements()) {
  508. if (ele.getEleName().equals("Blackstart")) {
  509. return -ele.getEnergyPerElement();
  510. }
  511. }
  512. return 0;
  513. }
  514. private void setPowerPlantBlackstartResistance(float resistance) {
  515. for (HolonElement ele : powerPlant.getElements()) {
  516. if (ele.getEleName().equals("Blackstart")) {
  517. ele.setEnergyPerElement(resistance);
  518. }
  519. }
  520. }
  521. private boolean blackstartRunning() {
  522. for (HolonElement ele : powerPlant.getElements()) {
  523. if (ele.getEleName().equals("Blackstart")) {
  524. if (ele.isActive()) {
  525. return true;
  526. } else {
  527. return false;
  528. }
  529. }
  530. }
  531. return false;
  532. }
  533. private void activateBlackstart() {
  534. for (HolonElement ele : powerPlant.getElements()) {
  535. if (ele.getEleName().equals("Blackstart")) {
  536. ele.setActive(true);
  537. }
  538. }
  539. }
  540. private void deactivateBlackstart() {
  541. for (HolonElement ele : powerPlant.getElements()) {
  542. if (ele.getEleName().equals("Blackstart")) {
  543. ele.setActive(false);
  544. }
  545. }
  546. }
  547. private LinkedList<HolonObject> getRenewableProducers() {
  548. LinkedList<HolonObject> list = new LinkedList<HolonObject>();
  549. for (HolonObject holonObject : control.getModel().getAllHolonObjectsOnCanvas()) {
  550. if (holonObject.getObjName().contentEquals("House")) {// TODO: das reicht so nicht da muss noch gecheckt
  551. // werden ob es renewables gibt
  552. list.add(holonObject);
  553. }
  554. }
  555. return list;
  556. }
  557. private LinkedList<HolonObject> getConsumers() {
  558. LinkedList<HolonObject> list = new LinkedList<HolonObject>();
  559. for (HolonObject holonObject : control.getModel().getAllHolonObjectsOnCanvas()) {
  560. if (holonObject.getObjName().contentEquals("House")) {// TODO: das reicht so nicht da muss noch gecheckt
  561. // werden ob es consumer gibt
  562. list.add(holonObject);
  563. }
  564. }
  565. return list;
  566. }
  567. /**
  568. * To let the User See the current state without touching the Canvas.
  569. */
  570. private void updateVisual() {
  571. System.out.println("Start updateVisual in Iteration: " + control.getModel().getCurIteration());
  572. control.calculateStateAndVisualForCurrentTimeStep();
  573. control.updateCanvas();
  574. System.out.println("Finish updateVisual in Iteration: " + control.getModel().getCurIteration());
  575. }
  576. }