de.uni.freiburg.iig.telematik.sepia.util.PNRefinement Maven / Gradle / Ivy
Show all versions of SEPIA Show documentation
package de.uni.freiburg.iig.telematik.sepia.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import de.invation.code.toval.validate.ParameterException;
import de.uni.freiburg.iig.telematik.sepia.petrinet.abstr.AbstractFlowRelation;
import de.uni.freiburg.iig.telematik.sepia.petrinet.abstr.AbstractMarking;
import de.uni.freiburg.iig.telematik.sepia.petrinet.abstr.AbstractPetriNet;
import de.uni.freiburg.iig.telematik.sepia.petrinet.abstr.AbstractPlace;
import de.uni.freiburg.iig.telematik.sepia.petrinet.abstr.AbstractTransition;
/**
* This class provides methods for Petri net refinement.
* Refinement operations aim to reduce Petri nets in shape and structure without changing their behavior.
*
* @author Thomas Stocker
*
*/
public class PNRefinement {
/**
* This method removes redundant places from the given Petri net.
* A place is redundant when the net contains another place with exactly the same input and output transitions.
*
* @param net
* Petri net to refine.
*/
public static , T extends AbstractTransition, F extends AbstractFlowRelation, M extends AbstractMarking, S extends Object>
void
refine(AbstractPetriNet
net) {
List
placeList = new ArrayList
(net.getPlaces());
// Build equivalence classes of places having the same relations.
List> eqClasses = new ArrayList>();
try {
for (P place : placeList) {
boolean inserted = false;
for (List eqClass : eqClasses) {
if (eqClass.get(0).hasEqualRelations(place)) {
eqClass.add(place);
inserted = true;
break;
}
}
if (!inserted) {
eqClasses.add(new ArrayList
(Arrays.asList(place)));
}
}
// Find redundant places
// -> Each equivalence class that holds more than one element
// contains such places
placeList.clear();
for (List
eqClass : eqClasses) {
if (eqClass.size() > 1) {
placeList.addAll(eqClass.subList(1, eqClass.size()));
}
}
// Remove redundant places.
for (P place : placeList) {
net.removePlace(place.getName());
}
} catch (ParameterException e) {
// Cannot happen, since only places of the net itself are used in computation
e.printStackTrace();
}
}
}