Class MutableAntiSymmetricPreferenceImpl
- java.lang.Object
-
- io.github.oliviercailloux.j_voting.preferences.classes.MutableAntiSymmetricPreferenceImpl
-
- All Implemented Interfaces:
AntiSymmetricPreference
,MutableAntiSymmetricPreference
,Preference
public class MutableAntiSymmetricPreferenceImpl extends Object implements MutableAntiSymmetricPreference
This structure keeps the mutable graph as in the original. It maintains a transitive closure iffasGraph()
has been called iff it guarantees that the transitive closure of its mutable graph minus its reflective part is acyclic.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MutableAntiSymmetricPreference
about(Voter voter)
boolean
addAlternative(Alternative alternative)
Adds an alternative to the Preference if it does not exist already.boolean
addStrictPreference(Alternative a1, Alternative a2)
Adds an edge from a1 to a2, so that a1 is preferred to a2 (a1 > a2), if the edge does not exist yet.Graph<Alternative>
asGraph()
In the graph : a relation from a to b means "a is at least as good as b".MutableGraph<Alternative>
asMutableGraph()
This graph is not necessarily transitively closed.static MutableAntiSymmetricPreference
empty()
boolean
equals(Object obj)
Set<Alternative>
getAlternatives()
The returned set reads through this object: if this object is mutable, any modification to this object modifies the returned set, and conversely.Voter
getVoter()
static MutableAntiSymmetricPreference
given(Graph<Alternative> graph)
static MutableAntiSymmetricPreference
given(Voter voter, Graph<Alternative> graph)
int
hashCode()
String
toString()
-
-
-
Method Detail
-
empty
public static MutableAntiSymmetricPreference empty()
-
about
public static MutableAntiSymmetricPreference about(Voter voter)
-
given
public static MutableAntiSymmetricPreference given(Graph<Alternative> graph)
-
given
public static MutableAntiSymmetricPreference given(Voter voter, Graph<Alternative> graph)
-
getVoter
public Voter getVoter()
- Specified by:
getVoter
in interfacePreference
- Returns:
Voter
instance of the preference, Returns the voter 0 if no specific voter is associated to this preference
-
getAlternatives
public Set<Alternative> getAlternatives()
Description copied from interface:Preference
The returned set reads through this object: if this object is mutable, any modification to this object modifies the returned set, and conversely.- Specified by:
getAlternatives
in interfacePreference
- Returns:
- alternatives's set
-
addAlternative
public boolean addAlternative(Alternative alternative)
Description copied from interface:MutableAntiSymmetricPreference
Adds an alternative to the Preference if it does not exist already. This alternative is not preferred to any other of the preference, it is being added isolated.- Specified by:
addAlternative
in interfaceMutableAntiSymmetricPreference
-
asGraph
public Graph<Alternative> asGraph()
Description copied from interface:AntiSymmetricPreference
In the graph : a relation from a to b means "a is at least as good as b". This graph can’t be modified, but is not necessarily immutable. Reflexive and transitive. This graph is anti-symmetric.- Specified by:
asGraph
in interfaceAntiSymmetricPreference
- Specified by:
asGraph
in interfacePreference
- Returns:
- the Graph corresponding to the Preference
-
asMutableGraph
public MutableGraph<Alternative> asMutableGraph()
Description copied from interface:MutableAntiSymmetricPreference
This graph is not necessarily transitively closed. This method might refuse that an edge be added that would result in the transitive closure violating anti-symmetry, though it will not necessarily check (but it is guaranteed to check if asGraph() has been called previously). If such a situation happens, and is not detected (thus implying that asGraph() has never been called), an exception will be raised the first time asGraph() will be called, unless possibly the transitive closure no more violates anti-symmetry at that time (behavior is undefined in such a case). This graph is irreflexive and may thus be considered as representing a (possibly partly reduced) strict preference relation. The convention that this graph be reflexive would not work: the method nodes().add() would possibly have to create a reflexive edge, which would be surprising.- Specified by:
asMutableGraph
in interfaceMutableAntiSymmetricPreference
-
addStrictPreference
public boolean addStrictPreference(Alternative a1, Alternative a2)
Description copied from interface:MutableAntiSymmetricPreference
Adds an edge from a1 to a2, so that a1 is preferred to a2 (a1 > a2), if the edge does not exist yet. If one of them is not in the graph, they are added.- Specified by:
addStrictPreference
in interfaceMutableAntiSymmetricPreference
- Parameters:
a1
- preferred alternative to a2a2
- "lower" alternative
-
-