All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jbpt.petri.untangling.AbstractUntanglingRun Maven / Gradle / Ivy

Go to download

The jBPT code library is a compendium of technologies that support research on design, execution, and evaluation of business processes.

The newest version!
package org.jbpt.petri.untangling;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.jbpt.petri.AbstractRun;
import org.jbpt.petri.IFlow;
import org.jbpt.petri.IMarking;
import org.jbpt.petri.INetSystem;
import org.jbpt.petri.INode;
import org.jbpt.petri.IPlace;
import org.jbpt.petri.IStep;
import org.jbpt.petri.ITransition;

@SuppressWarnings("serial")
public class AbstractUntanglingRun, N extends INode, P extends IPlace, T extends ITransition, M extends IMarking> 
		extends AbstractRun 
		implements IUntanglingRun
{
	public AbstractUntanglingRun() {
		super();
	}

	public AbstractUntanglingRun(INetSystem sys) {
		super(sys);
	}

	HashMap,Integer> s2p = new HashMap, Integer>();
	HashMap>> i2s = new HashMap>>();
	
	boolean isSignificant = true;
	
	class Interval {
		private int l;
	    private int r;
	    
	    public Interval(int l, int r){
	        this.l = l;
	        this.r = r;
	    }
	    
	    public int getL() { return l; }
	    public int getR() { return r; }
	    public void setL(int l) { this.l = l; }
	    public void setR(int r) { this.r = r; }
	    
	    @Override
		public String toString() {
			return "["+this.l+","+this.r+"]";
		}
	}
	
	@Override
	public boolean append(T transition) {
		boolean result = super.append(transition);
			
		if (result) {
			int last = this.size()-1;
			IStep step = this.get(last);
			Integer preLast = this.s2p.get(step);
			this.s2p.put(step,last);
			
			if (preLast!=null) {
				this.s2p.put(step,last);
				Interval interval = new Interval(preLast,last);
				
				Set> steps = new HashSet>();
				for (int i=interval.getL()+1; i>> entry : this.i2s.entrySet()) {
				entry.getValue().remove(step);
				
				if (entry.getValue().isEmpty())
					this.isSignificant = false;
			}
		}
		
		return result;
	}

	@Override
	public IStep remove(int arg0) {
		throw new UnsupportedOperationException("Cannot modify runs by adding steps at arbitrary position.");
	}

	@SuppressWarnings("unchecked")
	@Override
	public IUntanglingRun clone() {
		AbstractUntanglingRun run = null;
		try {
			run = AbstractUntanglingRun.class.newInstance();
		} catch (InstantiationException exception) {
			return null;
		} catch (IllegalAccessException exception) {
			return null;
		}
		
		run.initialMarking = (M) this.initialMarking.clone();
		run.currentMarking = (M) this.initialMarking.clone();
		run.sys = this.sys;
		run.possibleExtensions = new HashSet(run.sys.getEnabledTransitionsAtMarking(run.currentMarking));
		run.copyTransitions(this);
		
		return (IUntanglingRun) run;
	}

	@Override
	public void clear() {
		throw new UnsupportedOperationException("Cannot modify runs by adding steps at arbitrary position.");
	}

	@Override
	public boolean isSignificant() {
		return this.isSignificant;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy