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) )); } }
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 )); }
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); }
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); }
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 )); }
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); }
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); }
public Agent() { this.Inventory = new Inventory(); this.PriceBeliefs = new PriceBeliefs(); }