@ -31,6 +31,7 @@ import parser.*;
import parser.ast.* ;
import parser.ast.* ;
import parser.type.* ;
import parser.type.* ;
import prism.* ;
import prism.* ;
import javax.swing.* ;
import javax.swing.* ;
import userinterface.* ;
import userinterface.* ;
import java.util.* ;
import java.util.* ;
@ -64,7 +65,8 @@ public class GUIExperiment
private Result res ;
private Result res ;
/** Creates a new instance of GUIExperiment */
/** Creates a new instance of GUIExperiment */
public GUIExperiment ( GUIExperimentTable table , GUIMultiProperties guiProp , PropertiesFile prop , UndefinedConstants cons , ModulesFile mod , String modString , boolean useSimulation )
public GUIExperiment ( GUIExperimentTable table , GUIMultiProperties guiProp , PropertiesFile prop , UndefinedConstants cons , ModulesFile mod , String modString ,
boolean useSimulation )
{
{
this . table = table ;
this . table = table ;
this . guiProp = guiProp ;
this . guiProp = guiProp ;
@ -138,7 +140,7 @@ public class GUIExperiment
public void startExperiment ( )
public void startExperiment ( )
{
{
theThread = new ExperimentThread ( guiProp , this , cons , mod , prop ) ;
theThread = new ExperimentThread ( guiProp , this , cons , mod , prop ) ;
running = true ;
running = true ;
theThread . start ( ) ;
theThread . start ( ) ;
}
}
@ -181,9 +183,9 @@ public class GUIExperiment
public void stop ( )
public void stop ( )
{
{
if ( running & & theThread ! = null )
{
if ( useSimulation ) guiProp . getPrism ( ) . getSimulator ( ) . stopSampling ( ) ;
if ( running & & theThread ! = null ) {
if ( useSimulation )
guiProp . getPrism ( ) . getSimulator ( ) . stopSampling ( ) ;
theThread . interrupt ( ) ;
theThread . interrupt ( ) ;
}
}
}
}
@ -200,7 +202,8 @@ public class GUIExperiment
private PropertiesFile propertiesFile ;
private PropertiesFile propertiesFile ;
private GUIExperiment exp ;
private GUIExperiment exp ;
public ExperimentThread ( GUIMultiProperties guiProp , GUIExperiment exp , UndefinedConstants undefinedConstants , ModulesFile modulesFile , PropertiesFile propertiesFile )
public ExperimentThread ( GUIMultiProperties guiProp , GUIExperiment exp , UndefinedConstants undefinedConstants , ModulesFile modulesFile ,
PropertiesFile propertiesFile )
{
{
super ( guiProp ) ;
super ( guiProp ) ;
this . exp = exp ;
this . exp = exp ;
@ -223,8 +226,7 @@ public class GUIExperiment
definedPFConstants = null ;
definedPFConstants = null ;
res = null ;
res = null ;
try
{
try {
SwingUtilities . invokeAndWait ( new Runnable ( )
SwingUtilities . invokeAndWait ( new Runnable ( )
{
{
public void run ( )
public void run ( )
@ -236,22 +238,21 @@ public class GUIExperiment
}
}
} ) ;
} ) ;
for ( i = 0 ; i < undefinedConstants . getNumModelIterations ( ) ; i + + )
{
for ( i = 0 ; i < undefinedConstants . getNumModelIterations ( ) ; i + + ) {
definedMFConstants = undefinedConstants . getMFConstantValues ( ) ;
definedMFConstants = undefinedConstants . getMFConstantValues ( ) ;
if ( definedMFConstants ! = null ) if ( definedMFConstants . getNumValues ( ) > 0 ) logln ( "\nModel constants: " + definedMFConstants ) ;
if ( definedMFConstants ! = null )
if ( definedMFConstants . getNumValues ( ) > 0 )
logln ( "\nModel constants: " + definedMFConstants ) ;
/ / set values for ModulesFile constants
/ / set values for ModulesFile constants
try {
try {
modulesFile . setUndefinedConstants ( definedMFConstants ) ;
modulesFile . setUndefinedConstants ( definedMFConstants ) ;
}
catch ( PrismException e ) {
} catch ( PrismException e ) {
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
errorLog ( e . getMessage ( ) ) ;
errorLog ( e . getMessage ( ) ) ;
try {
try {
setMultipleErrors ( definedMFConstants , null , e ) ;
setMultipleErrors ( definedMFConstants , null , e ) ;
}
catch ( PrismException e2 ) {
} catch ( PrismException e2 ) {
error ( "Problem storing results" ) ;
error ( "Problem storing results" ) ;
}
}
undefinedConstants . iterateModel ( ) ;
undefinedConstants . iterateModel ( ) ;
@ -259,21 +260,19 @@ public class GUIExperiment
}
}
/ / only do explicit model construction if necessary
/ / only do explicit model construction if necessary
if ( ! useSimulation )
{
if ( ! useSimulation & & modulesFile . getModelType ( ) ! = ModelType . PTA ) {
/ / build model
/ / build model
try {
try {
logln ( "\n-------------------------------------------" ) ;
logln ( "\n-------------------------------------------" ) ;
model = prism . buildModel ( modulesFile ) ;
model = prism . buildModel ( modulesFile ) ;
clear = false ;
clear = false ;
}
catch ( PrismException e ) {
} catch ( PrismException e ) {
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
errorLog ( e . getMessage ( ) ) ;
errorLog ( e . getMessage ( ) ) ;
try {
try {
setMultipleErrors ( definedMFConstants , null , e ) ;
setMultipleErrors ( definedMFConstants , null , e ) ;
}
catch ( PrismException e2 ) {
} catch ( PrismException e2 ) {
error ( "Problem storing results" ) ;
error ( "Problem storing results" ) ;
}
}
undefinedConstants . iterateModel ( ) ;
undefinedConstants . iterateModel ( ) ;
@ -282,10 +281,8 @@ public class GUIExperiment
/ / remove any deadlocks ( don ' t prompt - probably should )
/ / remove any deadlocks ( don ' t prompt - probably should )
StateList states = model . getDeadlockStates ( ) ;
StateList states = model . getDeadlockStates ( ) ;
if ( states ! = null )
{
if ( states . size ( ) > 0 )
{
if ( states ! = null ) {
if ( states . size ( ) > 0 ) {
guiProp . log ( "\nWarning: " + states . size ( ) + " deadlock states detected; adding self-loops in these states...\n" ) ;
guiProp . log ( "\nWarning: " + states . size ( ) + " deadlock states detected; adding self-loops in these states...\n" ) ;
model . fixDeadlocks ( ) ;
model . fixDeadlocks ( ) ;
}
}
@ -297,123 +294,129 @@ public class GUIExperiment
}
}
/ / collect information for simulation if required
/ / collect information for simulation if required
if ( useSimulation & & ! reuseInfo )
{
if ( useSimulation & & ! reuseInfo ) {
try {
try {
info = null ;
info = null ;
info = GUISimulationPicker . defineSimulationWithDialog ( guiProp . getGUI ( ) , modulesFile . getInitialValues ( ) , modulesFile , "(" + definedMFConstants + ")" ) ;
}
catch ( PrismException e ) {
info = GUISimulationPicker . defineSimulationWithDialog ( guiProp . getGUI ( ) , modulesFile . getInitialValues ( ) , modulesFile , "("
+ definedMFConstants + ")" ) ;
} catch ( PrismException e ) {
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
errorLog ( e . getMessage ( ) ) ;
errorLog ( e . getMessage ( ) ) ;
try {
try {
setMultipleErrors ( definedMFConstants , null , e ) ;
setMultipleErrors ( definedMFConstants , null , e ) ;
}
catch ( PrismException e2 ) {
} catch ( PrismException e2 ) {
error ( "Problem storing results" ) ;
error ( "Problem storing results" ) ;
}
}
if ( ! clear ) model . clear ( ) ;
if ( ! clear )
model . clear ( ) ;
undefinedConstants . iterateModel ( ) ;
undefinedConstants . iterateModel ( ) ;
continue ;
continue ;
}
}
/ / if info is null , the user clicked cancel
/ / if info is null , the user clicked cancel
if ( info = = null ) break ;
if ( info = = null )
break ;
/ / if there are multiple models , offer the chance to reuse simulation info
/ / if there are multiple models , offer the chance to reuse simulation info
if ( undefinedConstants . getNumModelIterations ( ) > 1 & & ! reuseInfoAsked ) {
if ( undefinedConstants . getNumModelIterations ( ) > 1 & & ! reuseInfoAsked ) {
reuseInfoAsked = true ;
reuseInfoAsked = true ;
int q = guiProp . questionYesNo ( "Do you want to reuse the same initial state and simulation\n" +
"parameters for the remaining models in this experiment?\n" +
"If not you will be prompted for new values for each one." ) ;
if ( q = = 0 ) reuseInfo = true ;
int q = guiProp . questionYesNo ( "Do you want to reuse the same initial state and simulation\n"
+ "parameters for the remaining models in this experiment?\n" + "If not you will be prompted for new values for each one." ) ;
if ( q = = 0 )
reuseInfo = true ;
}
}
}
}
/ / for distributed simulation , pass control to the GUISimulatorDistributionDialog
/ / for distributed simulation , pass control to the GUISimulatorDistributionDialog
if ( useSimulation & & info . isDistributed ( ) )
{
if ( useSimulation & & info . isDistributed ( ) ) {
try {
try {
GUISimulatorDistributionDialog dist = new GUISimulatorDistributionDialog ( guiProp . getGUI ( ) , prism . getSimulator ( ) , true ) ;
GUISimulatorDistributionDialog dist = new GUISimulatorDistributionDialog ( guiProp . getGUI ( ) , prism . getSimulator ( ) , true ) ;
dist . show ( exp , this , modulesFile , propertiesFile , undefinedConstants , propertyToCheck , info ) ;
dist . show ( exp , this , modulesFile , propertiesFile , undefinedConstants , propertyToCheck , info ) ;
/ / new GUISimulatorDistributionDialog ( guiProp . getGUI ( ) , prism . getSimulator ( ) , true ) . show ( modulesFile , undefinedConstants , propertyToCheck , info ) ;
/ / new GUISimulatorDistributionDialog ( guiProp . getGUI ( ) , prism . getSimulator ( ) , true ) . show ( modulesFile , undefinedConstants , propertyToCheck , info ) ;
}
catch ( PrismException e ) {
} catch ( PrismException e ) {
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
errorLog ( e . getMessage ( ) ) ;
errorLog ( e . getMessage ( ) ) ;
try {
try {
setMultipleErrors ( definedMFConstants , null , e ) ;
setMultipleErrors ( definedMFConstants , null , e ) ;
}
catch ( PrismException e2 ) {
} catch ( PrismException e2 ) {
error ( "Problem storing results" ) ;
error ( "Problem storing results" ) ;
}
}
if ( ! clear ) model . clear ( ) ;
if ( ! clear )
model . clear ( ) ;
undefinedConstants . iterateModel ( ) ;
undefinedConstants . iterateModel ( ) ;
continue ;
continue ;
}
}
}
}
/ / for simulation where "simultaneous property checking" is enabled . . .
/ / for simulation where "simultaneous property checking" is enabled . . .
else if ( useSimulation & & prism . getSettings ( ) . getBoolean ( PrismSettings . SIMULATOR_SIMULTANEOUS ) & & undefinedConstants . getNumPropertyIterations ( ) > 1 )
{
else if ( useSimulation & & prism . getSettings ( ) . getBoolean ( PrismSettings . SIMULATOR_SIMULTANEOUS )
& & undefinedConstants . getNumPropertyIterations ( ) > 1 ) {
try {
try {
logln ( "\n-------------------------------------------" ) ;
logln ( "\n-------------------------------------------" ) ;
logln ( "\nSimulating: " + propertyToCheck ) ;
logln ( "\nSimulating: " + propertyToCheck ) ;
if ( definedMFConstants ! = null ) if ( definedMFConstants . getNumValues ( ) > 0 ) logln ( "Model constants: " + definedMFConstants ) ;
if ( definedMFConstants ! = null )
if ( definedMFConstants . getNumValues ( ) > 0 )
logln ( "Model constants: " + definedMFConstants ) ;
logln ( "Property constants: " + undefinedConstants . getPFDefinedConstantsString ( ) ) ;
logln ( "Property constants: " + undefinedConstants . getPFDefinedConstantsString ( ) ) ;
log ( "Simulation parameters: approx = " + info . getApprox ( ) + ", conf = " + info . getConfidence ( ) + ", num samples = " + info . getNoIterations ( ) + ", max path len = " + info . getMaxPathLength ( ) + ")\n" ) ;
prism . modelCheckSimulatorExperiment ( modulesFile , propertiesFile , undefinedConstants , results , propertyToCheck , info . getInitialState ( ) , info . getNoIterations ( ) , info . getMaxPathLength ( ) ) ;
log ( "Simulation parameters: approx = " + info . getApprox ( ) + ", conf = " + info . getConfidence ( ) + ", num samples = "
+ info . getNoIterations ( ) + ", max path len = " + info . getMaxPathLength ( ) + ")\n" ) ;
prism . modelCheckSimulatorExperiment ( modulesFile , propertiesFile , undefinedConstants , results , propertyToCheck , info
. getInitialState ( ) , info . getNoIterations ( ) , info . getMaxPathLength ( ) ) ;
/ / update progress meter
/ / update progress meter
/ / ( all properties simulated simultaneously so can ' t get more accurate feedback at the moment anyway )
/ / ( all properties simulated simultaneously so can ' t get more accurate feedback at the moment anyway )
table . progressChanged ( ) ;
table . progressChanged ( ) ;
}
catch ( PrismException e ) {
} catch ( PrismException e ) {
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
/ / in case of error , report it ( in log only ) , store as result , and go on to the next model
errorLog ( e . getMessage ( ) ) ;
errorLog ( e . getMessage ( ) ) ;
try {
try {
setMultipleErrors ( definedMFConstants , null , e ) ;
setMultipleErrors ( definedMFConstants , null , e ) ;
}
catch ( PrismException e2 ) {
} catch ( PrismException e2 ) {
error ( "Problem storing results" ) ;
error ( "Problem storing results" ) ;
}
}
undefinedConstants . iterateModel ( ) ;
undefinedConstants . iterateModel ( ) ;
continue ;
continue ;
}
}
}
else
{
} else {
/ / iterate through as many properties as necessary
/ / iterate through as many properties as necessary
for ( k = 0 ; k < undefinedConstants . getNumPropertyIterations ( ) ; k + + )
{
for ( k = 0 ; k < undefinedConstants . getNumPropertyIterations ( ) ; k + + ) {
/ / interrupt if requested
/ / interrupt if requested
if ( interrupted ( ) ) throw new InterruptedException ( ) ;
if ( interrupted ( ) )
throw new InterruptedException ( ) ;
try
{
try {
/ / set values for PropertiesFile constants
/ / set values for PropertiesFile constants
if ( propertiesFile ! = null )
{
if ( propertiesFile ! = null ) {
definedPFConstants = undefinedConstants . getPFConstantValues ( ) ;
definedPFConstants = undefinedConstants . getPFConstantValues ( ) ;
propertiesFile . setUndefinedConstants ( definedPFConstants ) ;
propertiesFile . setUndefinedConstants ( definedPFConstants ) ;
}
}
/ / do model checking
/ / do model checking
logln ( "\n-------------------------------------------" ) ;
logln ( "\n-------------------------------------------" ) ;
logln ( "\n" + ( useSimulation ? "Simulating" : "Model checking" ) + ": " + propertyToCheck ) ;
if ( definedMFConstants ! = null ) if ( definedMFConstants . getNumValues ( ) > 0 ) logln ( "Model constants: " + definedMFConstants ) ;
if ( definedPFConstants ! = null ) if ( definedPFConstants . getNumValues ( ) > 0 ) logln ( "Property constants: " + definedPFConstants ) ;
if ( useSimulation ) log ( "Simulation parameters: approx = " + info . getApprox ( ) + ", conf = " + info . getConfidence ( ) + ", num samples = " + info . getNoIterations ( ) + ", max path len = " + info . getMaxPathLength ( ) + ")\n" ) ;
if ( ! useSimulation )
{
res = prism . modelCheck ( model , propertiesFile , propertyToCheck ) ;
}
logln ( "\n" + ( useSimulation ? "Simulating" : "Model checking" ) + ": " + propertyToCheck ) ;
if ( definedMFConstants ! = null )
if ( definedMFConstants . getNumValues ( ) > 0 )
logln ( "Model constants: " + definedMFConstants ) ;
if ( definedPFConstants ! = null )
if ( definedPFConstants . getNumValues ( ) > 0 )
logln ( "Property constants: " + definedPFConstants ) ;
if ( useSimulation )
log ( "Simulation parameters: approx = " + info . getApprox ( ) + ", conf = " + info . getConfidence ( ) + ", num samples = "
+ info . getNoIterations ( ) + ", max path len = " + info . getMaxPathLength ( ) + ")\n" ) ;
if ( ! useSimulation ) {
/ / PTA model checking
if ( modulesFile . getModelType ( ) = = ModelType . PTA ) {
res = prism . modelCheckPTA ( modulesFile , propertiesFile , propertyToCheck ) ;
}
/ / Non - PTA model checking
else {
else {
res = prism . modelCheckSimulator ( modulesFile , propertiesFile , propertyToCheck , info . getInitialState ( ) , info . getNoIterations ( ) , info . getMaxPathLength ( ) ) ;
res = prism . modelCheck ( model , propertiesFile , propertyToCheck ) ;
}
}
} else {
res = prism . modelCheckSimulator ( modulesFile , propertiesFile , propertyToCheck , info . getInitialState ( ) , info
. getNoIterations ( ) , info . getMaxPathLength ( ) ) ;
}
}
catch ( PrismException e )
{
} catch ( PrismException e ) {
/ / in case of error , report it ( in log only ) , store exception as the result and proceed
/ / in case of error , report it ( in log only ) , store exception as the result and proceed
errorLog ( e . getMessage ( ) ) ;
errorLog ( e . getMessage ( ) ) ;
res = new Result ( e ) ;
res = new Result ( e ) ;
@ -425,8 +428,7 @@ public class GUIExperiment
{
{
try {
try {
GUIExperiment . this . setResult ( definedMFConstants , definedPFConstants , res ) ;
GUIExperiment . this . setResult ( definedMFConstants , definedPFConstants , res ) ;
}
catch ( PrismException e ) {
} catch ( PrismException e ) {
error ( "Problem storing results" ) ;
error ( "Problem storing results" ) ;
}
}
}
}
@ -439,7 +441,8 @@ public class GUIExperiment
yield ( ) ;
yield ( ) ;
}
}
}
}
if ( ! clear ) model . clear ( ) ;
if ( ! clear )
model . clear ( ) ;
/ / iterate to next model
/ / iterate to next model
undefinedConstants . iterateModel ( ) ;
undefinedConstants . iterateModel ( ) ;
yield ( ) ;
yield ( ) ;
@ -457,12 +460,10 @@ public class GUIExperiment
} ) ;
} ) ;
experimentDone ( ) ;
experimentDone ( ) ;
if ( results . containsErrors ( ) ) errorDialog ( "One or more errors occured during this experiment.\nSelect \"View results\" or check the log for more information" ) ;
}
catch ( InterruptedException e )
{
try
{
if ( results . containsErrors ( ) )
errorDialog ( "One or more errors occured during this experiment.\nSelect \"View results\" or check the log for more information" ) ;
} catch ( InterruptedException e ) {
try {
SwingUtilities . invokeAndWait ( new Runnable ( )
SwingUtilities . invokeAndWait ( new Runnable ( )
{
{
public void run ( )
public void run ( )
@ -477,13 +478,16 @@ public class GUIExperiment
} ) ;
} ) ;
}
}
/ / catch and ignore possible exceptions from invokeAndWait call
/ / catch and ignore possible exceptions from invokeAndWait call
catch ( InterruptedException e2 ) { }
catch ( java . lang . reflect . InvocationTargetException e2 ) { }
if ( ! clear ) model . clear ( ) ;
catch ( InterruptedException e2 ) {
} catch ( java . lang . reflect . InvocationTargetException e2 ) {
}
if ( ! clear )
model . clear ( ) ;
experimentInterrupted ( ) ;
experimentInterrupted ( ) ;
}
}
/ / catch and ignore possible exception from invokeAndWait calls
/ / catch and ignore possible exception from invokeAndWait calls
catch ( java . lang . reflect . InvocationTargetException e ) { }
catch ( java . lang . reflect . InvocationTargetException e ) {
}
}
}
}
}
}
}