Java Reference
In-Depth Information
while (it.hasNext())
buffer.append(it.next()).append("\n");
return buffer.toString();
}
}
Interface Preference defines the operations offered to the negotiators by the
instances of class PreferenceMap . Method attribute() returns the detail of the
preference for an attribute. The evaluate() method evaluates a proposal or a
single attribute. Method rank() returns the rank of an attribute value. The
ensureAdmissible() method modifies an attribute or a proposal so that is
admissible. The decrease() method decreases the value of an attribute of a
proposal.
package Negotiation;
import java.util.*;
public interface Preference {
public AttributeMap attribute(String name);
public double evaluate(Proposal proposal);
public double evaluate(Attribute attribute);
public double rank(Attribute attribute);
public double rank(String name, Value value);
public Proposal bestProposal();
public void ensureAdmissible(Proposal attribute);
public void ensureAdmissible(Attribute proposal);
public Proposal decrease(Attribute attribute,
Proposal proposal);
}
Class PreferenceMap represents the user preferences. It implements the
collection of the attributes as a Map , where the attributes are inserted with
their names as key. The constructor is based on the Specification of the
problem. The methods setWeight() and add() are used to define the
preferences in terms of attribute weight and value rank.
The other methods implement the Preference interface. The ensure
Admissible() method checks if an attribute (or all the attributes of a proposal)
has an admissible value, i.e. that its value is included in the collection of
admissible values for that attribute; in case it is not admissible it replaces the
value by an admissible value with the closest ranking.
package Negotiation;
public class PreferenceMap implements Preference {
Map attributes # new Hashtable();
// build a preference map from the service specification
public PreferenceMap(Specification spec){
Iterator it # spec.attributes.values().iterator();
while (it.hasNext()){
AttributeSpec attrSpec # (AttributeSpec)it.next();
// the weight of every attribute is initialized to 0
Search WWH ::




Custom Search