org.decisiondeck.jmcda.structure.sorting.assignment
Class VersatileAssignments

java.lang.Object
  extended by org.decisiondeck.jmcda.structure.sorting.assignment.VersatileAssignments

public class VersatileAssignments
extends Object

This class implements both the methods from IAssignmentsWithCredibilities and IAssignmentsToMultiple, and thus provides auto conversion between credibilities and ‘‘no credibilities’’. When an alternative is assigned to several categories, with no credibilities specification, it is automatically interpreted as meaning that each category has an associated credibility of one divided by the number of categories to which this alternative has been assigned. It is probably not such a good idea for a user of this class to rely on that automatic conversion capability as it can be difficult to read and maintain, but it is permitted, and this allows for this object to be easily wrapped by objects that implement one of these interfaces specifically. This object may not implement both these interfaces because the related equality relations are incompatible (see definition in these interfaces documentation).

This class does not implement IOrderedAssignmentsWithCredibilities or IOrderedAssignmentsToMultiple, as the ordered case is not compatible with the non-ordered one: the former demands that the order on the categories be specified beforehand. Also this class can't implement IAssignmentsRead as this class authorizes an alternative to be assigned to more than one categories. It is however functionally equivalent if only the setter method appropriate to the single category case is used.


Constructor Summary
VersatileAssignments()
           
VersatileAssignments(IAssignmentsWithCredibilitiesRead assignments)
           
VersatileAssignments(VersatileAssignments copy)
          Copy constructor by value.
 
Method Summary
 boolean clear()
           
 Set<Alternative> getAlternatives()
           
 Set<Alternative> getAlternatives(Category category)
           
 Set<Category> getCategories()
           
 Set<Category> getCategories(Alternative alternative)
           
 Category getCategory(Alternative alternative)
           The alternative must not be assigned to more than one category (otherwise an exception is raised).
 Map<Category,Double> getCredibilities(Alternative alternative)
           
 boolean isCrisp()
           
 Map<Category,Double> remove(Alternative alternative)
           
 boolean setCategories(Alternative alternative, Set<Category> categories)
           Sets, replaces, or removes the assignment of an alternative.
 boolean setCategories(Set<Category> categories)
           Sets the categories this object will return to getCategories(), or removes them and restore the default behavior.
 boolean setCategory(Alternative alternative, Category category)
          Sets, replaces, or removes the assignment of an alternative.
 boolean setCredibilities(Alternative alternative, Map<Category,Double> credibilities)
          Sets, replaces, or removes the assignment of an alternative and the associated degrees of credibility.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersatileAssignments

public VersatileAssignments()

VersatileAssignments

public VersatileAssignments(VersatileAssignments copy)
Copy constructor by value.

Parameters:
copy - not null. The source data to be copied into this object.

VersatileAssignments

public VersatileAssignments(IAssignmentsWithCredibilitiesRead assignments)
Method Detail

setCategories

public boolean setCategories(Set<Category> categories)

Sets the categories this object will return to getCategories(), or removes them and restore the default behavior. The given categories should be a superset of the categories to which objects are and will be assigned, otherwise the contract of getCategories() will not be fulfilled.

When no categories is associated to this object, it returns the set of categories to which at least one alternative has been assigned.

Parameters:
categories - null to remove the associated categories (all the orderings are lost). A superset of the categories already used.
Returns:
true iff the categories changed.

isCrisp

public boolean isCrisp()
Returns:
true iff every assigned alternatives are assigned to exactly one category (thus with a credibility degree of one). Returns false iff at least one alternative is assigned to more than one category.

setCredibilities

public boolean setCredibilities(Alternative alternative,
                                Map<Category,Double> credibilities)
Sets, replaces, or removes the assignment of an alternative and the associated degrees of credibility. A zero value as a degree of credibility is considered as equivalent to a missing entry: it is interpreted as meaning that the given alternative is not assigned to the corresponding category.

Parameters:
alternative - not null.
credibilities - null or empty to assign the alternative to no category, i.e., to remove the assignment of the given alternative. The map entries may not contain a null key or value, the values must be positive or zero. If the map contains only zeroes, it is considered empty.
Returns:
true iff the call changed the assignments, i.e., iff the assignment existed and has been removed, or existed and has changed (be it a change in some credibility degrees or a change of category), or did not exist and has been added.

remove

public Map<Category,Double> remove(Alternative alternative)

setCategories

public boolean setCategories(Alternative alternative,
                             Set<Category> categories)

Sets, replaces, or removes the assignment of an alternative.

When this method is used to add an assignment, evenly shared degrees of credibility are added automatically for compatibility with getCredibilities(Alternative).

Parameters:
alternative - not null.
categories - null or empty to assign the alternative to no category, i.e., to remove the assignment of the given alternative.
Returns:
true iff the call changed the assignments, i.e. true iff the given alternative was assigned and the assignment has been removed, or was assigned to a not identical set of categories, or was not assigned and has been.

getCredibilities

public Map<Category,Double> getCredibilities(Alternative alternative)

getCategories

public Set<Category> getCategories(Alternative alternative)

setCategory

public boolean setCategory(Alternative alternative,
                           Category category)
Sets, replaces, or removes the assignment of an alternative. A credibility value of one is used.

Parameters:
alternative - not null.
category - null to remove the assignment.
Returns:
true iff the call changed the assignments, i.e. true iff the given alternative was assigned and the assignment has been removed, or was assigned to a different category, or was not assigned and has been assigned to a category.

getCategory

public Category getCategory(Alternative alternative)

The alternative must not be assigned to more than one category (otherwise an exception is raised). Note that this object needs this supplementary condition and thus can't implement correctly the interface for the single category case, because it already implements more complex cases, hence there is no guarantee that all alternatives are assigned to no more than one category.

Parameters:
alternative - not null.
Returns:
the category to which this alternative is assigned, or null iff this alternative is not assigned.

getCategories

public Set<Category> getCategories()

getAlternatives

public Set<Alternative> getAlternatives()

getAlternatives

public Set<Alternative> getAlternatives(Category category)

clear

public boolean clear()


Copyright © 2011. All Rights Reserved.