blob: e28039122a602c931e7b4036b639d725645da75d [file] [log] [blame]
Andrey Komarov2398d962016-09-26 15:11:23 +03001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onlab.graph;
18
19/**
20 * Default weigher returns identical weight for every graph edge. Basically it
21 * is a hop count weigher.
22 * Produces weights of {@link ScalarWeight} type.
23 *
24 * @param <V> vertex type
25 * @param <E> edge type
26 */
27public class DefaultEdgeWeigher<V extends Vertex, E extends Edge<V>>
28 implements EdgeWeigher<V, E> {
29
30 /**
31 * Common weight value for any link.
32 */
33 protected static final double HOP_WEIGHT_VALUE = 1;
34 /**
35 * Weight value for null path (without links).
36 */
37 protected static final double NULL_WEIGHT_VALUE = 0;
38
39 @Override
40 public Weight weight(E edge) {
41 return new ScalarWeight(HOP_WEIGHT_VALUE);
42 }
43
44 @Override
45 public Weight getInitialWeight() {
46 return new ScalarWeight(NULL_WEIGHT_VALUE);
47 }
48
49 @Override
50 public Weight getNonViableWeight() {
51 return ScalarWeight.NON_VIABLE_WEIGHT;
52 }
53}