2 * Copyright (c) 2020 Orange. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.algo.impl;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.graph.ConnectedEdge;
14 import org.opendaylight.graph.ConnectedVertex;
17 * This Class implements the Constrained Shortest Path First (CSPF) Path stored in the Priority Queue used by various
18 * Path Computation Algorithms.
20 * <p>The path corresponds to the computed path between the Source Vertex and the Current Vertex. Cost (based
21 * on TE Metric) and Delay are accumulated values from the source to the current vertex.
23 * <p>The class uses standard java "Comparable" interface to support "natural ordering" and thus implements
24 * the compareTo() method based on the "key" value. However, the equals() method uses Vertex Key for comparison.
25 * HashCode() method is also overridden by the Connected Vertex hashCode() method.
27 * @author Olivier Dugeon
31 public class CspfPath implements Comparable<CspfPath> {
33 /* Associated Connected Vertex: i.e. the current vertex in the Path */
34 private ConnectedVertex cvertex;
36 /* Path Length and associated cost and delay */
37 private float pathLength = 0;
38 private int cost = Integer.MAX_VALUE;
39 private int delay = Integer.MAX_VALUE;
41 /* Path as Connected Edge list from the source up to the Connected Vertex */
42 private ArrayList<ConnectedEdge> currentPath = new ArrayList<ConnectedEdge>();
44 /* Penultimate Connected Vertex in the current Path */
45 private Long predecessor;
47 public static final byte UNKNOWN = 0x00;
48 public static final byte ACTIVE = 0x01;
49 public static final byte SELECTED = 0x02;
50 public static final byte DOMINATED = 0x03;
51 public static final byte PROCESSED = 0x04;
52 private byte pathStatus;
53 /* Key used by the Priority Queue to sort the paths */
54 private Integer key = Integer.MAX_VALUE;
56 public CspfPath(ConnectedVertex vertex) {
57 this.cvertex = vertex;
60 public ConnectedVertex getVertex() {
64 public Long getVertexKey() {
65 return this.cvertex.getKey();
68 public CspfPath setCost(int cost) {
73 public int getCost() {
77 public CspfPath setDelay(int delay) {
82 public int getDelay() {
86 public CspfPath addConnectedEdge(ConnectedEdge edge) {
87 this.currentPath.add(edge);
91 public CspfPath replacePath(List<ConnectedEdge> list) {
92 if ((list != null) && (list.size() != 0)) {
93 this.currentPath.clear();
95 this.currentPath.addAll(list);
99 public List<ConnectedEdge> getPath() {
100 return this.currentPath;
103 public int getPathCount() {
104 return this.currentPath.size();
107 public CspfPath setPathStatus(byte status) {
108 this.pathStatus = status;
112 public byte getPathStatus() {
113 return this.pathStatus;
116 public CspfPath setPredecessor(Long vertexId) {
117 this.predecessor = vertexId;
121 public Long getPredecessor() {
122 return this.predecessor;
125 public CspfPath setPathLength(float length) {
126 this.pathLength = length;
130 public float getPathLength() {
131 return this.pathLength;
134 public void clearPath() {
135 this.currentPath.clear();
139 * Definition of the comparator method to be used by the java Priority Queue:
140 * "In the PQ the elements are classified relying on the "key" attribute. The "compareTo" method return a negative,
141 * zero or positive integer as this object is less than, equal to or greater than the specified object"
143 * The "key" attribute is here represented by the weight of the associated Vertex in the Path. For example in
144 * Shortest Path First algorithm, the key represent the cost between the source and the Vertex.
146 * The "equals" method performs the comparison on the Vertex Key. The "equals" method is used by the "remove"
147 * method of the priority queue
151 public CspfPath setKey(Integer key) {
156 public Integer getKey() {
161 public int compareTo(CspfPath other) {
162 return this.key.compareTo(other.getKey());
166 public boolean equals(Object object) {
167 if (!(object instanceof CspfPath)) {
171 CspfPath cspfPath = (CspfPath) object;
172 return this.getVertexKey().equals(cspfPath.getVertexKey());
176 public int hashCode() {
177 return this.cvertex.getKey().hashCode();