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

📄 solvermulti.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**    
  * 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.analytical;

import jmt.engine.math.Printer;

import java.io.PrintWriter;

/**
 * SolverMulti is an abstract class, which contains the methods
 * initialize and solve multiclass models.
 * @author Federico Granata, Stefano Omini

 */
public abstract class SolverMulti {

    /**---------------CONSTANTS DEFINITION------------------------*/

    //NEW
    //before modifying this class, these constants were imported from single class solver
    //@author Stefano Omini

    /** constant for Load Dependent service center  */
	public final static int LD = 0;

	/** constant for Load Independent service center  */
	public final static int LI = 1;

	/** constant for delay center*/
	public final static int DELAY = 2;

    //end NEW

    /** constant for Open Class */
    public final static int OPEN_CLASS = 0;

	/** constant for Closed Class  */
    public final static int CLOSED_CLASS = 1;

    /**---------------MODEL DEFINITION------------------------*/

	/** number of service centers */
    protected int stations = 0;

	/** number of classes  */
    protected int classes = 0;

	/** array of names of service centers*/
    protected String[] name;

	/** array of types of service centers */
    protected int[] type;

	/** service times for each service station, class, population<br>
     * [station] [class] [population] */
    protected double[][][] servTime;

	/** visits for each service station, class<br>
     * [station] [class] */
    protected double[][] visits;


    /**---------------MODEL SOLUTION------------------------*/

	/** throughput for each service station, class<br>
     * [station] [class] */
    protected double[][] throughput;

	/** utilization for each service station, class<br>
     * [station] [class] */
    protected double[][] utilization;

	/** queue lenght for each service station, class<br>
     * [station] [class] */
    protected double[][] queueLen;

	/** residence time for each service station, class<br>
     * [station] [class] */
    protected double[][] residenceTime;

	/** throughputs of the service centers<br>
     *  [station] */
    protected double[] scThroughput;

	/** utilization of the service centers<br>
     *  [station] */
    protected double[] scUtilization;

	/** queue lenght of the service centers<br>
     *  [station] */
    protected double[] scQueueLen;

	/** residence time of the service centers<br>
     *  [station] */
    protected double[] scResidTime;

	/** response time for each class<br>
     * [class] */
    protected double[] clsRespTime;

	/** throughput for each class<br>
     * [class] */
    protected double[] clsThroughput;

	/** average number of users for each class<br>
     * [class] */
    protected double[] clsNumJobs;

	/** System response time  */
    protected double sysResponseTime = 0;

	/** System throughput */
    protected double sysThroughput = 0;

	/** Number of jobs in the system */
    protected double sysNumJobs = 0;



	/** Printer writer: print formatted representations of objects to a text-output stream */
    protected PrintWriter pw = new PrintWriter(System.out, true);


    /**
     * Creates a multiclasss solver
     * @param classes number of classes.
     * @param stations number of stations.
     */
	public SolverMulti(int classes, int stations) {
		this.classes = classes;
		this.stations = stations;
		name = new String[stations];
		type = new int[stations];
		servTime = new double[stations][classes][];
        visits = new double[stations][classes];

        throughput = new double[stations][classes];
		queueLen = new double[stations][classes];
		utilization = new double[stations][classes];
		residenceTime = new double[stations][classes];

        scThroughput = new double[stations];
		scUtilization = new double[stations];
		scQueueLen = new double[stations];
		scResidTime = new double[stations];

        clsRespTime = new double[classes];
		clsThroughput = new double[classes];
		clsNumJobs = new double[classes];
	}

	/** Initializes the Multiclass solver with the model parameters.
	 *  @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 time of the service centers.
	 *  @param  v   matrix 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))
			return false; // wrong input.

        System.arraycopy(n, 0, name, 0, stations);
		System.arraycopy(t, 0, type, 0, stations);

        for (int i = 0; i < stations; i++) {

            System.arraycopy(v[i], 0, visits[i], 0, classes);

            for (int j = 0; j < classes; j++) {
				if (t[i] != LD)
					servTime[i][j] = new double[1];
				System.arraycopy(s[i][j], 0, servTime[i][j], 0, s[i][j].length);
			}
		}
		return true;
	}


    /**
     * Must be implemented to create a multi class model solver.
     */
	public abstract void solve();


    //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 the combined loads
     * of all the classes.
     * <br>
     * Must be implemented to create a multi class model solver.
     * <br>
     * WARNING: This method should be called before solving the system.
     * @return true if sufficient capacity exists for the given workload, false otherwise
     *
     *
     */
	public abstract boolean hasSufficientProcessingCapacity();

    //end NEW



	/** Returns the throughput of the given class for the requested station
	 *  @param  cent    the number of the service center
	 *  @param  cls    the customer class
	 *  @return the throughput
	 */
	public double getThroughput(int cent, int cls) {
		return throughput[cent][cls];
	}

	/**
	 * Returns the throughput of each class for each station
     * @return the throughput[center][class] matrix for the system
	 */
	public double[][] getThroughput() {
		return throughput;
	}

	/** Returns the utilization of the given class for the requested station
	 *  @param  cent    the number of the service center
	 *  @param  cls    the customer class
	 *  @return the utilization
	 */
	public double getUtilization(int cent, int cls) {
		return utilization[cent][cls];
	}

	/**
     * Returns the throughput of each class for each station
	 *  @return the utilization[center][class] matrix for the system
	 */
	public double[][] getUtilization() {
		return utilization;
	}


	/** Returns the queue length of the given class for the requested station
	 *  @param  cent    the number of the service center
	 *  @param  cls    the custumer class
	 *  @return the queue length
	 */
	public double getQueueLen(int cent, int cls) {
		return queueLen[cent][cls];
	}

	/**
     *  Returns the queue lenght of each class for each station

⌨️ 快捷键说明

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