StatisticGraph.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. package ui.view;
  2. import java.awt.BasicStroke;
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.RenderingHints;
  7. import java.awt.geom.GeneralPath;
  8. import java.util.ArrayList;
  9. import javax.swing.JPanel;
  10. import classes.AbstractCpsObject;
  11. import classes.CpsUpperNode;
  12. import classes.HolonElement;
  13. import classes.HolonObject;
  14. import classes.HolonSwitch;
  15. import classes.SubNet;
  16. import classes.TrackedDataSet;
  17. import ui.controller.Control;
  18. import ui.model.Model;
  19. public class StatisticGraph extends JPanel {
  20. /**
  21. *
  22. */
  23. private static final long serialVersionUID = 1L;
  24. // Maximum y Value
  25. float maximum = 0;
  26. // is the Simulation running?
  27. private boolean isSimRunning;
  28. // model and controller
  29. private Model model;
  30. private Control controller;
  31. // Graphics2D
  32. private Graphics2D g2;
  33. GeneralPath path = new GeneralPath();
  34. // Data
  35. private ArrayList<TrackedDataSet> dataSets = new ArrayList<>();
  36. /**
  37. * Constructor.
  38. *
  39. * @param model
  40. * the Model
  41. * @param control
  42. * the Controller
  43. */
  44. public StatisticGraph(final Model model, Control control) {
  45. this.controller = control;
  46. this.model = model;
  47. this.setBackground(Color.WHITE);
  48. }
  49. /**
  50. * Paints all Components on the Canvas.
  51. *
  52. * @param g
  53. * Graphics
  54. *
  55. */
  56. public void paintComponent(Graphics g) {
  57. super.paintComponent(g);
  58. // Graphics2D init
  59. g2 = (Graphics2D) g;
  60. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  61. g2.setRenderingHints(rh);
  62. // Paint the Grid
  63. g2.setStroke(new BasicStroke(0));
  64. g2.setColor(Color.BLACK);
  65. for (int i = 0; i <= this.getWidth(); i += 10) {
  66. g2.drawLine(i, 0, i, this.getHeight());
  67. }
  68. for (int i = 0; i <= this.getHeight(); i += 5) {
  69. g2.drawLine(0, i, this.getWidth(), i);
  70. }
  71. isSimRunning = true;
  72. // if sim is on
  73. if (isSimRunning) {
  74. g2.setStroke(new BasicStroke(3));
  75. // Calculate the Maximum
  76. calcMaximum();
  77. // Calculate values for each set and add them
  78. addValues();
  79. // Create Paths and draw them
  80. for (TrackedDataSet set : dataSets) {
  81. path.reset();
  82. switch (set.getProperty()) {
  83. case TrackedDataSet.CONSUMPTION:
  84. case TrackedDataSet.PRODUCTION:
  85. case TrackedDataSet.ACTIVATED_ELEMENTS:
  86. case TrackedDataSet.TOTAL_PRODUCTION:
  87. case TrackedDataSet.TOTAL_CONSUMPTION:
  88. case TrackedDataSet.AMOUNT_HOLONS:
  89. case TrackedDataSet.GROUP_CONSUMPTION:
  90. case TrackedDataSet.GROUP_PRODUCTION:
  91. case TrackedDataSet.AMOUNT_CLOSED_SWITCHES:
  92. case TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS:
  93. case TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS:
  94. case TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS:
  95. case TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS:
  96. case TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS:
  97. case TrackedDataSet.AMOUNT_BROKEN_EDGES:
  98. case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
  99. case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
  100. case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
  101. case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
  102. createPathFloats(set);
  103. break;
  104. case TrackedDataSet.ON_OFF:
  105. createPathBooleans(set);
  106. break;
  107. case TrackedDataSet.PERCENT_SUPPLIED:
  108. case TrackedDataSet.PERCENT_NOT_SUPPLIED:
  109. case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
  110. case TrackedDataSet.RATIO_PRODUCERS_CONSUMERS:
  111. createPathPercent(set);
  112. break;
  113. default:
  114. break;
  115. }
  116. g2.setColor(set.getColor());
  117. g2.draw(path);
  118. }
  119. }
  120. }
  121. /**
  122. * Add an Object to the Graph if the maximum has not reached yet.
  123. *
  124. * @param obj
  125. * the Object to add
  126. */
  127. public void addObject(TrackedDataSet set) {
  128. dataSets.add(set);
  129. }
  130. /**
  131. * Removes an Object from the Graph.
  132. *
  133. * @param id
  134. * the id of the Object to remove
  135. */
  136. public void removeObject(int id) {
  137. dataSets.remove(id);
  138. }
  139. /**
  140. * converts the number to fit the canvas.
  141. *
  142. * @param d
  143. * the number to convert
  144. * @return the converted number
  145. */
  146. public double convertToCanvasY(float d) {
  147. return Math.abs((this.getHeight() - (d * (this.getHeight() / maximum))));
  148. }
  149. /**
  150. * Does take into account which timestep is watched, calculates the max
  151. * values.
  152. *
  153. * @return the currentEnergy
  154. */
  155. public float getEnergyAtCurrentTimeStep(HolonObject obj) {
  156. float temp = 0;
  157. for (HolonElement e : obj.getElements()) {
  158. if (e.getActive()) {
  159. temp = temp + e.getEnergyAt()[model.getCurIteration()];
  160. }
  161. }
  162. return temp;
  163. }
  164. /**
  165. * Calculate the Max Value of the Graph
  166. */
  167. public void calcMaximum() {
  168. maximum = 0;
  169. for (TrackedDataSet set : dataSets) {
  170. float val = 0;
  171. switch (set.getProperty()) {
  172. case TrackedDataSet.CONSUMPTION:
  173. for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
  174. if (h.getEnergy() < 0) {
  175. val += h.getEnergy() * h.getAmount();
  176. }
  177. }
  178. val *= -1;
  179. break;
  180. case TrackedDataSet.PRODUCTION:
  181. for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
  182. if (h.getEnergy() > 0) {
  183. val += h.getEnergy() * h.getAmount();
  184. }
  185. }
  186. break;
  187. case TrackedDataSet.ACTIVATED_ELEMENTS:
  188. for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
  189. val += h.getAmount();
  190. }
  191. break;
  192. case TrackedDataSet.ON_OFF:
  193. val = 1;
  194. break;
  195. case TrackedDataSet.TOTAL_PRODUCTION:
  196. val = getMaxTotalProduction(model.getObjectsOnCanvas());
  197. break;
  198. case TrackedDataSet.TOTAL_CONSUMPTION:
  199. val = getMaxTotalConsumption(model.getObjectsOnCanvas());
  200. val *= -1;
  201. break;
  202. case TrackedDataSet.PERCENT_SUPPLIED:
  203. case TrackedDataSet.PERCENT_NOT_SUPPLIED:
  204. case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
  205. val = 1;
  206. break;
  207. case TrackedDataSet.GROUP_PRODUCTION:
  208. val = getMaxTotalProduction(((CpsUpperNode) set.getCpsObject()).getNodes());
  209. break;
  210. case TrackedDataSet.GROUP_CONSUMPTION:
  211. val = getMaxTotalConsumption(((CpsUpperNode) set.getCpsObject()).getNodes());
  212. val *= -1;
  213. break;
  214. case TrackedDataSet.AMOUNT_HOLONS:
  215. val = controller.getSimManager().getSubNets().size();
  216. for (int i = 0; i < model.getCurIteration(); i++) {
  217. if (val < set.getValues()[i]) {
  218. val = set.getValues()[i];
  219. }
  220. }
  221. break;
  222. case TrackedDataSet.AMOUNT_CLOSED_SWITCHES:
  223. val = model.getSwitches().size();
  224. break;
  225. case TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS:
  226. for (SubNet sub : controller.getSimManager().getSubNets()) {
  227. if (val < sub.getObjects().size()) {
  228. val = sub.getObjects().size();
  229. }
  230. }
  231. break;
  232. case TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS:
  233. case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
  234. case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
  235. float eCount = 0;
  236. for (SubNet sub : controller.getSimManager().getSubNets()) {
  237. for (HolonObject obj : sub.getObjects()) {
  238. eCount += obj.getElements().size();
  239. }
  240. if (val < eCount) {
  241. val = eCount;
  242. }
  243. eCount = 0;
  244. }
  245. break;
  246. case TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS:
  247. for (SubNet sub : controller.getSimManager().getSubNets()) {
  248. if (val < sub.getObjects().size()) {
  249. val = sub.getObjects().size();
  250. }
  251. }
  252. break;
  253. case TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS:
  254. for (SubNet sub : controller.getSimManager().getSubNets()) {
  255. float tempVal = -getMaxTotalConsumption(new ArrayList<AbstractCpsObject>(sub.getObjects()));
  256. if (val < tempVal) {
  257. val = tempVal;
  258. }
  259. }
  260. break;
  261. case TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS:
  262. for (SubNet sub : controller.getSimManager().getSubNets()) {
  263. float tempVal = getMaxTotalProduction(new ArrayList<AbstractCpsObject>(sub.getObjects()));
  264. if (val < tempVal) {
  265. val = tempVal;
  266. }
  267. }
  268. break;
  269. case TrackedDataSet.AMOUNT_BROKEN_EDGES:
  270. for (SubNet sub : controller.getSimManager().getSubNets()) {
  271. val += sub.getSwitches().size();
  272. }
  273. break;
  274. case TrackedDataSet.RATIO_PRODUCERS_CONSUMERS:
  275. val = 1;
  276. break;
  277. case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
  278. for (SubNet sub : controller.getSimManager().getSubNets()) {
  279. float tempVal = sub.getSwitches().size();
  280. if (val < tempVal) {
  281. val = tempVal;
  282. }
  283. }
  284. break;
  285. case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
  286. for (SubNet sub : controller.getSimManager().getSubNets()) {
  287. float tempVal = getMaxTotalProduction(new ArrayList<AbstractCpsObject>(sub.getObjects()));
  288. if (val < tempVal) {
  289. val = tempVal;
  290. }
  291. }
  292. break;
  293. default:
  294. maximum = 0;
  295. break;
  296. }
  297. if (val > maximum) {
  298. maximum = val;
  299. }
  300. }
  301. ((StatisticGraphPanel) this.getParent()).setMaximumLabel(maximum);
  302. }
  303. /**
  304. * Add the Current Values to each set
  305. */
  306. private void addValues() {
  307. for (TrackedDataSet set : dataSets) {
  308. float val = 0;
  309. switch (set.getProperty()) {
  310. case TrackedDataSet.CONSUMPTION:
  311. for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
  312. if (h.getEnergy() < 0 && h.getActive()) {
  313. val += Math.abs(h.getEnergyAt()[model.getCurIteration()]) * h.getAmount();
  314. }
  315. set.setValAt(val, model.getCurIteration());
  316. }
  317. break;
  318. case TrackedDataSet.PRODUCTION:
  319. for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
  320. if (h.getEnergy() > 0 && h.getActive()) {
  321. val += Math.abs(h.getEnergyAt()[model.getCurIteration()]) * h.getAmount();
  322. }
  323. set.setValAt(val, model.getCurIteration());
  324. }
  325. break;
  326. case TrackedDataSet.ACTIVATED_ELEMENTS:
  327. for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
  328. if (h.getActive()) {
  329. val += h.getAmount();
  330. }
  331. set.setValAt(val, model.getCurIteration());
  332. }
  333. break;
  334. case TrackedDataSet.ON_OFF:
  335. if (((HolonSwitch) set.getCpsObject()).getManualMode()) {
  336. if (((HolonSwitch) set.getCpsObject()).getActiveManual()) {
  337. set.setValAt(1, model.getCurIteration());
  338. } else {
  339. set.setValAt(0, model.getCurIteration());
  340. }
  341. } else {
  342. if (((HolonSwitch) set.getCpsObject()).getActiveAt()[model.getCurIteration()]) {
  343. set.setValAt(1, model.getCurIteration());
  344. } else {
  345. set.setValAt(0, model.getCurIteration());
  346. }
  347. }
  348. break;
  349. case TrackedDataSet.TOTAL_PRODUCTION:
  350. set.setValAt(getTotalProductionAt(model.getObjectsOnCanvas(), model.getCurIteration()),
  351. model.getCurIteration());
  352. break;
  353. case TrackedDataSet.TOTAL_CONSUMPTION:
  354. set.setValAt(-getTotalConsumptionAt(model.getObjectsOnCanvas(), model.getCurIteration()),
  355. model.getCurIteration());
  356. break;
  357. case TrackedDataSet.PERCENT_SUPPLIED:
  358. set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.SUPPLIED),
  359. model.getCurIteration());
  360. break;
  361. case TrackedDataSet.PERCENT_NOT_SUPPLIED:
  362. set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.NOT_SUPPLIED),
  363. model.getCurIteration());
  364. break;
  365. case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
  366. set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.PARTIALLY_SUPPLIED),
  367. model.getCurIteration());
  368. break;
  369. case TrackedDataSet.GROUP_PRODUCTION:
  370. set.setValAt(
  371. getTotalProductionAt(((CpsUpperNode) set.getCpsObject()).getNodes(), model.getCurIteration()),
  372. model.getCurIteration());
  373. break;
  374. case TrackedDataSet.GROUP_CONSUMPTION:
  375. set.setValAt(
  376. -getTotalConsumptionAt(((CpsUpperNode) set.getCpsObject()).getNodes(), model.getCurIteration()),
  377. model.getCurIteration());
  378. break;
  379. case TrackedDataSet.AMOUNT_HOLONS:
  380. set.setValAt(controller.getSimManager().getSubNets().size(), model.getCurIteration());
  381. break;
  382. case TrackedDataSet.AMOUNT_CLOSED_SWITCHES:
  383. for (HolonSwitch s : model.getSwitches()) {
  384. if (s.getState(model.getCurIteration())) {
  385. val++;
  386. }
  387. }
  388. set.setValAt(val, model.getCurIteration());
  389. break;
  390. case TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS:
  391. for (SubNet sub : controller.getSimManager().getSubNets()) {
  392. val += sub.getObjects().size();
  393. }
  394. val /= controller.getSimManager().getSubNets().size();
  395. set.setValAt(val, model.getCurIteration());
  396. break;
  397. case TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS:
  398. for (SubNet sub : controller.getSimManager().getSubNets()) {
  399. for (HolonObject obj : sub.getObjects()) {
  400. val += obj.getElements().size();
  401. }
  402. }
  403. val /= controller.getSimManager().getSubNets().size();
  404. set.setValAt(val, model.getCurIteration());
  405. break;
  406. case TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS:
  407. for (SubNet sub : controller.getSimManager().getSubNets()) {
  408. for (HolonObject obj : sub.getObjects()) {
  409. if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) > 0) {
  410. val++;
  411. }
  412. }
  413. }
  414. val /= controller.getSimManager().getSubNets().size();
  415. set.setValAt(val, model.getCurIteration());
  416. break;
  417. case TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS:
  418. for (SubNet sub : controller.getSimManager().getSubNets()) {
  419. val += -getTotalConsumptionAt(new ArrayList<AbstractCpsObject>(sub.getObjects()),
  420. model.getCurIteration());
  421. }
  422. val /= controller.getSimManager().getSubNets().size();
  423. set.setValAt(val, model.getCurIteration());
  424. break;
  425. case TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS:
  426. for (SubNet sub : controller.getSimManager().getSubNets()) {
  427. val += (getTotalProductionAt(new ArrayList<AbstractCpsObject>(sub.getObjects()),
  428. model.getCurIteration())
  429. + getTotalConsumptionAt(new ArrayList<AbstractCpsObject>(sub.getObjects()),
  430. model.getCurIteration()));
  431. }
  432. val /= controller.getSimManager().getSubNets().size();
  433. set.setValAt(val, model.getCurIteration());
  434. break;
  435. case TrackedDataSet.AMOUNT_BROKEN_EDGES:
  436. for (SubNet sub : controller.getSimManager().getSubNets()) {
  437. for (HolonSwitch s : sub.getSwitches()) {
  438. if (s.getState()) {
  439. val++;
  440. }
  441. }
  442. }
  443. set.setValAt(val, model.getCurIteration());
  444. break;
  445. case TrackedDataSet.RATIO_PRODUCERS_CONSUMERS:
  446. float prod = 0;
  447. float cons = 0;
  448. for (SubNet sub : controller.getSimManager().getSubNets()) {
  449. for (HolonObject obj : sub.getObjects()) {
  450. if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) > 0) {
  451. prod++;
  452. } else if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) < 0) {
  453. cons++;
  454. }
  455. }
  456. }
  457. val = prod / (prod + cons);
  458. set.setValAt(val, model.getCurIteration());
  459. break;
  460. case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
  461. for (SubNet sub : controller.getSimManager().getSubNets()) {
  462. val += sub.getSwitches().size();
  463. }
  464. val /= controller.getSimManager().getSubNets().size();
  465. set.setValAt(val, model.getCurIteration());
  466. break;
  467. case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
  468. for (SubNet sub : controller.getSimManager().getSubNets()) {
  469. for (HolonObject obj : sub.getObjects()) {
  470. for (HolonElement ele : obj.getElements()) {
  471. if (ele.getActive()) {
  472. val++;
  473. }
  474. }
  475. }
  476. }
  477. val /= controller.getSimManager().getSubNets().size();
  478. set.setValAt(val, model.getCurIteration());
  479. break;
  480. case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
  481. for (SubNet sub : controller.getSimManager().getSubNets()) {
  482. for (HolonObject obj : sub.getObjects()) {
  483. for (HolonElement ele : obj.getElements()) {
  484. if (!ele.getActive()) {
  485. val++;
  486. }
  487. }
  488. }
  489. }
  490. val /= controller.getSimManager().getSubNets().size();
  491. set.setValAt(val, model.getCurIteration());
  492. break;
  493. case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
  494. for (SubNet sub : controller.getSimManager().getSubNets()) {
  495. val += getTotalProductionAt(new ArrayList<AbstractCpsObject>(sub.getObjects()),
  496. model.getCurIteration());
  497. }
  498. val /= controller.getSimManager().getSubNets().size();
  499. set.setValAt(val, model.getCurIteration());
  500. break;
  501. default:
  502. break;
  503. }
  504. }
  505. }
  506. /**
  507. * create Path with floats
  508. *
  509. * @param set
  510. */
  511. private void createPathFloats(TrackedDataSet set) {
  512. if (set.getValues()[0] != -1) {
  513. path.moveTo(0, convertToCanvasY(set.getValues()[0]));
  514. } else {
  515. path.moveTo(1 * this.getWidth() / model.getIterations(), convertToCanvasY(set.getValues()[1]));
  516. }
  517. for (int i = 0; i < model.getCurIteration(); i++) {
  518. if (set.getValues()[i + 1] != -1) {
  519. path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
  520. convertToCanvasY(set.getValues()[i + 1]));
  521. } else {
  522. path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
  523. convertToCanvasY(set.getValues()[i + 2]));
  524. }
  525. }
  526. }
  527. /**
  528. * create Path with booleans(0 and 1)
  529. *
  530. * @param set
  531. */
  532. private void createPathBooleans(TrackedDataSet set) {
  533. if (set.getValues()[0] != -1) {
  534. path.moveTo(0, convertToCanvasY((float) (set.getValues()[0] * (maximum / 3 * 2)) + (maximum / 6)));
  535. } else {
  536. path.moveTo(1 * this.getWidth() / model.getIterations(),
  537. convertToCanvasY((float) (set.getValues()[1] * (maximum / 3 * 2)) + (maximum / 6)));
  538. }
  539. for (int i = 0; i < model.getCurIteration(); i++) {
  540. controller.addTextToConsole(set.getValues()[i] + "");
  541. if (set.getValues()[i + 1] != -1) {
  542. path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
  543. convertToCanvasY((float) (set.getValues()[i + 1] * (maximum / 3 * 2)) + (maximum / 6)));
  544. } else {
  545. path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
  546. convertToCanvasY((float) (set.getValues()[i + 2] * (maximum / 3 * 2)) + (maximum / 6)));
  547. }
  548. }
  549. }
  550. /**
  551. * create Path for percent values
  552. *
  553. * @param set
  554. */
  555. private void createPathPercent(TrackedDataSet set) {
  556. if (set.getValues()[0] != -1) {
  557. path.moveTo(0, convertToCanvasY(set.getValues()[0] * maximum));
  558. } else {
  559. path.moveTo(1 * this.getWidth() / model.getIterations(), convertToCanvasY(set.getValues()[1] * maximum));
  560. }
  561. for (int i = 0; i < model.getCurIteration(); i++) {
  562. if (set.getValues()[i + 1] != -1) {
  563. path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
  564. convertToCanvasY(set.getValues()[i + 1] * maximum));
  565. } else {
  566. path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
  567. convertToCanvasY(set.getValues()[i + 2] * maximum));
  568. }
  569. }
  570. }
  571. /**
  572. * get the max total production of the given Objects
  573. *
  574. * @param objects
  575. * List of Objects
  576. */
  577. private float getMaxTotalProduction(ArrayList<AbstractCpsObject> objects) {
  578. float val = 0;
  579. for (AbstractCpsObject obj : objects) {
  580. if (obj instanceof HolonObject) {
  581. for (HolonElement ele : ((HolonObject) obj).getElements()) {
  582. if (ele.getEnergy() > 0) {
  583. val += ele.getEnergy() * ele.getAmount();
  584. }
  585. }
  586. } else if (obj instanceof CpsUpperNode) {
  587. val += getMaxTotalProduction(((CpsUpperNode) obj).getNodes());
  588. }
  589. }
  590. return val;
  591. }
  592. /**
  593. * get the max total consumption of the given Objects
  594. *
  595. * @param objects
  596. * List of Objects
  597. */
  598. private float getMaxTotalConsumption(ArrayList<AbstractCpsObject> objects) {
  599. float val = 0;
  600. for (AbstractCpsObject obj : objects) {
  601. if (obj instanceof HolonObject) {
  602. for (HolonElement ele : ((HolonObject) obj).getElements()) {
  603. if (ele.getEnergy() < 0) {
  604. val += ele.getEnergy() * ele.getAmount();
  605. }
  606. }
  607. } else if (obj instanceof CpsUpperNode) {
  608. val += getMaxTotalConsumption(((CpsUpperNode) obj).getNodes());
  609. }
  610. }
  611. return val;
  612. }
  613. /**
  614. * get the max total production of the given Objects
  615. *
  616. * @param objects
  617. * List of Objects
  618. * @param tStep
  619. */
  620. private float getTotalProductionAt(ArrayList<AbstractCpsObject> objects, int tStep) {
  621. float val = 0;
  622. for (AbstractCpsObject obj : objects) {
  623. if (obj instanceof HolonObject) {
  624. for (HolonElement ele : ((HolonObject) obj).getElements()) {
  625. if (ele.getEnergyAt()[tStep] > 0 && ele.getActive()) {
  626. val += ele.getEnergyAt()[tStep] * ele.getAmount();
  627. }
  628. }
  629. } else if (obj instanceof CpsUpperNode) {
  630. val += getTotalProductionAt(((CpsUpperNode) obj).getNodes(), tStep);
  631. }
  632. }
  633. return val;
  634. }
  635. /**
  636. * get the total consumption of the given Objects at the given timestep
  637. *
  638. * @param objects
  639. * List of Objects
  640. * @param tStep
  641. */
  642. private float getTotalConsumptionAt(ArrayList<AbstractCpsObject> objects, int tStep) {
  643. float val = 0;
  644. for (AbstractCpsObject obj : objects) {
  645. if (obj instanceof HolonObject) {
  646. for (HolonElement ele : ((HolonObject) obj).getElements()) {
  647. if (ele.getEnergyAt()[tStep] < 0 && ele.getActive()) {
  648. val += ele.getEnergyAt()[tStep] * ele.getAmount();
  649. }
  650. }
  651. } else if (obj instanceof CpsUpperNode) {
  652. val += getTotalConsumptionAt(((CpsUpperNode) obj).getNodes(), tStep);
  653. }
  654. }
  655. return val;
  656. }
  657. /**
  658. * get the Percentage of how many objects with the given state are in the
  659. * given List
  660. *
  661. * @param objects
  662. * List of Objects
  663. */
  664. private float getPercentState(ArrayList<AbstractCpsObject> objects, int state) {
  665. float count = controller.getNumberHolonObjects(objects);
  666. float stateObjectss = controller.getNumberStateObjects(objects, state);
  667. return stateObjectss / count;
  668. }
  669. public ArrayList<TrackedDataSet> getDataSets() {
  670. return dataSets;
  671. }
  672. }