summaryrefslogtreecommitdiff
path: root/dmc2012_task/SimpleAgent.java
diff options
context:
space:
mode:
Diffstat (limited to 'dmc2012_task/SimpleAgent.java')
-rw-r--r--dmc2012_task/SimpleAgent.java77
1 files changed, 77 insertions, 0 deletions
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<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;
+ }
+
+}