summaryrefslogtreecommitdiff
path: root/dmc2012_task/SimpleAgent.java
blob: a33e9c586cb11cf9253f86dd9e0d46f1edf5a65a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Sample implementation of a pricing agent.
 * 
 * Chooses the mean of the the competitor prices of the last period as its own
 * price.
 * 
 */
public class SimpleAgent implements ShopAgentInterface {

    // list to store the prices of the competitors
    List<Double>  allPrices;

    // constants
    static double p_uvp    = 15.0;
    static double p_max    = 1.5 * p_uvp;
    static double p_ek     = 10.0;

    /**
     * Constructor.
     * 
     * Instantiates the price list.
     */
    public SimpleAgent() {
        allPrices = new ArrayList<Double>();
    }

    public double getPrice() throws Exception {
        
        // our price
        double ownPrice;
        
        // calculate the price; if first period choose p_uvp
        if (allPrices.size() == 0) {
            ownPrice = p_uvp;
        } else {
            ownPrice = getMeanPrice();
        }

        // map to p_max or p_min if needed
        if (ownPrice >= p_max)
            ownPrice = p_max - 0.5;
        if (ownPrice <= p_ek)
            ownPrice = 10.5;

        // round the price according to the requirements
        BigDecimal bd = new BigDecimal(ownPrice);
        ownPrice = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        
        return ownPrice;
    }

    public void parseSales(int sales) throws Exception {
    }

    public void parsePrices(List<Double> prices) throws Exception {
        allPrices = prices;
    }

    /**
     * Get the mean price.
     * 
     * @return mean of allPrices
     */
    private double getMeanPrice() {
        double s = 0.0;
        for (int i = 0; i < allPrices.size(); i++) {
            s = s + allPrices.get(i);
        }
        s = s / allPrices.size();
        return s;
    }

}