From a8eb5eb83fb762630c83a765967313f4ccb59493 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Sat, 12 May 2012 10:55:08 +0200 Subject: Add dmc 2012 official task files --- dmc2012_task/SimpleAgent.java | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 dmc2012_task/SimpleAgent.java (limited to 'dmc2012_task/SimpleAgent.java') diff --git a/dmc2012_task/SimpleAgent.java b/dmc2012_task/SimpleAgent.java new file mode 100644 index 0000000..a33e9c5 --- /dev/null +++ b/dmc2012_task/SimpleAgent.java @@ -0,0 +1,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 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(); + } + + 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 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; + } + +} -- cgit