⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 solversingleclosedmva.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	}



    /**
	 * Solves a single class closed model using MVA algorithm.<br>
     *
     * "input(...)" method must have been called before solving the model!!<br><br>
	 *
	 * To solve a closed model with N customers, all the models with
     * 0, 1, 2, ... N-1 customers must be solved before.
     * This method allows to save the results for these intermediate models.
     *
     * 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>
     *
     * @param intermediate true to save results for intermediate populations
	 */
	public void solve(boolean intermediate) {
		//tests if all the stations are load independent
		boolean loadIndep = true;
		for (int i = 0; i < stations && loadIndep; i++) {
			if (type[i] == Solver.LD)
				loadIndep = false;
		}

        //this var is used by "toString" method: if true, also intermediate
        //results will be written
        intermediate_results = intermediate;

		if (loadIndep) {
			solveSingleLI(intermediate);
		} else {
            //TODO: aggiungere caso intermediate=true per LD (dopo averlo implementato!!)

            //TODO: debug
            solveSingleLD(intermediate);
            //solveSingleLDErrCtrFaster(intermediate);
		}

		reorder();


	}




	/** Solves a single class closed model with only LI stations */
	private void solveSingleLI() {
		int k;//index of station
		int n;//index of customer
		double sum;

		//service demands: D = visits * servTime
        double[] D = new double[stations];

		//put all queue length to 0 for n = 0 customers in the network
		for (k = 0; k < stations; k++) {
			queueLen[k] = 0.0;
			D[k] = servTime[k][0] * visits[k];//uses D = S * V to speed up
		}

		//calculation of throughput for the whole network and of queue length for each station
		//recursively starting from 0 customer in network to max customers
		for (n = 1; n <= customers; n++) {
			sum = 0.0;

            for (k = 0; k < stations; k++) {
				switch (type[k]) {
                    case Solver.DELAY:
						residenceTime[k] = D[k];
						break;
					case Solver.LI:
						//recursion uses the queue length of the model with n-1 customers
                        residenceTime[k] = D[k] * (1 + queueLen[k]);
						break;
					case Solver.LD://not supported use another method
						throw new IllegalArgumentException("error in solveSingleLI, type of service centers must be delay or load Independent");
				}//end case

				sum += residenceTime[k];
			}//end loop through stations

            //OLD
            //totThroughput = n / sum;
            //NEW
            //@author Stefano Omini
            if (sum == 0) {
                //D = 0 --> v = 0
                totThroughput = 0;
            } else {
                totThroughput = n / sum;
            }


            //end NEW

			for (k = 0; k < stations; k++)
				queueLen[k] = totThroughput * residenceTime[k];
			//end loop through stations

		}//end loop through customers

		//the other indexes dependent on totThroughput
		for (k = 0; k < stations; k++) {
			throughput[k] = totThroughput * visits[k];
			totRespTime = customers / totThroughput;
			utilization[k] = totThroughput * D[k];
		}//end loop through stations

	}//end of solveSingleLI




    /** Solves a single class closed model with only LI stations, using
     * an approximated technique (which avoids recursion)
     *
     * @author Stefano Omini */
    //TODO: non funziona ancora tanto bene, in particolare alcuni valori di residence e queue sembrano poco precisi
	private void solveSingleLI_approx() {
		int k;//index of station
		int n;//index of customer
		double sum;

        double[] old_queueLen = new double[stations];

		//service demands: D = visits * servTime
        double[] D = new double[stations];

		//put all queue length to 0 for n = 0 customers in the network
		for (k = 0; k < stations; k++) {
			old_queueLen[k] = customers / stations;
            queueLen[k] = 0.0;
			D[k] = servTime[k][0] * visits[k];//uses D = S * V to speed up
		}

		//calculation of throughput for the whole network and of queue length for each station
		//recursively starting from 0 customer in network to max customers

        boolean finished = false; //true, when the specified precision has been reached

        do {
			sum = 0.0;

            for (k = 0; k < stations; k++) {
    			switch (type[k]) {
                    case Solver.DELAY:
						residenceTime[k] = D[k];
						break;
					case Solver.LI:
                        //approximate technique doesn't use recursion!!
                        residenceTime[k] = D[k] * customers * old_queueLen[k] / ( customers - 1 );;
						break;
				}//end case

				sum += residenceTime[k];
			}//end loop through stations

            totThroughput = customers / sum;
            int counter = 0;

			for (k = 0; k < stations; k++) {
				queueLen[k] = totThroughput * residenceTime[k];

                if ((Math.abs(queueLen[k] - old_queueLen[k])) < 0.0000001 )
                    counter++;
            }
			//end loop through stations

            if (counter == stations) {
                finished = true;
            }

            for (k = 0; k < stations; k++) {
				 old_queueLen[k] = queueLen[k];
            }

		} while (!finished);

		//the other indexes dependent on totThroughput
		for (k = 0; k < stations; k++) {
			throughput[k] = totThroughput * visits[k];
			totRespTime = customers / totThroughput;
			utilization[k] = totThroughput * D[k];
		}//end loop through stations

	}//end of solveSingleLI



    //NEW
    //@author Stefano Omini

    /**
     * Solves a single class closed model with only LI stations.
     * To solve a closed model with N customers, all the models with
     * 0, 1, 2, ... N-1 customers must be solved before.
     * This method allows to save the results for these intermediate models.
     * @param intermediate true to save results for intermediate populations
     *
     */
	private void solveSingleLI(boolean intermediate) {

        if (!intermediate) {
            //intermediate results mustn't be saved, then use
            //the base method
            solveSingleLI();
            return;
        }

        //create structures with intermediate results

        interm_throughput = new double[customers + 1][stations];
		interm_queueLen = new double[customers + 1][stations];
		interm_utilization = new double[customers + 1][stations];
		interm_residenceTime = new double[customers + 1][stations];

        interm_totThroughput = new double[customers + 1];
        interm_totRespTime = new double[customers + 1];
        interm_totUser = new double[customers + 1];

        int k;//index of station
		int n;//index of customer
		double sum;

		//service demands: D = visits * servTime
        double[] D = new double[stations];

		//put all queue length to 0 for n = 0 customers in the network
		for (k = 0; k < stations; k++) {

            //intermediate results: population = n = 0;
            interm_queueLen[0][k] = 0.0;
            interm_residenceTime[0][k] = 0.0;
            interm_throughput[0][k] = 0.0;
            interm_utilization[0][k] = 0.0;

            interm_totThroughput[0] = 0;
            interm_totRespTime[0] = 0;
            interm_totUser[0] = 0;

			D[k] = servTime[k][0] * visits[k];//uses D = S * V to speed up
		}

		//calculation of throughput for the whole network and of queue length for each station
		//recursively starting from 0 customer in network to max customers
        //intermediate results are saved
		for (n = 1; n <= customers; n++) {
			sum = 0.0;

            for (k = 0; k < stations; k++) {
				switch (type[k]) {
                    case Solver.DELAY:
						interm_residenceTime[n][k] = D[k];
						break;
					case Solver.LI:
						//recursion uses the queue length of the model with n-1 customers
                        interm_residenceTime[n][k] = D[k] * (1 + interm_queueLen[n-1][k]);
						break;
					case Solver.LD://not supported use another method
						throw new IllegalArgumentException("error in solveSingleLI, type of service centers must be delay or load Independent");
				}//end case

				sum += interm_residenceTime[n][k];
			}//end loop through stations

            interm_totThroughput[n] = n / sum;

            interm_totUser[n] = 0;

			for (k = 0; k < stations; k++){
				interm_queueLen[n][k] = interm_totThroughput[n] * interm_residenceTime[n][k];
                interm_throughput[n][k] = interm_totThroughput[n] * visits[k];
                interm_utilization[n][k] = interm_totThroughput[n] * D[k];

                interm_totRespTime[n] = customers / interm_totThroughput[n];
                interm_totUser[n] += interm_queueLen[n][k]; //of course must be equals to n
            }
			//end loop through stations

		}//end loop through customers


        //copy final results from last intermediate results (n=customers)
        //into the usual structure
        for (k = 0; k < stations; k++) {

            queueLen[k] = interm_queueLen[customers][k];
            residenceTime[k] = interm_residenceTime[customers][k];
            throughput[k] = interm_throughput[customers][k];
            utilization[k] = interm_utilization[customers][k];
        }
        totThroughput = interm_totThroughput[customers];
        totRespTime = interm_totRespTime[customers];
        totUser = interm_totUser[customers];

    }//end of solveSingleLI

    //end NEW
    //@author Stefano Omini


    /**
     * Solves a model with LI and LD stations
     */
	private void solveSingleLD() {
		int stat;//index of station
		int cust;//index of customer
		int k;//index of customers, in marginal probability
//		int sum;//internal variable for summations
		double[] X = new double[customers + 1];//throughput of subsystem

		//queue length vectors of precedent subsystem
		double[][] nsPrec = new double[stations][customers + 1];
		//queue length vectors of actual subsystem
		double[][] nsCorr = new double[stations][customers + 1];
		//utilization vectors of precedent subsystem
		double[][] usPrec = new double[stations][customers + 1];
		//utilization vectors of actual subsystem
		double[][] usCorr = new double[stations][customers + 1];

		//maginal probability of precedent subsystem
		double[] pPrec = new double[customers + 1];
		//marginal probability of current subsystem
		double[] pCorr = new double[customers + 1];

		double[] Y = new double[customers + 1];// 1/throughput of composite system
		double ws;//waiting time
		double wcomp;//composite waiting time
//		double prod;//internal variable


/*      OLD

		//loop over all stations, transform all stations in load dependent
		//it's not efficient must be changed
		for (stat = 0; stat < stations; stat++) {
			if (type[stat] != Solver.LD) {
				wcomp = servTime[stat][0];
				if (type[stat] == Solver.DELAY) {
					for (cust = 1; cust <= customers; cust++)
						//TODO: attenzione, qui va in out of bound, non c'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -