private long GetTotalValue() { long totalValue = 0L; Dictionary <int, Dictionary <string, int> > usedValues = forwardAuction.Bidders.ToDictionary(b => b.Idx, b => new Dictionary <string, int>()); foreach (IProductAuction p in forwardAuction.Products) { foreach (RobotBidder b in forwardAuction.Bidders) { int q = p.Demand(b.Idx); if (q > 0) { RobotDemand demand = b.GetRobotDemand(p.product_key); string valueKey = RobotBidder.ParseValueKey(p.product_key); Dictionary <string, int> usedCount = usedValues[b.Idx]; if (!usedCount.ContainsKey(valueKey)) { usedCount.Add(valueKey, 0); } for (int i = usedCount[valueKey]; i < usedCount[valueKey] + q; ++i) { long v = i < demand.Values.Length ? demand.Values[i] : 0; if (v == 0) { Console.WriteLine("won item with no value"); } long adjVal = (long)Math.Round(b.AdjustedValue(p, demand, v), 0); long adjPrice = (long)Math.Round(b.AdjustedPrice(p), 0); b.AssignItem(new ItemAssignment() { auction_id = auctionModel.id, clock_item_id = p.Model.clock_item_id, pea_category_id = SmrForwardAuction.CategoryToId(p.category), price = p.PostedPrice, value = v, value_discounted = adjVal, price_discounted = adjPrice, profit = (long)Math.Round(b.CalculateLicenseProfit(p, demand, v)) }); totalValue += adjVal; } usedCount[valueKey] += q; } } } return(totalValue); }
public Auction( auction a, Dictionary <string, clock_item> keyToPEA, List <bidder> bidders, IEnumerable <bidder_assigned_strategy> strategies, parameter p, AuctionStatusViewModel auctionVM) { rand = new Random(a.seed); this.keyToPEA = keyToPEA; auctionModel = a; List <AuctionItem> items = CreateAuctionItems(keyToPEA.Values); this.bidders = CreateBidders(bidders, p.activity_requirement, strategies, items); forwardAuction = new SmrForwardAuction(this.bidders.ToArray(), items, p, rand); auctionStatus = new AuctionStatus(); auctionStatusVM = auctionVM; }