1

I am a beginner in Jason and in Agentspeak.I am interesting in making an English Auction with one Auctioneer and two Bidders.I have created the following files, but when I run them, nothing happens.I do not know where the problem is.Can you help me?Thanks in advance!

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,_)).
katios
  • 11
  • 2

1 Answers1

0

Everything sounds to be working, at least in Jason point of view (ignoring the logic behind your application - English Auction).

Try to use a debug tool:

  • Option 1: After run by "play" button, in "MAS Console" you can launch the debugger by "debug" button. There you can check their mental state and step by step run your app.
  • Option 2: if you are using jEdit or Eclipse Jason's Plugin you can launch the running process by the green bug icon.
  • Option 3: open the Jason's debug web page. When you run your app (and it is compiling well) you propably will see a message like "Jason Http Server running on http://192.168.0.10:3273", where this 192.168.0.10 is your IP address (so, it will change according to your computer/network configurations).
  • Option 4: Add some debug messages.

Like this I have done in 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,_)).
Cleber Jorge Amaral
  • 1,316
  • 13
  • 26