Edge.java 6.9 KB

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