Jade Library — Мобильность агентов между контейнерами

Я написал фрагмент кода, представляющий агент, использующий jade-библиотеку, путешествующую по контейнерам. У моего агента есть Cyclic Behavior, который использует простые операторы switch-case для перемещения по контейнерам. Он запускается в «Основном контейнере», затем переходит в «Контейнер-1», затем переходит в «Контейнер-2», а затем переходит в «Контейнер-1» и так далее! Проблема здесь, когда он хочет вернуться, он не делает! Нет ошибки о неизвестном Container или что-то в этом роде.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MyAgentPool;

import jade.core.Agent;
import jade.core.ContainerID;
import jade.core.behaviours.CyclicBehaviour;

/**
 *
 * @author King Hadi
*/
public class MyAgent00 extends Agent {       
@Override
protected void takeDown() {
    // TODO Auto-generated method stub
    super.takeDown();
    System.out.print("goodbye!");
}

@Override
protected void setup() {
    // TODO Auto-generated method stub
    super.setup();
    System.out.println("Hello I'm " + this.getLocalName());
    this.addBehaviour(new MyBehaviour());
   }
}

class MyBehaviour extends CyclicBehaviour {

private int step = 0;

@Override
public void action() {
    // TODO Auto-generated method stub
    switch (step) {
        case 0: {
            System.out.println("step variable is: "+ step);
            step++;
            ContainerID destination = new ContainerID();
            destination.setName("Container-2");                                
            System.out.println("waiting 2 seconds! before traveling ... ");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                

            myAgent.doMove(destination);
            break;
        }
        case 1: {
            System.out.println("step variable is: "+ step);
            step++;
            ContainerID destination1 = new ContainerID();
            destination1.setName("Container-1");                
            System.out.println("waiting 2 seconds! before traveling ... ");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                

            myAgent.doMove(destination1);
            break;
        }
        case 2: {
            System.out.println("step variable is: "+ step);
            step--;
            ContainerID destination2 = new ContainerID();
            destination2.setName("Container-2");                                
            System.out.println("waiting 2 seconds! before traveling ...");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                                
            myAgent.doMove(destination2);
            break;
        }
        default: {
            System.out.println("step variable is: "+ step);
            step = 0;
            ContainerID destination = new ContainerID();
            destination.setName("Main-Contianer");
            myAgent.doMove(destination);
            System.out.println("waiting 2 seconds! before traveling ...");

            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                
            break;
        }
    }
}
}

кто-нибудь знает, почему этот код не работает? спасибо! :)


person Hadi    schedule 22.03.2012    source источник
comment
что происходит, когда вы его развертываете? Пожалуйста, объясните   -  person Purushottam    schedule 28.04.2012


Ответы (1)


Вы допустили орфографическую ошибку в операторе Default Switch:

destination.setName("Main-Contianer");

Должно быть:

destination.setName("Main-Container");
person Andries D.    schedule 16.11.2015