Advertisement
Guest User

Graph Vertex

a guest
Nov 12th, 2017
1,026
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package dijkstra;
  2.  
  3. public class Vertex implements Comparable{
  4.     private int id;
  5.     private float distance;
  6.     private Vertex parent;
  7.    
  8.     public Vertex(){
  9.         distance = Float.MAX_VALUE; // "infinity"
  10.         parent = null; 
  11.     }
  12.    
  13.     public Vertex(int id){
  14.         this.id = id;
  15.         distance = Float.MAX_VALUE; // "infinity"
  16.         parent = null; 
  17.     }
  18.  
  19.     public int getId() {
  20.         return id;
  21.     }
  22.  
  23.     public void setId(int id) {
  24.         this.id = id;
  25.     }
  26.  
  27.     public float getDistance() {
  28.         return distance;
  29.     }
  30.    
  31.     public void setDistance(float distance) {
  32.         this.distance = distance;
  33.     }
  34.    
  35.     public Vertex getParent() {
  36.         return parent;
  37.     }
  38.    
  39.     public void setParent(Vertex parent){
  40.         this.parent = parent;
  41.     }
  42.    
  43.     public int compareTo(Object o) {
  44.         Vertex other = (Vertex) o;
  45.         return Double.compare(this.distance, other.distance);
  46.     }
  47. }
Advertisement
RAW Paste Data Copied
Advertisement