Skip to content

Commit

Permalink
now is able to extend and remove removeable colors from color types i…
Browse files Browse the repository at this point in the history
…n manual edit
  • Loading branch information
mtygesen committed Sep 27, 2024
1 parent df55893 commit fc34121
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
.idea
.vscode
.r
.bzr-repo
build
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dk/aau/cs/model/CPN/ColorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean contains(Color color){
}
return false;
}

public Color getColorByName(String name){
for (Color c : colors) {
if(c.getColorName().equals(name)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ private void isColorTypeUsedInVariable(ColorType colorType, List<String> message
}
}

public boolean canColorBeRemoved(Color color, ArrayList<String> messages) {
public boolean canColorBeRemoved(Color color, List<String> messages) {
isColorTypeUsedInProduct(color.getColorType(), messages);
for (TimedArcPetriNet tapn : allTemplates()) {
for (TimedPlace p : tapn.places()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public JComboBox[] getColorTypeComboBoxesArray() {
private void initPanel() {
colorcomboBoxPanel = new JPanel();
colorcomboBoxPanel.setLayout(new GridBagLayout());

//This panel contains all comboboxes, there can be more than one with ProductTypes
comboBoxPanel = new JPanel(new GridBagLayout());
//In case it is a really large product type we have a scrollPane
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ package dk.aau.cs.model.CPN.ConstantsParser;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import dk.aau.cs.model.CPN.Color;
import dk.aau.cs.model.CPN.ColorType;
import dk.aau.cs.model.tapn.Constant;
import dk.aau.cs.model.tapn.TimedArcPetriNet;
import dk.aau.cs.model.CPN.Variable;
import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork;
import dk.aau.cs.model.tapn.TimedPlace;
import dk.aau.cs.model.CPN.Expressions.ArcExpression;
import dk.aau.cs.model.tapn.TimedToken;
import dk.aau.cs.model.CPN.ColorMultiset;

import java.util.HashMap;
import java.util.Map;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -92,24 +100,72 @@ public class ConstantsParser {

// Generate error messages
for (String key : canBeRemovedBitMap.keySet()) {
boolean skip = false;

if (constants.containsKey(key) ||
variables.containsKey(key) && canBeRemovedBitMap.get(key) ||
key.equals("dot") ||
colorTypes.containsKey(key) &&
(colorTypes.get(key).equals(constantsMap.get(key)) ||
colorTypes.get(key).isIntegerRange())) {
key.equals("dot")) {
continue;
} else if (variables.containsKey(key) && !canBeRemovedBitMap.get(key)) {
boolean skip = false;
for (Variable v : network.variables()) {
if (v.getName().equals(key)) {
skip = v.getColorType().equals(variables.get(key).getColorType());
}
}
}

if (skip) continue;
if (skip) continue;
} else if (colorTypes.containsKey(key)) {
if (colorTypes.get(key).equals(constantsMap.get(key))) continue;

ColorType newCt = colorTypes.get(key);
ColorType ct = (ColorType)constantsMap.get(key);

List<Color> removedColors = new ArrayList<Color>();

for (Color color : ct.getColorList()) {
if (!newCt.contains(color)) {
removedColors.add(color);
}
}

int removeableColors = 0;
for (Color c : removedColors) {
List<String> newMessagesList = new ArrayList<String>();
boolean colorCanBeRemoved = network.canColorBeRemoved(c, newMessagesList);
if (colorCanBeRemoved) {
++removeableColors;
} else {
List<String> messagesList = messages.get(key);
messagesList.addAll(newMessagesList);
messages.put(key, messagesList);
}
}

// Update place color types
for (TimedArcPetriNet tapn : network.allTemplates()) {
for (TimedPlace p : tapn.places()) {
if (p.getColorType().equals(ct)) {
p.setColorType(newCt);
}

ArcExpression expression = p.getExprWithNewColorType(newCt);
if (expression != p.getTokensAsExpression()) {
ColorMultiset cm = expression.eval(network.getContext());
if (cm != null) {
List<TimedToken> tokensToAdd = new ArrayList<TimedToken>(p.tokens());
for (TimedToken token : cm.getTokens(p)) {
tapn.marking().remove(token);
}

p.updateTokens(tokensToAdd, expression);
}
}
}
}

if (removeableColors == removedColors.size()) {
continue;
}
}

Object obj = constantsMap.get(key);
if (!canBeRemovedBitMap.get(key)) {
Expand Down

0 comments on commit fc34121

Please sign in to comment.