Ejemplo n.º 1
0
        public IEnumerable <Offer> GenerateOffers(Inventory inventory, PriceBeliefs priceBeliefs, double totalDemand)
        {
            var demand = this.GetDemand(priceBeliefs, totalDemand);

            foreach (var pair in demand)
            {
                var(commodity, amount) = (pair.Key, pair.Value);
                var current = inventory.Get(commodity);

                yield return(new Offer(
                                 OfferType.Buy,
                                 commodity,
                                 priceBeliefs.GetRandom(commodity),
                                 Math.Max(0, amount - current)
                                 ));
            }
        }
Ejemplo n.º 2
0
        public Dictionary <string, double> GetDemand(PriceBeliefs priceBeliefs, double totalDemand)
        {
            var list = this.GetFavorabilities(priceBeliefs)
                       .Select(pair => new
            {
                Commodity = pair.Key,
                Demand    = (this.threshold < pair.Value) ? pair.Value : 0
            })
                       .ToList();

            var ratio = 1 / list.Sum(x => x.Demand);

            return(list.ToDictionary(
                       x => x.Commodity,
                       x => ratio * x.Demand
                       ));
        }
Ejemplo n.º 3
0
        public void SCSP_Splits_Price()
        {
            var priceBeliefs = new PriceBeliefs();

            priceBeliefs.Set(ALPHA, 1, 2);
            priceBeliefs.Set(BRAVO, 1, 1);

            var costBeliefs = new CostBeliefs(priceBeliefs);

            costBeliefs.Begin();
            costBeliefs.Consume(ALPHA, 10);
            costBeliefs.Produce(BRAVO, 4);
            var result = costBeliefs.End().ToDictionary(x => x.Commodity);

            Assert.AreEqual(2.5, result[BRAVO].MinPrice);
            Assert.AreEqual(5, result[BRAVO].MaxPrice);
        }
Ejemplo n.º 4
0
        public void MCSP_Splits_Price()
        {
            var priceBeliefs = new PriceBeliefs();

            priceBeliefs.Set(ALPHA, 1, 2);
            priceBeliefs.Set(BRAVO, 2, 3);
            priceBeliefs.Set(CHARLIE, 1, 1);

            var costBeliefs = new CostBeliefs(priceBeliefs);

            costBeliefs.Begin();
            costBeliefs.Consume(ALPHA, 10);
            costBeliefs.Consume(BRAVO, 20);
            costBeliefs.Produce(CHARLIE, 5);
            var result = costBeliefs.End().ToDictionary(x => x.Commodity);

            Assert.AreEqual(10, result[CHARLIE].MinPrice);
            Assert.AreEqual(16, result[CHARLIE].MaxPrice);
        }
Ejemplo n.º 5
0
        private Dictionary <string, double> GetFavorabilities(PriceBeliefs priceBeliefs)
        {
            var list = this.weights
                       .Select(pair =>
            {
                var(commodity, weight) = (pair.Key, pair.Value);
                var price = priceBeliefs.Get(commodity).Item2;
                return(new
                {
                    Commodity = commodity,
                    Value = weight / price
                });
            })
                       .ToList();

            var totalValue = list.Sum(x => x.Value);

            return(list.ToDictionary(
                       x => x.Commodity,
                       x => x.Value / totalValue
                       ));
        }
Ejemplo n.º 6
0
        public void SCMP_Simple()
        {
            var priceBeliefs = new PriceBeliefs();

            priceBeliefs.Set(ALPHA, 1, 2);
            priceBeliefs.Set(BRAVO, 1, 1);
            priceBeliefs.Set(CHARLIE, 1, 1);

            var costBeliefs = new CostBeliefs(priceBeliefs);

            costBeliefs.Begin();
            costBeliefs.Consume(ALPHA, 10);
            costBeliefs.Produce(BRAVO, 2);
            costBeliefs.Produce(CHARLIE, 3);
            var result = costBeliefs.End().ToDictionary(x => x.Commodity);

            Assert.AreEqual(2, result[BRAVO].MinPrice);
            Assert.AreEqual(4, result[BRAVO].MaxPrice);

            Assert.AreEqual(2, result[CHARLIE].MinPrice);
            Assert.AreEqual(4, result[CHARLIE].MaxPrice);
        }
Ejemplo n.º 7
0
        public void SCMP_Uses_PriceBeliefs_To_Balance_Price()
        {
            var priceBeliefs = new PriceBeliefs();

            priceBeliefs.Set(ALPHA, 1, 4);
            priceBeliefs.Set(BRAVO, 1, 6);
            priceBeliefs.Set(CHARLIE, 2, 4);

            var costBeliefs = new CostBeliefs(priceBeliefs);

            costBeliefs.Begin();
            costBeliefs.Consume(ALPHA, 8);
            costBeliefs.Produce(BRAVO, 2);
            costBeliefs.Produce(CHARLIE, 3);
            var result = costBeliefs.End().ToDictionary(x => x.Commodity);

            Assert.AreEqual(1, result[BRAVO].MinPrice);
            Assert.AreEqual(8, result[BRAVO].MaxPrice);

            Assert.AreEqual(2, result[CHARLIE].MinPrice);
            Assert.AreEqual(5.33, result[CHARLIE].MaxPrice, 0.01);
        }
Ejemplo n.º 8
0
 public Agent()
 {
     this.Inventory    = new Inventory();
     this.PriceBeliefs = new PriceBeliefs();
 }