java.lang.Cloneable
public class PreferenceGraph
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Field | Description |
---|---|---|
static int |
AT_LEAST_RELATIONS |
Possible value of
consideredRelations parameter,
used when only relations "at least" are considered |
static int |
AT_MOST_RELATIONS |
Possible value of
consideredRelations parameter,
used when only relations "at most" are considered |
boolean |
incrementIndex |
Tells if vertices are numbered starting from zero (
incrementIndex == false )
or from one (incrementIndex == true ) when this preference graph is printed to a string
or to a disk file. |
Constructor | Description |
---|---|
PreferenceGraph(int numberOfObjects,
boolean useAtLeastRelations,
boolean useAtMostRelations) |
Constructor for
PreferenceGraph class. |
Modifier and Type | Method | Description |
---|---|---|
int |
addVertex() |
Adds new vertex to this preference graph and returns its index.
|
void |
calculateTransitiveClosure() |
Calculates transitive closure of this preference graph
by independent calculation of transitive closure for each relation "at least" and "at most".
If for some pair of vertices, satisfaction degree of some considered relation "at least" or "at most" is lower than 1.0, then it is assumed that relation is satisfied when satisfaction degree is >= 0.5, and relation is not satisfied, when satisfaction degree is < 0.5. Thus, this method makes each relation "at least" and "at most" discrete (i.e., with only two possible satisfaction degrees: 1.0 and 0.0 <lack of relation>). Does not modify satisfaction degrees for pairs of vertices of type (x,x). |
java.lang.Object |
clone() |
Clones this preference graph
|
boolean |
containsObject(int objectIndex) |
Checks whether this preference graph contains object with given index
|
boolean |
containsVertex(int vertexIndex) |
Checks whether this preference graph contains vertex with given index
|
java.util.HashSet<Field> |
getAtLeastRelationReferenceValues() |
Gets set of all reference values of "at least" relations present in this preference graph
|
double |
getAtLeastRelationSatisfactionDegree(int vertexIndex1,
int vertexIndex2,
Field referenceValue) |
Gets satisfaction degree for "at least" relation with given reference value and pair of vertices with given indices
|
java.util.Hashtable<Field,java.lang.Double> |
getAtLeastRelationSatisfactionDegrees(int vertexIndex1,
int vertexIndex2) |
Gets hash table with keys corresponding to reference values of relations "at least",
and values corresponding to satisfaction degrees of these relations,
for ordered pair of vertices with given indices
|
java.util.HashSet<Field> |
getAtMostRelationReferenceValues() |
Gets set of all reference values of "at most" relations present in this preference graph
|
double |
getAtMostRelationSatisfactionDegree(int vertexIndex1,
int vertexIndex2,
Field referenceValue) |
Gets satisfaction degree for "at most" relation with given reference value and pair of vertices with given indices
|
java.util.Hashtable<Field,java.lang.Double> |
getAtMostRelationSatisfactionDegrees(int vertexIndex1,
int vertexIndex2) |
Gets hash table with keys corresponding to reference values of relations "at most",
and values corresponding to satisfaction degrees of these relations,
for ordered pair of vertices with given indices
|
int |
getCardinalityOfRelation(Field referenceValue,
int consideredRelations) |
Gets cardinality of relation "at least" / "at most" with given reference value, i.e., the number of arcs
in this preference graph that reflect considered relation "at least" / "at most"
|
java.util.ArrayList<java.lang.Integer> |
getCycleAtLeast(Field referenceValue) |
Checks if this graph contains a cycle for relation "at least" with given reference value,
and if so, then returns just one cycle from possibly many cycles.
|
java.util.ArrayList<java.lang.Integer> |
getCycleAtMost(Field referenceValue) |
Checks if this graph contains a cycle for relation "at most" with given reference value,
and if so, then returns just one cycle from possibly many cycles.
|
int |
getMaxVertexIndex() |
Gets theoretical maximal vertex index in this preference graph.
SIC! |
int |
getNumberOfObjects() |
Gets number of objects in this preference graph.
SIC! |
int |
getNumberOfVertices() |
Gets number of vertices in this preference graph.
|
java.util.HashSet<java.lang.Integer> |
getObjectsIndices() |
Gets set of all indices of objects that are present in this preference graph.
SIC! |
java.util.Hashtable<java.lang.Integer,java.lang.Integer> |
getRanks(Field referenceValue,
int consideredRelations) |
Gets hash table mapping indices of vertices to ranks of these vertices,
for "at least" / "at most" relation with given reference value.
|
int |
getSumOfCardinalitiesOfRelations(int consideredRelations) |
Gets sum of cardinalities of all "at least" / "at most" relations present in this preference graph
|
java.util.HashSet<java.lang.Integer> |
getVertexComponentObjects(int vertexIndex) |
Gets set of indices of all objects that are contained in the vertex with given index.
|
int |
getVertexIndex(int objectIndex) |
Gets index of a vertex that contains object with given index.
|
java.util.ArrayList<java.lang.Integer> |
getVerticesIndices() |
Gets ascendingly ordered list of all indices of vertices that are present in this preference graph
|
boolean |
isAcyclic(Field referenceValue,
int consideredRelations) |
Checks if relation at least/at most with given reference value is acyclic.
|
boolean |
isComplete(Field referenceValue,
int consideredRelations) |
Checks if relation at least/at most with given reference value is complete.
|
boolean |
isCycle(java.util.ArrayList<java.lang.Integer> listOfVertexIndices,
Field referenceValue,
int consideredRelations) |
Checks whether given list of vertex indices corresponds to a cycle for relation "at least" / "at most" with given reference value.
|
boolean |
isTransitive(Field referenceValue,
int consideredRelations) |
Checks if relation at least/at most with given reference value is transitive.
If for some pair of vertices, satisfaction degree of considered relation is lower than 1.0, then it is assumed that this relation holds when satisfaction degree is >= 0.5, and relation does not hold, when satisfaction degree is < 0.5. Does not take into account self-loops, i.e., pairs of vertices of type (x,x). |
boolean |
isUseAtLeastRelations() |
Tells if this preference graph can contain relations "at least"
|
boolean |
isUseAtMostRelations() |
Tells if this preference graph can contain relations "at most"
|
void |
readPreferenceGraph(java.lang.String filePath) |
Reads preference graph from file with given path
|
void |
removeAllCycles() |
Removes all cycles in this preference graph by replacing each cycle with a single vertex,
inheriting from component objects their input and output arcs.
If there are two or more input (or output) arcs to (from) a cycle and that arcs start (end) in the same vertex from outside the cycle, then in the resulting graph there will be only one input (output) arc to (from) a compound vertex that replaces the cycle, with satisfaction degree equal to maximum satisfaction degree over the set of corresponding input (output) satisfaction degrees. Works only if this preference graph is defined using only one binary relation "at least" or "at most". If for some pair of objects, satisfaction degree of considered relation "at least" or "at most" is lower than 1.0, then it is assumed that relation holds when satisfaction degree is >= 0.5, and relation does not hold, when satisfaction degree is < 0.5. |
void |
removeArc(int vertexIndex1,
int vertexIndex2,
Field referenceValue,
int consideredRelations) |
Removes from this preference graph an arc between vertices with given indices,
for "at least" / "at most" relation with given reference value,
if such an arc is present in this graph.
|
void |
removeArcs(int vertexIndex1,
int vertexIndex2,
int consideredRelations) |
Removes from this preference graph all "at least" / "at most" arcs between vertices with given indices.
|
void |
removeVertex(int vertexIndex) |
Removes from this preference graph vertex with given index (and thus, removes also all objects contained in that vertex).
|
void |
restrictToAsymmetricalRelations() |
Restricts each relation "at least" and "at most" to its asymmetrical part only.
|
void |
revertArcs(Field referenceValue,
int consideredRelations) |
Reverts all arcs corresponding to relation "at least" or "at most" with given reference value.
For example, if pair (x,y) belongs to relation "at most -1.0" and consideredRelations == AT_MOST_RELATIONS ,
then pair (y,x) is added to relation "at least 1.0" and pair (x,y) is deleted from relation "at most -1.0". |
void |
revertScArcs() |
Reverts all arcs corresponding to relation (at most) Sc.
|
void |
setAtLeastRelationSatisfactionDegree(int vertexIndex1,
int vertexIndex2,
Field referenceValue,
double satisfactionDegree) |
Sets satisfaction degree for "at least" relation with given reference value and pair of vertices with given indices
|
void |
setAtLeastRelationSatisfactionDegrees(int vertexIndex1,
int vertexIndex2,
java.util.Hashtable<Field,java.lang.Double> atLeastRelationSatisfactionDegrees) |
Sets hash table with keys corresponding to reference values of relations "at least",
and values corresponding to satisfaction degrees of these relations,
for ordered pair of vertices with given indices.
SIC! |
void |
setAtMostRelationSatisfactionDegree(int vertexIndex1,
int vertexIndex2,
Field referenceValue,
double satisfactionDegree) |
Sets satisfaction degree for "at most" relation with given reference value and pair of vertices with given indices
|
void |
setAtMostRelationSatisfactionDegrees(int vertexIndex1,
int vertexIndex2,
java.util.Hashtable<Field,java.lang.Double> atMostRelationSatisfactionDegrees) |
Sets hash table with keys corresponding to reference values of relations "at most",
and values corresponding to satisfaction degrees of these relations,
for ordered pair of vertices with given indices.
SIC! |
java.lang.String |
toDOTString() |
Gets string representation of this preference graph in DOT format.
|
java.lang.String |
toString() |
Gets multiline string representation of this preference graph.
|
void |
writeDOTPreferenceGraph(java.lang.String filePath) |
Writes this preference graph to DOT-format file with given path.
|
void |
writePreferenceGraph(java.lang.String filePath) |
Writes this preference graph to file with given path.
|
public boolean incrementIndex
incrementIndex == false
)
or from one (incrementIndex == true
) when this preference graph is printed to a string
or to a disk file.public static int AT_LEAST_RELATIONS
consideredRelations
parameter,
used when only relations "at least" are consideredpublic static int AT_MOST_RELATIONS
consideredRelations
parameter,
used when only relations "at most" are consideredpublic PreferenceGraph(int numberOfObjects, boolean useAtLeastRelations, boolean useAtMostRelations)
PreferenceGraph
class.
Constructs preference graph with numberOfObjects
vertices and initially no arcs.numberOfObjects
- number of objects in this preference graphuseAtLeastRelations
- tells if this preference graph can contain relations "at least"useAtMostRelations
- tells if this preference graph can contain relations "at most"InvalidValueException
- when given number of objects is not greater than zero
or when both useAtLeastRelations
and useAtMostRelations
is false
public java.util.Hashtable<Field,java.lang.Double> getAtLeastRelationSatisfactionDegrees(int vertexIndex1, int vertexIndex2)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexnull
if there is no relation "at least" for the considered pair of verticesInvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
ValueNotFoundException
- when this preference graph can not contain any relation "at least"public java.util.Hashtable<Field,java.lang.Double> getAtMostRelationSatisfactionDegrees(int vertexIndex1, int vertexIndex2)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexnull
if there is no relation "at most" for the considered pair of verticesInvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
ValueNotFoundException
- when this preference graph can not contain any relation "at most"public void setAtLeastRelationSatisfactionDegrees(int vertexIndex1, int vertexIndex2, java.util.Hashtable<Field,java.lang.Double> atLeastRelationSatisfactionDegrees)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexatLeastRelationSatisfactionDegrees
- hash table mapping reference values of "at least" relations
to their satisfaction degrees, for ordered pair of vertices with given indices;
if null
, then considered pair of vertices is removed from all relations "at least"InvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
,
when hash table with satisfaction degrees is not null
, but empty
or when hash table with satisfaction degrees is not null
,
but some satisfaction degree is not in interval (0,1]ValueNotFoundException
- when this preference graph can not contain any relation "at least"public void setAtMostRelationSatisfactionDegrees(int vertexIndex1, int vertexIndex2, java.util.Hashtable<Field,java.lang.Double> atMostRelationSatisfactionDegrees)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexatMostRelationSatisfactionDegrees
- hash table mapping reference values of "at most" relations
to their satisfaction degrees, for ordered pair of vertices with given indices;
if null
, then considered pair of vertices is removed from all relations "at most"InvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
,
when hash table with satisfaction degrees is not null
, but empty
or when hash table with satisfaction degrees is not null
,
but some satisfaction degree is not in interval (0,1]ValueNotFoundException
- when this preference graph can not contain any relation "at most"public double getAtLeastRelationSatisfactionDegree(int vertexIndex1, int vertexIndex2, Field referenceValue)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexreferenceValue
- reference value of relation "at least"InvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
ValueNotFoundException
- when this preference graph can not contain any relation "at least"public double getAtMostRelationSatisfactionDegree(int vertexIndex1, int vertexIndex2, Field referenceValue)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexreferenceValue
- reference value of relation "at most"InvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
ValueNotFoundException
- when this preference graph can not contain any relation "at most"public void setAtLeastRelationSatisfactionDegree(int vertexIndex1, int vertexIndex2, Field referenceValue, double satisfactionDegree)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexreferenceValue
- reference value of relation "at least"satisfactionDegree
- satisfaction degree for "at least" relation, from interval [0,1];
value 0.0 means that considered pair of vertices should be removed from relation
with given reference valueInvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
or when satisfaction degree is greater than oneValueNotFoundException
- when this preference graph can not contain any relation "at least"public void setAtMostRelationSatisfactionDegree(int vertexIndex1, int vertexIndex2, Field referenceValue, double satisfactionDegree)
vertexIndex1
- index of the first vertexvertexIndex2
- index of the second vertexreferenceValue
- reference value of relation "at most"satisfactionDegree
- satisfaction degree for "at most" relation, from interval [0,1];
value 0.0 means that considered pair of vertices should be removed from relation
with given reference valueInvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
or when satisfaction degree is greater than oneValueNotFoundException
- when this preference graph can not contain any relation "at most"public int getNumberOfObjects()
public int getNumberOfVertices()
public boolean isUseAtLeastRelations()
true
if this preference graph can contain relations "at least",
false
otherwisepublic boolean isUseAtMostRelations()
true
if this preference graph can contain relations "at most",
false
otherwisepublic java.util.HashSet<Field> getAtLeastRelationReferenceValues()
null
if relations "at least" are not usedpublic java.util.HashSet<Field> getAtMostRelationReferenceValues()
null
if relations "at most" are not usedpublic int getCardinalityOfRelation(Field referenceValue, int consideredRelations)
referenceValue
- reference value of relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
InvalidValueException
- when consideredRelations
is neither
AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
public int getSumOfCardinalitiesOfRelations(int consideredRelations)
consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
InvalidValueException
- when consideredRelations
is neither
AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
public void removeAllCycles()
InvalidValueException
- when preference graph does not contain exactly one binary relation at least or at mostpublic void calculateTransitiveClosure()
public void restrictToAsymmetricalRelations()
public boolean isCycle(java.util.ArrayList<java.lang.Integer> listOfVertexIndices, Field referenceValue, int consideredRelations)
listOfVertexIndices
- list of vertices to be verified if it is a path of vertex indices from a cycle of this preference graphreferenceValue
- reference value of considered relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
true
if given list is a path of vertex indices from a cycle of this preference graph,
false
otherwiseInvalidValueException
- when considered relations are none of AT_LEAST_RELATIONS
and AT_MOST_RELATIONS
,
when considered relations are AT_LEAST_RELATIONS
but this preference graph cannot contain relations "at least",
or when considered relations are AT_MOST_RELATIONS
but this preference graph cannot contain relations "at most",public java.util.ArrayList<java.lang.Integer> getCycleAtLeast(Field referenceValue)
referenceValue
- reference value of considered relation "at least"null
if there is no cycleValueNotFoundException
- when this preference graph can not contain any relation "at least"InvalidValueException
- when this preference graph contains no relation "at least" with given reference valuepublic java.util.ArrayList<java.lang.Integer> getCycleAtMost(Field referenceValue)
referenceValue
- reference value of considered relation "at most"null
if there is no cycleValueNotFoundException
- when this preference graph can not contain any relation "at most"InvalidValueException
- when this preference graph contains no relation "at most" with given reference valuepublic java.util.Hashtable<java.lang.Integer,java.lang.Integer> getRanks(Field referenceValue, int consideredRelations)
referenceValue
- reference value of relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
InvalidValueException
- when consideredRelations
is neither AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
ValueNotFoundException
- when consideredRelations == AT_LEAST_RELATIONS
and
this preference graph can not contain any relation "at least"
or when consideredRelations == AT_MOST_RELATIONS
and
this preference graph can not contain any relation "at most"public java.util.HashSet<java.lang.Integer> getVertexComponentObjects(int vertexIndex)
vertexIndex
- index of the vertex in this preference graphInvalidValueException
- when this preference graph does not contain a vertex with index vertexIndex
public int getVertexIndex(int objectIndex)
objectIndex
- index of an object for which index of encompassing vertex should be retrievedInvalidValueException
- when given object index is incorrectpublic boolean containsVertex(int vertexIndex)
vertexIndex
- vertex index to checktrue
if this preference graph contains vertex with given index,
false
otherwisepublic boolean containsObject(int objectIndex)
objectIndex
- object index to checktrue
if this preference graph contains object with given index,
false
otherwisepublic int getMaxVertexIndex()
public int addVertex()
public void removeArc(int vertexIndex1, int vertexIndex2, Field referenceValue, int consideredRelations)
vertexIndex1
- index of the vertex where the arc startsvertexIndex2
- index of the vertex where the arc endsreferenceValue
- reference value of considered relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
InvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
or when consideredRelations
are neither AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
ValueNotFoundException
- when consideredRelations == AT_LEAST_RELATIONS
and
this preference graph can not contain any relation "at least"
or when consideredRelations == AT_MOST_RELATIONS
and
this preference graph can not contain any relation "at most"public void removeArcs(int vertexIndex1, int vertexIndex2, int consideredRelations)
vertexIndex1
- index of the vertex where the arcs startvertexIndex2
- index of the vertex where the arcs endconsideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
InvalidValueException
- when this preference graph does not contain the vertex
with index vertexIndex1
or vertexIndex2
or when consideredRelations
are neither AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
ValueNotFoundException
- when consideredRelations == AT_LEAST_RELATIONS
and
this preference graph can not contain any relation "at least"
or when consideredRelations == AT_MOST_RELATIONS
and
this preference graph can not contain any relation "at most"public void removeVertex(int vertexIndex)
vertexIndex
- index of the vertex that should be removed from this preference graphInvalidValueException
- when this preference graph does not contain a vertex with index vertexIndex
public void revertScArcs()
ValueNotFoundException
- when this preference graph cannot contain relations S or Scpublic void revertArcs(Field referenceValue, int consideredRelations)
consideredRelations == AT_MOST_RELATIONS
,
then pair (y,x) is added to relation "at least 1.0" and pair (x,y) is deleted from relation "at most -1.0".
Moreover, if before reversal pair (y,x) is already in relation "at least 1.0",
then satisfaction degree of the corresponding arc is taken to be the maximum of two satisfaction degrees.referenceValue
- reference value of considered relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
InvalidValueException
- when consideredRelations
are neither AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
ValueNotFoundException
- when this preference graph cannot simultaneously contain relations at least and at mostInvalidTypeException
- when given reference value has type different than FloatField
public java.util.ArrayList<java.lang.Integer> getVerticesIndices()
public java.util.HashSet<java.lang.Integer> getObjectsIndices()
public boolean isAcyclic(Field referenceValue, int consideredRelations)
getCycle(Field, int)
method.referenceValue
- reference value of considered relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
true
if relation at least/at most with given reference value is acyclic, false
otherwiseInvalidValueException
- when consideredRelations
are neither AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
public boolean isComplete(Field referenceValue, int consideredRelations)
referenceValue
- reference value of considered relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
true
if relation at least/at most with given reference value is complete, false
otherwiseInvalidValueException
- when consideredRelations
are neither AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
public boolean isTransitive(Field referenceValue, int consideredRelations)
referenceValue
- reference value of considered relation "at least" / "at most"consideredRelations
- must be either AT_LEAST_RELATIONS
or AT_MOST_RELATIONS
true
if relation at least/at most with given reference value is transitive, false
otherwiseInvalidValueException
- when consideredRelations
are neither AT_LEAST_RELATIONS
nor AT_MOST_RELATIONS
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toDOTString()
public void writePreferenceGraph(java.lang.String filePath) throws java.io.IOException
filePath
- path to the file where this preference graph should be savedjava.io.IOException
- when file with given path can't be opened for writepublic void writeDOTPreferenceGraph(java.lang.String filePath) throws java.io.IOException
filePath
- path to the DOT-format file where this preference graph should be savedjava.io.IOException
- when file with given path can't be opened for writepublic void readPreferenceGraph(java.lang.String filePath) throws java.io.IOException
filePath
- path to file with preference graphjava.io.IOException
- when file with given path can't be opened for read