1

我是 Jason 和 Agentspeak 的初学者。我对与一个拍卖师和两个投标人进行英语拍卖很感兴趣。我创建了以下文件,但是当我运行它们时,什么也没有发生。我不知道问题出在哪里。你能帮我吗?提前谢谢!

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();
    }
}

行动者.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,_)).

拍卖.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,_)).

asl.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,_)).
4

1 回答 1

0

至少从 Jason 的角度来看,一切听起来都正常(忽略您的应用程序背后的逻辑 - 英式拍卖)。

尝试使用调试工具:

  • 选项 1:通过“播放”按钮运行后,在“MAS 控制台”中,您可以通过“调试”按钮启动调试器。在那里您可以检查他们的心理状态并逐步运行您的应用程序。
  • 选项 2:如果您使用 jEdit 或 Eclipse Jason 的插件,您可以通过绿色错误图标启动正在运行的进程。
  • 选项 3:打开 Jason 的调试网页。当您运行您的应用程序(并且编译良好)时,您可能会看到类似“Jason Http Server running on http://192.168.0.10:3273 ”的消息,其中 192.168.0.10 是您的 IP 地址(因此,它将根据您的计算机/网络配置进行更改)。
  • 选项 4:添加一些调试消息。

就像我在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,_)).
于 2018-06-05T14:09:30.477 回答