Java Reference
In-Depth Information
pref.add(attribute.getName(),values[j],rankValue);
}
}
// the weight of each attribute is proportional to the
// variance of the availability of the values of each
// attribute i.e. higher weight to attributes that have
// scarcely available values
it_attr
#
specification.attributes().iterator();
for
(
int
i
#
0; it_attr.hasNext();
!!
i)
{ // for each attribute
AttributeSpec attribute
#
(AttributeSpec)it_attr.next();
pref.setWeight(attribute.getName(),sigma[i]/sumSigma);
}
return
pref;
}
// evaluates the validity of a proposal
public boolean
valid(Proposal proposal){
if
(proposal
##
null
)
return false
;
Map coordinates
#
new
Hashtable();
Iterator it
#
proposal.getAttributes().iterator();
while
(it.hasNext()){
Attribute attribute
#
(Attribute)it.next();
coordinates.put(attribute.getName(),
attribute.getValue());
}
return
valid(coordinates);
}
public boolean
valid(Map coordinates){
Iterator it
#
resources.iterator();
while
(it.hasNext()){
Resource resource
#
(Resource)it.next();
if
(resource.match(coordinates)
&& resource.available>0)
return true
;
}
return false
;
}
// return the number of available resources
private int
sumAvailable(){
Iterator it
#
resources.iterator();
int
sum
#
0;
while
(it.hasNext()){
Resource resource
#
(Resource)it.next();
sum
!#
resource.available;
}
return
sum;
}