gspn.java

来自「Petri网分析工具PIPE is open-source」· Java 代码 · 共 1,440 行 · 第 1/4 页

JAVA
1,440
字号
	 * for quantitative analysis.	 * @param DataLayer	 * 	 */	private boolean isEFCGSPN (DataLayer pnmlData) {		return extendedFreeChoiceNet(pnmlData);	}	//######################################################################################################################		/**Generate the reachability set using myTree function	 * Add each marking to an arraylist, testing to see if the	 * marking is already present before adding.	 * 	 *	 * @param DataLayer	 * @return	 */	private StateList getReachabilitySet (DataLayer pnmlData) throws TreeTooBigException {		int [][] fim = pnmlData.getForwardsIncidenceMatrix();		int [][] bim = pnmlData.getBackwardsIncidenceMatrix();		PNMatrix plus = new PNMatrix (fim);		PNMatrix minus = new PNMatrix(bim);		int[] marking = pnmlData.getCurrentMarkupMatrix();		int markSize = pnmlData.getPlaces().length;		StateList reachSetArray = new StateList();		myTree reachSet = new myTree(marking, plus, minus, reachSetArray, pnmlData);		return reachSetArray;	}//######################################################################################################################	/**Get the initial marking of the supplied net	 * 	 * @param pnmlData	 * @return	 */	private int[] getMarking(DataLayer pnmlData){				int places = pnmlData.getPlaces().length;		int[] marking = new int[places];		for (int i = 0; i <places; i++){			marking[i] = pnmlData.getPlace(i).getInitialMarking();		}		return marking;	}	//######################################################################################################################		/**Caluculate whether a transition is enabled given a specific marking	 * 	 * @param DataLayer - the net  	 * @param int[] - the marking	 * @param int - the specific transition to test for enabled status	 * @return boolean - an array of booleans specifying which transitions are enabled in the specified marking	 */	private boolean getTransitionEnabledStatus(DataLayer pnmlData, int[] marking, int transition) {		int transCount = pnmlData.getTransitions().length;		boolean[] result;		result = new boolean[transCount];		boolean answer;		int[][] CMinus = pnmlData.getBackwardsIncidenceMatrix();		int placeCount = pnmlData.getPlaces().length;				for (int k = 0; k < transCount; k++) { //initialise matrix to true			result[k] = true;		}		for (int i = 0; i <transCount;i++) {			for (int j = 0; j <placeCount; j++){				if (marking[j] < CMinus[j][i])					result[i] = false;			}		}		//print(result);		return result[transition];	}	//######################################################################################################################		/**Caluculate which transitions are enabled given a specific marking	 * 	 * @param DataLayer - the net  	 * @param int[] - the marking	 * @return boolean[] - an array of booleans specifying which transitions are enabled in the specified marking	 */	private boolean[] getTransitionEnabledStatusArray(DataLayer pnmlData, int[] marking) {		int transCount = pnmlData.getTransitions().length;		boolean[] result;		result = new boolean[transCount];		boolean hasTimed = false;		boolean hasImmediate = false;		int[][] CMinus = pnmlData.getBackwardsIncidenceMatrix();		int placeCount = pnmlData.getPlaces().length;		Transition[] transArray = pnmlData.getTransitions();				for (int k = 0; k < transCount; k++) { //initialise matrix to true			result[k] = true;		}		for (int i = 0; i <transCount;i++) {			for (int j = 0; j <placeCount; j++){				if (marking[j] < CMinus[j][i])					result[i] = false;			}		}		return result;	}//######################################################################################################################		private boolean[] getTangibleTransitionEnabledStatusArray(DataLayer pnmlData, int[] marking) {		int transCount = pnmlData.getTransitions().length;		boolean[] result;		result = new boolean[transCount];		boolean hasTimed = false;		boolean hasImmediate = false;		int[][] CMinus = pnmlData.getBackwardsIncidenceMatrix();		int placeCount = pnmlData.getPlaces().length;		Transition[] transArray = pnmlData.getTransitions();				for (int k = 0; k < transCount; k++) { //initialise matrix to true			result[k] = true;		}		for (int i = 0; i <transCount;i++) {			for (int j = 0; j <placeCount; j++){				if (marking[j] < CMinus[j][i])					result[i] = false;			}		}		for (int i = 0; i<transCount; i++) {			if (transArray[i].getTimed()==true){				hasTimed = true;			}			else {				hasImmediate = true;			}		}		if (hasTimed&&hasImmediate){			for (int i = 0; i<transCount; i++){				if (transArray[i].getTimed()==true){					result[i] = false;				}			}		}		//print(result);		return result;	}	//######################################################################################################################	/**Work out if a specified marking describes a tangible state.	 * A state is either tangible (all enabled transitions are timed)	 * or vanishing (there exists at least one enabled state that is transient, i.e. untimed).	 * If an immediate transition exists, it will automatically fire before a timed transition.	 * @param DataLayer - the net to be tested	 * @param int[] - the marking of the net to be tested	 * @return boolean - is it tangible or not	 */	private boolean isTangibleState(DataLayer pnmlData, int[] marking) {		Transition[] trans = pnmlData.getTransitions();		int numTrans = trans.length;		boolean hasTimed = false;		boolean hasImmediate = false;		for (int i = 0; i < numTrans; i++ ){			if (getTransitionEnabledStatus(pnmlData, marking, i) == true){				if (trans[i].getTimed()== true){  					//If any immediate transtions exist, the state is vanishing 					//as they will fire immediately				hasTimed = true;				}				else if (trans[i].getTimed()!= true) {					hasImmediate = true;				}			}		}		if (hasTimed == true && hasImmediate == false)			return true;		else		return false;	}//######################################################################################################################	/**This function takes a reachability set 	 * and splits it into subsets of tangible and vanishing states	 * @param DataLayer - the net to be processed	 * @param StateList - the entire reachability set	 * @param StateList - the list to be populated with vanishing states	 * @param StateList - the list to be populated with tangible states	 *	 */	private void getVanishingAndTangible(DataLayer pnmlData, StateList reachabilitySet, StateList vanishing, StateList tangible) {		int size = reachabilitySet.size();		for (int i = 0; i < size; i++) {			String id = reachabilitySet.getID(i);			if (isTangibleState(pnmlData, reachabilitySet.get(i))) 				tangible.add(reachabilitySet.get(i),id);			else				vanishing.add(reachabilitySet.get(i),id);			}	}	//######################################################################################################################	/**This function calculates the mean number of visits at a particular transition, given a particular embedded Markov Process	 * @param double[] - the embedded Markov Process	 * @return Matrix	 * 	 */	private Matrix calcMeanNumVisits (double[] embeddedMarkovProcess) {		int size = embeddedMarkovProcess.length;		Matrix result = new Matrix(size,size);		for (int i = 0; i<size; i++) {			for (int j = 0; j <size; j++){			result.set(i,j,embeddedMarkovProcess[i]/embeddedMarkovProcess[j]);				}		}		return result;	}//######################################################################################################################	/**This function determines the sojourn time for each state in a specified set of states.	 * @param DataLater - the net to be analysed	 * @param StateList - the list of tangible markings	 * @return double[] - the array of sojourn times for each specific state	 * 	 */	private double[] calcSojournTime (DataLayer pnmldata, StateList tangibleStates) {		int numStates = tangibleStates.size();		int numTrans = pnmldata.getTransitions().length;		Transition[] trans = pnmldata.getTransitions();		double[] sojournTime = new double[numStates];			for (int i = 0; i < numStates; i++) {		boolean[] transStatus = getTransitionEnabledStatusArray(pnmldata, tangibleStates.get(i));				double weights = 0;			for (int j = 0; j <numTrans; j++) {				if (transStatus[j] == true){					weights += trans[j].getRate();				}			}			sojournTime[i] = 1/weights;		}		return sojournTime;	}//######################################################################################################################			//This is an intemediate calculation used to determine steady state distributions for tangible states.	private double xHat(double[] piBar, double[] sojournTimes) {		int size = piBar.length;		double xHat = 0;		for (int i = 0; i< size; i++) {			xHat += (piBar[i] *sojournTimes[i]);		}		return xHat;	}	//######################################################################################################################	//This calculates the mean cycle times Tc(Mi) for tangible markings Mi	private double[] calcMeanCycleTimes (double[] embeddedMarkovChain, double xHat) {		int size = embeddedMarkovChain.length;		double[] meanCycleTimes = new double[size];		for (int i = 0; i < size; i++) {			meanCycleTimes[i] = xHat/embeddedMarkovChain[i];		}		return meanCycleTimes;			}//######################################################################################################################	private double[] getSteadyStateDistribution (double[] meanCycleTimes, double[] sojournTimes) {		int size = meanCycleTimes.length;		double[] steadyStateDistribution = new double[size];		for (int i = 0; i<size; i++){			steadyStateDistribution[i] = (sojournTimes[i]/meanCycleTimes[i]);		}		return steadyStateDistribution;	}	//######################################################################################################################	/**Test for condition Equal Conflict.  I.E., for all t1, t2	 * in the set of transitions, where t1<>t2, that share the same	 * input place, either t1, t2 are both in the set of timed transitions (T1)	 * or t1, t2 are both in the set of immediate transitions (T2).	 * 	 * @param DataLayer	 * @return boolean	 */	private boolean testEqualConflict (DataLayer pnmlData) {				Place[] places = pnmlData.getPlaces();		Arc[] arcs = pnmlData.getArcs();		Transition[] trans = pnmlData.getTransitions();		int arcsCount = arcs.length;		int placesCount = places.length;				for (int i = 0; i < placesCount ; i++)		{			boolean hasTimed = false;			boolean hasUntimed = false;			//get arcs with places[i] as source			for (int j = 0; j < arcsCount; j++)			{					if (arcs[j].getSource()==places[i]){					PlaceTransitionObject targ = arcs[j].getTarget();					if (((Transition)targ).getTimed() == true) {							hasTimed = true;					} else {					hasUntimed = true;					}				}			if (hasTimed== true && hasUntimed == true)				return false;			}		}		return true;	}	//######################################################################################################################	/**Calculate the probability of changing from one marking to another	 * Works out the intersection of transitions enabled to fire at a particular	 * marking, transitions that can be reached from a particular marking and the 	 * intersection of the two.  Then sums the firing rates of the intersection	 * and divides it by the sum of the firing rates of the enabled transitions.	 * @param DataLayer  	 * @param int[] - marking1	 * @param int[] - marking2	 * @return double - the probability	 */		private double probMarkingAToMarkingB(DataLayer pnmlData, int[] marking1, int[] marking2){			int markSize = marking1.length;		int[][] incidenceMatrix = pnmlData.getIncidenceMatrix();		int transCount = pnmlData.getTransitions().length;		boolean[] marking1EnabledTransitions = new boolean[transCount];// = getTransitionEnabledStatus(pnmlData, marking1); //get list of transitions enabled at marking1		boolean[] matchingTransition = new boolean[transCount];		for (int i = 0; i <transCount; i++) {		marking1EnabledTransitions[i] = getTransitionEnabledStatus(pnmlData, marking1, i);		}				//**************************************************** *************************************************		for (int j = 0; j <transCount; j ++) {			matchingTransition[j] = true;  //initialise matrix of potential transition values to true		}		//*****************************************************************************************************		//get transition needed to fire to get from marking1 to marking2		for (int i = 0; i < transCount; i++) {			for (int k = 0; k <markSize; k++) {			//if the sum of the incidence matrix and marking 1 doesn't equal marking 2, 			//set that candidate transition possibility to be false 				if (((int)marking1[k] + (int)incidenceMatrix[k][i])!= (int)marking2[k]){					matchingTransition[i] = false;					}			}		}		//if the state is tangible, all transitions will be timed, 		//so all can be considered in the probability calculation.		//Otherwise, reset the enabled status of timed transitions to false, as immediate transitions		//will always fire first.				if (isTangibleState(pnmlData, marking1)== false) { 			for (int i = 0; i <transCount; i++) {				if (pnmlData.getTransitions()[i].getTimed() == true) {					marking1EnabledTransitions[i] = false;				}			}		}		//*****************************************************************************************************

⌨️ 快捷键说明

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