basicsimulator.java
来自「Rakiura JFern是一个非常轻型的带有模拟器的Petri网络框架」· Java 代码 · 共 136 行
JAVA
136 行
// This is copyrighted source file, part of Rakiura JFern package. // See the file LICENSE for copyright information and the terms and conditions// for copying, distributing and modifications of Rakiura JFern package.// Copyright (C) 1999-2002 by Mariusz Nowostawski and others [http://www.rakiura.org]package org.rakiura.cpn;/**/import java.util.ArrayList;import java.util.Iterator;import java.util.List;/** * Basic implementation of the simulator. This is a very simple, * single threaded simulator. To use it, simply write: *<pre> * Net net = //obtain the reference to the net object * Simulator sim = new BasicSimulator(net); * // to run it in step mode, just use: * boolean enabledTransitions = true; * while (enabledTransitions) { * sim.step(); * // perform some analysis or * // user-interactions here * } * * //to run it continuously, use: * sim.run(); *<pre> * *<br><br> * BasicSimulator.java<br> * Created: Tue Sep 26 16:36:38 2000<br> * *@author <a href="mariusz@rakiura.org">Mariusz Nowostawski</a> *@version 2.1.0 $Revision: 1.6 $ *@since 1.0 */public class BasicSimulator implements Simulator { /** Handle to the net. */ private Net net; /** List of transitions. */ private List transitions; /** List of enabled bindings for a step. */ private List enabled; /** * Creates a new <code>BasicSimulator</code> instance. * @param aNet a <code>Net</code> value. */ public BasicSimulator(final Net aNet) { this.net = aNet; processNetStructure(); } /** * Runs a single step of the simulation. The first transition from * the enabled transitions will be picked (see {@link #occurrence}, * and fired. This method returns <code>true</code> if there are * still more enabled transitions, and <code>false</code> if there * is no more enabled transitions left. *@return a <code>boolean</code> value, <code>true</code> * if there are still more enabled transitions, and <code>false</code> * if there is no more enabled transitions left. */ public boolean step() { // initial evaluation of net inscriptions processNetStructure(); if (this.enabled.size() > 0) { ((Transition) this.enabled.get(0)).fire(); } // re-evaluation processNetStructure(); return (this.enabled.size() > 0); } /** * Runs the simulator in continuous mode. * It will step through the net until no transition * is enabled. This method implementation is equivalent * of <code> while (step()); </code> code. */ public void run() { while (step()) {} } /** * Returns the handle to the net. *@return a <code>Net</code> value */ public Net net() { return this.net; } /** * Returns the list of all enabled transitions. This method * returns all enabled transitions with the appropriate * marking for each of them. *@return a <code>List</code> of all enabled transitions. */ public List occurrence(){ return this.enabled; } /** * Prepares the net internal representation for simulation. */ private void processNetStructure(){ this.transitions = this.net.transitions(); this.enabled = enabledTransitionList(); } /** * Prepares the list of all enabled transitions. *@return a <code>List</code> value with enabled transitions. */ private List enabledTransitionList(){ final List list = new ArrayList(this.transitions.size()); final Iterator iter = this.transitions.iterator(); while (iter.hasNext()){ Transition trans = (Transition) iter.next(); if (trans.isEnabled()) { list.add(trans); } } return list; } } // BasicSimulator//////////////////// end of file ////////////////////
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?