CS 226 Homework 6 Written: Due Monday April 2 Programming: Due Friday April 6 Note: The TA asks that you also put your email address on your homework to make it easier to associate people's written and programming work. Written: R-8.5 R-8.10 R-8.16 C-8.10 Programming: An online auction is the method whereby Google or Yahoo decide what ads to place on a WEB page, given the keywords that appear in it. That is, if there are three searches with the keyword "book," then there are three "auctions" of that keyword to a set of bidders. The winning bidder is allowed to place an ad on the search page. Typically, each bidder supplies a set of terms they care about, a total advertising budget, and the amount they are willing to pay for each placement (the "bid"). One of the main issues is to rank order the available bidders based on the amount of the bid, their total budget, and so forth. You are to implement a heap-based system for handling internet bids. For simplicity, we'll assume the following: 1) Each bidder is only interested in a single keyword 2) The keywords for a given page are considered individually. So, for example, even if you are Barnes and Noble and sell books, DVDs and CDs, you have a separate bid in for each one (e.g. having a user searching for a book on DVDs does not change the auction structure). So, to implement this, do the following: 1. Implement the HeapPriorityQueue following the outline of the book (note you can download most of the code from their WEB site just by cutting and pasting from the figures) 2. Create an AuctionEntry (which will be the value stored in the Heap) that consists of: 1. The bidder (a string) 2. The bid topic (string) 3. The budget available (double) 4. The amount the bidder is willing to pay for placement (double) 3. Create an AuctionKey that consists of just the bid and the budget. 4. Derive your own Auction class that extends HeapPriorityQueue in the following ways: a. It is created by supplying a keyword (e.g. "book" or "CD") and a comparator (i.e. an instance of a class that implements Comparator) that operates on AuctionKey. b. It contains a method String keyword() that returns a string that is the keyword associated with this auction. You can use this to determine what an auction bids on. c. It contains a method Entry addBidder(AuctionEntry) that inserts a new key-entry pair representing a bidder into the internal heap. d. It contains a method AuctionEntry doBid() which 1) Finds and removes the lowest (based on the comparator) element of the heap. 2) Decrements the budget of this bidder by the bid amount 3) Re-inserts the bidder into the heap with the following exceptions a) If the budget is empty, it does not re-insert b) If the budget is less than the bid, it sets the bid equal to the available budget. 4) Returns the entry that was removed from the heap (with the original bid price when the entry was removed) or Returns null if the Heap is empty. 5. Implement two comparators: a) A comparator that ranks based purely on the available bid so that the highest bidder appears at the top of the heap. b) A comparator that ranks by computing the product of the bid and the budget so that either a high bid or a high budget gets preference. Demonstrate your program on the following data (which you may hardcode into your main program): Three keywords: books, cars, vacations Two bidders for each: books: Barnes and Noble (bid $1,budget 100) Walmart (bid 20c, budget 1000) cars: Mercedes (bid $100, budget 1000) Ford (bid $10, budget 1000) vacations: (Expedia and Orbitz, both bid $1 and budget 1000) Keep an array of the three auctions (books, cars, vacations) and execute the auction on a file of keywords, one per line. Each line is one execution of the auction for that keyword. The auction data should be in a text file called "auction.txt" (it must be called auction.txt for interoperability of test files) that has a single keyword per line. Print out: The winning entry for each keyword and the bid that was taken The total revenue over all auctions at the end of the file Do this for both comparators separately, one after the other, in the same program. So, for example, if auction.txt contained books books cars vacations Your output would be Barnes and Noble, $1 Barnes and Noble, $1 Mercedes, $100 Expedia, $1 <---- this is indeterminate; could also be Orbitz Total revenue: $103 Walmart, 20c Walmart, 20c Mercedes, $100 Expedia, $1 <---- this is indeterminate; could also be Orbitz Total revenue: $101.40 Extra Credit 1 (5 pts): Set up the program to read the auction data from another file rather than hard-coding it. Call the file auctionconfig.txt with the format keyword bidder bid budget Example: books Barnes&Noble 1.00 100.00 cars Mercedes 200.00 1000.00 Etc... Each line is a bid for the given keyword. Only consider keywords and bidders that do not contain spaces; bids and budgets should be in double format. For extra credit 2 (5 pts): Implement and demonstrate an adaptable auction, where, at any time, the bid and budget can be changed. This would be keyed in the input with two special lines: ** term bidder newbid ## term bidder newbudget e.g. if auction.txt has books card books ** book Barnes&Noble 1 ## book Barnes&Noble 1000 Then the program should update the bid and budget for the Barnes&Noble and reinsert it into the heap to maintain proper ordering.