⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reversedutchauction.java

📁 中間件開發详细说明:清华大学J2EE教程讲义(ppt)-Tsinghua University J2EE tutorial lectures (ppt) [上载源码成为会员下载此源码] [成为VIP会
💻 JAVA
字号:
/*
 * Title:        GridSim Toolkit
 * Description:  GridSim (Grid Simulation) Toolkit for Modeling and Simulation
 *               of Parallel and Distributed Systems such as Clusters and Grids
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * $Id: ReverseDutchAuction.java,v 1.3 2006/03/23 03:40:56 anthony Exp $
 */
package gridsim.auction;

import eduni.simjava.Sim_port;

/**
 * This class represents a Reverse Dutch Auction. 
 * In a reverse auction, buyers start the auction and the
 * lowest bid is considered the best. Therefore, the
 * Dutch auction becomes ascending and starts with
 * the min price going until the max price.
 *
 * @author       Marcos Dias de Assuncao
 * @since        GridSim Toolkit 4.0
 * @see gridsim.auction.Auction
 * @see gridsim.auction.OneSidedAuction
 * @see gridsim.auction.AuctionTags
 */
public class ReverseDutchAuction extends OneSidedAuction {
    private MessageBid bestBid;
	
    /**
     * Constructor
     * @param auctionName a name for the auction
     * @param auctioneerID the GridSim id of the auctioneer 
     * @param durationOfRounds simulation time of the duration of each round 
     * @param totalRound the number of rounds
     * @param output the auctioneer's output port  
     * @throws Exception
     * @see gridsim.GridSim
     */
    public ReverseDutchAuction(String auctionName, int auctioneerID, 
    		double durationOfRounds, int totalRound, Sim_port output)throws Exception {
    	super(auctionName, auctioneerID, AuctionTags.REVERSE_DUTCH_AUCTION, 
    	durationOfRounds, totalRound, output); 
    }
    
    /**
     * Constructor
     * @param auctionName a name for the auction
     * @param durationOfRounds simulation time of the duration of each round 
     * @param totalRound the number of rounds
     * @throws Exception
     * @see gridsim.GridSim
     */
    public ReverseDutchAuction(String auctionName,  
    		double durationOfRounds, int totalRound)throws Exception {
    	super(auctionName, AuctionTags.REVERSE_DUTCH_AUCTION, 
    	durationOfRounds, totalRound); 
    }

	/**
	 * This method is called when a round is started
	 * @see gridsim.auction.OneSidedAuction#onStart(int)
	 */
    public void onStart(int round) {
		if (round == 1) {
			super.setCurrentPrice(super.getMinPrice());
		}

		MessageCallForBids msg = new MessageCallForBids(super
				.getAuctionID(), super.getAuctionProtocol(), 
				super.getCurrentPrice(), super.currentRound());
		
		msg.setAttributes(super.getAttributes());
		super.broadcastMessage(msg);
	}
	
	/**
	 * This method is called when the auction finishes
	 * @see gridsim.auction.OneSidedAuction#onStop()
	 */
	public void onStop() {
		int winner = super.getWinner();
		MessageInformOutcome iout = new MessageInformOutcome(super
				.getAuctionID(), super.getAuctionProtocol(), winner, super
				.getFinalPrice());
		
		iout.setAttributes(super.getAttributes());
		super.broadcastMessage(iout);
	}

	/**
	 * This method is invoked when a round finishes
	 * @see gridsim.auction.OneSidedAuction#onClose(int)
	 */
	public void onClose(int round) {
		if (round >= super.getNumberOfRounds()) {
			if (bestBid == null)
				super.setFinalPrice(super.getCurrentPrice());
		} else {
			double increase = super.getMaxPrice()
					/ (super.getNumberOfRounds() - 1);
			super.setCurrentPrice((float) super.getCurrentPrice()
					+ increase);
		}
	}

	/**
	 * This method is called when a bid is received. 
	 * @see gridsim.auction.OneSidedAuction#onReceiveBid(gridsim.auction.MessageBid)
	 */
	public void onReceiveBid(MessageBid bid) {
		double price = bid.getPrice();
		super.setFinalPrice(price);
		if (price <= super.getReservePrice()) {
			super.setWinner(bid.getBidder());
		}
		bestBid = bid;
		closeAuction();
	}

	/**
	 * Called when a reject bid is received.
	 * @see gridsim.auction.OneSidedAuction#onReceiveRejectCallForBid(gridsim.auction.MessageRejectCallForBid)
	 */
	public void onReceiveRejectCallForBid(MessageRejectCallForBid mrej) {
		// do nothing for now...
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -