public double GlobalLikelihood(ActivationBinaryTree tree, List <ParametrizedTemplate> model, ActivationNode conflictResolution) { double result = 0; ActivationTreeBuilder treeBuilder = new(); var kOfConflictActivations = GetConflict(tree); var constraints = model .Where(x => x.TemplateDescription.TemplateParametersType == TemplateTypes.BiTemplate) .SelectMany(x => x.TemplateInstances).Cast <BiTemplate>().ToList(); foreach (var resolution in kOfConflictActivations) { var gama = 0; foreach (var constraint in constraints) { var tempTree = treeBuilder.BuildTree(conflictResolution.Subtrace, constraint); if (GetFulfillment(tempTree).Contains(resolution)) { gama += 1; } else if (GetViolation(tempTree).Contains(resolution)) { gama += 1; } } result += gama; } return(result / kOfConflictActivations.Count); }
/// <summary> /// Assigns activation type (fulfillment, conflict, violation, none) to /// each event in provided list based on activation tree. /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <param name="events">Events to which type should be assigned.</param> /// <returns>Wrapped events from list events with assigned type.</returns> private List <WrappedEventActivation> GetEventActivationTypes(ActivationBinaryTree tree, List <Event> events) { var fulfilment = GetFulfillment(tree); var violation = GetViolation(tree); var conflict = GetConflict(tree, violation, fulfilment); return(GetEventActivationTypes(events, fulfilment, conflict, violation)); }
/// <summary> /// Get nodes (maximal subtraces) containing given activation /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <param name="intr">List of activations for which corresponding nodes should be returned.</param> /// <returns>List of nodes containing at least one of activities from parameter intr</returns> private IEnumerable <ActivationNode> GetNodesWith(ActivationBinaryTree tree, List <Event> intr) { if (intr is null) { return(new List <ActivationNode>()); } return(tree.Leaves.Where(node => !node.IsDead && node.MaxFulfilling && node.Subtrace.Intersect(intr).Any())); }
/// <summary> /// Get all fulfilling activations from the activation tree. /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <returns>All fulfilling activations.</returns> public List <Event> GetFulfillment(ActivationBinaryTree tree) { return(tree.Leaves .Where(x => x.MaxFulfilling) .Select(x => x.Subtrace) .Aggregate((x, y) => x .Intersect(y, new EventEqualityComparer()) .ToList()) .Where(x => tree.Constraint.IsActivation(x)) .ToList()); }
/// <summary> /// Get all violating activations from the activation tree. /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <returns>All violating activations.</returns> public List <Event> GetViolation(ActivationBinaryTree tree) { var all = tree.Leaves .Where(x => x.MaxFulfilling) .SelectMany(x => x.Subtrace); return(tree.Leaves .SelectMany(x => x.Subtrace) .Except(all) .Where(x => tree.Constraint.IsActivation(x)) .ToList()); }
public double LocalLikelihood(ActivationBinaryTree tree, ActivationNode conflictResolution) { var trace = tree.Leaves.Where(n => n.MaxFulfilling) .SelectMany(n => n.Subtrace) .Distinct(new EventEqualityComparer()) .ToList(); var nf = conflictResolution.Subtrace.Count(tree.Constraint.IsActivation); var na = trace.Count(tree.Constraint.IsActivation); return(nf / (double)na); }
/// <summary> /// Get all conflicting activations from the activation tree. /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <returns>All conflicting activations.</returns> public List <Event> GetConflict(ActivationBinaryTree tree, List <Event> violations = null, List <Event> fulfilments = null) { violations ??= GetViolation(tree); fulfilments ??= GetFulfillment(tree); return(tree.Leaves .Where(x => x.MaxFulfilling) .SelectMany(x => x.Subtrace) .Except(violations) .Except(fulfilments) .Where(x => tree.Constraint.IsActivation(x)) .ToList()); }
/// <summary> /// Local likelihood of conflict resolutions (conflicting maximal subtrace). /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <param name="conflictResolution">List of conflicting leaves/subtraces</param> /// <returns> /// Dictionary where key is conflicting resolution and value is its /// local likelihood from interval (0, 1) /// </returns> public Dictionary <ActivationNode, double> LocalLikelihood(ActivationBinaryTree tree, List <ActivationNode> conflictResolution = null) { var conflicts = GetConflict(tree); conflictResolution ??= GetConflictNodes(tree, conflicts); var na = conflictResolution .Aggregate(0, (num, c) => num + c.Subtrace .Count(tree.Constraint.IsActivation)); return(conflictResolution .ToDictionary(x => x, y => LocalLikelihoodNode(y, na, tree.Constraint))); }
/// <summary> /// Get nodes (maximal subtraces) containing violating activation /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <param name="conflicts"> /// List of violating activations for which nodes should be returned. /// If null, all violating nodes in the tree will be returned. /// </param> /// <returns>List of violating nodes</returns> public List <ActivationNode> GetViolationNodes(ActivationBinaryTree tree, List <Event> violations = null) { violations ??= GetViolation(tree); return(GetNodesWith(tree, violations).ToList()); }
/// <summary> /// Get nodes (maximal subtraces) containing conflicting activation /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <param name="conflicts"> /// List of conflicting activations for which nodes should be returned. /// If null, all conflicting nodes in the tree will be returned. /// </param> /// <returns>List of conflicting nodes</returns> public List <ActivationNode> GetConflictNodes(ActivationBinaryTree tree, List <Event> conflicts = null) { conflicts ??= GetConflict(tree); return(GetNodesWith(tree, conflicts).ToList()); }
/// <summary> /// Get nodes (maximal subtraces) containing fulfilling activation /// </summary> /// <param name="tree">Tree representing evaluation of constraint over some trace.</param> /// <param name="conflicts"> /// List of fulfilling activations for which nodes should be returned. /// If null, all fulfilling nodes in the tree will be returned. /// </param> /// <returns>List of fulfilling nodes</returns> public List <ActivationNode> GetFulfillNodes(ActivationBinaryTree tree, List <Event> fulfillments = null) { fulfillments ??= GetFulfillment(tree); return(GetNodesWith(tree, fulfillments).ToList()); }