📄 dispatcher_exact.java
字号:
/**
* Copyright (C) 2006, Laboratorio di Valutazione delle Prestazioni - Politecnico di Milano
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package jmt.engine.simDispatcher;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.InputSource;
import org.apache.xerces.parsers.DOMParser;
import javax.xml.parsers.*;
import jmt.gui.exact.utils.ArrayUtils;
import jmt.common.exception.SolverException;
import java.util.Arrays;
import java.io.File;
import java.io.FileReader;
/**
* This class is a "stripped" copy of ExactModel used to check saturation before dispatching
* @author Stefano Omini
*/
public class Dispatcher_Exact {
public static final int STATION_DELAY = 0;
public static final int STATION_LI = 1; //load independent
public static final int STATION_LD = 2; //load dependent
public static final int CLASS_CLOSED = 0;
public static final int CLASS_OPEN = 1;
//true if the model is closed
private boolean closed;
//true if the model is open
private boolean open;
//true if the model contains load dependent stations
private boolean ld;
//true if the model has been modified
private boolean changed;
//true if results are available
private boolean hasResults;
//true if the results are valid (no modify has been made in the model after results computation)
private boolean resultsOK;
//description of the model
private String description;
/***********************STATIONS AND CLASSES******************************/
//number of service centers
private int stations;
//number of classes
private int classes;
//total population (computed as the sum of all closed class populations)
private int maxpop;
//class data is class population for closed classes, class arrival rate for open classes
//dim: classData[classes]
private double[] classData;
//station names
//dim: stationNames[stations]
private String[] stationNames;
//station types
//dim: stationTypes[stations]
private int[] stationTypes;
//class names
//dim: classNames[classes]
private String[] classNames;
//class types
//dim: classTypes[classes]
private int[] classTypes;
/***********************SERVICE PARAMETERS**************************/
/**
* visits to the service centers
* dim: visits[stations][classes]
*/
private double[][] visits;
/**
* service times of the service centers
* dim: serviceTimes[stations][classes][p]
* p=maxpop if stationTypes[s]==STATION_LD
* p=1 otherwise
*/
private double[][][] serviceTimes;
/***********************RESULTS******************************/
/**
* queue lengths
* dim: queueLen[stations][classes+1]
*/
private double[][] queueLen;
/**
* throughput
* dim: throughput[stations+1][classes+1]
*/
private double[][] throughput;
/**
* residence times
* dim: resTime[stations+1][classes+1]
*/
private double[][] resTimes;
/**
* utilization
* dim: util[stations][classes+1]
*/
private double[][] util;
private File modelFile;
private String modelFilePath;
private Document document;
public Dispatcher_Exact(File modelFile){
this.modelFile = modelFile;
this.modelFilePath = modelFile.getAbsolutePath();
try {
init();
} catch (SolverException se){
se.printStackTrace();
}
}
public Dispatcher_Exact(String modelPath){
this.modelFilePath = modelPath;
this.modelFile = new File (modelPath);
try {
init();
} catch (SolverException se){
se.printStackTrace();
}
}
private void init() throws SolverException{
try {
DOMParser parser = new DOMParser();
FileReader fr = new FileReader(modelFile);
parser.parse(new InputSource(fr));
document = parser.getDocument();
if (!loadDocument(document)) {
throw new SolverException("Error loading model from tempfile", null);
}
} catch (SAXException e) {
throw new SolverException("XML parse error in tempfile", e);
} catch (Exception e) {
throw new SolverException("Error loading model from tempfile", e);
}
}
/**
* Clears all the results
*/
public void discardResults() {
hasResults = false;
resultsOK = false;
queueLen = null;
throughput = null;
resTimes = null;
util = null;
changed = true;
}
/**
* sets all the result data for this model.
* @throws IllegalArgumentException if any argument is null or not of the correct size
*/
public void setResults(double[][] queueLen, double[][] throughput, double[][] resTimes, double[][] util) {
//OLD
//int stp = stations + 1;
//int clp = classes + 1;
//NEW
//@author Stefano Omini
int stp = stations;
int clp = classes;
//end NEW
if (queueLen == null || queueLen.length != stations || queueLen[0].length != clp) throw new IllegalArgumentException("queueLen must be non null and of size [stations+1][classes+1]");
if (throughput == null || throughput.length != stp || throughput[0].length != clp) throw new IllegalArgumentException("throughput must be non null and of size [stations+1][classes+1]");
if (resTimes == null || resTimes.length != stp || resTimes[0].length != clp) throw new IllegalArgumentException("resTimes must be non null and of size [stations+1][classes+1]");
if (util == null || util.length != stations || util[0].length != clp) throw new IllegalArgumentException("util must be non null and of size [stations][classes+1]");
//TODO: non controlla il numero di classi per tutte le stazioni, ma solo per la prima!!
this.queueLen = ArrayUtils.copy2(queueLen);
this.throughput = ArrayUtils.copy2(throughput);
this.resTimes = ArrayUtils.copy2(resTimes);
this.util = ArrayUtils.copy2(util);
hasResults = true;
resultsOK = true;
changed = true;
}
/**
* Gets the model description
* @return the model description
*/
public String getDescription() {
return description;
}
/**
* Sets the model description
* @param description the model description
*/
public void setDescription(String description) {
if (!changed) if (description.equals(this.description)) return;
this.description = description;
changed = true;
}
/**
* @return true if this object describes a multiclass system
*/
public boolean isMultiClass() {
return (classes > 1);
}
/**
* @return true if this object describes a closed system
*/
public boolean isClosed() {
return closed;
}
/**
* @return true if this object describes an open system
*/
public boolean isOpen() {
return open;
}
/**
* @return true if this object describes a mixed system
*/
public boolean isMixed() {
//mixed = true only if closed = false and open = false
return !(closed || open);
}
/**
* @return true if this object describes a system containing LD stations
*/
public boolean isLd() {
return ld;
}
/**
* @return number of service centers
*/
public int getStations() {
return stations;
}
/**
* @return number of classes
*/
public int getClasses() {
return classes;
}
/**
* @return total population
*/
public int getMaxpop() {
return maxpop;
}
/**
* @return names of the service centers
*/
public String[] getStationNames() {
return stationNames;
}
/**
* sets the names of the service centers.
* @param stationNames the names of the service centers
* @throws IllegalArgumentException if the array is not of the correct size
*/
public void setStationNames(String[] stationNames) {
if (stationNames.length != stations) throw new IllegalArgumentException("stationNames.length!=stations");
if (!changed) if (Arrays.equals(this.stationNames, stationNames)) return;
this.stationNames = stationNames;
changed = true;
}
/**
* @return names of the classes
*/
public String[] getClassNames() {
return classNames;
}
/**
* sets the names of the classes.
* @param classNames the names of the classes
* @throws IllegalArgumentException if the array is not of the correct size
*/
public void setClassNames(String[] classNames) {
if (classNames.length != classes) throw new IllegalArgumentException("classNames.length!=classes");
if (!changed) if (Arrays.equals(this.classNames, classNames)) return;
this.classNames = classNames;
changed = true;
}
/**
* @return data for the classes.
*/
public double[] getClassData() {
return classData;
}
/**
* @return type of the classes
*/
public int[] getClassTypes() {
return classTypes;
}
/**
* sets the type of the classes
* @param classTypes the type of the classes
* @throws IllegalArgumentException if the array is not of the correct size
*/
public void setClassTypes(int[] classTypes) {
if (classTypes.length != classes) throw new IllegalArgumentException("classTypes.length!=classes");
if (!changed || resultsOK) if (Arrays.equals(this.classTypes, classTypes)) return;
this.classTypes = classTypes;
closed = calcClosed();
open = calcOpen();
changed = true;
resultsOK = false;
}
/**
* @return type of the stations
*/
public int[] getStationTypes() {
return stationTypes;
}
/**
* @return the matrix of visits
*/
public double[][] getVisits() {
return visits;
}
/**
* sets the matrix of visits
* @param visits the matrix of visits
* @throws IllegalArgumentException if the matrix is not of the correct size
*/
public void setVisits(double[][] visits) {
if (visits.length != stations || visits[0].length != classes) throw new IllegalArgumentException("incorrect array dimension");
if (!changed || resultsOK) if (ArrayUtils.equals2(this.visits, visits)) return;
this.visits = visits;
changed = true;
resultsOK = false;
}
/**
* @return the matrix of service times
*/
public double[][][] getServiceTimes() {
return serviceTimes;
}
/**
* sets the matrix of service times
* @param serviceTimes the matrix of service times
* @throws IllegalArgumentException if the matrix is not of the correct size
*/
public void setServiceTimes(double[][][] serviceTimes) {
if (serviceTimes.length != stations || serviceTimes[0].length != classes) throw new IllegalArgumentException("incorrect array dimension");
if (!changed || resultsOK) if (ArrayUtils.equals3(this.serviceTimes, serviceTimes)) return;
int currSize;
double[][] subST;
//validate sizes
for (int s = 0; s < stations; s++) {
currSize = (stationTypes[s] == STATION_LD ? maxpop : 1);
//TODO: se stazione
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -