GoalRefinement GenerateGoalRefinement(Goal parent) { var mode = (_options.MinGoalBranchingFactor + _options.MaxGoalBranchingFactor) / 2; var nbchild = Triangular.Sample(_random, _options.MinGoalBranchingFactor, _options.MaxGoalBranchingFactor, mode); var refinement = new GoalRefinement(_model) { ParentGoalIdentifier = parent.Identifier }; do { refinement.RefinementPattern = _faker.PickRandom <RefinementPattern> (); } while (refinement.RefinementPattern == RefinementPattern.None || refinement.RefinementPattern == RefinementPattern.Case); for (int i = 0; i < nbchild; i++) { var c = GenerateGoal(); refinement.Add(c); } _model.Add(refinement); return(refinement); }
void KeepObstructedGoal(Resolution resolution) { // Get the anchor goal var anchor = resolution.AnchorIdentifier; var anchor_goal = _model.Goal(anchor); // Get the refinements in which the anchor goal is involved var refinements = _model.GoalRefinements(x => x.SubGoalIdentifiers.Any(y => y.Identifier == anchor)); // Create a new goal var new_anchor = new Goal(_model); new_anchor.Name = anchor_goal.Name; new_anchor.FormalSpec = anchor_goal.FormalSpec; _model.Add(new_anchor); // Replace anchor goal by new goal in refinements foreach (var r in refinements) { r.SubGoalIdentifiers = new HashSet <GoalRefinee> (r.SubGoalIdentifiers.Where(x => x.Identifier != anchor)); r.Add(new_anchor); } // Create a new refinement with anchor goal and cm goal var new_refinement = new GoalRefinement(_model); new_refinement.ParentGoalIdentifier = new_anchor.Identifier; new_refinement.Add(anchor); new_refinement.Add(resolution.ResolvingGoalIdentifier); _model.Add(new_refinement); Obstacle obstacle = resolution.Obstacle(); propagator.DownPropagateAddConjunct (resolution, new Not(obstacle.FormalSpec), obstacle.Name != null ? "Not " + obstacle.Name : null); // Set the probability of the resolved obstacle to 0 // TODO Use a flag "resolved" obstacle.Resolved = true; //_model.satisfactionRateRepository.AddObstacleSatisfactionRate (obstacle.Identifier, new DoubleSatisfactionRate (0)); // Remove the resolution, its appearans in refinements and obstructions //Delete (resolution); }
public override void Handle(Goal element, ParsedRefinedByAttribute attribute, KAOSModel model) { var refinement = new GoalRefinement(model); refinement.SetParentGoal(element); // Parse the reference to children foreach (var child in attribute.ParsedRefinees) { var id = child.Identifier; var param = child.Parameters; IRefineeParameter refineeParameter = null; if (param != null) { if (param is ParsedPrimitiveRefineeParameter <double> ) { var cast = ((ParsedPrimitiveRefineeParameter <double>)param); refineeParameter = new PrimitiveRefineeParameter <double> (cast.Value); } else { throw new NotImplementedException(); } } Goal refinee; DomainProperty domprop; DomainHypothesis domhyp; if ((refinee = model.goalRepository.GetGoal(id)) != null) { refinement.Add(refinee, refineeParameter); } else if ((domprop = model.domainRepository.GetDomainProperty(id)) != null) { refinement.Add(domprop, refineeParameter); } else if ((domhyp = model.domainRepository.GetDomainHypothesis(id)) != null) { refinement.Add(domhyp, refineeParameter); } else { refinee = new Goal(model, id) { Implicit = true }; model.goalRepository.Add(refinee); refinement.Add(refinee); } } // Parse the context if (!string.IsNullOrEmpty(attribute.ContextIdentifier)) { var id = attribute.ContextIdentifier; Context context; if ((context = model.modelMetadataRepository.GetContext(id)) == null) { context = new Context(model, id); model.modelMetadataRepository.Add(context); } refinement.ContextIdentifier = context.Identifier; } // Parse the refinement pattern provided if (attribute.RefinementPattern != null) { if (attribute.RefinementPattern.Name == ParsedRefinementPatternName.Milestone) { refinement.RefinementPattern = RefinementPattern.Milestone; } else if (attribute.RefinementPattern.Name == ParsedRefinementPatternName.Case) { refinement.RefinementPattern = RefinementPattern.Case; } else if (attribute.RefinementPattern.Name == ParsedRefinementPatternName.IntroduceGuard) { refinement.RefinementPattern = RefinementPattern.IntroduceGuard; } else if (attribute.RefinementPattern.Name == ParsedRefinementPatternName.DivideAndConquer) { refinement.RefinementPattern = RefinementPattern.DivideAndConquer; } else if (attribute.RefinementPattern.Name == ParsedRefinementPatternName.Uncontrollability) { refinement.RefinementPattern = RefinementPattern.Uncontrollability; } else if (attribute.RefinementPattern.Name == ParsedRefinementPatternName.Unmonitorability) { refinement.RefinementPattern = RefinementPattern.Unmonitorability; } else { throw new BuilderException("Unsupported pattern " + refinement.RefinementPattern, attribute); } } if (!refinement.IsEmpty) { model.Add(refinement); } }