//TODO: convert all lists to arrays by index to improve performance public void CleanUp() { sender.CleanUp(); sender = null; canidateBid = null; canidateTile = null; kb = null; foreach (SearchTile s in openTiles) { s.CleanUp(); } openTiles.Clear(); openTiles = null; foreach (SearchTile s in tilesInAuction) { s.CleanUp(); } tilesInAuction.Clear(); tilesInAuction = null; foreach (SearchTile s in claimedTiles) { s.CleanUp(); } claimedTiles.Clear(); claimedTiles = null; foreach (SearchTile s in searchedTiles) { s.CleanUp(); } searchedTiles.Clear(); searchedTiles = null; }
private void ProcessBid(Packet p) { BidMessage bidMsg = (BidMessage)p.message; // Debug.Log ("Processing bid for Agent " + p.src.ID + " on tile " + bidMsg.tileId + " with amount " + bidMsg.bidAmount); /* Determine if the agent should bid for a different tile */ SearchTileBid recvBid = new SearchTileBid(p.src.ID, bidMsg.bidAmount); if (this.goalTile == null && this.bidKnowledge.CandidateTile != null && bidMsg.tileId == this.bidKnowledge.CandidateTile.id) //&& this.canidateBid != null // If the recv bid is better than my bid, reset { if (recvBid.IsBetterThan(this.bidKnowledge.CandidateBid)) { this.bidKnowledge.CandidateTile.SetAsClaimed(recvBid); this.bidKnowledge.ResetCandidateAndGoalTile(); } } else if (this.goalTile != null && bidMsg.tileId == this.goalTile.id) { // If the recv bid is better than my claimed bid, give up on that tile and assert that the other // if (recvBid.IsBetterThan(this.goalTile.acceptedBid)) { this.goalTile.acceptedBid = recvBid; this.bidKnowledge.ResetCandidateAndGoalTile(); // this.sender.SendClaimed (bidMsg.tileId, recvBid.agentId, recvBid.value); } } bidKnowledge.AddBidForTile(bidMsg.tileId, new SearchTileBid(p.src.ID, bidMsg.bidAmount)); }
public void CleanUp() { if (bids != null) { bids.Clear(); bids = null; } acceptedBid = null; }
public SearchTileBid GetHighestBid() { SearchTileBid topBid = (SearchTileBid)bids[0]; foreach (SearchTileBid bid in bids) { if (bid.IsBetterThan(topBid)) { topBid = bid; } } return(topBid); }
public void AddBidForTile(int searchTileId, SearchTileBid bid) { /* Search for the tile in the set that is currently in auction */ foreach (SearchTile tile in tilesInAuction) { if (searchTileId == tile.id) { // WorldStateManager.MarkTileAsHasBid (this); tile.AddBid(bid, this.myId == bid.agentId); return; } } /* This is the first bid for the tile */ foreach (SearchTile tile in openTiles) { if (searchTileId == tile.id) { this.MoveTile(tile, this.openTiles, this.tilesInAuction); tile.AddBid(bid, this.myId == bid.agentId); WorldStateManager.MarkTileAsHasBid(tile); return; } } // If we can't find the tile, it's been claimed or searched SearchTile searchTile = this.FindTileWithId(this.claimedTiles, searchTileId); // If it's found as a claimed tile if (searchTile != null) { // Debug.Log("Agent " + this.myId + " got a bid for a claimed tile"); // Send a claimed message giving the agents belived state sender.SendClaimed(searchTile.id, searchTile.acceptedBid.agentId, searchTile.acceptedBid.value); return; } // Otherwise, the tile has been searched. Send searched message. searchTile = this.FindTileWithId(this.searchedTiles, searchTileId); if (searchTile != null) { // Debug.Log("Agent " + this.myId + " got a bid for a searched tile"); sender.SendSearched(searchTile.id); return; } // Debug.Log("ERROR -> Adding bid for tile that does not exist."); }
public bool IsBetterThan(SearchTileBid bid) { if (bid == null) { Debug.Log("ERROR: comparing Search Tile to null bid"); return(false); } if (this.value > bid.value) { return(true); } else if (this.value == bid.value && this.agentId > bid.agentId) { return(true); } return(false); }
public void AddBid(SearchTileBid bid, bool isMyBid) { /* If this is the first bid */ if (bids == null) { bids = new ArrayList(); auctionEndTime = AUCTION_TIME; this.state = TileState.HASBID; } else { auctionEndTime += .25f * AUCTION_TIME; } //if (isMyBid) { // auctionEndTime = Mathf.Max(3.0f, AUCTION_TIME); // Extend the timeout if receive a second bid. //} bids.Add(bid); }
private void SendBidForNextBestTile() { SearchTile tile = this.GetNextBestTile(this.kb.agent.sensorModule.gps.position, this.kb.updates); // Check if there are any tiles left to be claimed if (tile == null) { //isDone = true; // Debug.Log ("No more tiles to bid on"); // if (this.IsMapSearched () ) { Debug.Log ("Agent "+this.kb.agent.ID+" thinks the map is searched"); } this.ResetCandidateAndGoalTile(); return; } this.ResetCandidateAndGoalTile(); this.kb.SetTempGoal(tile); this.canidateTile = tile; int tileId = canidateTile.id; float bidAmount = this.BidEvaluation(this.kb.agent.sensorModule.gps.position, this.canidateTile.center, this.kb.updates); this.canidateBid = new SearchTileBid(this.kb.agent.ID, bidAmount); this.AddBidForTile(tileId, this.canidateBid); this.sender.SendBid(tileId, bidAmount); // Debug.Log (this.kb.agent.ID + " Just Sent a bid"); }
private void SendBidForNextBestTile() { SearchTile tile = this.bidKnowledge.GetNextBestTile(agent.sensorModule.gps.position, this.updates); // Check if there are any tiles left to be claimed if (tile == null) { //isDone = true; // if (this.bidKnowledge.IsMapSearched () ) { Debug.Log ("Agent "+this.agent.ID+" thinks the map is searched"); } this.bidKnowledge.ResetCandidateAndGoalTile(); return; } this.ResetGoalTile(); this.tempGoal = tile; this.bidKnowledge.SetCandidateTile(tile); int tileId = tile.id; float bidAmount = this.bidKnowledge.BidEvaluation(agent.sensorModule.gps.position, tile.center, this.updates); SearchTileBid canidateBid = new SearchTileBid(this.agent.ID, bidAmount); this.bidKnowledge.SetCandidateBid(canidateBid); this.bidKnowledge.AddBidForTile(tileId, canidateBid); this.sender.SendBid(tileId, bidAmount); }
public void SetCandidateBid(SearchTileBid b) { this.canidateBid = b; }
public void RecvClaimedMessage(int srcId, int searchTileId, int agentId, float bestBidAmount) { if (agentId == this.myId) { return; } SearchTileBid recvClaimBid = new SearchTileBid(agentId, bestBidAmount); SearchTile tile = this.FindTileWithId(this.tilesInAuction, searchTileId); if (tile != null) { // If the received claim is the best bid, mark the tile as claimed if (recvClaimBid.IsBetterThan(tile.GetHighestBid())) { tile.SetAsClaimed(new SearchTileBid(agentId, bestBidAmount)); this.MoveTile(tile, this.tilesInAuction, this.claimedTiles); if ((CandidateTile != null && CandidateTile.id == tile.id) || (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id)) { this.ResetCandidateAndGoalTile(); } } else { // Get the highest bid for the tile claimed tile.SetAsClaimed(tile.GetHighestBid()); this.MoveTile(tile, this.tilesInAuction, this.claimedTiles); // If I have claimed this tile let others know if ((CandidateTile != null && CandidateTile.id == tile.id) || (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id)) { WorldStateManager.MarkTileAsClaimed(tile); this.sender.SendClaimed(tile.id, tile.acceptedBid.agentId, tile.acceptedBid.value); } } return; } tile = this.FindTileWithId(this.openTiles, searchTileId); if (tile != null) { tile.SetAsClaimed(new SearchTileBid(agentId, bestBidAmount)); this.MoveTile(tile, this.openTiles, this.claimedTiles); return; } // Check if the tile has been claimed tile = this.FindTileWithId(this.claimedTiles, searchTileId); if (tile != null) { if (tile.acceptedBid.IsBetterThan(recvClaimBid)) { if ((CandidateTile != null && CandidateTile.id == tile.id) || (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id)) { //Debug.Log("Recv claimed for tile "+tile.id+", I agent "+ this.myId+" have claimed."); this.sender.SendClaimed(tile.id, tile.acceptedBid.agentId, tile.acceptedBid.value); } } else { // The recv claim is better, so update knowledge if ((CandidateTile != null && CandidateTile.id == tile.id) || (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id)) { ResetCandidateAndGoalTile(); } tile.acceptedBid.agentId = agentId; tile.acceptedBid.value = bestBidAmount; } } // Otherwise, the tile has been claimed by another agent or searched already tile = this.FindTileWithId(this.searchedTiles, searchTileId); if (tile != null) { this.sender.SendSearched(searchTileId); return; } }
public void SetAsClaimed(SearchTileBid bestBid) { acceptedBid = bestBid; state = TileState.CLAIMED; searchTimeout = 0.0f; }