Skip to content
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
90 changes: 90 additions & 0 deletions src/paramwrapper/Formula.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package paramwrapper;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Logger;

import com.sun.media.sound.PortMixerProvider;

import java.util.logging.Level;

public class Formula {
private static final Logger LOGGER = Logger.getLogger(Formula.class.getName());
private ParamWrapper paramWrapper;
File modelFile;
FileWriter modelWriter;
File propertyFile;
FileWriter propertyWriter;
File resultsFile;
String formula;

public Formula(ParamWrapper paramWrapper) {
this.paramWrapper = paramWrapper;
}

public void setModelFile(String model, String param) {
try {
modelFile = File.createTempFile(model, param);
FileWriter modelWriter = new FileWriter(modelFile);
modelWriter.write(model);
modelWriter.flush();
modelWriter.close();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
}

public File getModelFile() {
return modelFile;
}

public void setPropertyFile(String property, String prop) {
try {
propertyWriter = new FileWriter(propertyFile);
propertyWriter.write(property);
propertyWriter.flush();
propertyWriter.close();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
}

public File getPropertyFile() {
return propertyFile;
}

public void setResultsFile(String result) {
try {
resultsFile = File.createTempFile(result, null);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
}

public File getResultsFile() {
return resultsFile;
}

public String getFormula() {
return formula.trim().replaceAll("\\s+", "");
}

public void setFormula() {
try {
formula = paramWrapper.invokeModelChecker(modelFile.getAbsolutePath(), propertyFile.getAbsolutePath(),
resultsFile.getAbsolutePath());
}catch (IOException e){
LOGGER.log(Level.SEVERE, e.toString(), e);
}
}

public void setParametricFormula() {
try {
formula = paramWrapper.invokeParametricModelChecker(modelFile.getAbsolutePath(), propertyFile.getAbsolutePath(),
resultsFile.getAbsolutePath());
}catch (IOException e){
LOGGER.log(Level.SEVERE, e.toString(), e);
}
}
}
91 changes: 43 additions & 48 deletions src/paramwrapper/ParamWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*
*/
public class ParamWrapper implements ParametricModelChecker {
private static final Logger LOGGER = Logger.getLogger(ParamWrapper.class.getName());
private static final Logger LOGGER = Logger.getLogger(ParamWrapper.class.getName());

private String paramPath;
private final String prismPath = "/opt/prism-4.2.1-src/bin/prism";
private boolean usePrism = false;

public ParamWrapper(String paramPath) {
this.paramPath = paramPath;
this.paramPath = paramPath;
}

public String fdtmcToParam(FDTMC fdtmc) {
Expand All @@ -46,60 +46,55 @@ public String getReliability(FDTMC fdtmc) {
}

private String evaluate(String model, String property) {
try {
File modelFile = File.createTempFile("model", "param");
FileWriter modelWriter = new FileWriter(modelFile);
modelWriter.write(model);
modelWriter.flush();
modelWriter.close();

File propertyFile = File.createTempFile("property", "prop");
FileWriter propertyWriter = new FileWriter(propertyFile);
propertyWriter.write(property);
propertyWriter.flush();
propertyWriter.close();

File resultsFile = File.createTempFile("result", null);

String formula;
if (usePrism && !model.contains("param")) {
formula = invokeModelChecker(modelFile.getAbsolutePath(),
propertyFile.getAbsolutePath(),
resultsFile.getAbsolutePath());
} else {
formula = invokeParametricModelChecker(modelFile.getAbsolutePath(),
propertyFile.getAbsolutePath(),
resultsFile.getAbsolutePath());
}
return formula.trim().replaceAll("\\s+", "");
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
Formula formula = new Formula(this);

// File modelFile = File.createTempFile("model", "param");
// FileWriter modelWriter = new FileWriter(modelFile);
// modelWriter.write(model);
// modelWriter.flush();
// modelWriter.close();
formula.setModelFile("model", "param");

// File propertyFile = File.createTempFile("property", "prop");
// FileWriter propertyWriter = new FileWriter(propertyFile);
// propertyWriter.write(property);
// propertyWriter.flush();
// propertyWriter.close();

formula.setPropertyFile("property", "prop");

// File resultsFile = File.createTempFile("result", null);
formula.setResultsFile("result");

// String formula;
if (usePrism && !model.contains("param")) {
// formula = invokeModelChecker(modelFile.getAbsolutePath(),
// propertyFile.getAbsolutePath(),
// resultsFile.getAbsolutePath());
formula.setFormula();
} else {
// formula = invokeParametricModelChecker(modelFile.getAbsolutePath(),
// propertyFile.getAbsolutePath(),
// resultsFile.getAbsolutePath());
formula.setParametricFormula();
}
return "";
return formula.getFormula();

}

private String invokeParametricModelChecker(String modelPath,
String propertyPath,
String resultsPath) throws IOException {
String commandLine = paramPath+" "
+modelPath+" "
+propertyPath+" "
+"--result-file "+resultsPath;
return invokeAndGetResult(commandLine, resultsPath+".out");
protected String invokeParametricModelChecker(String modelPath, String propertyPath, String resultsPath)
throws IOException {
String commandLine = paramPath + " " + modelPath + " " + propertyPath + " " + "--result-file " + resultsPath;
return invokeAndGetResult(commandLine, resultsPath + ".out");
}

private String invokeModelChecker(String modelPath,
String propertyPath,
String resultsPath) throws IOException {
String commandLine = prismPath+" "
+modelPath+" "
+propertyPath+" "
+"-exportresults "+resultsPath;
String invokeModelChecker(String modelPath, String propertyPath, String resultsPath) throws IOException {
String commandLine = prismPath + " " + modelPath + " " + propertyPath + " " + "-exportresults " + resultsPath;
return invokeAndGetResult(commandLine, resultsPath);
}

private String invokeAndGetResult(String commandLine, String resultsPath) throws IOException {
LOGGER.fine(commandLine);
LOGGER.fine(commandLine);
Process program = Runtime.getRuntime().exec(commandLine);
int exitCode = 0;
try {
Expand All @@ -110,7 +105,7 @@ private String invokeAndGetResult(String commandLine, String resultsPath) throws
}
List<String> lines = Files.readAllLines(Paths.get(resultsPath), Charset.forName("UTF-8"));
// Formula
return lines.get(lines.size()-1);
return lines.get(lines.size() - 1);
}

}