blob: a184660234d6d7e5ad05be4469ae0413b5fc2d40 [file] [log] [blame]
Andrey Komarov2398d962016-09-26 15:11:23 +03001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Andrey Komarov2398d962016-09-26 15:11:23 +03003 *
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
Yuta HIGUCHIfa9ee8c2017-02-02 20:00:14 -080039 /**
40 * Default weight based on hop count.
41 * {@value #HOP_WEIGHT_VALUE}
42 */
43 public static final ScalarWeight DEFAULT_HOP_WEIGHT =
44 new ScalarWeight(HOP_WEIGHT_VALUE);
45
46 /**
47 * Default initial weight.
48 * {@value #NULL_WEIGHT_VALUE}
49 */
50 public static final ScalarWeight DEFAULT_INITIAL_WEIGHT =
51 new ScalarWeight(NULL_WEIGHT_VALUE);
52
Andrey Komarov2398d962016-09-26 15:11:23 +030053 @Override
54 public Weight weight(E edge) {
Yuta HIGUCHIfa9ee8c2017-02-02 20:00:14 -080055 return DEFAULT_HOP_WEIGHT;
Andrey Komarov2398d962016-09-26 15:11:23 +030056 }
57
58 @Override
59 public Weight getInitialWeight() {
Yuta HIGUCHIfa9ee8c2017-02-02 20:00:14 -080060 return DEFAULT_INITIAL_WEIGHT;
Andrey Komarov2398d962016-09-26 15:11:23 +030061 }
62
63 @Override
64 public Weight getNonViableWeight() {
65 return ScalarWeight.NON_VIABLE_WEIGHT;
66 }
67}