source: src/main/java/agents/similarity/Similarity.java@ 346

Last change on this file since 346 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.7 KB
Line 
1package agents.similarity;
2
3import java.util.ArrayList;
4
5import genius.core.Bid;
6import genius.core.Domain;
7import genius.core.xml.SimpleElement;
8
9public class Similarity {
10 private Domain fDomain;
11 private double fWeights[];
12 private ArrayList<SimilarityFunction> fSimilarityFunctions;
13
14 public Similarity(Domain pDomain) {
15 fDomain = pDomain;
16 fSimilarityFunctions = new ArrayList<SimilarityFunction>();
17 }
18
19 public final double getSimilarity(Bid pMyBid, Bid pOpponentBid) {
20 double lSimilarity = 0;
21 for (int i = 0; i < fSimilarityFunctions.size(); i++) {
22 lSimilarity += fWeights[i]
23 * fSimilarityFunctions.get(i).getSimilarityValue(pMyBid,
24 pOpponentBid);
25 }
26
27 return lSimilarity;
28 }
29
30 public void loadFromXML(SimpleElement pRoot) {
31 SimpleElement lXMLUtilitySpace = (SimpleElement) (pRoot
32 .getChildByTagName("utility_space")[0]);
33 SimpleElement lXMLObjective = (SimpleElement) (lXMLUtilitySpace
34 .getChildByTagName("objective")[0]);
35 Object[] lXMLIssue = lXMLObjective.getChildByTagName("issue");
36 fWeights = new double[lXMLIssue.length];
37 for (int j = 0; j < lXMLIssue.length; j++) {
38 Object[] lXMLSimFn = ((SimpleElement) (lXMLIssue[j]))
39 .getChildByTagName("similarity_function");
40 if (lXMLSimFn == null || lXMLSimFn.length == 0) {
41 continue;
42 }
43 SimilarityFunction lSimFn = new SimilarityFunction(fDomain);
44 // load weights
45 fWeights[j] = Double.valueOf(((SimpleElement) (lXMLSimFn[0]))
46 .getAttribute("weight"));
47 lSimFn.loadFromXML((SimpleElement) (lXMLSimFn[0]), Integer
48 .valueOf(((SimpleElement) (lXMLIssue[j]))
49 .getAttribute("index")));
50 fSimilarityFunctions.add(lSimFn);
51 }// for
52 }
53}
Note: See TracBrowser for help on using the repository browser.