public void Handle(KAOSCoreElement element, ParsedElement attribute) { foreach (var builder in attributeBuilders) { var genericArguments = builder.GetType().BaseType.GetGenericArguments(); if (genericArguments[0].IsAssignableFrom(element.GetType()) && genericArguments[1].IsAssignableFrom(attribute.GetType())) { var method = builder.GetType().GetMethod("Handle", new[] { genericArguments[0], genericArguments[1], typeof(KAOSModel) }); if (method == null) { throw new Exception("Cannot find method Handle with generic parameters."); } try { method.Invoke(builder, new object[] { element, attribute, model }); } catch (TargetInvocationException e) { Console.WriteLine(e.InnerException); throw e.InnerException; } } } }
public UnsupportedValue(KAOSCoreElement element, ParsedAttribute attribute, object value) : base(string.Format("'{0}' is not supported in '{1}' on '{2}'", value?.GetType()?.Name, attribute?.GetType()?.Name, element?.GetType()?.Name), attribute) { }
/// <summary> /// Creates a new monitoring infrastructure for the specified formulas. /// The projection is used to compute the hash of the observed states. /// </summary> /// <param name="elements">The goals to monitor.</param> /// <param name="storage">The storage.</param> /// <param name="defaultProjection">Projection.</param> public KAOSCoreElementMonitor(KAOSModel model, KAOSCoreElement elements, TimeSpan monitoringDelay) { Ready = false; this.model = model; this.MonitoringDelay = monitoringDelay; }
protected void Handle <U>(KAOSCoreElement element, U value, string propertyName) { var definitionProperty = element.GetType().GetProperty(propertyName); if (definitionProperty == null) { throw new InvalidOperationException(string.Format("'{0}' has no property '{1}'", element.GetType(), propertyName)); } if (definitionProperty.PropertyType != typeof(U)) { throw new InvalidOperationException(string.Format("Type of property '{1}' in '{0}' is not '{2}'", element.GetType(), propertyName, typeof(T).Name)); } definitionProperty.SetValue(element, value, null); }
public virtual void PreBuildObstructionSet(Goal goal) { prebuilt_element = goal; obstructionSuperset = new ObstructionSuperset(goal); }
public static void Main(string[] args) { Console.WriteLine("*** This is UncertaintyPropagator from KAOSTools. ***"); Console.WriteLine("*** For more information on KAOSTools see <https://github.com/ancailliau/KAOSTools> ***"); Console.WriteLine("*** Please report bugs to <https://github.com/ancailliau/KAOSTools/issues> ***"); Console.WriteLine(); Console.WriteLine("*** Copyright (c) 2017, Université catholique de Louvain ***"); Console.WriteLine(""); string rootname = "root"; options.Add("root=", "Specify the root goal for which to compute the satisfaction rate. (Default: root)", v => rootname = v); int n_samples = 1000; options.Add("n_samples=", $"Specify the number of samples to use to perform Monte-Carlo simulation. (Default: {n_samples})", v => n_samples = int.Parse(v)); string outfile = null; options.Add("outfile=", "Specify the file to export the raw values, in csv.", v => outfile = v); bool doCombine = false; var combine = ExpertCombinationMethod.MendelSheridan; options.Add("combine=", "Combine the estimates from the experts using the specified method.", v => { doCombine = true; if (v.Equals("cook")) { combine = ExpertCombinationMethod.Cook; } else if (v.Equals("mendel-sheridan") | v.Equals("mendelsheridan") | v.Equals("ms")) { combine = ExpertCombinationMethod.MendelSheridan; } else { PrintError($"Combination method '{v}' is not known"); Environment.Exit(1); } }); Init(args); KAOSCoreElement root = model.Goal(rootname); if (root == null) { root = model.Obstacle(rootname); if (root == null) { PrintError("The goal or obstacle '" + rootname + "' was not found."); } } try { if (doCombine) { expert_combination = new ExpertCombinator(model, combine); expert_combination.Combine(); } IPropagator _propagator; _propagator = new BDDBasedUncertaintyPropagator(model, n_samples); SimulatedSatisfactionRate esr = null; if (root is Goal g) { esr = (SimulatedSatisfactionRate)_propagator.GetESR(g); } else if (root is Obstacle o) { esr = (SimulatedSatisfactionRate)_propagator.GetESR(o); } Console.WriteLine(root.FriendlyName + ":"); Console.WriteLine(" Mean: {0:P}", esr.Mean); if (root is Goal g2) { Console.WriteLine(" Required Satisfaction Rate: {0:P}", g2.RDS); Console.WriteLine(" Violation Uncertainty: {0:P}", esr.ViolationUncertainty(g2.RDS)); Console.WriteLine(" Uncertainty Spread: {0}", esr.UncertaintySpread(g2.RDS)); } if (doCombine && combine == ExpertCombinationMethod.Cook) { var stats = (CookFrameworkStatistics)expert_combination.GetStatistics(); Console.WriteLine(); Console.WriteLine("-- Information score (Cook):"); foreach (var item in stats.InformationScores) { Console.WriteLine($" {item.Key} : {item.Value}"); } Console.WriteLine("-- Calibration score (Cook):"); foreach (var item in stats.CalibrationScores) { Console.WriteLine($" {item.Key} : {item.Value}"); } Console.WriteLine("-- Combination weights (Cook):"); foreach (var item in stats.Weights) { Console.WriteLine($" {item.Key.Name} : {item.Value}"); } } if (!string.IsNullOrEmpty(outfile)) { var out_filename = Environment.ExpandEnvironmentVariables(outfile); using (var f = File.CreateText(out_filename)) { f.WriteLine(root.Identifier); f.Write(string.Join("\n", esr.Values)); } } } catch (Exception e) { PrintError("An error occured during the computation. (" + e.Message + ").\n" + "Please report this error to <https://github.com/ancailliau/KAOSTools/issues>.\n" + "----------------------------\n" + e.StackTrace + "\n----------------------------\n"); } }