Как переместить событие из одного связанного списка в другой - PullRequest
1 голос
/ 01 мая 2019

Я работаю над проектом для моего класса симуляции, который вращается вокруг симуляции аэропорта. Цель состоит в том, чтобы события приходили на разные станции или терминалы, и мне нужен автобус, чтобы доставить события в их правильное место назначения. Я могу создавать события и помещать их в правильный терминал. У меня возникают проблемы с перемещением события из одного связанного списка в другой.

Например, если событие появляется на станции А, мне нужно, чтобы оно село в автобус и вышло на терминале.

while(passengers < 200){

     /*
     * This first section is where I create my events and place 
     * them in their appropriate places.
     */


    Random ran = new Random();
    int x = ran.nextInt(4) + 1;

    for(int i = 1; i <= x; i++){

    //passengers arrival time
        double U = random.nextFloat();
        double nextArrival =  -(Math.log(U))/lambda;    
    //double nextDeparture = -(Math.log(U))/mu;

    //determines place of origin and destination
        Random r = new Random();
        int randnum = r.nextInt(places.length);
        int randnum1 = r.nextInt(places.length - 1);
        String o = places[randnum];
        String d;
        if(o.equalsIgnoreCase("Terminal") ) d = places[randnum1];
        else d = places[3];

    //creates new event
        Event a = new Event(nextArrival, o, d);

    //place event at origin
        if(o.equalsIgnoreCase("StationA")){
            StationA.insert(a);
            StationA.curSize++;
        }
        else if(o.equalsIgnoreCase("StationB")){
            StationB.insert(a);
            StationB.curSize++;
        }
        else if(o.equalsIgnoreCase("StationC")){
            StationC.insert(a);
            StationC.curSize++;
        }
        else {
            Terminal.insert(a);
            Terminal.curSize++;
        }


        passengers++;

    }

    /*
     * Now bus has to go to all stations and terminal
     */

    //BUS GOES TO STATION A
    //people have to get off bus first

    if(Bus.isEmpty()) break;
    else {
        while(StationA.curSize != StationA.limit){
            boolean w = Bus.findEventTF("StationA");
            if(w = true){
                //find an event that needs to get off bus
                Event a = Bus.findEvent("StationA");
                //place event stationa completed list
                CompletedA.addLast(a);
                //increase current size of stationa completed list
                CompletedA.curSize++;
                //remove event from bus
                Bus.delete(a);
                //decrease current size of bus list
                Bus.curSize--;
            }
        }
    }

    //people have to get on bus from station a

    if(StationA.isEmpty()) break;
    else {
        while(Bus.curSize != Bus.limit){
            boolean w = Bus.findEventTF("Terminal");
            if(w = true){
                //find an event that needs to get on bus
                Event a = StationA.findEvent("Terminal");
                //place event on bus
                Bus.addLast(a);
                //increase current size of bus
                Bus.curSize++;
                //remove event from StationA
                StationA.delete(a);
                //decrease current size of stationa
                StationA.curSize--;
            }
        }
    }

    /*
     * 
     * Right now im trying to work on Station A and Terminal
     * before i add Station B & C
     * 
     */

    //BUS GOES TO TERMINAL
    //people have to get off bus first

    if(Bus.isEmpty()) break;
    else {
        while(Terminal.curSize != Terminal.limit){
            boolean w = Bus.findEventTF("Terminal");
            if(w = true){
                //find an event that needs to get off bus
                Event a = Bus.findEvent("Terminal");
                //place event terminal completed list
                CompletedT.addLast(a);
                //increase current size of terminal completed list
                CompletedT.curSize++;
                //remove event from bus
                Bus.delete(a);
                //decrease current size of bus list
                Bus.curSize--;
            }
        }
    }

    //people have to get on bus from terminal

    if(Terminal.isEmpty()) break;
    else {
        while(Bus.curSize != Bus.limit){
            //boolean w = Bus.findEventTFTerm('S');
            if(Bus.findEventTFTerm('S') = true){
                //find an event that needs to get on bus
                Event a = StationA.findEventTerm('S');
                //place event on bus
                Bus.addLast(a);
                //increase current size of bus
                Bus.curSize++;
                //remove event from StationA
                Terminal.delete(a);
                //decrease current size of terminal
                Terminal.curSize--;
            }
        }
    }

}

Если я делаю первую часть в одиночку, это работает, когда я пытаюсь что-то передвинуть, это не так. Любая помощь будет принята с благодарностью. Если вы хотите, чтобы я добавил код из моего класса связанного списка, дайте мне знать. Спасибо.

...