java.lang.Object
org.jgrapht.alg.vertexcover.util.RatioVertex<V>
- Type Parameters:
V- the graph vertex type
- All Implemented Interfaces:
java.lang.Comparable<RatioVertex<V>>
public class RatioVertex<V> extends java.lang.Object implements java.lang.Comparable<RatioVertex<V>>
Helper class for vertex covers. Guarantees that vertices can be sorted, thereby obtaining a
unique ordering.
- Author:
- Joris Kinable
-
Field Summary
Fields Modifier and Type Field Description protected intdegreedegree of this vertexintIDunique id, used to guarantee that compareTo never returns 0java.util.Map<RatioVertex<V>,java.lang.Integer>neighborsMap of neighbors, and a count of the number of edges to this neighborVvoriginal vertexdoubleweightweight of the vertex -
Constructor Summary
Constructors Constructor Description RatioVertex(int ID, V v, double weight)Create a new ratio vertex -
Method Summary
Modifier and Type Method Description voidaddNeighbor(RatioVertex<V> v)Add a neighbor.intcompareTo(RatioVertex<V> other)booleanequals(java.lang.Object o)intgetDegree()Returns the degree of the vertexdoublegetRatio()Returns the ratio between the vertex' weight and its degreeinthashCode()voidremoveNeighbor(RatioVertex<V> v)Remove a neighbor.java.lang.StringtoString()
-
Field Details
-
Constructor Details
-
RatioVertex
Create a new ratio vertex- Parameters:
ID- unique idv- the vertexweight- the vertex weight
-
-
Method Details
-
addNeighbor
Add a neighbor.- Parameters:
v- the neighbor
-
removeNeighbor
Remove a neighbor.- Parameters:
v- the neighbor to remove
-
getDegree
public int getDegree()Returns the degree of the vertex- Returns:
- degree of the vertex
-
getRatio
public double getRatio()Returns the ratio between the vertex' weight and its degree- Returns:
- the ratio between the vertex' weight and its degree
-
compareTo
- Specified by:
compareToin interfacejava.lang.Comparable<V>
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-