123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package holeg.model;
- import com.google.gson.annotations.Expose;
- /**
- * The class "CpsEdge" represents the connections on the GUI. Each connection
- * contains a max. capacity, a flow, a status (isWorking), tags (for internal
- * use of electricity flow), source and destination
- *
- * @author Gruppe14
- */
- public class Edge {
- // Max. capacity of the Edge, if flow is greater than the status --> is
- // Working would be false
- @Expose
- public float maxCapacity;
- // Source
- AbstractCanvasObject a;
- // Destination
- AbstractCanvasObject b;
- @Expose
- private boolean breakedManuel = false;
- @Expose
- private boolean unlimitedCapacity = false;
-
-
-
-
-
- /**
- * Getter for the length of the Cable.
- * Always calculate never saved.
- * Needs to be profiled whats better.
- * @return
- */
- public float getLength() {
- return a.getPosition().getDistance(b.getPosition());
- }
- /**
- * Constructor with a user-defined max. capacity
- *
- * @param a Source
- * @param b Destination
- * @param maxCap Maximum Capacity
- */
- public Edge(AbstractCanvasObject a, AbstractCanvasObject b, float maxCap) {
- setA(a);
- setB(b);
- this.maxCapacity = maxCap;
- }
-
- /**
- * Clone Constructor
- *
- * @param a Source
- * @param b Destination
- * @param maxCap Maximum Capacity
- */
- public Edge(Edge other) {
- setA(other.a);
- setB(other.b);
- this.maxCapacity = other.maxCapacity;
- }
- /**
- * Getter for the Source.
- *
- * @return the a
- */
- public AbstractCanvasObject getA() {
- return a;
- }
- /**
- * Set the Source to a new one.
- *
- * @param a the a to set
- */
- public void setA(AbstractCanvasObject a) {
- this.a = a;
- }
- /**
- * Getter for the destination.
- *
- * @return the b
- */
- public AbstractCanvasObject getB() {
- return b;
- }
- /**
- * Set the Destination to a new one.
- *
- * @param b the b to set
- */
- public void setB(AbstractCanvasObject b) {
- this.b = b;
- }
-
- /**
- * Check if a CpsEdge is Connected to the AbstractCpsObject.
- * @param holonObject the AbstractCpsObject to check.
- * @return true if either a or b is the AbstractCpsObject to check.
- */
- public boolean isConnectedTo(AbstractCanvasObject holonObject)
- {
- return (holonObject.equals(a) || holonObject.equals(b));
- }
- @Override
- public String toString(){
- String A = (a == null) ? "null" : a.getName() + "[" + a.getId()+ "]";
- String B = (b == null) ? "null" : b.getName() + "[" + b.getId()+ "]";
- return "CpsEdge: " + A + " to " + B;
- }
- public boolean isBreakedManuel() {
- return breakedManuel;
- }
- public void setBreakedManuel(boolean breakedManuel) {
- this.breakedManuel = breakedManuel;
- }
- public boolean isUnlimitedCapacity() {
- return unlimitedCapacity;
- }
- public void setUnlimitedCapacity(boolean unlimitedCapacity) {
- this.unlimitedCapacity = unlimitedCapacity;
- }
- /*
- * STATE
- */
- public enum EdgeState{
- Working, Burned
- }
- private EdgeState state = initState();
- private float flowEnergy = 0;
-
- public EdgeState getState() {
- return state;
- }
- //TODO(Tom 2021-12-3): public -> package
- public void reset() {
- state = initState();
- }
- private EdgeState initState() {
- if (breakedManuel) {
- return EdgeState.Burned;
- }else {
- return EdgeState.Working;
- }
- }
-
- public float getActualFlow() {
- return flowEnergy;
- }
-
-
- public float getEnergyFromConneted() {
- float energy = 0.0f;
- if(getA() instanceof HolonObject hO && hO.getActualEnergy() > 0) {
- energy += hO.getActualEnergy();
- }
- if(getB() instanceof HolonObject hO && hO.getActualEnergy() > 0) {
- energy += hO.getActualEnergy();
- }
- return energy;
- }
- //TODO(Tom 2021-12-3): public -> package
- public void setActualFlow(float energyToSupplyInTheNetwork) {
- flowEnergy = energyToSupplyInTheNetwork;
- }
- //TODO(Tom 2021-12-3): public -> package
- public void setState(EdgeState state) {
- this.state = state;
- }
- }
|