Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* This file is part of jasima, v1.3, the Java simulator for manufacturing and
* logistics.
*
* Copyright (c) 2015 jasima solutions UG
* Copyright (c) 2010-2015 Torsten Hildebrandt and jasima contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*******************************************************************************/
package jasima.core.simulation;
import jasima.core.random.RandomFactory;
import jasima.core.simulation.Simulation.SimEvent;
import jasima.core.util.TypeUtil;
import jasima.core.util.Util;
import jasima.core.util.ValueStore;
import jasima.core.util.observer.Notifier;
import jasima.core.util.observer.NotifierAdapter;
import jasima.core.util.observer.NotifierListener;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
*
* Base class for a discrete event simulation. This class doesn't do much, but
* only maintains an event queue and manages simulation time.
*
*
* The typical life cycle of a simulation would be to create it, and
* subsequently set any parameters. Afterwards {@link #init()} has to be called
* before the actual simulation can be performed in {@link #run()}. After
* completing a simulation the {@link #done()}-method should be called to
* perform clean-up, collecting simulation results, etc.
*
*
* @author Torsten Hildebrandt, 2012-02-08
* @version
* "$Id: Simulation.java 753 2015-07-27 15:29:49Z [email protected] $"
*/
public class Simulation implements Notifier, ValueStore {
public static final String QUEUE_IMPL_KEY = "jasima.core.simulation.Simulation.queueImpl";
public static final String QUEUE_IMPL_DEF = EventHeap.class.getName();
/**
* Base class for notifier events (NOT simulation events, they are not
* handled by the event queue, just send to listeners).
*/
public static class SimEvent {
}
// constants for default events thrown by a simulation
public static final SimEvent SIM_INIT = new SimEvent();
public static final SimEvent SIM_START = new SimEvent();
public static final SimEvent SIM_END = new SimEvent();
public static final SimEvent SIM_DONE = new SimEvent();
public static final SimEvent COLLECT_RESULTS = new SimEvent();
public enum SimMsgCategory {
OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL
}
public static class SimPrintEvent extends SimEvent {
public final Simulation sim;
public final SimMsgCategory category;
private String messageFormatString;
private Object[] params;
private String message;
public SimPrintEvent(Simulation sim, SimMsgCategory category,
String message) {
super();
if (message == null)
throw new NullPointerException();
this.sim = sim;
this.category = category;
this.message = message;
}
public SimPrintEvent(Simulation sim, SimMsgCategory category,
String messageFormatString, Object... params) {
super();
this.sim = sim;
this.category = category;
this.messageFormatString = messageFormatString;
this.params = params;
this.message = null;
}
public String getMessage() {
// lazy creation of message only when needed
if (message == null) {
message = String.format(Util.DEF_LOCALE, messageFormatString,
params);
messageFormatString = null;
params = null;
}
return message;
}
@Override
public String toString() {
return getMessage();
}
}
public static interface EventQueue {
/** Insert an event in the queue. */
public void insert(Event e);
/** Extract the (chronologically) next event from the queue. */
public Event extract();
}
// /////////// simulation parameters
private double simulationLength = 0.0d;
private RandomFactory rndStreamFactory;
private HashMap