All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.uni.freiburg.iig.telematik.jagal.graph.weighted.WeightedEdge Maven / Gradle / Ivy

Go to download

JAGAL provides implementations for directed graphs (weighted and unweighted) and various types of transition systems as well as utils for graph traversal and modification.

The newest version!
package de.uni.freiburg.iig.telematik.jagal.graph.weighted;

import de.uni.freiburg.iig.telematik.jagal.graph.Edge;
import de.uni.freiburg.iig.telematik.jagal.graph.Vertex;

/**
 * Represents an edge that maintains a weight.
 *
 * @author Thomas Stocker
 * @param 
 *
 */
public class WeightedEdge> extends Edge implements Comparable> {

        public static final int DEFAULT_WEIGHT = 1;
        private double weight = DEFAULT_WEIGHT;

        public WeightedEdge() {
        }

        public WeightedEdge(V source, V target) {
                super(source, target);
        }

        public WeightedEdge(V source, V target, double weight) {
                this(source, target);
                this.weight = weight;
        }

        /**
         * Returns the weight of this edge.
         *
         * @return The edge weight.
         */
        public double getWeight() {
                return weight;
        }

        /**
         * Sets the weight of this edge.
         *
         * @param weight Edge weight.
         */
        public void setWeight(double weight) {
                this.weight = weight;
        }

        public WeightedEdge clone() {
                return new WeightedEdge<>(source, target, weight);
        }

        @Override
        public int compareTo(WeightedEdge o) {
                if (this == o) {
                        return 0;
                }
                if (o == null) {
                        return 0;
                }
                if (o.getClass() != getClass()) {
                        return 0;
                }

                if (this.weight < ((WeightedEdge) o).getWeight()) {
                        return 1;
                }
                if (this.weight > ((WeightedEdge) o).getWeight()) {
                        return -1;
                }
                return 0;
        }

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = super.hashCode();
                long temp;
                temp = Double.doubleToLongBits(weight);
                result = prime * result + (int) (temp ^ (temp >>> 32));
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj) {
                        return true;
                }
                if (!super.equals(obj)) {
                        return false;
                }
                if (getClass() != obj.getClass()) {
                        return false;
                }
                @SuppressWarnings("unchecked")
                WeightedEdge other = (WeightedEdge) obj;
                return Double.doubleToLongBits(weight) == Double.doubleToLongBits(other.weight);
        }

        @Override
        public String toString() {
                return "(" + source + "-" + weight + "->" + target + ")";
        }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy