Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCAT Module #82

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pipe-gui/src/main/java/pipe/gui/plugin/concrete/RCATModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pipe.gui.plugin.concrete;

import pipe.gui.widget.RCATForm;
import pipe.gui.plugin.GuiModule;
import uk.ac.imperial.pipe.models.petrinet.PetriNet;

import javax.swing.*;
import java.awt.*;

/**
* RCAT Module that is dynamically loaded into the GUI
*/
public class RCATModule implements GuiModule{
/**
* Starts the RCAT module
* @param petriNet current Petri net to use
*/
@Override
public void start(PetriNet petriNet) {
JFrame frame = new JFrame("RCAT for Stochastic Petri Nets");
FileDialog selector = new FileDialog(frame, "Select petri net", FileDialog.LOAD);
frame.setContentPane(new RCATForm(petriNet, selector).getPrimPanel());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}

/**
*
* @return RCAT Module
*/
@Override
public String getName() {
return "RCAT for Stochastic Petri Nets";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,12 @@ private void nameTextFieldFocusLost(java.awt.event.FocusEvent evt) {

public void createEditorWindow(String token) {
Window window = SwingUtilities.getWindowAncestor(rootPane);
EscapableDialog guiDialog = new EscapableDialog(window, "PIPE2", true);
EscapableDialog guiDialog = new EscapableDialog(window, "PIPE5", true);
ArcFunctionEditor feditor =
new ArcFunctionEditor(this, guiDialog, petriNetController.getPetriNet(), arcController, token);
guiDialog.add(feditor);
guiDialog.setSize(270, 230);
guiDialog.setVisible(true);
guiDialog.dispose();
}

public void setWeight(String func, String id) {
Expand Down
7 changes: 4 additions & 3 deletions pipe-gui/src/main/java/pipe/gui/widgets/PlaceEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ private boolean canSetCapacity() {
*
* @return the capacity spinner value
*/
private Double getCapacitySpinnerValue() {
return (Double) capacitySpinner.getValue();
private int getCapacitySpinnerValue() {
return (int) capacitySpinner.getValue();
}

/**
Expand Down Expand Up @@ -484,7 +484,8 @@ private void cancelButtonHandler(java.awt.event.ActionEvent evt) {
* @param evt
*/
private void capacitySpinnerStateChanged(javax.swing.event.ChangeEvent evt) {
Double capacity = (Double) capacitySpinner.getValue();

int capacity = (int) capacitySpinner.getValue();
setCapacityVisible(capacity);
}

Expand Down
2 changes: 1 addition & 1 deletion pipe-gui/src/main/java/pipe/views/ArcView.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private void addIntermediatePoints() {
for (ArcPoint arcPoint : model.getArcPoints()) {
if (!arcPath.contains(arcPoint)) {
arcPath.insertIntermediatePoint(arcPoint, index);
index++;
}
index++;
}
}

Expand Down
133 changes: 133 additions & 0 deletions pipe-module-gui/src/main/java/pipe/gui/rcat/BuildingBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package pipe.gui.rcat;

import uk.ac.imperial.pipe.models.petrinet.*;

import java.text.AttributedString;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;

/**
* Class for generating Building Blocks - a set of Places and Transitions
* such that for every input transition there exists an output transition.
*
* @author Tanvi Potdar
*/
public class BuildingBlock {
/**
* collection of places in the building block
*/
private Collection<Place> places;
/**
* collection of transitions in the building block
*/
private Collection<Transition> transitions;
/**
* symbolic input transition rates stored as strings
*/
private Map<Transition,String> inputRates;
/**
* symbolic output transition rates stored as strings
*/
private Map<Transition,String> outputRates;


/**
* constructor for the building block
* @param places
* @param transitions
*/
public BuildingBlock(Collection<Place> places, Collection<Transition> transitions){
this.places = places;
this.transitions = transitions;
}

/**
* gets the places in the building block
* @return places
*/
public Collection<Place> getPlaces() {
return places;
}

/**
* sets the places in the building block to the collection provided
* @param places
*/
public void setPlaces(Collection<Place> places) {
this.places = places;
}

/**
* gets the transitions in the building block
* @return transitions
*/
public Collection<Transition> getTransitions() {
return transitions;
}

/**
* sets the transitions in the building block to the collection provided
* @param transitions
*/
public void setTransitions(Collection<Transition> transitions) {
this.transitions = transitions;
}

/**
* gets all the places and transitions in the building block
* @return places and transitions
*/
public Collection<Connectable> getConnectables(){
Collection<Connectable> connectables = new HashSet<>();
connectables.addAll(places);
connectables.addAll(transitions);
return connectables;

}

/**
* Unknown input rates represented as strings
* @param petriNet
* @return input rates of the building block
*/
public Map<Transition,String> getInputRates(PetriNet petriNet) {
for(Transition transition: getTransitions()){
if(petriNet.outboundArcs(transition).size()>0){
inputRates.keySet().add(transition);
inputRates.values().add("x_" + transition.getId());
}
}
return inputRates;
}

/**
*Returns the known rates of the output transitions in the building block
* @param petriNet
*/
public Map<Transition,String> getOutputRates(PetriNet petriNet) {
for(Transition transition: getTransitions()){
if(petriNet.inboundArcs(transition).size()>0){
outputRates.keySet().add(transition);
outputRates.values().add(transition.getRateExpr());
}
}
return inputRates;
}

/**
* get input rates in the building block
* @return input rates
*/
public void setInputRates(Map<Transition, String> inputRates) {
this.inputRates = inputRates;
}

/**
* get output rates in the building block
* @return output rates
*/
public void setOutputRates(Map<Transition, String> outputRates) {
this.outputRates = outputRates;
}
}
162 changes: 162 additions & 0 deletions pipe-module-gui/src/main/java/pipe/gui/rcat/BuildingBlockCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package pipe.gui.rcat;

import pipe.gui.widget.RCATForm;
import uk.ac.imperial.pipe.exceptions.PetriNetComponentException;
import uk.ac.imperial.pipe.models.petrinet.*;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

/**
* Controller for the RCAT Module
* @author Tanvi Potdar
*/
public class BuildingBlockCreator {

/**
* called by the splitBB Jbutton to split the Petri Net into building blocks
* @param petriNet
* @return
* @throws PetriNetComponentException
*/
public Collection<BuildingBlock> splitIntoBuildingBlocks(PetriNet petriNet) throws PetriNetComponentException {

Collection<BuildingBlock> listOfBuildingBlocks = new HashSet<>();

RcatPlaceVisitor rcatPlaceVisitor = new RcatPlaceVisitor(petriNet);
Collection<Place> visitedPlaces = rcatPlaceVisitor.visitedPlaces;

for(Place place: petriNet.getPlaces()){
if(! visitedPlaces.contains(place)){
place.accept(rcatPlaceVisitor);
BuildingBlock buildingBlock = rcatPlaceVisitor.buildingBlock;
listOfBuildingBlocks.add(buildingBlock);
}
}

return listOfBuildingBlocks;

}

/**
* class that creates a Visitor for the places in a Petri Net
* so as to delineate the actions required of a place when it
* is visited, i.e.,
* 1. get its neighbours
* 2. create a building block using the place and its neighbours
*/

private static class RcatPlaceVisitor implements PlaceVisitor {
/**
* current petri net
*/
private PetriNet petriNet;
/**
* set of places that the visitor has already visited
*/
private final Collection<Place> visitedPlaces = new HashSet<>();
/**
* building block created for the place in question
*/
private BuildingBlock buildingBlock;

/**
* Constructor for the RCATPlaceVisitor class
* @param petriNet in use
*/
RcatPlaceVisitor(PetriNet petriNet) {
this.petriNet = petriNet;
}

/**
* specifies the actions that should happen when a
* place is visited by the RCATPlaceVisitor
* @param place
* @throws PetriNetComponentException
*/
@Override
public void visit(Place place) throws PetriNetComponentException {
visitedPlaces.add(place);
searchForBuildingBlock(place);
}

/**
*creates a building block for the place in question
* @param place
* @throws PetriNetComponentException
*/
private void searchForBuildingBlock(Place place) throws PetriNetComponentException {
Collection<Place> bbPlaces = new HashSet<>();
bbPlaces.add(place);

for(Place neighbour: getNeighbours(place)){
if(!visitedPlaces.contains(neighbour)){
this.visit(neighbour);
}
bbPlaces.add(neighbour);
}

buildingBlock = new BuildingBlock(bbPlaces, getAllTransitionsInBuildingBlock(bbPlaces));
}

/**
* gets all the transitions in a building block
* @param places in the building block
* @return all the transitions in each place in a Building Block
*/
public Collection<Transition> getAllTransitionsInBuildingBlock(Collection<Place> places){
Collection<Transition> allTrans = new HashSet<>();
for(Place place: places){
for(Arc arc: petriNet.getArcs()){
if(place.equals(arc.getSource())){
allTrans.add((Transition)arc.getTarget());
}
if(place.equals(arc.getTarget())){
allTrans.add((Transition)arc.getSource());
}
}
}
return allTrans;
}

/**
*gets the neighbours of the place in question
* @param place
* @return the neighbours of the place, i.e , all the places that have the ~ relation with p
* The ~ relation: p1~p2 if they share inbound arcs
*/
public Iterable<Place> getNeighbours(Place place){
Collection<Place> neighbours = new HashSet<>();
Collection<Transition> visitedTransitions = new HashSet<>();
Collection<Transition> outputTransitionsForSinglePlace = new ArrayList<>();

for(uk.ac.imperial.pipe.models.petrinet.Arc arc: petriNet.getArcs()){
if(place.equals(arc.getSource())){
outputTransitionsForSinglePlace.add((Transition) arc.getTarget());
}
}

for(Transition transition: outputTransitionsForSinglePlace){
if(! (visitedTransitions.contains(transition))){
Collection<InboundArc> inboundArcs = petriNet.inboundArcs(transition);
for(InboundArc inboundArc : inboundArcs){
Place inboundPlace = inboundArc.getSource();
if(!place.equals(inboundPlace)){
neighbours.add(inboundPlace);
}
}

}
visitedTransitions.add(transition);
}
return neighbours;
}


}



}
Loading