我是Jason和Agentspeak的初学者。我有兴趣用一个Auctioneer和两个Bidders进行英国拍卖。我创建了以下文件,但是当我运行它们时,没有任何反应。我不知道在哪里问题是。你可以帮帮我吗?先谢谢!
ActioneerGUI.JAVA
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import jason.architecture.*;
import jason.asSemantics.ActionExec;
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Literal;
import javax.swing.*;
/** example of agent architecture's functions overriding */
public class AuctioneerGUI extends AgArch {
JTextArea jt;
JFrame f;
JButton auction;
int auctionId = 0;
public AuctioneerGUI() {
jt = new JTextArea(10, 30);
auction = new JButton("Start new auction");
auction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
auctionId++;
Literal goal = ASSyntax.createLiteral("start_auction", ASSyntax.createNumber(auctionId));
getTS().getC().addAchvGoal(goal, null);
auction.setEnabled(false);
}
});
f = new JFrame("Auctioneer agent");
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(BorderLayout.CENTER, new JScrollPane(jt));
f.getContentPane().add(BorderLayout.SOUTH, auction);
f.pack();
f.setVisible(true);
}
@Override
public void act(ActionExec action) { //, List<ActionExec> feedback) {
if (action.getActionTerm().getFunctor().startsWith("show_winner")) {
jt.append("Winner of auction " + action.getActionTerm().getTerm(0));
jt.append(" is " + action.getActionTerm().getTerm(1) + "\n");
action.setResult(true);
actionExecuted(action);
auction.setEnabled(true); // enable GUI button
} else {
super.act(action); // send the action to the environment to be performed.
}
}
@Override
public void stop() {
f.dispose();
super.stop();
}
}
actioneer.asl
// this agent manages the auction and identify the winner
initial_value (8).
+!start_auction(N) // this goal is created by the GUI of the agent
<- .broadcast(tell, auction(N));
.broadcast(tell, initial_value (IV)).
// announce current bid
@pb2[atomic]
+place_bid(N,_) // receives bids and checks for new winner
: .findall(b(V,A),place_bid(N,V)[source(A)],L) &
.length(L,2) // all 2 expected bids was received
<- .max(L,b(V,W));
.broadcast(tell, current_bid(CB)).
@pb1[atomic]
+place_bid(N,_) // receives bids and checks for new winner
: .findall(b(V,A),place_bid(N,V)[source(A)],L) &
.length(L,2) // all 2 expected bids was received
<- .max(L,b(V,W));
.print("Winner is ",W," with ", V);
show_winner(N,W); // show it in the GUI
.broadcast(tell, winner(W));
.abolish(place_bid(N,_)).
auction.mas2j
// English auction
MAS auction {
infrastructure: Centralised
agents: ag1;
ag2;
auctioneer agentArchClass AuctioneerGUI;
}
ag2.asl
max_bid (10).
@lbid
+auction(N)[source(S)] : true
<- .send(S, tell, place_bid(N,0)).
+place_bid(N,CB):CB<MB
<-place_bid(N,CB)[source(A)];
.send(S, tell, place_bid(N,CB+1)).
+place_bid(N,CB):CB=MB
<-place_bid(N,CB)[source(A)];
.send(S, tell, place_bid(N,CB)).
+place_bid(N,CB):CB>MB
<-.abolish(place_bid(N,_)).
ag1.asl
max_bid (9).
@lbid
+auction(N)[source(S)] : true
<- .send(S, tell, place_bid(N,0)).
+place_bid(N,CB):CB<MB
<-place_bid(N,CB)[source(A)];
.send(S, tell, place_bid(N,CB+1)).
+place_bid(N,CB):CB=MB
<-place_bid(N,CB)[source(A)];
.send(S, tell, place_bid(N,CB)).
+place_bid(N,CB):CB>MB
<-.abolish(place_bid(N,_)).
答案 0 :(得分:1)
一切听起来都有效,至少在杰森的观点上(忽略了你的应用背后的逻辑 - 英国拍卖)。
尝试使用调试工具:
就像我在auctioneer.asl中所做的那样:
// this agent manages the auction and identify the winner
initial_value(8).
+!start_auction(N) // this goal is created by the GUI of the agent
<- .print("Start a new auction!!!");
.broadcast(tell, auction(N));
.broadcast(tell, initial_value (IV)).
// announce current bid
@pb2[atomic]
+place_bid(N,_) // receives bids and checks for new winner
: .findall(b(V,A),place_bid(N,V)[source(A)],L) &
.length(L,2) // all 2 expected bids was received
<- .print("place_bid was received.");
.max(L,b(V,W));
.broadcast(tell, current_bid(CB)).
@pb1[atomic]
+place_bid(N,_) // receives bids and checks for new winner
: .findall(b(V,A),place_bid(N,V)[source(A)],L) &
.length(L,2) // all 2 expected bids was received
<- .max(L,b(V,W));
.print("Winner is ",W," with ", V);
show_winner(N,W); // show it in the GUI
.broadcast(tell, winner(W));
.abolish(place_bid(N,_)).