Package net.sf.tweety.commons.util
Class MapTools<E,F>
- java.lang.Object
-
- net.sf.tweety.commons.util.MapTools<E,F>
-
- Type Parameters:
E
- Domain class of the mapsF
- Range class of the maps
public class MapTools<E,F> extends java.lang.Object
This class provides some utility functions for maps.- Author:
- Matthias Thimm
-
-
Constructor Summary
Constructors Constructor Description MapTools()
-
Method Summary
Modifier and Type Method Description java.util.Set<java.util.Map<E,F>>
allBijections(java.util.Collection<E> domain, java.util.Collection<F> range)
Computes all bijections from E to F.java.util.Set<java.util.Map<E,F>>
allMaps(java.util.Map<java.util.Set<E>,java.util.Set<F>> relations)
Computes the complete set of maps from E to F such that the following condition holds.java.util.Set<java.util.Map<E,F>>
allMaps(java.util.Set<? extends E> domain, java.util.Set<? extends F> range)
This methods computes all maps from domain to range.java.util.Set<java.util.Map<E,F>>
allMapsSingleSource(java.util.Map<E,java.util.Set<F>> relations)
Computes the complete set of maps from E to F such that the following condition holds.java.util.Map<E,F>
combine(java.util.Set<java.util.Map<E,F>> singleMaps)
Combines all maps in singleMaps to one maps containing every assignment of each map in singleMaps.static boolean
isInjective(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)
Checks whether the given map is injective, i.e.
-
-
-
Method Detail
-
allMaps
public java.util.Set<java.util.Map<E,F>> allMaps(java.util.Map<java.util.Set<E>,java.util.Set<F>> relations)
Computes the complete set of maps from E to F such that the following condition holds. For every map "m" in the result the set m.keySet() is equal to the union of all sets S with S in relations.keySet() and each element "e" in m.keySet() is mapped to an element "f" such that "f" in relations.get(S) with "e" in S. For example the map:
{a,b} => {1,2}
{c,d} => {3}
{f} => {4,5}
yields the set of maps:
a=>1, b=>1, c=>3, d=>3, f=>4
a=>1, b=>1, c=>3, d=>3, f=>5
a=>1, b=>2, c=>3, d=>3, f=>4
a=>1, b=>2, c=>3, d=>3, f=>5
a=>2, b=>1, c=>3, d=>3, f=>4
a=>2, b=>1, c=>3, d=>3, f=>5
a=>2, b=>2, c=>3, d=>3, f=>4
a=>2, b=>2, c=>3, d=>3, f=>5- Parameters:
relations
- a map from sets of E to sets of F.- Returns:
- a set of maps from E to F.
-
allMapsSingleSource
public java.util.Set<java.util.Map<E,F>> allMapsSingleSource(java.util.Map<E,java.util.Set<F>> relations)
Computes the complete set of maps from E to F such that the following condition holds. For every map "m" in the result the set m.keySet() is equal to relations.keySet() and each element "e" in m.keySet() is mapped to an element "f" such that "f" in relations.get(S) with "e" in S. For example the map:
a => {1,2}
b => {3}
c => {4,5}
yields the set of maps:
a=>1, b=>3, c=>4
a=>1, b=>3, c=>5
a=>2, b=>3, c=>4
a=>2, b=>3, c=>5- Parameters:
relations
- a map from sets of E to sets of F.- Returns:
- a set of maps from E to F.
-
allBijections
public java.util.Set<java.util.Map<E,F>> allBijections(java.util.Collection<E> domain, java.util.Collection<F> range)
Computes all bijections from E to F. E and F have to be of the same cardinality.- Parameters:
domain
- some set.range
- some set.- Returns:
- all bijections from E to F.
-
allMaps
public java.util.Set<java.util.Map<E,F>> allMaps(java.util.Set<? extends E> domain, java.util.Set<? extends F> range)
This methods computes all maps from domain to range.- Parameters:
domain
- a set of elements.range
- a set of elements- Returns:
- a set of maps, where every map maps any element of domain to an element of range.
-
combine
public java.util.Map<E,F> combine(java.util.Set<java.util.Map<E,F>> singleMaps) throws java.lang.IllegalArgumentException
Combines all maps in singleMaps to one maps containing every assignment of each map in singleMaps.- Parameters:
singleMaps
- the set of maps to be combined.- Returns:
- a single map.
- Throws:
java.lang.IllegalArgumentException
- if one key is used in more than one map of singleMaps.
-
isInjective
public static boolean isInjective(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)
Checks whether the given map is injective, i.e. whether no two different keys are assigned the same value.- Parameters:
map
- a map- Returns:
- "true" iff the given map is injective.
-
-