Edge.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. package classes;
  2. import com.google.gson.annotations.Expose;
  3. import java.util.ArrayList;
  4. /**
  5. * The class "CpsEdge" represents the connections on the GUI. Each connection
  6. * contains a max. capacity, a flow, a status (isWorking), tags (for internal
  7. * use of electricity flow), source and destination
  8. *
  9. * @author Gruppe14
  10. */
  11. public class Edge {
  12. // Max. capacity of the Edge, if flow is greater than the status --> is
  13. // Working would be false
  14. @Expose
  15. private float maxCapacity;
  16. @Expose
  17. private float realLength = 1;
  18. @Expose
  19. private boolean overrideInPerUnit = false;
  20. @Expose
  21. private float overrideResistance = 0;
  22. @Expose
  23. private float overrideReactance = 0;
  24. @Expose
  25. private float overrideShuntSusceptance = 0;
  26. @Expose
  27. private float overrideTapRatio = 1;
  28. ArrayList<Integer> tags;
  29. // for internal use --> flow of electricity (simulation state)
  30. ArrayList<Integer> pseudoTags;
  31. // Source
  32. AbstractCanvasObject a;
  33. // Destination
  34. AbstractCanvasObject b;
  35. /**
  36. * Getter for the length of the Cable.
  37. * Always calculate never saved.
  38. * Needs to be profiled whats better.
  39. * @return
  40. */
  41. public float getLength() {
  42. return (float)a.getPosition().Distance(b.getPosition());
  43. }
  44. public float getRealLength() {
  45. return realLength;
  46. }
  47. public boolean getOverrideInPerUnit() {
  48. return overrideInPerUnit;
  49. }
  50. public float getOverrideResistance() {
  51. return overrideResistance;
  52. }
  53. public float getOverrideReactance() {
  54. return overrideReactance;
  55. }
  56. public float getOverrideShuntSusceptance() {
  57. return overrideShuntSusceptance;
  58. }
  59. public float getOverrideTapRatio() {
  60. return overrideTapRatio;
  61. }
  62. @Expose
  63. private boolean breakedManuel = false;
  64. @Expose
  65. private boolean unlimitedCapacity = false;
  66. /**
  67. * Constructor without max. capacity (by default as 100)
  68. *
  69. * @param a Source
  70. * @param b Destination
  71. */
  72. public Edge(AbstractCanvasObject a, AbstractCanvasObject b) {
  73. setA(a);
  74. setB(b);
  75. if(a == null) {
  76. System.out.println("A == NULL");
  77. }
  78. if(a == null) {
  79. System.out.println("B == NULL");
  80. }
  81. this.maxCapacity = 100;
  82. pseudoTags = new ArrayList<>();
  83. }
  84. /**
  85. * Constructor with a user-defined max. capacity
  86. *
  87. * @param a Source
  88. * @param b Destination
  89. * @param maxCap Maximum Capacity
  90. */
  91. public Edge(AbstractCanvasObject a, AbstractCanvasObject b, float maxCap) {
  92. setA(a);
  93. setB(b);
  94. this.maxCapacity = maxCap;
  95. pseudoTags = new ArrayList<>();
  96. }
  97. /**
  98. * Getter for the max. capacity
  99. *
  100. * @return the capacity
  101. */
  102. public float getCapacity() {
  103. return maxCapacity;
  104. }
  105. /**
  106. * Setter for the max. capacity
  107. *
  108. * @param cap the Capacity to set
  109. */
  110. public void setCapacity(float cap) {
  111. this.maxCapacity = cap;
  112. }
  113. public void setRealLength(float realLength) {
  114. this.realLength = realLength;
  115. }
  116. public void setOverrideInPerUnit(boolean overrideInPerUnit) {
  117. this.overrideInPerUnit = overrideInPerUnit;
  118. }
  119. public void setOverrideResistance(float overrideResistance) {
  120. this.overrideResistance = overrideResistance;
  121. }
  122. public void setOverrideReactance(float overrideReactance) {
  123. this.overrideReactance = overrideReactance;
  124. }
  125. public void setOverrideShuntSusceptance(float overrideShuntSusceptance) {
  126. this.overrideShuntSusceptance = overrideShuntSusceptance;
  127. }
  128. public void setOverrideTapRatio(float overrideTapRatio) {
  129. this.overrideTapRatio = overrideTapRatio;
  130. }
  131. /**
  132. * Getter for the Source.
  133. *
  134. * @return the a
  135. */
  136. public AbstractCanvasObject getA() {
  137. return a;
  138. }
  139. /**
  140. * Set the Source to a new one.
  141. *
  142. * @param a the a to set
  143. */
  144. public void setA(AbstractCanvasObject a) {
  145. this.a = a;
  146. }
  147. /**
  148. * Getter for the destination.
  149. *
  150. * @return the b
  151. */
  152. public AbstractCanvasObject getB() {
  153. return b;
  154. }
  155. /**
  156. * Set the Destination to a new one.
  157. *
  158. * @param b the b to set
  159. */
  160. public void setB(AbstractCanvasObject b) {
  161. this.b = b;
  162. }
  163. /**
  164. * Getter for the ArrayList of tags.
  165. *
  166. * @return tags tags for this edge
  167. */
  168. public ArrayList<Integer> getTags() {
  169. return tags;
  170. }
  171. /**
  172. * set the tags into a new set of tags.
  173. *
  174. * @param tags tags for this edge
  175. */
  176. public void setTags(ArrayList<Integer> tags) {
  177. this.tags = tags;
  178. }
  179. /**
  180. * Add a new tag to the ArrayList.
  181. *
  182. * @param tag tag for the ArrayList
  183. */
  184. public void addTag(int tag) {
  185. if (!tags.contains(tag)) {
  186. tags.add(tag);
  187. }
  188. }
  189. /**
  190. * checks whether list contains all given tags
  191. *
  192. * @param toCheck tags that are checked
  193. * @param list list to be checked
  194. * @return true if all tags in toCheck are contained in list, false otherwise
  195. */
  196. public boolean containsTags(ArrayList<Integer> list, ArrayList<Integer> toCheck) {
  197. if (toCheck.size() == 0) {
  198. return true;
  199. } else {
  200. for (Integer i : toCheck) {
  201. if (!(list.contains(i))) {
  202. return false;
  203. }
  204. }
  205. return true;
  206. }
  207. }
  208. public void addPseudoTag(int tag) {
  209. if (!pseudoTags.contains(tag)) {
  210. pseudoTags.add(tag);
  211. }
  212. }
  213. public void setPseudoTag(ArrayList<Integer> list) {
  214. pseudoTags = list;
  215. }
  216. public ArrayList<Integer> getPseudoTags() {
  217. return pseudoTags;
  218. }
  219. public void recalculateTags() {
  220. for (Integer i : pseudoTags) {
  221. if (!tags.contains(i)) {
  222. tags.add(i);
  223. }
  224. }
  225. }
  226. /**
  227. * Check if a CpsEdge is Connected to the AbstractCpsObject.
  228. * @param holonObject the AbstractCpsObject to check.
  229. * @return true if either a or b is the AbstractCpsObject to check.
  230. */
  231. public boolean isConnectedTo(AbstractCanvasObject holonObject)
  232. {
  233. return (holonObject.equals(a) || holonObject.equals(b));
  234. }
  235. @Override
  236. public String toString(){
  237. String A = (a == null) ? "null" : a.getName() + "[" + a.getId()+ "]";
  238. String B = (b == null) ? "null" : b.getName() + "[" + b.getId()+ "]";
  239. return "CpsEdge: " + A + " to " + B;
  240. }
  241. public boolean isBreakedManuel() {
  242. return breakedManuel;
  243. }
  244. public void setBreakedManuel(boolean breakedManuel) {
  245. this.breakedManuel = breakedManuel;
  246. }
  247. public boolean isUnlimitedCapacity() {
  248. return unlimitedCapacity;
  249. }
  250. public void setUnlimitedCapacity(boolean unlimitedCapacity) {
  251. this.unlimitedCapacity = unlimitedCapacity;
  252. }
  253. }