Package org.jgrapht.alg.vertexcover.util
Class RatioVertex<V>
- 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 int
degree
degree of this vertexint
ID
unique id, used to guarantee that compareTo never returns 0java.util.Map<RatioVertex<V>,java.lang.Integer>
neighbors
Map of neighbors, and a count of the number of edges to this neighborV
v
original vertexdouble
weight
weight of the vertex
-
Constructor Summary
Constructors Constructor Description RatioVertex(int ID, V v, double weight)
Create a new ratio vertex
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNeighbor(RatioVertex<V> v)
Add a neighbor.int
compareTo(RatioVertex<V> other)
boolean
equals(java.lang.Object o)
int
getDegree()
Returns the degree of the vertexdouble
getRatio()
Returns the ratio between the vertex' weight and its degreeint
hashCode()
void
removeNeighbor(RatioVertex<V> v)
Remove a neighbor.java.lang.String
toString()
-
-
-
Field Detail
-
v
public final V v
original vertex
-
weight
public double weight
weight of the vertex
-
ID
public final int ID
unique id, used to guarantee that compareTo never returns 0
-
degree
protected int degree
degree of this vertex
-
neighbors
public final java.util.Map<RatioVertex<V>,java.lang.Integer> neighbors
Map of neighbors, and a count of the number of edges to this neighbor
-
-
Constructor Detail
-
RatioVertex
public RatioVertex(int ID, V v, double weight)
Create a new ratio vertex- Parameters:
ID
- unique idv
- the vertexweight
- the vertex weight
-
-
Method Detail
-
addNeighbor
public void addNeighbor(RatioVertex<V> v)
Add a neighbor.- Parameters:
v
- the neighbor
-
removeNeighbor
public void removeNeighbor(RatioVertex<V> v)
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
public int compareTo(RatioVertex<V> other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<V>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-