Browse Source
(export-iterations) introduce --exportiterations option, ExportIterations helper classes for C and Java
(export-iterations) introduce --exportiterations option, ExportIterations helper classes for C and Java
Generates HTML file with the individual steps of the iterative procedures. Relies on external JavaScript and CSS. Is already prepared for exporting interval iteration steps (possibility to export multiple vectors with type flag per iteration step) git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@12073 bbc10eb1-c90d-0410-af57-cb519fbb1720master
23 changed files with 402 additions and 1 deletions
-
110prism/include/ExportIterations.h
-
8prism/include/PrismHybrid.h
-
1prism/include/PrismHybridGlob.h
-
8prism/include/PrismMTBDD.h
-
1prism/include/PrismMTBDDGlob.h
-
8prism/include/PrismNative.h
-
2prism/include/PrismNativeGlob.h
-
8prism/include/PrismSparse.h
-
1prism/include/PrismSparseGlob.h
-
1prism/include/prism.h
-
153prism/src/explicit/ExportIterations.java
-
17prism/src/hybrid/PrismHybrid.cc
-
6prism/src/hybrid/PrismHybrid.java
-
1prism/src/mtbdd/Makefile
-
15prism/src/mtbdd/PrismMTBDD.cc
-
6prism/src/mtbdd/PrismMTBDD.java
-
3prism/src/prism/Prism.java
-
14prism/src/prism/PrismNative.cc
-
6prism/src/prism/PrismNative.java
-
8prism/src/prism/PrismSettings.java
-
6prism/src/prism/prism.cc
-
14prism/src/sparse/PrismSparse.cc
-
6prism/src/sparse/PrismSparse.java
@ -0,0 +1,110 @@ |
|||
//============================================================================== |
|||
// |
|||
// Copyright (c) 2016- |
|||
// Authors: |
|||
// * Joachim Klein <klein@tcs.inf.tu-dresden.de> (TU Dresden) |
|||
// |
|||
//------------------------------------------------------------------------------ |
|||
// |
|||
// This file is part of PRISM. |
|||
// |
|||
// PRISM is free software; you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation; either version 2 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// PRISM is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with PRISM; if not, write to the Free Software Foundation, |
|||
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
// |
|||
//============================================================================== |
|||
|
|||
|
|||
#ifndef EXPORT_ITERATIONS_H |
|||
#define EXPORT_ITERATIONS_H |
|||
|
|||
#include <cstdio> |
|||
#include <string> |
|||
#include <math.h> |
|||
|
|||
#include <cudd.h> |
|||
#include <dd.h> |
|||
#include "dv.h" |
|||
#include "prism.h" |
|||
#include <odd.h> |
|||
|
|||
class ExportIterations { |
|||
private: |
|||
FILE *fp; |
|||
|
|||
public: |
|||
/** |
|||
* Constructor, provide filename. |
|||
*/ |
|||
ExportIterations(const char* title = "", const char* filename = get_export_iterations_filename()) { |
|||
fp = fopen(filename, "w"); |
|||
|
|||
fprintf(fp, "<!DOCTYPE html>\n"); |
|||
fprintf(fp, "<html><head>\n"); |
|||
fprintf(fp, "<meta charset=\"utf-8\">\n"); |
|||
fprintf(fp, "<!-- HTML file automatically generated by the PRISM model checker -->\n"); |
|||
fprintf(fp, "<!-- For visualising the individual steps of a value iteration computation -->\n"); |
|||
fprintf(fp, "<!-- Loads supporting Javascript and CSS from www.prismmodelchecker.org -->\n"); |
|||
fprintf(fp, "<title>%s</title>\n", title); |
|||
fprintf(fp, "<link rel='stylesheet' href='http://www.prismmodelchecker.org/js/res/iteration-vis-v1.css'>\n"); |
|||
fprintf(fp, "<script src=\"http://www.prismmodelchecker.org/js/res/d3.js-v4/d3.min.js\"></script>\n"); |
|||
fprintf(fp, "<body onload='init();'>\n"); |
|||
fprintf(fp, "<h1>%s</h1>\n", title); |
|||
fprintf(fp, "<svg></svg>\n"); |
|||
fprintf(fp, "<script src=\"http://www.prismmodelchecker.org/js/res/iteration-vis-v1.js\"></script>\n"); |
|||
} |
|||
|
|||
/** |
|||
* Export the given vector, with size n and given type (0 = normal, VI from below, 1 = VI from above) |
|||
*/ |
|||
void exportVector(double *soln, int n, int type) { |
|||
fprintf(fp, "<script>addVector(["); |
|||
for (int i = 0; i < n; i++) { |
|||
if (i>0) fprintf(fp, ","); |
|||
double d = soln[i]; |
|||
if (isinf(d)) { |
|||
if (d > 0) |
|||
fprintf(fp, "Infinity"); |
|||
else |
|||
fprintf(fp, "-Infinity"); |
|||
} else { |
|||
fprintf(fp, "%.17g", soln[i]); |
|||
} |
|||
} |
|||
fprintf(fp, "],%d)</script>\n", type); |
|||
fflush(fp); |
|||
} |
|||
|
|||
/** |
|||
* Export the given MTBDD vector, with num_rvars row variables, |
|||
* odd for reachable state space and type (0= normal, VI from below, 1 = VI from above) |
|||
*/ |
|||
void exportVector(DdNode *dd, DdNode **rvars, int num_rvars, ODDNode* odd, int type) |
|||
{ |
|||
double* vec = mtbdd_to_double_vector(ddman, dd, rvars, num_rvars, odd); |
|||
|
|||
// get number of states |
|||
int n = odd->eoff + odd->toff; |
|||
|
|||
exportVector(vec, n, type); |
|||
delete[] vec; |
|||
} |
|||
|
|||
/** Destructor, close file */ |
|||
~ExportIterations() { |
|||
fprintf(fp, "</body></html>\n"); |
|||
fclose(fp); |
|||
} |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,153 @@ |
|||
//============================================================================== |
|||
// |
|||
// Copyright (c) 2016- |
|||
// Authors: |
|||
// * Joachim Klein <klein@tcs.inf.tu-dresden.de> (TU Dresden) |
|||
// |
|||
//------------------------------------------------------------------------------ |
|||
// |
|||
// This file is part of PRISM. |
|||
// |
|||
// PRISM is free software; you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation; either version 2 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// PRISM is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with PRISM; if not, write to the Free Software Foundation, |
|||
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
// |
|||
//============================================================================== |
|||
|
|||
package explicit; |
|||
|
|||
import dv.DoubleVector; |
|||
import prism.PrismException; |
|||
import prism.PrismFileLog; |
|||
import prism.PrismLog; |
|||
|
|||
/** |
|||
* Class for exporting / visualising the value vectors in |
|||
* a numerical iteration algorithm. |
|||
* |
|||
*/ |
|||
public class ExportIterations { |
|||
private static String defaultFilename = "iterations.html"; |
|||
|
|||
private PrismLog log; |
|||
|
|||
public ExportIterations(String title) throws PrismException |
|||
{ |
|||
this(title, PrismFileLog.create(defaultFilename)); |
|||
} |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param log the log used for export |
|||
*/ |
|||
public ExportIterations(String title, PrismLog log) |
|||
{ |
|||
this.log = log; |
|||
|
|||
log.println("<!DOCTYPE html>"); |
|||
log.println("<html><head>"); |
|||
log.println("<meta charset=\"utf-8\">"); |
|||
log.println("<!-- HTML file automatically generated by the PRISM model checker -->"); |
|||
log.println("<!-- For visualising the individual steps of a value iteration computation -->"); |
|||
log.println("<!-- Loads supporting Javascript and CSS from www.prismmodelchecker.org -->"); |
|||
log.println("<title>" + title + "</title>"); |
|||
log.println("<link rel='stylesheet' href='http://www.prismmodelchecker.org/js/res/iteration-vis-v1.css'>"); |
|||
log.println("<script src=\"http://www.prismmodelchecker.org/js/res/d3.js-v4/d3.min.js\"></script>"); |
|||
log.println("<body onload='init();'>"); |
|||
log.println("<h1>" + title + "</h1>"); |
|||
log.println("<svg></svg>"); |
|||
log.println("<script src=\"http://www.prismmodelchecker.org/js/res/iteration-vis-v1.js\"></script>"); |
|||
} |
|||
|
|||
/** |
|||
* Export the given vector. |
|||
* @param soln the value vector |
|||
*/ |
|||
public void exportVector(double[] soln) |
|||
{ |
|||
exportVector(soln, 0); |
|||
} |
|||
|
|||
/** |
|||
* Export the given vector. |
|||
* @param soln the value vector |
|||
* @param type the vector type (0 = normal, VI from below, 1 = VI from above) |
|||
*/ |
|||
public void exportVector(double[] soln, int type) |
|||
{ |
|||
log.print("<script>addVector(["); |
|||
for (int i = 0; i < soln.length; i++) { |
|||
if (i>0) log.print(","); |
|||
double d = soln[i]; |
|||
exportValue(d); |
|||
} |
|||
log.print("]," + type + ")</script>\n"); |
|||
} |
|||
|
|||
/** |
|||
* Export the given vector. |
|||
* @param soln the value vector |
|||
*/ |
|||
public void exportVector(DoubleVector soln) |
|||
{ |
|||
exportVector(soln, 0); |
|||
} |
|||
|
|||
/** |
|||
* Export the given vector. |
|||
* @param soln the value vector |
|||
* @param type the vector type (0 = normal, VI from below, 1 = VI from above) |
|||
*/ |
|||
public void exportVector(DoubleVector soln, int type) |
|||
{ |
|||
log.print("<script>addVector(["); |
|||
for (int i = 0, n = soln.getSize(); i < n; i++) { |
|||
if (i>0) log.print(","); |
|||
double d = soln.getElement(i); |
|||
exportValue(d); |
|||
} |
|||
log.print("]," + type + ")</script>\n"); |
|||
} |
|||
|
|||
private void exportValue(double d) |
|||
{ |
|||
if (d == Double.POSITIVE_INFINITY) { |
|||
log.print("Infinity"); |
|||
} else if (d == Double.NEGATIVE_INFINITY) { |
|||
log.print("-Infinity"); |
|||
} else { |
|||
log.print(d); |
|||
} |
|||
} |
|||
|
|||
/** Print footer, export log */ |
|||
public void close() |
|||
{ |
|||
log.println("\n</body></html>"); |
|||
} |
|||
|
|||
public static void setDefaultFilename(String newDefaultFilename) |
|||
{ |
|||
defaultFilename = newDefaultFilename; |
|||
} |
|||
|
|||
public static String getDefaultFilename() |
|||
{ |
|||
return defaultFilename; |
|||
} |
|||
|
|||
public static void resetDefaultFilename() |
|||
{ |
|||
defaultFilename = "iterations.html"; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue