📄 exactmodel.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.gui.exact;
import jmt.gui.exact.utils.ArrayUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.util.Arrays;
/**
* An object grouping all the data describing a system.
* <br><br>
* WARNING:
* ACCESS TO THIS OBJECT MUST BE IMPLEMENTED IN A TRANSACTION-LIKE SYNCHRONIZED WAY!
*
* @author alyf (Andrea Conti), Stefano Omini, Bertoli Marco
*/
public class ExactModel implements ExactConstants {
//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 visits are set (otherwise they will be all unitary)
private boolean unitaryVisits;
//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][iterations]
*/
private double[][][] queueLen;
/**
* throughput
* dim: throughput[stations+1][classes+1][iterations]
*/
private double[][][] throughput;
/**
* residence times
* dim: resTime[stations+1][classes+1][iterations]
*/
private double[][][] resTimes;
/**
* utilization
* dim: util[stations][classes+1][iterations]
*/
private double[][][] util;
/*****************************************************************/
//parameters for randomization
private static final double MAXRAND=100;
private static final double MAXRANGE=10;
/*****************************************************************/
/********************** WHAT-IF ANALYSIS *** Bertoli Marco *******/
/** Number of iterations (1 for normal usage, >1 for what-if analysis) */
private int iterations = 1;
/** Index of class selected for what-if analysis. -1 means all classes */
private int whatIfClass = -1;
/** Index of station selected for what-if analysis. -1 means all stations */
private int whatIfStation = -1;
/**
* Type of what-if analysis
* @see ExactConstants
*/
private String whatIfType;
/** Array with considered values */
private double[] whatIfValues;
/*****************************************************************/
/**
* make an object with default values
*/
public ExactModel() {
setDefaults();
}
/**
* copy constructor
*/
public ExactModel(ExactModel e) {
closed = e.closed;
open = e.open;
unitaryVisits = e.unitaryVisits;
hasResults = e.hasResults;
resultsOK = e.resultsOK;
changed = e.changed;
stations = e.stations;
classes = e.classes;
maxpop = e.maxpop;
description = e.description;
stationNames = ArrayUtils.copy(e.stationNames);
stationTypes = ArrayUtils.copy(e.stationTypes);
classNames = ArrayUtils.copy(e.classNames);
classTypes = ArrayUtils.copy(e.classTypes);
classData = ArrayUtils.copy(e.classData);
visits = ArrayUtils.copy2(e.visits);
serviceTimes = ArrayUtils.copy3(e.serviceTimes);
// What-if analysis
iterations = e.iterations;
whatIfClass = e.whatIfClass;
whatIfStation = e.whatIfStation;
whatIfType = e.whatIfType;
whatIfValues = e.whatIfValues;
if (hasResults) {
queueLen = ArrayUtils.copy3(e.queueLen);
throughput = ArrayUtils.copy3(e.throughput);
resTimes = ArrayUtils.copy3(e.resTimes);
util = ArrayUtils.copy3(e.util);
}
}
/**
* Clears all the results
*/
public void discardResults() {
queueLen = null;
throughput = null;
resTimes = null;
util = null;
discardChanges();
}
/**
* Discards all change elements but does not touch results
*/
public void discardChanges() {
hasResults = false;
resultsOK = false;
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) {
if (queueLen == null || queueLen.length != stations || queueLen[0].length != classes) throw new IllegalArgumentException("queueLen must be non null and of size [stations][classes][iterations]");
if (throughput == null || throughput.length != stations || throughput[0].length != classes) throw new IllegalArgumentException("throughput must be non null and of size [stations][classes][iterations]");
if (resTimes == null || resTimes.length != stations || resTimes[0].length != classes) throw new IllegalArgumentException("resTimes must be non null and of size [stations][classes][iterations]");
if (util == null || util.length != stations || util[0].length != classes) throw new IllegalArgumentException("util must be non null and of size [stations][classes][iterations]");
// non controlla il numero di classi per tutte le stazioni, ma solo per la prima!!
this.queueLen = ArrayUtils.copy3(queueLen);
this.throughput = ArrayUtils.copy3(throughput);
this.resTimes = ArrayUtils.copy3(resTimes);
this.util = ArrayUtils.copy3(util);
hasResults = true;
iterations = queueLen[0][0].length;
resultsOK = true;
changed = true;
}
/**
* sets all the result data for this model. This is called when only one iteration is performed.
* @throws IllegalArgumentException if any argument is null or not of the correct size
*/
public void setResults(double[][] queueLen, double[][] throughput, double[][] resTimes, double[][] util) {
resetResults();
setResults(queueLen, throughput, resTimes, util, 0);
}
/**
* Sets ResultsOK flag
* @param value value of ResultsOK flag
*/
public void setResultsOK(boolean value) {
this.resultsOK = value;
}
/**
* sets all the result data for this model. This is called on multiple iterations (what-if analysis)
* @throws IllegalArgumentException if any argument is null or not of the correct size
*/
public void setResults(double[][] queueLen, double[][] throughput, double[][] resTimes, double[][] util, int iteration) {
if (queueLen == null || queueLen.length != stations || queueLen[0].length != classes) throw new IllegalArgumentException("queueLen must be non null and of size [stations][classes]");
if (throughput == null || throughput.length != stations || throughput[0].length != classes) throw new IllegalArgumentException("throughput must be non null and of size [stations][classes]");
if (resTimes == null || resTimes.length != stations || resTimes[0].length != classes) throw new IllegalArgumentException("resTimes must be non null and of size [stations][classes]");
if (util == null || util.length != stations || util[0].length != classes) throw new IllegalArgumentException("util must be non null and of size [stations][classes]");
if (iteration >= iterations) throw new IllegalArgumentException("iteration is greater than expected number of iterations");
// Creates an array for single iteration
ArrayUtils.copy2to3(queueLen, this.queueLen, iteration);
ArrayUtils.copy2to3(throughput, this.throughput, iteration);
ArrayUtils.copy2to3(resTimes, this.resTimes, iteration);
ArrayUtils.copy2to3(util, this.util, iteration);
hasResults = true;
resultsOK = true;
changed = true;
}
/**
* Resets arrays used to store results
*/
public void resetResults() {
queueLen = new double[stations][classes][iterations];
throughput = new double[stations][classes][iterations];
resTimes = new double[stations][classes][iterations];
util = new double[stations][classes][iterations];
hasResults = false;
changed = true;
}
/**
* Initialize the object with defaults:
* 1 closed class, 1 LI station, 0 customers, all visits to one, all service times to zero, no results
*/
public void setDefaults() {
closed = true;
hasResults = false;
resultsOK = false;
stations = 1;
classes = 1;
// perch
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -