TestAlgo.java 22 KB

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