Skip to content

Commit

Permalink
new decision procedure for Bounds, relying on two Reachability problems
Browse files Browse the repository at this point in the history
  • Loading branch information
yanntm committed Mar 25, 2024
1 parent 34e2ca9 commit ddfca1f
Showing 1 changed file with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;


import android.util.SparseIntArray;
import fr.lip6.move.gal.application.Application;
import fr.lip6.move.gal.application.mcc.MccTranslator;
import fr.lip6.move.gal.mcc.properties.ConcurrentHashDoneProperties;
import fr.lip6.move.gal.mcc.properties.DoneProperties;
import fr.lip6.move.gal.structural.CoverWalker;
import fr.lip6.move.gal.structural.GlobalPropertySolvedException;
import fr.lip6.move.gal.structural.ISparsePetriNet;
import fr.lip6.move.gal.structural.InvariantCalculator;
import fr.lip6.move.gal.structural.Property;
import fr.lip6.move.gal.structural.PropertyType;
import fr.lip6.move.gal.structural.RandomExplorer;
import fr.lip6.move.gal.structural.SparsePetriNet;
Expand Down Expand Up @@ -111,10 +114,11 @@ private static void checkStatus(SparsePetriNet spn, List<Expression> tocheck, Li
}


public static List<Integer> applyReductions(SparsePetriNet spn, DoneProperties doneProps, List<Integer> initMaxStruct) {
public static List<Integer> applyReductions(MccTranslator reader, DoneProperties doneProps, List<Integer> initMaxStruct) {
int iter;
int iterations =0;

SparsePetriNet spn = reader.getSPN();
// need to protect some variables
List<Integer> tocheckIndexes = new ArrayList<>();
List<Expression> tocheck = new ArrayList<>(spn.getProperties().size());
Expand Down Expand Up @@ -309,7 +313,8 @@ public static List<Integer> applyReductions(SparsePetriNet spn, DoneProperties d

if (spn.getProperties().removeIf(p -> doneProps.containsKey(p.getName())))
iter++;




if (!isBounded.isPresent()) {
// check if we still have inf upper bounds
Expand Down Expand Up @@ -388,9 +393,68 @@ public static List<Integer> applyReductions(SparsePetriNet spn, DoneProperties d
iterations++;
} while ( (iterations<=1 || iter > 0 || !lastMaxSeen.equals(maxSeen)) && ! spn.getProperties().isEmpty());


reader.setSpn(spn,false);

testWithReachability(reader,maxSeen,maxStruct,doneProps);

return maxStruct;
}

private static void testWithReachability(MccTranslator ori, List<Integer> maxSeen, List<Integer> maxStruct,
DoneProperties doneProps) {

SparsePetriNet spnori = ori.getSPN();
MccTranslator subproblem = ori.copy();
SparsePetriNet spn = subproblem.getSPN();
spn.getProperties().clear();
for (int id=0; id < spnori.getProperties().size() ; id++) {
Property prop = spnori.getProperties().get(id);
if (maxStruct.get(id) > 0) {
Property reachMax = new Property(
Expression.nop(Op.EF,
Expression.nop(Op.EQ, prop.getBody(), Expression.constant(maxStruct.get(id)))), PropertyType.INVARIANT, prop.getName()+"MAX" );
spn.getProperties().add(reachMax);
}
Property seenIsBound = new Property(
Expression.nop(Op.AG,
Expression.nop(Op.LEQ, prop.getBody(), Expression.constant(maxSeen.get(id)))), PropertyType.INVARIANT, prop.getName()+"MIN" );
spn.getProperties().add(seenIsBound);
}
DoneProperties localDone = new ConcurrentHashDoneProperties();

try {
ReachabilitySolver.applyReductions(subproblem,localDone,100);
} catch (GlobalPropertySolvedException e) {
e.printStackTrace();
}
for (Entry<String, Boolean> ent : localDone.entrySet()) {
if (ent.getKey().endsWith("MAX") && ent.getValue()) {
// We *can* reach the structural max.
String pname = ent.getKey().substring(0,ent.getKey().length()-3);
int id = -1;
for (id = 0; id < spnori.getProperties().size() ; id++) {
if (spnori.getProperties().get(id).getName().equals(pname)) {
break;
}
}
doneProps.put(pname, maxStruct.get(id), "REACHABILITY_MAX");
} else if (ent.getKey().endsWith("MIN") && ent.getValue()) {
// We *cannot exceed* the seen value.
String pname = ent.getKey().substring(0,ent.getKey().length()-3);
int id = -1;
for (id = 0; id < spnori.getProperties().size() ; id++) {
if (spnori.getProperties().get(id).getName().equals(pname)) {
break;
}
}
doneProps.put(pname, maxSeen.get(id), "REACHABILITY_MIN");
}
System.out.println("Result : " + ent);
}

}

private static void printBounds(String rule, List<Integer> maxSeen, List<Integer> maxStruct) {
StringBuilder sb = new StringBuilder();
sb.append("Max Seen:");
Expand Down

0 comments on commit ddfca1f

Please sign in to comment.