📄 solversingleclosedmva.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
*/
/*
* SolverSingleClosedMVA.java
* Created on 13 novembre 2002, 10.48
*/
package jmt.analytical;
import jmt.engine.math.Printer;
/**
* Solves a single class closed model, using Aggregated Mean Value Analysis algorithm.
* @author Federico Granata, Stefano Omini
*/
public class SolverSingleClosedMVA extends Solver {
public static final boolean DEBUG = false;
//NEW
//Now SolverSingleClosedMVA extends Solver
//
//@author Stefano Omini
/**
* number of customers or jobs in the system
*/
protected int customers = 0;
//end NEW
//NEW
//Intermediate results
//@author stefano Omini
/**
* Tells whether intermediate results have been computed or not
*/
protected boolean intermediate_results = false;
/** array containing the throughput for each population and for each
* service center
* <br>[population][service center]
*/
protected double[][] interm_throughput;
/** array containing the utilization for each population and for each
* service center
* <br>[population][service center]
*/
protected double[][] interm_utilization;
/** array containing the queue length for each population and for each
* service center
* <br>[population][service center]
*/
protected double[][] interm_queueLen;
/** array containing the residence time for each population and for each
* service center (residence time = time spent in queue + time spent in service)
* <br>[population][service center]
*/
protected double[][] interm_residenceTime;
/** total throughput for each population */
protected double[] interm_totThroughput;
/** total response time for each population*/
protected double[] interm_totRespTime;
/** total number of users for each population*/
protected double[] interm_totUser;
//end NEW
/* ------------------------
Class variables
* ------------------------ */
private int[] position;//the original position of the station before the
//reordering
private int countLI; //number of LI & Delay stations
/* ------------------------
Constructor
* ------------------------ */
/**
* Creates a new instance of SolverSingleClosedMVA
* @param stat number of stations
* @param cust number of customers
*/
public SolverSingleClosedMVA(int cust, int stat) {
//OLD
//super(stat, cust);
//NEW
//old parameters were inverted!
//@author Stefano Omini
//OLD
//Unuseful: no longer extends SolverSingleClosedExact
//super(cust, stat);
stations = stat;
customers = cust;
name = new String[stat];
type = new int[stat];
//one service time for each possible population (from 1 to customers)
//position 0 is used for LI stations
servTime = new double[stat][];
visits = new double[stat];
throughput = new double[stat];
queueLen = new double[stat];
utilization = new double[stat];
residenceTime = new double[stat];
position = new int[stat];
//NEW
//@author Stefano Omini
//the structures with intermediate results are allocated only if
//requested
interm_throughput = null;
interm_utilization = null;
interm_queueLen = null;
interm_residenceTime = null;
interm_totThroughput = null;
interm_totRespTime = null;
interm_totUser = null;
//end NEW
}
/* ------------------------
Methods: initialization
* ------------------------ */
/** Initializes the solver with the system parameters.
* It must be called before trying to solve the model.
* <br>
* WARNING: This method changes the order of the stations (LI and DELAY before, LD after):
* the original order is restored only after calling the "solve" method
* (so if you solve the model, you don't need to reorder results,
* they are reordered by the "solve" method itself; otherwise, if you
* don't solve the model after calling "input" method, you may have some problems).
* @param n array of names of service centers.
* @param t array of the types (LD or LI) of service centers.
* @param s matrix of service times of the service centers.
* @param v array of visits to the service centers.
* @return true if the operation is completed with success
*/
public boolean input(String[] n, int[] t, double[][] s, double[] v) {
if ((n.length > stations) || (t.length > stations) || (s.length > stations) || (v.length > stations))
// wrong input.
return false;
//number of not LD stations
countLI = 0;
for (int i = 0; i < t.length; i++) {
if (t[i] != Solver.LD)
countLI++;
}
//OLD
//if (!(countLI != 0 || countLI != t.length)) {
//NEW
//@author Stefano Omini
if (!(countLI > 0 && countLI < t.length)) {
//end NEW
//TODO: controllare la nuova condizione
//stations are either only LI or only LD
for (int i = 0; i < stations; i++) {
position[i] = i;
//copy names, types and visits
name[i] = n[i];
type[i] = t[i];
visits[i] = v[i];
//copy service times
if (type[i] == Solver.LD) {
//LD
//an array of customers+1 elements is created
//the first element for LD center is set to 0)
//the others are the values for each population
servTime[i] = new double[customers + 1];
if (s[i].length != customers + 1)
return false;
for (int j = 0; j <= customers; j++) {
if (j == 0) {
servTime[i][j] = 0;
} else {
servTime[i][j] = s[i][j];
}
}
} else {
//LI
//only one element
servTime[i] = new double[1];
servTime[i][0] = s[i][0];
}
}
} else {
//there are both LI and LD stations: change the order
//LI stations are put first (i.e. from position 0 to position countLI-1)
//LD stations are put after all LI stations (i.e. from position count to the end)
int countLD = 0;
int countInserted = 0;
for (int i = 0; i < stations; i++) {
if (t[i] != Solver.LD) {
//LI + Delay
position[countInserted] = i;
name[countInserted] = n[i];
type[countInserted] = t[i];
visits[countInserted] = v[i];
servTime[countInserted] = new double[1];
servTime[countInserted][0] = s[i][0];
countInserted++;
} else {
//LD
position[countLI + countLD] = i;
name[countLI + countLD] = n[i];
type[countLI + countLD] = t[i];
visits[countLI + countLD] = v[i];
servTime[countLI + countLD] = new double[customers + 1];
if (s[i].length != customers + 1)
return false;
for (int j = 0; j <= customers; j++) {
if (j == 0) {
servTime[countLI + countLD][j] = 0;
} else {
servTime[countLI + countLD][j] = s[i][j];
}
}
countLD++;
}
}
}
return true;
}
/* ------------------------
Methods to solve the model with MVA
* ------------------------ */
//NEW
//@author Stefano Omini
/**
* A system is said to have sufficient capacity to process a given load
* <tt>lambda</tt> if no service center is saturated as a result of such a load.
* <br>
* WARNING: This method should be called before solving the system.
* @return true if sufficient capacity exists for the given workload, false otherwise
*/
public boolean hasSufficientProcessingCapacity() {
//closed class: no saturation problem
return true;
}
//end NEW
/*
public void indexes() {
//TODO: non implementato!!!!
}
//overrides indexes() of SolverSingleClosedExact
*/
/**
* Solves a single class closed model using MVA algorithm.<br>
* "input(...)" method must have been called before solving the model!!<br><br>
* Reference:<br>
* <em>
* G.Balbo, S.C.Bruell, L.Cerchio, D.Chiaberto, L.Molinatti<br>
* "Mean Value Analysis of Closed Load Dependent Networks"<br>
* </em>
*/
public void solve() {
//tests if all the resources, stations, are load independent
boolean loadIndep = true;
for (int i = 0; i < stations && loadIndep; i++) {
if (type[i] == Solver.LD)
loadIndep = false;
}
if (loadIndep) {
solveSingleLI();
//solveSingleLI_approx();
} else {
solveSingleLD();
//solveSingleLDErrCtr();
//solveSingleLDErrCtrFast();
//solveSingleLDErrCtrFaster();
//solveSingleLD2();
}
//"input" method has changed the order of the stations.
//this method has to be called to restore the original order.
reorder();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -