亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? bookselleragent.java

?? JADE實(shí)例——多Agent系統(tǒng)展示(圖書(shū)交易系統(tǒng))
?? JAVA
字號(hào):
package bookTrading.seller;

import jade.core.Agent;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.proto.SSContractNetResponder;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPANames;
import jade.domain.FIPAAgentManagement.*;
import jade.content.ContentElementList;
import jade.content.ContentManager;
import jade.content.onto.*;
import jade.content.onto.basic.Action;
import jade.content.lang.*;
import jade.content.lang.sl.SLCodec;
import jade.content.lang.Codec.CodecException;

import bookTrading.ontology.*;

import java.util.*;

public class BookSellerAgent extends Agent {
	// The catalogue of books available for sale
	private Map catalogue = new HashMap();
	// The GUI to interact with the user
	private BookSellerGui myGui; 
	private Codec codec = new SLCodec();
	private Ontology ontology = BookTradingOntology.getInstance();
	
	/**
	 * Agent initializations
	 */
	protected void setup(){
		//Creat and show the GUI
		myGui = new BookSellerGuiImpl(this);
		myGui.show();
		
		getContentManager().registerLanguage(codec);
		getContentManager().registerOntology(ontology);
		
		// Add the behaviout serving calls for price from buyer agents
		addBehaviour(new CallForOfferServer(this));
		
		// Add the behaviour serving purchase requests from buyer agents
//		addBehaviour(new PurchaseOrderServer());
		
		// Register the book-selling service in the yellow pages
		DFAgentDescription dfd = new DFAgentDescription();
		dfd.setName(getAID());
		ServiceDescription sd = new ServiceDescription();
		sd.setType("Book-selling");
		sd.setName(getLocalName()+"-Book-selling");
		dfd.addServices(sd);
		try {
			DFService.register(this, dfd);
		}
		catch (FIPAException fe) {
			fe.printStackTrace();
		}
		
		// Printout a welcome message
		System.out.println("Seller-agent " + getAID().getName()
				+ " is ready.");
	}
	
	/**
	 * Agent clean-up
	 */
	protected void takeDown(){
		// Deregister from the yellow pages
		try {
			DFService.deregister(this);
		}
		catch (FIPAException fe) {
			fe.printStackTrace();
		}
		
		//Dispose the GUI if it is there
		if(myGui != null){
			myGui.dispose();
		}
		
		//Printout a dismissal message
		System.out.println("Seller-agent " + getAID().getName()
				+ "terminating.");
	}
	
	/**
	 *  This method is called by the GUI when the user inserts a new
	 *  book for sale
	 *  @param title The title of the book for sale
	 *  @param initialPrice The initial price
	 *  @param minPrice The minimum price
	 *  @param deadline The deadline by which to sell the book
	 */
	public void putForSale(String title, float initPrice,
			float minPrice, Date deadline){
		addBehaviour(new PriceManager(this,
				title, initPrice, minPrice, deadline));
	}
	
	private class PriceManager extends TickerBehaviour{
		private String title;
		private float minPrice, currentPrice, deltaP;
		private long initTime, deadline, deltaT;
		
		private PriceManager(Agent a, String t, float ip, float mp, Date d){
			super(a, 60000);	// tick every minute
			title = t;
			minPrice = mp;
			currentPrice = ip;
			deltaP = ip - mp;
			deadline = d.getTime();
			initTime = System.currentTimeMillis();
			deltaT = deadline - initTime;
		}
		
		public void onStart(){
			// Insert the book in the catalogue of books available for sale
			catalogue.put(title, this);
			super.onStart();
		}
		
		public void onTick(){
			long currentTime = System.currentTimeMillis();
			if(currentTime > deadline){
				// Deadline expired
				myGui.notifyUser("Cannot sell book" + title);
				catalogue.remove(title);
				stop();
			} else {
				// Compute the current price
				long elapsedTime = currentTime - initTime;
				currentPrice = minPrice + deltaP * (1 - (float)((double)elapsedTime / (double)deltaT));
			}
		}
		
		public float getCurrentPrice(){
			return currentPrice;
		}
	}
	
	/**
	   Inner class CallForOfferServer.
	   This is the behaviour used by Book-seller agents to serve
	 	  incoming call for offer from buyer agents.
	   If the indicated book is in the local catalogue, the seller agent
	 	  replies with a PROPOSE message specifying the price. Otherwise
	 	  a REFUSE message is sent back.
	*/
	private class CallForOfferServer extends CyclicBehaviour{
		private MessageTemplate mt = MessageTemplate.and(
				MessageTemplate.MatchProtocol(FIPANames.InteractionProtocol.FIPA_CONTRACT_NET),
				MessageTemplate.MatchPerformative(ACLMessage.CFP));
		
		public CallForOfferServer(Agent a) {
			super(a);
		}
		
		public void action(){
			ACLMessage cfp = myAgent.receive(mt);
			if(cfp != null) {
				// Message received.Process it
				myAgent.addBehaviour(new SSContractNetResponder(myAgent, cfp){
					protected ACLMessage handleCfp(ACLMessage cfp) {
						ACLMessage reply = cfp.createReply();
						try {
							ContentManager cm = myAgent.getContentManager();
							Action act = (Action)cm.extractContent(cfp);
							Sell sellAction = (Sell)act.getAction();
							Book book = sellAction.getItem();
							PriceManager pm = (PriceManager)catalogue.get(book.getTitle());
							if(pm != null) {
								// The requested book is available for sale. Reply with the price
								reply.setPerformative(ACLMessage.PROPOSE);
								ContentElementList cel = new ContentElementList();
								cel.add(act);
								Costs costs = new Costs();
								costs.setItem(book);
								costs.setPrice(pm.getCurrentPrice());
								cel.add(costs);
								cm.fillContent(reply, cel);						
							}
							else{
								// The requested book is NOT available for sale .
								reply.setPerformative(ACLMessage.REFUSE);
							}
						}
						catch (OntologyException oe) {
							oe.printStackTrace();
							reply.setPerformative(ACLMessage.NOT_UNDERSTOOD);
						}
						catch (CodecException ce) {
							ce.printStackTrace();
							reply.setPerformative(ACLMessage.NOT_UNDERSTOOD);
						}
						return reply;
					}
					
					protected ACLMessage handleAcceptProposal(
							ACLMessage cfp, ACLMessage propose, ACLMessage accept) {
						ACLMessage reply = accept.createReply();
						try {
							ContentManager cm = myAgent.getContentManager();
							ContentElementList cel =
								(ContentElementList)cm.extractContent(accept);
							Costs costs = (Costs)cel.get(1);
							Book book = costs.getItem();
							float price = costs.getPrice();
							
							PriceManager pm = (PriceManager)catalogue.get(book.getTitle());
							if(pm != null && pm.getCurrentPrice() <= price){
								// The requested book is available for sale. Reply with the price
								catalogue.remove(book.getTitle());
								pm.stop();
								myGui.notifyUser("Book " + book.getTitle()
										+ " has been sold to "
										+ accept.getSender() + ".");
								
								reply.setPerformative(ACLMessage.INFORM);
								reply.setContent(accept.getContent());
							}
							else{
								// The requested book is NOT available for sale .
								reply.setPerformative(ACLMessage.FAILURE);
							}
						}
						catch (OntologyException oe) {
							oe.printStackTrace();
							reply.setPerformative(ACLMessage.FAILURE);
							myGui.notifyUser("accept proposal from "
									+ accept.getSender()
									+ " can't be understood.");
						}
						catch (CodecException ce) {
							ce.printStackTrace();
							reply.setPerformative(ACLMessage.FAILURE);
							myGui.notifyUser("accept proposal from "
									+ accept.getSender()
									+ " can't be understood.");
						}
						return reply;
					}
				});				
			}
			else {
				block();
			}
		}
	}//End of inner class CallForOfferServer
	
	/**
	   Inner class PurchaseOrderServer.
	   This is the behaviour used by Book-seller agents to serve
	 	  incoming purchase order from buyer agents.
	   If the indicated book is in the local catalogue, the seller agent
	 	  replies with a INFORM message specifying the price. Otherwise
	 	  a REFUSE message is sent back.
	*/
	/*private class PurchaseOrderServer extends CyclicBehaviour{
		private MessageTemplate mt = MessageTemplate.and(
				MessageTemplate.MatchProtocol("fipa-contract-net"),
				MessageTemplate.MatchPerformative(ACLMessage.ACCEPT_PROPOSAL));
				
		public void action(){
			ACLMessage msg = myAgent.receive(mt);
			if(msg != null){
				// Message received.Process it
				ACLMessage reply = msg.createReply();
				
				try {
					ContentManager cm = myAgent.getContentManager();
					ContentElementList cel =
						(ContentElementList)cm.extractContent(msg);
					Costs costs = (Costs)cel.get(1);
					Book book = costs.getItem();
					float price = costs.getPrice();
					
					PriceManager pm = (PriceManager)catalogue.get(book.getTitle());
					if(pm != null && pm.getCurrentPrice() <= price){
						// The requested book is available for sale. Reply with the price
						reply.setPerformative(ACLMessage.INFORM);
						reply.setContent(msg.getContent());
					}
					else{
						// The requested book is NOT available for sale .
						reply.setPerformative(ACLMessage.FAILURE);
					}
				}
				catch (OntologyException oe) {
					oe.printStackTrace();
					reply.setPerformative(ACLMessage.FAILURE);
					myGui.notifyUser("accept proposal from "
							+ msg.getSender()
							+ " can't be understood.");
				}
				catch (CodecException ce) {
					ce.printStackTrace();
					reply.setPerformative(ACLMessage.FAILURE);
					myGui.notifyUser("accept proposal from "
							+ msg.getSender()
							+ " can't be understood.");
				}
				myAgent.send(reply);
			}
			else {
				block();
			}
		}
	}//End of inner class PurchaseOrderServer
*/}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕中文乱码欧美一区二区| 91捆绑美女网站| 欧美日韩成人激情| 一区二区三区丝袜| 成人av第一页| 国产精品热久久久久夜色精品三区| 国产在线视视频有精品| 精品国产乱码久久久久久久| 裸体一区二区三区| 精品久久久久久久久久久久久久久久久 | 九九久久精品视频| 日韩精品专区在线影院重磅| 性做久久久久久| 69p69国产精品| 免费看日韩a级影片| 欧美成人a视频| 国产在线精品不卡| 欧美国产视频在线| av在线不卡免费看| 亚洲美女免费视频| 欧美日韩一区二区三区在线| 亚洲国产日产av| 欧美一区二区三区日韩| 国产综合色视频| 一区二区三区欧美日韩| 欧美一区二区日韩| 91女神在线视频| 蜜桃传媒麻豆第一区在线观看| 国产婷婷色一区二区三区| 波多野结衣中文字幕一区二区三区 | 国产成都精品91一区二区三| 国产精品久久久爽爽爽麻豆色哟哟 | 欧美自拍丝袜亚洲| 精品亚洲国产成人av制服丝袜| 国产精品电影一区二区| 日韩免费观看高清完整版 | 亚洲精品一二三四区| 日韩精品一区二区三区在线 | 樱花草国产18久久久久| 欧美成人欧美edvon| 色88888久久久久久影院按摩 | 国产a级毛片一区| 午夜精品一区二区三区电影天堂| 亚洲国产精品传媒在线观看| 在线电影一区二区三区| av亚洲产国偷v产偷v自拍| 免费观看久久久4p| 一区二区成人在线| 国产欧美日韩另类视频免费观看| 69堂亚洲精品首页| 一本色道亚洲精品aⅴ| 国产精品亚洲人在线观看| 日韩av网站免费在线| 亚洲精品乱码久久久久| 国产精品国产三级国产| 欧美精品一区二区三区四区| 91精品国产色综合久久不卡电影| 日本韩国欧美一区二区三区| 成人动漫av在线| 国产成人午夜精品5599| 国产一区在线视频| 精品影视av免费| 日韩国产精品久久久| 亚洲成av人**亚洲成av**| 亚洲人午夜精品天堂一二香蕉| 欧美国产精品久久| 日本一区二区三区久久久久久久久不 | 国产欧美一区二区精品久导航 | 国产91精品在线观看| 久久99国产精品久久99| 日本伊人色综合网| 日韩国产精品91| 婷婷开心激情综合| 天天操天天干天天综合网| 亚洲午夜免费电影| 夜夜揉揉日日人人青青一国产精品 | 91精品国产欧美日韩| 欧美一区二区视频在线观看| 欧美日本不卡视频| 亚洲精品高清视频在线观看| 亚洲精品国产精品乱码不99| 一区二区三区四区不卡在线| 亚洲综合视频在线观看| 亚洲激情成人在线| 亚洲高清免费观看高清完整版在线观看| 亚洲猫色日本管| 香蕉久久一区二区不卡无毒影院 | 亚洲bdsm女犯bdsm网站| 日本欧美加勒比视频| 国内一区二区视频| 成人精品免费看| 91美女片黄在线观看| 欧美又粗又大又爽| 欧美一区二区免费视频| 精品国产乱码久久久久久久久| 国产校园另类小说区| 最新热久久免费视频| 亚洲一区二区偷拍精品| 五月天一区二区三区| 精品一区二区三区视频| 成人美女视频在线观看| 色偷偷成人一区二区三区91| 欧美日韩国产成人在线91 | 国产色91在线| 亚洲欧美日韩精品久久久久| 亚洲成av人片一区二区梦乃| 国产在线精品免费av| 91日韩一区二区三区| 欧美一区二区福利视频| 国产日韩精品视频一区| 亚洲一区免费观看| 国产在线不卡视频| 色香蕉成人二区免费| 欧美sm美女调教| 亚洲欧美国产三级| 蜜臀久久久99精品久久久久久| 成人丝袜视频网| 欧美精品欧美精品系列| 中文字幕成人av| 日韩精品亚洲专区| av成人免费在线| 日韩一区二区三区视频在线| 国产精品国产三级国产三级人妇| 亚洲成人一区二区在线观看| 国产成人午夜精品影院观看视频 | 大白屁股一区二区视频| 欧美日韩你懂的| 欧美经典一区二区| 日本视频在线一区| 色天天综合色天天久久| 久久久高清一区二区三区| 亚洲图片一区二区| 不卡视频在线看| 欧美精品一区二区在线播放| 亚洲高清免费观看高清完整版在线观看| 国产精品77777竹菊影视小说| 欧美日韩国产片| 综合激情成人伊人| 国产精品影音先锋| 欧美一区二区三区小说| 亚洲高清免费在线| 色综合激情五月| 日本一区二区综合亚洲| 蜜桃av噜噜一区| 欧美日韩一卡二卡三卡| 亚洲人吸女人奶水| 不卡高清视频专区| 欧美国产综合色视频| 精品在线免费观看| 欧美mv日韩mv| 蜜桃久久久久久| 欧美一区二区三区在线| 午夜视频在线观看一区二区 | 欧日韩精品视频| 亚洲丝袜精品丝袜在线| 高清日韩电视剧大全免费| 欧美videos中文字幕| 看电视剧不卡顿的网站| 欧美一区二区精美| 免费的国产精品| 欧美一级片在线看| 美脚の诱脚舐め脚责91| 91麻豆精品国产91久久久使用方法 | 国产精品久久久久久久久搜平片 | 欧美在线制服丝袜| 亚洲伦理在线免费看| 91亚洲精品一区二区乱码| 国产精品高潮久久久久无| 成人国产精品免费| 国产精品国产三级国产aⅴ中文| 成人午夜免费视频| 国产精品第一页第二页第三页| av动漫一区二区| 国产激情一区二区三区四区 | 久久国产三级精品| 欧美sm极限捆绑bd| 国产一区二区按摩在线观看| 亚洲精品在线免费播放| 国产成人综合亚洲91猫咪| 日本一区二区三区电影| 成人av网址在线观看| 亚洲手机成人高清视频| 欧美网站一区二区| 人人爽香蕉精品| 久久亚洲精精品中文字幕早川悠里| 激情成人午夜视频| 中文字幕av一区 二区| 91小宝寻花一区二区三区| 亚洲一二三四区不卡| 欧美精品色一区二区三区| 精品在线播放免费| 国产精品另类一区| 欧美三片在线视频观看| 美国欧美日韩国产在线播放| 国产日韩精品一区| 91福利小视频| 久久不见久久见免费视频1| 国产日韩欧美亚洲| 日本黄色一区二区| 激情亚洲综合在线|