public static FurtherTestingOutput FindCounterExamples(FurtherTestingInput input) { var log = new LogService(); try { IAnalyzer analyzer = new UIMain.Analyzer(); if (input.EnableLogging) { analyzer.LoggingOn(log); } else { analyzer.LoggingOff(); log.LogDebug("Logging is disabled."); } Stopwatch sw = new Stopwatch(); sw.Start(); var cexBifurcates = analyzer.findCExBifurcates(input.Model, input.Analysis); var cexCycles = analyzer.findCExCycles(input.Model, input.Analysis); var cexFixPoints = analyzer.findCExFixpoint(input.Model, input.Analysis); sw.Stop(); var cexs = new List <CounterExampleOutput>(); if (FSharpOption <BifurcationCounterExample> .get_IsSome(cexBifurcates)) { cexs.Add(cexBifurcates.Value); } if (FSharpOption <CycleCounterExample> .get_IsSome(cexCycles)) { cexs.Add(cexCycles.Value); } if (FSharpOption <FixPointCounterExample> .get_IsSome(cexFixPoints)) { cexs.Add(cexFixPoints.Value); } log.LogDebug(string.Format("Finding Counter Examples took {0} to run.", sw.Elapsed)); return(new FurtherTestingOutput { CounterExamples = cexs.ToArray(), ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } catch (Exception ex) { var version = typeof(Analysis).Assembly.GetName().Version; log.LogError(String.Format("Failed when looking for counter examples. Assembly version: {0}. Exception: {1}", version, ex)); return(new FurtherTestingOutput { Error = ex.Message, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } }
public static AnalysisOutput Analyze(AnalysisInput input) { var log = new LogService(); try { IAnalyzer analyzer = new UIMain.Analyzer(); if (input.EnableLogging) { analyzer.LoggingOn(log); } else { analyzer.LoggingOff(); log.LogDebug("Logging is disabled."); } Stopwatch sw = new Stopwatch(); sw.Start(); var result = analyzer.checkStability(input); sw.Stop(); log.LogDebug(string.Format("The analysis took {0}", sw.Elapsed)); if (result.Status != StatusType.Stabilizing && result.Status != StatusType.NotStabilizing) { throw new Exception("The stability status is neither 'Stabilizing' nor 'NotStabilizing'; result error: " + (result.Error == null ? "<null>" : result.Error)); } return(new AnalysisOutput { Error = result.Error, Ticks = result.Ticks, Status = result.Status, Time = (int)Math.Round(sw.Elapsed.TotalSeconds, 1), ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } catch (Exception ex) { var version = typeof(Analysis).Assembly.GetName().Version; log.LogError(String.Format("Analysis failed. Assembly version: {0}. Exception: {1}", version, ex)); // Return an Unknown if fails return(new AnalysisOutput { Status = StatusType.Error, Error = ex.Message, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } }
public static SimulationOutput Simulate(SimulationInput input) { var log = new LogService(); try { IAnalyzer analyzer = new UIMain.Analyzer(); if (input.EnableLogging) { analyzer.LoggingOn(log); } else { analyzer.LoggingOff(); log.LogDebug("Logging is disabled."); } Stopwatch sw = new Stopwatch(); sw.Start(); var output = analyzer.simulate_tick(input.Model, input.Variables); sw.Stop(); log.LogDebug(string.Format("The simulation took {0}", sw.Elapsed)); return(new SimulationOutput { Variables = output, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null, }); } catch (Exception ex) { var version = typeof(Simulation).Assembly.GetName().Version; log.LogError(String.Format("Simulation failed. Assembly version: {0}. Exception: {1}", version, ex)); return(new SimulationOutput { ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } }
public static LTLAnalysisResult Simulate(LTLSimulationAnalysisInputDTO input) { LogService log = new LogService(); try { string formula = input.Formula; string num_of_steps = input.Number_of_steps; IAnalyzer analyzer = new UIMain.Analyzer(); if (input.EnableLogging) { analyzer.LoggingOn(log); } else { analyzer.LoggingOff(); log.LogDebug("Logging is disabled."); } Stopwatch sw = new Stopwatch(); sw.Start(); var result = analyzer.checkLTLSimulation(input, formula, num_of_steps); sw.Stop(); log.LogDebug(string.Format("The LTL simulation took {0}", sw.Elapsed)); if (FSharpOption <LTLAnalysisResultDTO> .get_IsNone(result)) { return(new LTLAnalysisResult { Error = null, Ticks = null, Status = LTLStatus.Unknown, Loop = -1, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } else { var res = result.Value; var status = res.Status; return(new LTLAnalysisResult { Error = res.Error, Ticks = res.Ticks, Status = status ? LTLStatus.True : LTLStatus.False, Loop = res.Loop, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } } catch (Exception ex) { var version = typeof(Analysis).Assembly.GetName().Version; log.LogError(String.Format("LTL simulation failed. Assembly version: {0}. Exception: {1}", version, ex)); return(new LTLAnalysisResult { Error = ex.Message, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }); } }
public static Tuple <LTLAnalysisResult, LTLAnalysisResult> Polarity(LTLPolarityAnalysisInputDTO input) { LogService log = new LogService(); try { string formula = input.Formula; string num_of_steps = input.Number_of_steps; FSharpOption <bool> polarity = FSharpOption <bool> .None; if (input.Polarity != LTLStatus.Unknown) { polarity = new FSharpOption <bool>(input.Polarity == LTLStatus.True); } IAnalyzer analyzer = new UIMain.Analyzer(); if (input.EnableLogging) { analyzer.LoggingOn(log); } else { analyzer.LoggingOff(); log.LogDebug("Logging is disabled."); } Stopwatch sw = new Stopwatch(); sw.Start(); var result = analyzer.checkLTLPolarity(input, formula, num_of_steps, polarity); sw.Stop(); log.LogDebug(string.Format("The LTL polarity check took {0}", sw.Elapsed)); var positive = new LTLAnalysisResult { Error = result.Item1.Error, Ticks = result.Item1.Ticks, Status = result.Item1.Status ? LTLStatus.True : LTLStatus.False, Loop = result.Item1.Loop, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }; LTLAnalysisResult negative = null; if (result.Item2 != null && !FSharpOption <LTLAnalysisResultDTO> .get_IsNone(result.Item2)) { negative = new LTLAnalysisResult { Error = result.Item2.Value.Error, Ticks = result.Item2.Value.Ticks, Status = result.Item2.Value.Status ? LTLStatus.True : LTLStatus.False, Loop = result.Item2.Value.Loop, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }; } return(new Tuple <LTLAnalysisResult, LTLAnalysisResult>(positive, negative)); } catch (Exception ex) { var version = typeof(Analysis).Assembly.GetName().Version; log.LogError(String.Format("LTL Polarity check failed. Assembly version: {0}. Exception: {1}", version, ex)); return(new Tuple <LTLAnalysisResult, LTLAnalysisResult>(new LTLAnalysisResult { Error = ex.Message, ErrorMessages = log.ErrorMessages.Length > 0 ? log.ErrorMessages.ToArray() : null, DebugMessages = log.DebugMessages.Length > 0 ? log.DebugMessages.ToArray() : null }, null)); } }