📄 commonmodel.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.common.definitions;
import jmt.gui.common.CommonConstants;
import jmt.gui.common.Defaults;
import jmt.gui.common.definitions.parametric.ParametricAnalysisDefinition;
import jmt.gui.common.routingStrategies.ProbabilityRouting;
import jmt.gui.common.util.BDMap;
import jmt.gui.common.util.BDMapImpl;
import jmt.gui.common.util.CachedHashMap;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: OrsotronIII
* Date: 24-mag-2005
* Time: 9.46.43
* Modified by Bertoli Marco
*
*
* Modified by Francesco D'Aquino
*/
public class CommonModel implements CommonConstants, ClassDefinition,
StationDefinition, SimulationDefinition, BlockingRegionDefinition{
//key generator
long incrementalKey = 0;
Long seed;
Integer maxSamples;
Double maxDuration;
boolean useRandomSeed = true;
double pollingInterval;
protected MeasureDefinition results = null;
protected Boolean disableStatistic = Boolean.FALSE;
// Used to tell if model have to be saved
protected boolean save = false;
/**
* search keysets for classes, stations and measures
*/
protected Vector classesKeyset = new Vector(),
noSourceSinkKeyset = new Vector(),
stationsKeyset = new Vector(),
measuresKeyset = new Vector(),
blockingRegionsKeyset = new Vector(),
measuresBlockingKeyset = new Vector(),
blockableStations = new Vector();
/**
* Hashmap for classes parameters
*/
protected HashMap classDataHM = new CachedHashMap(),
/**
* Hashmap containing station parameters
*/
stationDataHM = new CachedHashMap(),
/**
* Hashmap containing measure parameters
*/
measureDataHM = new CachedHashMap(),
/**
* Hashmap containing blocking region parameters
*/
blockingDataHM = new CachedHashMap(),
/**
* Hashmap containing measure parameters
*/
blockingMeasureDataHM = new CachedHashMap();
/**
* BDMap containing station connections. On X coordinate will be put stationKeys for
* connection targets, on Y for sources.
*/
// protected BDMap connectionsBDM = new CachedBDMap(),
protected BDMap connectionsBDM = new BDMapImpl(),
/**
* BDMap containing a set of station details for each station and each class.
* on X coordinate must be put class search keys, on Y station search keys.
*/
stationDetailsBDM = new BDMapImpl(),
// stationDetailsBDM = new CachedBDMap(),
/**
* BDMap containing a set of blocking region details for each blocking region and each class.
* on X coordinate must be put class search keys, on Y blocking region search keys.
*/
blockingDetailsBDM = new BDMapImpl();
// ------------------ Francesco D'Aquino ----------------------
private ParametricAnalysisDefinition parametricAnalysisModel;
private boolean parametricAnalysisEnabled;
// -------------- end Francesco D'Aquino ----------------------
/**
* Tells if current model is to be saved
* @return true if model is to be saved
*/
public boolean toBeSaved() {
return save;
}
/**
* Resets save state. This MUST be called each time a model is saved
*/
public void resetSaveState() {
save = false;
}
/**Creates a new instance of <code>CommonModel</code>*/
public CommonModel(){
seed = Defaults.getAsLong("simulationSeed");
maxDuration = Defaults.getAsDouble("simulationMaxDuration");
maxSamples = Defaults.getAsInteger("maxSimulationSamples");
pollingInterval = Defaults.getAsDouble("simulationPolling").doubleValue();
//TODO: eventually load the parametricAnalysisEnabled state from default
parametricAnalysisEnabled = false;
}
//model class definition methods
/**
* This method returns the entire set of class keys.
*/
public synchronized Vector getClassKeys(){
return classesKeyset;
}
/**
* This method returns the set of open class keys.
*
* Author: Francesco D'Aquino
*/
public Vector getOpenClassKeys() {
Vector classes = this.getClassKeys();
Vector openClassKeys = new Vector(0,1);
for (int i=0;i<classes.size();i++) {
Object thisClass = classes.get(i);
if (this.getClassType(thisClass)==CommonConstants.CLASS_TYPE_OPEN)
openClassKeys.add(thisClass);
}
return openClassKeys;
}
/**
* This method returns the sum of population of each close class
*
* @return the total close class population
*
* Author: Francesco D'Aquino
*/
public int getTotalCloseClassPopulation() {
int sum=0;
Vector closeClasses = getClosedClassKeys();
for (int i=0;i<closeClasses.size();i++) {
sum += getClassPopulation(closeClasses.get(i)).intValue();
}
return sum;
}
/**
* This method returns the set of closed class keys.
*/
public synchronized Vector getClosedClassKeys(){
Vector closedClasses = new Vector(0,1);
for (int i=0;i<classesKeyset.size();i++) {
Object thisClassKey = classesKeyset.get(i);
int classType = getClassType(thisClassKey);
if (classType == CommonConstants.CLASS_TYPE_CLOSED) closedClasses.add(thisClassKey);
}
return closedClasses;
}
/**
* Returns name of the class linked to the specific key
* */
public synchronized String getClassName(Object key){
if(classesKeyset.contains(key)){
return ((ClassData)classDataHM.get(key)).name;
}else return null;
}
/**
* Sets name of the class linked to the specific key
* */
public synchronized void setClassName(String name, Object key){
if(classDataHM.containsKey(key)){
String oldName = ((ClassData)classDataHM.get(key)).name;
((ClassData)classDataHM.get(key)).name = name;
if (!oldName.equals(name))
save = true;
}
}
/**
* Returns type of the class linked to the specific key. Type of class is represented by
* an int number whose value is contained in <code>JSIMConstants</code>.
* */
public synchronized int getClassType(Object key){
if(classesKeyset.contains(key)){
return ((ClassData)classDataHM.get(key)).type;
}else return -1;
}
/**
* Sets type of the class linked to the specific key. Type of class is represented by
* an int number whose value is contained in <code>JSIMConstants</code>.
* */
public synchronized void setClassType(int type, Object key){
//Must check for class presence
ClassData cd;
if(classDataHM.containsKey(key)){
cd = ((ClassData)classDataHM.get(key));
}else return;
int classTypeInt = cd.type;
//if new type is different from the former one, population and distribution
//values are senseless, so they must be erased both
if(classTypeInt != type){
save = true;
cd.distribution = cd.population = null;
cd.type = type;
if(type == CLASS_TYPE_OPEN){
cd.distribution = Defaults.getAsNewInstance("classDistribution");
}else if(type == CLASS_TYPE_CLOSED){
cd.population = Defaults.getAsInteger("classPopulation");
cd.refSource = null;
}
}
}
/**
* Returns name of the class linked to the specific key
* */
public synchronized int getClassPriority(Object key){
if(classesKeyset.contains(key)){
return ((ClassData)classDataHM.get(key)).priority;
}else return -1;
}
/**
* Sets name of the class linked to the specific key
* */
public synchronized void setClassPriority(int priority, Object key){
if(classDataHM.containsKey(key)){
int oldPriority = ((ClassData)classDataHM.get(key)).priority;
((ClassData)classDataHM.get(key)).priority = priority;
if (oldPriority != priority)
save = true;
}
}
/**
* Returns population of the class linked to the specific key. Return value is an integer
* if specified class is a closed class, null, otherwise.
* */
public synchronized Integer getClassPopulation(Object key){
if(classDataHM.containsKey(key)){
return ((ClassData)classDataHM.get(key)).population;
}else return null;
}
/**
* Sets population of the class linked to the specific key
* */
public synchronized void setClassPopulation(Integer population, Object key){
ClassData cd;
if(classDataHM.containsKey(key)){
cd = (ClassData)classDataHM.get(key);
}else return;
if(cd.type == CLASS_TYPE_CLOSED) {
if (!cd.population.equals(population))
save = true;
cd.population = population;
}
else cd.population = null;
}
/**
* Returns inter-arrival time distribution of the class linked to the specific key.
* Return value is an object representing distribution if specified class is an open
* class, null otherwise.
* */
public synchronized Object getClassDistribution(Object key){
ClassData cd;
if(classDataHM.containsKey(key)){
cd = (ClassData)classDataHM.get(key);
}else return null;
return cd.distribution;
}
/**
* Sets inter-arrival time distribution of the class linked to the specific key
* */
public synchronized void setClassDistribution(Object distribution, Object key){
ClassData cd;
if(classDataHM.containsKey(key)){
cd = (ClassData)classDataHM.get(key);
}else return;
if(cd.type == CLASS_TYPE_OPEN) {
if (!cd.distribution.equals(distribution))
save= true;
cd.distribution = distribution;
}
else cd.population = null;
}
/**Returns a class parameter, given the class key of search, and the parameter name
* specified by proper code.*/
public synchronized Object getClassParameter(Object key, int parameterName){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -