📄 commonmodel.java
字号:
* Gets preloaded jobs on a given station for given class
* @param stationKey search's key for station
* @param classKey search's key for class
* @return preloaded jobs
* Author: Bertoli Marco
*/
public Integer getPreloadedJobs(Object stationKey, Object classKey) {
StationClassData current =
(StationClassData)stationDetailsBDM.get(classKey, stationKey);
if(current!=null){
return current.preload;
}else return null;
}
/**
* Returns number of jobs totally allocated for specified class.
* @param classKey class jobs to be preloaded belong to.
* @return umber of jobs totally to be preloaded.
*/
public synchronized Integer getPreloadedJobsNumber(Object classKey) {
int foundJob = 0;
for (int i=0; i < stationsKeyset.size(); i++)
foundJob += this.getPreloadedJobs(stationsKeyset.get(i), classKey).intValue();
return new Integer(foundJob);
}
public boolean getUseRandomSeed() {
return useRandomSeed;
}
public void setUseRandomSeed(boolean value) {
if (useRandomSeed != value)
save = true;
this.useRandomSeed = value;
}
public void setSimulationSeed(Long seed) {
if (!this.seed.equals(seed))
save = true;
this.seed = seed;
}
public Long getSimulationSeed() {
return seed;
}
public void setMaximumDuration(Double durationSeconds) {
if (!this.maxDuration.equals(durationSeconds))
save = true;
this.maxDuration = durationSeconds;
}
public Double getMaximumDuration() {
return maxDuration;
}
/**
* Gets polling interval for temporary measures
* @return polling interval for temporary measures
*/
public double getPollingInterval() {
return pollingInterval;
}
/**
* Sets polling interval for temporary measures
* @param pollingInterval polling interval for temporary measures
*/
public void setPollingInterval(double pollingInterval) {
if (this.pollingInterval != pollingInterval)
save = true;
this.pollingInterval = pollingInterval;
}
/**
* Sets maximum number of simulation samples
*
* @param maxSamples maximum number of simulation samples
*/
public void setMaxSimulationSamples(Integer maxSamples) {
if (!this.maxSamples.equals(maxSamples))
save = true;
this.maxSamples = maxSamples;
}
/**
* Returns maximum number of simulation samples
*
* @return maximum number of simulation samples
*/
public Integer getMaxSimulationSamples() {
return maxSamples;
}
/**
* Tells if statistic check was disabled as simulation stopping criteria
* @return the disableStatistic
*/
public Boolean getDisableStatistic() {
return disableStatistic;
}
/**
* Sets if statistic check was disabled as simulation stopping criteria
* @param disableStatistic the disableStatistic to set
*/
public void setDisableStatistic(Boolean disableStatistic) {
this.disableStatistic = disableStatistic;
}
/**
* This method is used to manage number of jobs for a given class. If class is closed
* all spare jobs will be allocated to its reference source (if it's not in a
* blocking region, otherwise a different station is chosen), if for some reasons more
* jobs are allocated than max population, they are reduced.
* @param classKey search's key for class to be considered
* Author: Bertoli Marco
*/
public synchronized void manageJobs(Object classKey) {
if (this.getClassType(classKey) == CLASS_TYPE_CLOSED) {
int population = this.getClassPopulation(classKey).intValue();
int foundJob = getPreloadedJobsNumber(classKey).intValue();
if (population > foundJob) {
Object chosenStation = this.getClassRefStation(classKey);
if (chosenStation == null)
return;
// If refStation is in a blocking region, chose the station outside the region with more jobs
// (as reference station cannot be preloaded)
if (getStationBlockingRegion(chosenStation) != null) {
int preloadMax = -1;
for (int i=0; i<stationsKeyset.size(); i++) {
Object key = stationsKeyset.get(i);
if (getStationBlockingRegion(key) == null &&
getPreloadedJobs(key, classKey).intValue() > preloadMax) {
preloadMax = getPreloadedJobs(key, classKey).intValue();
chosenStation = key;
}
}
}
// Increments amount of jobs in chosen station to cover all spare one
int allocate = population - foundJob + this.getPreloadedJobs(chosenStation, classKey).intValue();
this.setPreloadedJobs(new Integer(allocate), chosenStation, classKey);
}
else if (population < foundJob)
// Removes jobs from stations until allocated jobs = population
for (int i=0; i<stationsKeyset.size() && population < foundJob; i++) {
int jobs = this.getPreloadedJobs(stationsKeyset.get(i), classKey).intValue();
if (jobs <= foundJob - population) {
this.setPreloadedJobs(new Integer(0), stationsKeyset.get(i), classKey);
foundJob -= jobs;
}
else {
this.setPreloadedJobs(new Integer(jobs - (foundJob - population)), stationsKeyset.get(i), classKey);
break;
}
}
}
}
/**
* This method is used to manage number of jobs for every class. If class is closed
* all spare jobs will be allocated to its reference source, if for some reasons more
* jobs are allocated than max population, they are reduced. Uses this method only
* when strictly necessary as is can be slow if the model is big.
* Author: Bertoli Marco
*/
public void manageJobs() {
for (int i=0; i<classesKeyset.size(); i++)
manageJobs(classesKeyset.get(i));
}
// --- Methods to manage simulation results -- Bertoli Marco --------------------------------------------
/**
* Returns last simulation results
* @return simulation results or null if no simulation was performed
*/
public MeasureDefinition getSimulationResults() {
return results;
}
/**
* Sets simulation results
* @param results simulation results data structure
*/
public void setSimulationResults (MeasureDefinition results) {
this.results = results;
save = true;
}
/**
* Tells if current model contains simulation results
* @return true iff <code>getSimulationResults()</code> returns a non-null object
*/
public boolean containsSimulationResults() {
return (results != null);
}
//Francesco D'Aquino ----------------------
/**
* Return true if queue animation is enabled
*
* @return true if the animation is enabled
*/
public boolean isAnimationEnabled() {
return false;
}
/**
* Enable or disable queue animation
*
* @param isEnabled - set it to true to enable queue animation
*/
public void setAnimationEnabled(boolean isEnabled) {
}
/**
* Checks if the parametric analysis has been enabled
*
* @return true if the parametric analysis has been enabled
*/
public boolean isParametricAnalysisEnabled() {
return parametricAnalysisEnabled;
}
/**
* Enable / disable parametric analysis
* @param enabled
*/
public void setParametricAnalysisEnabled(boolean enabled) {
if (parametricAnalysisEnabled != enabled)
save = true;
parametricAnalysisEnabled = enabled;
}
/**
* Sets the parametric analysis definition
*
* @param pad the parametric analysis definition to be set
*/
public void setParametricAnalysisModel(ParametricAnalysisDefinition pad) {
parametricAnalysisModel = pad;
}
/**
* Tells model that some data has been changed and need to be saved. This
* is used by Parametric Analysis
*/
public void setSaveChanged() {
save = true;
}
/**
* Gets the ParametricAnalysisModel. If parametric analysis is not enabled
* the returned value may be not meaningful.
* @return the parametricAnalysisModel
*/
public ParametricAnalysisDefinition getParametricAnalysisModel() {
return parametricAnalysisModel;
}
/**
* Returns the class key given its name. It returns <code>null</code>
* if no such class is found.
* @param className the name of the class
* @return the key of the class whose name is <code>className</code>
*/
public Object getClassByName(String className) {
for (int i=0; i<classesKeyset.size(); i++) {
Object thisClass = classesKeyset.get(i);
if (getClassName(thisClass).equals(className))
return thisClass;
}
return null;
}
/**
* Returns the key of the station whose name is <code>stationName</code>. It
* returns <code>null</code> if no such station is found.
* @param stationName the name of the station
* @return the key of the station
*/
public Object getStationByName(String stationName) {
for (int i=0; i<stationsKeyset.size(); i++) {
Object thisStation = stationsKeyset.get(i);
if (getStationName(thisStation).equals(stationName))
return thisStation;
}
return null;
}
// end Francesco D'Aquino ------------------------------
// ------------------------------------------------------------------------------------------------------
// --- Blocking Region Definition --- Bertoli Marco ----------------------------------------------
/**
* Adds a new blocking region to the model
*
* @param name name of new blocking region
* @param type type of new blocking region
* @return search's key for new blocking region
*/
public Object addBlockingRegion(String name, String type) {
Object key = new Long(++incrementalKey);
//If this blocking region has already been created, don't add search key to the list.
if(!blockingRegionsKeyset.contains(key))
blockingRegionsKeyset.add(key);
BlockingRegionData newBlocking = new BlockingRegionData(name,
type,
Defaults.getAsInteger("blockingMaxJobs")
);
blockingDataHM.put(key, newBlocking);
// Adds region-class specific data
addBlockingDetails(key);
save = true;
return key;
}
/**
* Removes a blocking region from the model
*
* @param key Search's key for region to be deleted
*/
public void deleteBlockingRegion(Object key) {
if(blockingRegionsKeyset.contains(key)){
BlockingRegionData bd = (BlockingRegionData) blockingDataHM.remove(key);
// Removes blocking region from station reference
Iterator it =bd.stations.iterator();
while (it.hasNext()) {
Object stationKey = it.next();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -