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

📄 peparoni.java

📁 PEPA模型性能分析工具
💻 JAVA
字号:
package trans;

import gui.PepaConsole;
import gui.PepaPanel;
import matrix.Linbcg;
import matrix.Matrix;
import matrix.Sor;
import semantic.Action;
import semantic.ParserException;
import semantic.RateException;
import semantic.State;
import semantic.Symbol;
import semantic.Process;
import semantic.Activity;

public class Peparoni {
	private Process sysPro;
	public PQueue components;
	private NQueue model;
	public int volumn;
	private int size;
	private boolean isValidate;
	private Matrix modelmatrix;
	private Linbcg matrix;
	private Sor sorproblem;
	public static int itol=1;
    public static double tol = 1.0E-15;
    public static int itmax = 100;
    public int iter=0;
    public double err;
    public static boolean gmres = true;
    public static double omegadef = 1.0;
    public static int norm = 1;
    public int[] ija;
    private double[] sa;
	private double[] x;
	private double[] throughout;
	private long tick=0;
	private long tock=0;
	public static boolean isThroughout;
	public static Action selAct;
	
	public void pepaModel(String s)
	{
		isValidate=false;
		Lexer lexer=new Lexer(s);

		PepaConsole.addArgument("--开始检测模型语法定义...\n");
		
		Symbol sym=null;
		State transfer=new State();
		Parsing model=new Parsing(lexer,transfer);
		
		try {
			sym=model.parser();
			sysPro=(Process)sym.value;
			isValidate=true;
			PepaConsole.addArgument("--检测成功!\n");
		}catch (ParserException pe)
		{
				PepaConsole.addArgument("--"+pe.toString()+"\n");
		}
		catch(RateException re)
		{
				PepaConsole.addArgument("--"+re.toString()+"\n");
		}
		selAct=null;
		isThroughout=false;
	}
	public static void setSelectAct(String act)
	{
		if(act==null)
		{	selAct=null;
			isThroughout=false;
		}
		else
		{
			isThroughout=true;
			selAct=new Action(act);
		}
	}
	public void derive() throws RateException
	{
		if(isValidate)
		{
			double through=0.0;
			boolean deadlock=false;
			PepaPanel.clearStates();
			PepaPanel.clearSolution();
			PepaConsole.addArgument("--开始分析模型...\n");
			tick = System.currentTimeMillis();
			
			int loc1,loc2;
			int index=0;
			size=0;
			Process pro,pro1;
			Activity act;
			NPair pair;
			model=new NQueue();
			components=new PQueue();
			NQueue proexplore=new NQueue();
			NQueue driver=new NQueue();
			proexplore.push((Object)sysPro);
			components.put(sysPro);
			while(!proexplore.isEmpty())
			{
				pro=(Process)proexplore.pop();
				loc1=components.find(pro);
				PepaPanel.setStates(loc1+":\t"+pro.toString()+"\n");
				driver=pro.derivatives();
				if(driver.isEmpty())
				{
					if(deadlock!=true)
						PepaConsole.addArgument("--发现死锁状态:");
					deadlock=true;
					PepaConsole.addArgument(loc1+" ");
				}
				while(!driver.isEmpty())
				{
					pair=(NPair)driver.pop();
					size++;
					act=pair.fst;
					if(isThroughout)
					{
						if(selAct.equals(act))
							through+=act.getRate().fintValue();
					}
					pro1=pair.snd;
					index=components.Count();
					loc2=components.put(pro1);
					if(loc2>index)
					{
						proexplore.push((Object)pro1);
					}
					MPair mpair=new MPair(loc1,loc2,act.getRate());
					model.push((Object)mpair);
				}
				
			}
			volumn=components.Count();
			initialMatrix();
			
			tock = System.currentTimeMillis();

			if(!deadlock)
			{
				PepaConsole.addArgument("--模型分析成功!\n");
			}
			else
				PepaConsole.addArgument("\n");
			PepaConsole.addArgument("--状态空间维度为:"+volumn+"\n");
			PepaConsole.addArgument("--状态转移总数:"+size+"\n");
			PepaConsole.addArgument("--产生状态空间花费时间:"+computeTimeDifference(tick, tock)+"秒!\n");
			
		}
	}
	private void initialMatrix() throws RateException
	{
		size=1+volumn+1+size;
		modelmatrix=new Matrix(size,volumn);
		int pos=volumn+1;
		int index=pos+1;
		int x_pos_t,x_pos,y_pos;
		double r,d;
		MPair mpair;
		NQueue value=new NQueue();
		value.concat(model);
		
		x_pos_t=0;
		r=0.0;
		
		while(!value.isEmpty())
		{
			pos++;
			mpair=(MPair)value.pop();
			x_pos=mpair.getX();
			y_pos=mpair.getY();
			d=mpair.getValue();
			modelmatrix.setValue(pos,y_pos,d);
			if(x_pos!=x_pos_t)
			{
				if(x_pos_t!=0)
					modelmatrix.setValue(x_pos_t,index,r);
				r=-d;
				index=pos;
				x_pos_t=x_pos;
			}
			else
			{
				r-=d;
			}
		}
		modelmatrix.setValue(x_pos_t,index,r);
		modelmatrix.setValue(volumn+1,size,0.0);
		
		this.ija=modelmatrix.ija;
		this.sa=modelmatrix.sa;
		
		modelmatrix.Trans();
		
	}
	public void solve()
	{
		PepaConsole.addArgument("--开始进行稳态分析,请稍等...\n");
		PepaPanel.clearSolution();
		
		double[] b=new double[volumn+1];
		x=new double[volumn+1];
		b[volumn]=1.0;
		matrix=new Linbcg(modelmatrix.ija,modelmatrix.sa,volumn);
		
		tick = System.currentTimeMillis();
		
		matrix.solve(volumn, b, x, itol, tol, itmax, iter, err,gmres);
		
		tock = System.currentTimeMillis();
		PepaConsole.addArgument("--计算稳态概率花费的时间:"+computeTimeDifference(tick, tock)+"秒!\n");
		
		showResult();
		System.gc();
	}
	public void SORsolve()
	{
		PepaConsole.addArgument("--开始进行稳态分析,请稍等...\n");
		PepaPanel.clearSolution();
		
		double[] b=new double[volumn+1];
		x=new double[volumn+1];
		b[volumn]=1.0;
		sorproblem=new Sor(modelmatrix.ija,modelmatrix.sa);
		
		tick = System.currentTimeMillis();
		
		sorproblem.solve(volumn,b,x,omegadef,tol, itmax, iter,norm,err);
		
		tock = System.currentTimeMillis();
		PepaConsole.addArgument("--计算稳态概率花费的时间:"+computeTimeDifference(tick, tock)+"秒!\n");
		
		showResult();
		System.gc();
	}
	private void showResult()
	{
		for(int i=1;i<=volumn;i++)
		{
			PepaPanel.setSolution(i+":\t"+x[i]+"\n");
		}
	}
	private static double computeTimeDifference(long start, long end)
	{
        double s = (double) start;
        double e = (double) end;
        return (e-s)/1000;
    }
}

⌨️ 快捷键说明

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