Skip to content
Snippets Groups Projects
testShipArrivalProcess.java 2.27 KiB
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
package mv3302.run;

import mv3302.Ship;
import mv3302.ShipArrivalProcess;
import mv3302.TwoCranesBerth;
import simkit.Adapter;
import simkit.Schedule;
import simkit.SimEventListener;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.util.SimplePropertyDumper;

/**
 *
 * @author dansl
 */
public class testShipArrivalProcess {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Ship ship = new Ship(5.0);
        
        System.out.println(ship.getRemainingUnloadingTime());
        ship.work(2);
        System.out.println(ship.getRemainingUnloadingTime());
        
        RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance("Exponential", .7);
        RandomVariate unloadingTimeGenerator = RandomVariateFactory.getInstance("Uniform", 0.5, 1.5);
        ShipArrivalProcess shipArrivalProcess = new ShipArrivalProcess(interarrivalTimeGenerator, unloadingTimeGenerator);
        System.out.println(shipArrivalProcess);
        
        TwoCranesBerth twoCranesBerth = new TwoCranesBerth();
        System.out.println(twoCranesBerth);
        
        //        TwoCranesBerth will "hear" ShipArrivalProcess(ShipArrival) events
        shipArrivalProcess.addSimEventListener(twoCranesBerth);

//        The twoCranesBerth will "hear" the ShipArrival events of the
//        first as Arrival events
        Adapter adapter = new Adapter("ShipArrival", "Arrival");
        adapter.connect(shipArrivalProcess, twoCranesBerth);

//        This was used for debugging model
        SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);

        twoCranesBerth.addPropertyChangeListener(simplePropertyDumper);
        shipArrivalProcess.addPropertyChangeListener(simplePropertyDumper);
        
        //        Was "true" when debugging model
        Schedule.setVerbose(true);
                double stopTime = 10.0;
        Schedule.stopAtTime(stopTime);

//        Initialized & run 
        Schedule.reset();
        Schedule.startSimulation();
        
    }
    
}