Commit add8aaed authored by Simone Vuotto's avatar Simone Vuotto

Bug fixes

parent 1e37a19d
Pipeline #197 passed with stages
in 2 minutes and 20 seconds
......@@ -93,13 +93,21 @@ public class LTLDcSpec extends LTLSpec {
}
/**
* Create a new numeric assignment that contains a numeric assignment defined by the LTL(Dc) boolean variables.
* The LTL(Dc) boolean variables are kept in the new assignment, alongside the numeric value.
*
* @param assignment the LTL(Dc) boolean assignment to evaluate
* @return the new assigment extended with the numeric variables
*/
public NumericAssignment fromBool2Numeric(Assignment assignment) {
NumericAssignment na = new NumericAssignment();
HashMap<String, Assignment> numericAssignments = new HashMap<>();
for(Atom a: assignment.getAssignments().keySet()) {
if(a.getProperty(Atom.PROPERTY_NUMERIC) == null) {
na.add(a, assignment.getValue(a));
} else {
na.add(a, assignment.getValue(a));
if(a.getProperty(Atom.PROPERTY_NUMERIC) != null) {
numericAssignments.putIfAbsent((String) a.getProperty(Atom.PROPERTY_NUMERIC_VAR), new Assignment());
numericAssignments.get(a.getProperty(Atom.PROPERTY_NUMERIC_VAR)).add(a, assignment.getValue(a));
}
......@@ -117,14 +125,20 @@ public class LTLDcSpec extends LTLSpec {
return na;
}
public Assignment fromNumeric2Bool(NumericAssignment numericAssignment) {
Assignment assignment = new Assignment(numericAssignment);
/**
* Creates a new numerical assignments that contains the LTL(Dc) boolean variables corresponding to the numeric
* values in the input assignment.
* The numeric variables are kept in the new assignment, alongside the LTL(Dc) boolean values.
* @param numericAssignment the numeric assignment to evaluate
* @return the new assignment extended with the LTL(Dc) boolean variables
*/
public NumericAssignment fromNumeric2Bool(NumericAssignment numericAssignment) {
for(Map.Entry<Atom, Float> entry: numericAssignment.getFloatAssignments().entrySet()) {
assignment.add(getDcAssignment(entry.getKey().getName(), entry.getValue()));
numericAssignment.add(getDcAssignment(entry.getKey().getName(), entry.getValue()));
}
return assignment;
return numericAssignment;
}
/**
......
......@@ -9,6 +9,12 @@ public class NumericAssignment extends Assignment {
private final HashMap<Atom, Float> numericAssignmentsMap;
public NumericAssignment(NumericAssignment assignment) {
super(assignment);
this.numericAssignmentsMap = (HashMap) assignment.numericAssignmentsMap.clone();
}
public NumericAssignment() {
numericAssignmentsMap = new HashMap<>();
}
......@@ -23,6 +29,25 @@ public class NumericAssignment extends Assignment {
}
}
@Override
public NumericAssignment combine(Assignment assignment) {
try {
NumericAssignment newAss = new NumericAssignment(this);
newAss.add(assignment);
newAss.setStartBeta(this.isStartBeta() || assignment.isStartBeta());
if(assignment instanceof NumericAssignment) {
for(Map.Entry<Atom, Float> ass: ((NumericAssignment) assignment).getFloatAssignments().entrySet()) {
newAss.add(ass.getKey(), ass.getValue());
}
}
return newAss;
} catch (IllegalArgumentException e) {
return null;
}
}
public Map<Atom, Float> getFloatAssignments() {
return numericAssignmentsMap;
}
......
......@@ -136,6 +136,10 @@ public class PSP2LTL implements ExpressionVisitor {
public void visitCompareExpression(CompareExpression exp) {
Float threshold = null;
String varName = null;
exp.getLeftExp().accept(this);
exp.getRightExp().accept(this);
if(exp.getLeftExp() instanceof NumberExpression)
threshold = ((NumberExpression)exp.getLeftExp()).floatValue();
if(exp.getLeftExp() instanceof VariableExpression)
......
......@@ -118,8 +118,8 @@ public class TestingEnvironment {
private Assignment exec(Assignment i) {
Assignment o;
if(spec != null) {
NumericAssignment numericInput = spec.fromBool2Numeric(i);
o = sut.exec(numericInput);
i = spec.fromBool2Numeric(i);
o = sut.exec(i);
if(o instanceof NumericAssignment) {
o = spec.fromNumeric2Bool((NumericAssignment) o);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment