Package com.jgalgo.graph
Interface IWeightFunctionInt
-
- All Superinterfaces:
Comparator<Integer>
,IntComparator
,IWeightFunction
,WeightFunction<Integer>
,WeightFunctionInt<Integer>
- All Known Subinterfaces:
IWeightsByte
,IWeightsInt
,IWeightsShort
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface IWeightFunctionInt extends WeightFunctionInt<Integer>, IWeightFunction
Weight function that maps graph edges or vertices ofIntGraph
to integer weights.This interface is a specific version of
IWeightFunction
forIntGraph
.Some algorithms implementations support only integers weights, or run faster in such a case. This interface is the API for these algorithms for the edges (or vertices) integer weights.
// Create a directed graph with three vertices and edges between them IntGraph g = IntGraph.newDirected(); int v1 = g.addVertex(); int v2 = g.addVertex(); int v3 = g.addVertex(); int e1 = g.addEdge(v1, v2); int e2 = g.addEdge(v2, v3); int e3 = g.addEdge(v1, v3); // Assign some weights to the edges IWeightsInt weights = g.addEdgesWeights("weightsKey", int.class); weights.set(e1, 1); weights.set(e2, 3); weights.set(e3, 15); IWeightFunctionInt weightFunc = weights; // Calculate the shortest paths from v1 to all other vertices ShortestPathSingleSource ssspAlgo = ShortestPathSingleSource.newInstance(); ShortestPathSingleSource.Result ssspRes = ssspAlgo.computeShortestPaths(g, weightFunc, v1); // Print the shortest path from v1 to v3 assert ssspRes.distance(v3) == 4; assert ssspRes.getPath(v3).edges().equals(IntList.of(e1, e2)); System.out.println("Distance from v1 to v3 is: " + ssspRes.distance(v3)); System.out.println("The shortest path from v1 to v3 is:"); for (int e : ssspRes.getPath(v3).edges()) { int u = g.edgeSource(e), v = g.edgeTarget(e); System.out.println(" " + e + "(" + u + ", " + v + ")"); }
- Author:
- Barak Ugav
-
-
Field Summary
-
Fields inherited from interface com.jgalgo.graph.IWeightFunction
CardinalityWeightFunction
-
Fields inherited from interface com.jgalgo.graph.WeightFunction
CardinalityWeightFunction
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default int
compare(int e1, int e2)
Compare two elements by their weights.default int
compare(Integer e1, Integer e2)
Deprecated.Please usecompare(int, int)
instead to avoid un/boxing.default double
weight(int element)
Deprecated.Please useweightInt(int)
instead to avoid un/boxing, and tp avoid the cast toint
.default double
weight(Integer element)
Deprecated.Please useweightInt(int)
instead to avoid un/boxing, and tp avoid the cast toint
.int
weightInt(int element)
Get the integer weight of an element.default int
weightInt(Integer element)
Deprecated.Please useweightInt(int)
instead to avoid un/boxing.default double
weightSum(Iterable<Integer> elements)
Get the sum of the weights of multiple elements.-
Methods inherited from interface java.util.Comparator
equals, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntComparator
reversed, thenComparing, thenComparing
-
-
-
-
Method Detail
-
weightInt
int weightInt(int element)
Get the integer weight of an element.- Parameters:
element
- an element identifier- Returns:
- the integer weight of the element
- Throws:
NoSuchVertexException
- if this weight container holds vertices weights andelement
is not a valid vertex identifier in the graphNoSuchEdgeException
- if this weight container holds edges weights andelement
is not a valid edge identifier in the graph
-
weightInt
@Deprecated default int weightInt(Integer element)
Deprecated.Please useweightInt(int)
instead to avoid un/boxing.Get the integer weight of an element.- Specified by:
weightInt
in interfaceWeightFunctionInt<Integer>
- Parameters:
element
- an element identifier- Returns:
- the weight of the element
-
weight
@Deprecated default double weight(int element)
Deprecated.Please useweightInt(int)
instead to avoid un/boxing, and tp avoid the cast toint
.Get the weight of an element.- Specified by:
weight
in interfaceIWeightFunction
- Parameters:
element
- an element identifier- Returns:
- the weight of the element
-
weight
@Deprecated default double weight(Integer element)
Deprecated.Please useweightInt(int)
instead to avoid un/boxing, and tp avoid the cast toint
.Get the weight of an element.- Specified by:
weight
in interfaceIWeightFunction
- Specified by:
weight
in interfaceWeightFunction<Integer>
- Specified by:
weight
in interfaceWeightFunctionInt<Integer>
- Parameters:
element
- an element identifier- Returns:
- the weight of the element
-
compare
default int compare(int e1, int e2)
Description copied from interface:IWeightFunction
Compare two elements by their weights.- Specified by:
compare
in interfaceIntComparator
- Specified by:
compare
in interfaceIWeightFunction
-
compare
@Deprecated default int compare(Integer e1, Integer e2)
Deprecated.Please usecompare(int, int)
instead to avoid un/boxing.Compare two elements by their weights.- Specified by:
compare
in interfaceComparator<Integer>
- Specified by:
compare
in interfaceIntComparator
- Specified by:
compare
in interfaceIWeightFunction
- Specified by:
compare
in interfaceWeightFunction<Integer>
- Specified by:
compare
in interfaceWeightFunctionInt<Integer>
-
weightSum
default double weightSum(Iterable<Integer> elements)
Description copied from interface:WeightFunction
Get the sum of the weights of multiple elements.- Specified by:
weightSum
in interfaceIWeightFunction
- Specified by:
weightSum
in interfaceWeightFunction<Integer>
- Specified by:
weightSum
in interfaceWeightFunctionInt<Integer>
- Parameters:
elements
- a collection of elements- Returns:
- the sum of the weights of the elements
-
-