public TrackingExteriorCrackLSM(IPropagator propagator, double tipEnrichmentAreaRadius,
                                        IHeavisideSingularityResolver singularityResolver)
        {
            this.propagator = propagator;
            this.tipEnrichmentAreaRadius = tipEnrichmentAreaRadius;

            this.crackPath     = new List <CartesianPoint>();
            this.levelSetsBody = new Dictionary <XNode, double>();
            this.levelSetsTip  = new Dictionary <XNode, double>();
            this.tipElements   = new List <XContinuumElement2D>();

            this.crackBodyNodesAll          = new HashSet <XNode>();
            this.crackBodyNodesModified     = new HashSet <XNode>();
            this.crackBodyNodesNearModified = new HashSet <XNode>();
            this.crackBodyNodesNew          = new HashSet <XNode>();
            this.crackBodyNodesRejected     = new HashSet <XNode>();
            this.crackTipNodesNew           = new HashSet <XNode>();
            this.crackTipNodesOld           = new HashSet <XNode>();
            this.ElementsModified           = new HashSet <XContinuumElement2D>();

            //this.levelSetUpdater = new LevelSetUpdaterOLD();
            this.levelSetUpdater = new LevelSetUpdaterStolarska();
            //this.meshInteraction = new StolarskaMeshInteraction(this);
            //this.meshInteraction = new HybridMeshInteraction(this);
            this.meshInteraction     = new SerafeimMeshInteraction(this);
            this.SingularityResolver = singularityResolver;
        }
Beispiel #2
0
 public MultiplePingSimulation(float speed, float time, Mesh polyhedraMesh, IPropagator propagator, int startVertex = 0) : base(speed, time)
 {
     this.propagator  = propagator;
     this.startVertex = startVertex;
     pingQueue        = new Queue <int>();
     pings            = new SortedSet <Tuple <double, int> >();
 }
        public double GetMinimalCost(Goal goal, IPropagator propagator)
        {
            var countermeasure_goals = _model.Resolutions().Select(x => x.ResolvingGoalIdentifier).Distinct();

            // Initialize vector
            var mapping = Enumerable.Zip(Enumerable.Range(0, countermeasure_goals.Count()), countermeasure_goals, (arg1, arg2) => new { arg1, arg2 })
                          .ToDictionary(item => item.arg1, item => item.arg2);

            double[] sampling = GetInitialSampling(countermeasure_goals, mapping);

            var random = new Random();
            var rho    = .1;

            int i = 0;

            while (Iterations < StoppingCriterion & i < MaxIterations)
            {
                var gammaT = IterateCost(goal, propagator, sampling, mapping, random, rho);
                if (Math.Abs(gammaT - lastGammaT) <= EPSILON)
                {
                    Iterations++;
                }
                else
                {
                    Iterations = 0;
                }

                lastGammaT = gammaT;

                Console.WriteLine($"{gammaT:0.00} | " + string.Join(" ", sampling.Select(x => $"{x:0.00}")));
                i++;
            }

            return(lastGammaT);
        }
        private double GetScore(Goal goal, IPropagator propagator, HashSet <string> selection)
        {
            double maxSatRate;
            var    r = _model.Resolutions().Where(x => selection.Contains(x.ResolvingGoalIdentifier));

            // Integrate the selection
            foreach (var resolution in r)
            {
                integrator.Integrate(resolution);
            }

            var satRate = (DoubleSatisfactionRate)propagator.GetESR(goal);
            //var all_goals_satisfied = (satRate.SatisfactionRate > goal.RDS);

            //if (all_goals_satisfied) {
            var cost = selection.Count();

            maxSatRate = satRate.SatisfactionRate;

            foreach (var resolution in r)
            {
                integrator.Remove(resolution);
            }

            return(maxSatRate);
        }
        public TracerShim(Trace.Tracer tracer, IPropagator textFormat)
        {
            this.tracer     = tracer ?? throw new ArgumentNullException(nameof(tracer));
            this.propagator = textFormat ?? throw new ArgumentNullException(nameof(textFormat));

            this.ScopeManager = new ScopeManagerShim(this.tracer);
        }
Beispiel #6
0
        private static SpanContext ExtractPropagatedContext(IPropagator propagator, HttpRequest request)
        {
            try
            {
                // extract propagation details from http headers
                var requestHeaders = request.Headers;

                if (requestHeaders != null)
                {
                    var headersCollection = new DictionaryHeadersCollection();

                    foreach (var header in requestHeaders)
                    {
                        string   key    = header.Key;
                        string[] values = header.Value.ToArray();

                        if (key != null && values.Length > 0)
                        {
                            headersCollection.Add(key, values);
                        }
                    }

                    return(propagator.Extract(headersCollection));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error extracting propagated HTTP headers.");
            }

            return(null);
        }
        private double GetScore(IEnumerable <Goal> goals, IPropagator propagator, HashSet <string> selection, out IEnumerable <string> rootsSatisfied)
        {
            var r = _model.Resolutions().Where(x => selection.Contains(x.ResolvingGoalIdentifier));
            var rootGoalsSatisfied = new HashSet <string> ();

            integrator = new SoftResolutionIntegrator(_model);
            Console.WriteLine("---- Computing score for " + string.Join(",", selection) + ".");
            // Integrate the selection
            foreach (var resolution in r)
            {
                Console.WriteLine("Integrate " + resolution.ResolvingGoalIdentifier);
                integrator.Integrate(resolution);
            }

            var p2 = new BDDBasedPropagator(_model);

            //var all_goals_satisfied = true;
            var avg_sat_rate = 0.0;

            foreach (var goal in goals)
            {
                var satRate = ((DoubleSatisfactionRate)p2.GetESR(goal));
                avg_sat_rate += satRate.SatisfactionRate;
                if (satRate.SatisfactionRate >= goal.RDS)
                {
                    rootGoalsSatisfied.Add(goal.Identifier);
                }

                Console.WriteLine("Cost " + selection.Count);
                Console.WriteLine("Selected cm: " + string.Join(",", selection));
                Console.WriteLine($"{goal.Identifier} : {satRate.SatisfactionRate} >= {goal.RDS}.");
            }

            //var all_goals_satisfied = (satRate.SatisfactionRate > goal.RDS);


            var cost = selection.Count();


            foreach (var resolution in r)
            {
                integrator.Remove(resolution);
            }

            //if (!all_goals_satisfied)
            //{
            //	Console.WriteLine("---- not all goal satisfied, returning score = 0");
            //	return 0;
            //}

            rootsSatisfied = rootGoalsSatisfied;

            //if (satRate > goal.RDS) {
            Console.WriteLine("---- returning score = " + (avg_sat_rate / goals.Count()));
            return(avg_sat_rate / goals.Count());
            //} else {
            //	return 0;
            //}
        }
 public ApplicationInsightsTracer(TelemetryConfiguration config, IScopeManager scopeManager,
                                  IPropagator <ITextMap> propagator, ITimeProvider timeProvider, Endpoint localEndpoint)
 {
     Client        = new TelemetryClient(config);
     _config       = config;
     ScopeManager  = scopeManager;
     _propagator   = propagator;
     TimeProvider  = timeProvider;
     LocalEndpoint = localEndpoint;
 }
        /// <summary>
        ///     Add a new propagator to a stack.
        /// </summary>
        /// <param name="propagator"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public PropagatorStack AddPropagator(IPropagator propagator)
        {
            if (propagator == null)
            {
                throw new ArgumentNullException(nameof(propagator));
            }

            Propagators.Add(propagator);
            return(this);
        }
Beispiel #10
0
 public CompositeTextMapPropagatorTests()
 {
     _multiplexer = new CompositeTextMapPropagator(
         new[]
     {
         new ExamplePropagatorStub("propagator-1", "propagation-1", canExtract: false),
         new ExamplePropagatorStub("propagator-2", "propagation-2", canExtract: true),
         new ExamplePropagatorStub("propagator-3", "propagation-3", canExtract: true)
     });
 }
Beispiel #11
0
 /// <summary>
 ///     Add a new propagator to a stack.
 /// </summary>
 /// <param name="propagator"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public PropagatorStack AddPropagator(IPropagator propagator)
 {
     if (propagator == null)
     {
         throw new ArgumentNullException(nameof(propagator));
     }
     _logger.Trace($"Adding {propagator.GetType()} to PropagatorStack.");
     Propagators.Add(propagator);
     return(this);
 }
Beispiel #12
0
 public ZipkinTracer(ZipkinTracerOptions options)
 {
     _propagator   = options.Propagator ?? new B3Propagator();
     _reporter     = options.Reporter;
     LocalEndpoint = options.LocalEndpoint;
     TimeProvider  = options.TimeProvider ?? new DateTimeOffsetTimeProvider();
     ScopeManager  = options.ScopeManager ?? new AsyncLocalScopeManager();
     IdProvider    = options.IdProvider ?? ThreadLocalRngSpanIdProvider.TraceId128BitProvider;
     Sampler       = options.Sampler ?? NoSampler.Instance;
     Options       = options;
 }
Beispiel #13
0
 public MockZipkinTracer(Endpoint localEndpoint     = null, ITimeProvider timeProvider = null,
                         ISpanIdProvider idProvider = null,
                         IScopeManager scopeManager = null, IPropagator <ITextMap> propagtor = null, ITraceSampler sampler = null)
 {
     LocalEndpoint  = localEndpoint ?? Endpoint.Testing;
     TimeProvider   = timeProvider ?? new DateTimeOffsetTimeProvider();
     IdProvider     = idProvider ?? ThreadLocalRngSpanIdProvider.TraceId128BitProvider;
     ScopeManager   = scopeManager ?? NoOp.ScopeManager;
     _propagator    = propagtor ?? new B3Propagator();
     Sampler        = sampler ?? NoSampler.Instance;
     CollectedSpans = new ConcurrentQueue <Span>();
 }
        public void Register(string format, IPropagator propagator)
        {
            if (string.IsNullOrWhiteSpace(format))
            {
                throw new ArgumentException("The format can not be null, empty or whitespace");
            }

            if (propagator == null)
            {
                throw new ArgumentNullException(nameof(propagator));
            }
            propagators[format] = propagator;
        }
Beispiel #15
0
    public IPropagator AddDependent(IPropagator dependent, bool biDirectional)
    {
        if (!_dependencyList.Contains(dependent))
        {
            _dependencyList.Add(dependent);
        }

        if (biDirectional)
        {
            dependent.AddDependent(this, false);
        }

        return(this);
    }
Beispiel #16
0
    public IPropagator RemoveDependent(IPropagator dependent, bool biDirectional)
    {
        if (_dependencyList.Contains(dependent))
        {
            _dependencyList.Remove(dependent);

            if (biDirectional)
            {
                dependent.RemoveDependent(this, false);
            }
        }

        return(this);
    }
        private IEnumerable <Candidate> Iterate(IEnumerable <Goal> goals, IPropagator propagator, double[] sampling, Dictionary <int, string> mapping, Random random, double rho)
        {
            var candidates = new List <Candidate>();

            for (int i = 0; i < N; i++)
            {
                HashSet <string> selection = GetRandomSelection(sampling, mapping, random);

                var satRate = GetScore(goals, propagator, selection, out IEnumerable <string> nb_root_sat);
                candidates.Add(new Candidate(selection, satRate, nb_root_sat));
            }

            for (int i = 0; i < N; i++)
            {
                candidates[i].Rank = 1 + candidates.Count(x => candidates[i].Dominate(x));
            }

            candidates = candidates.OrderBy(x => x.Rank).ToList();

            for (int i = 0; i < N; i++)
            {
                var c = candidates[i];
                Console.WriteLine($"{c.Rank:00} | {c.cost} {c.nb_root_sat} {c.score:0.00} | " + string.Join(",", c.cm));
            }
            Console.WriteLine();

            var gammaT = candidates[(int)Math.Ceiling((1 - rho) * N)].Rank;

            var new_sampling        = new double[sampling.Length];
            var normalizationFactor = 0;

            for (int i = 0; i < sampling.Length; i++)
            {
                int c = candidates.Count(x => x.Rank <= gammaT & x.cm.Contains(mapping[i]));
                new_sampling[i]      = c;
                normalizationFactor += c;
                //Console.WriteLine($"sampling[{i}] = {c}");
            }



            for (int i = 0; i < sampling.Length; i++)
            {
                sampling[i] = alpha * sampling[i] + (1 - alpha) * (new_sampling[i] / normalizationFactor);
            }

            Console.WriteLine($"{gammaT:0.00} | " + string.Join(" ", sampling.Select(x => $"{x:0.00}")));

            return(candidates.Where(x => x.Rank == 1));
        }
        private double Iterate(double minCost, Goal goal, IPropagator propagator, double[] sampling, Dictionary <int, string> mapping, Random random, double rho)
        {
            var candidates = new List <Candidate>();

            for (int i = 0; i < N; i++)
            {
                HashSet <string> selection = GetRandomSelection(sampling, mapping, random);
                if (selection.Count() > minCost)
                {
                    // Ignore solution
                    candidates.Add(new Candidate(selection, 0));
                }
                else
                {
                    var maxSatRate = GetScore(goal, propagator, selection);
                    if (maxSatRate > goal.RDS)
                    {
                        candidates.Add(new Candidate(selection, maxSatRate));
                    }
                    else
                    {
                        candidates.Add(new Candidate(selection, 0));
                    }
                }
            }

            candidates = candidates.OrderBy(x => x.score).ToList();

            var gammaT = candidates[(int)Math.Ceiling((1 - rho) * N)].score;

            var normalizationFactor = 0;

            for (int i = 0; i < sampling.Length; i++)
            {
                int c = candidates.Count(x => x.score >= gammaT & x.cm.Contains(mapping[i]));
                sampling[i]          = c;
                normalizationFactor += c;
                //Console.WriteLine($"sampling[{i}] = {c}");
            }

            for (int i = 0; i < sampling.Length; i++)
            {
                sampling[i] /= normalizationFactor;
            }

            return(gammaT);
        }
        private Tracer(IScopeManager scopeManager, IPropagator propagator, Options options, ISpanRecorder spanRecorder)
        {
            ScopeManager  = scopeManager;
            _spanRecorder = spanRecorder;
            _propagator   = propagator;
            _options      = options;

            var protocol = _options.Satellite.UsePlaintext ? "http" : "https";
            // TODO: refactor to support changing proto
            var url =
                $"{protocol}://{_options.Satellite.SatelliteHost}:{_options.Satellite.SatellitePort}/{LightStepConstants.SatelliteReportPath}";

            _httpClient = new LightStepHttpClient(url, _options);

            // assignment to a variable here is to suppress warnings that we're not awaiting an async method
            _reportLoop = new Timer(e => Flush(), null, TimeSpan.Zero, _options.ReportPeriod);
        }
Beispiel #20
0
        private Tracer(IScopeManager scopeManager, IPropagator propagator, Options options, ISpanRecorder spanRecorder, ILightStepHttpClient client)
        {
            ScopeManager  = scopeManager;
            _spanRecorder = spanRecorder;
            _propagator   = propagator;
            _options      = options;
            _logger.Debug(
                $"Creating new tracer with GUID {_options.TracerGuid}. Project Access Token: {_options.AccessToken}, Report Period: {_options.ReportPeriod}, Report Timeout: {_options.ReportTimeout}.");
            var protocol = _options.Satellite.UsePlaintext ? "http" : "https";
            var url      =
                $"{protocol}://{_options.Satellite.SatelliteHost}:{_options.Satellite.SatellitePort}/{LightStepConstants.SatelliteReportPath}";

            _httpClient = client ?? new LightStepHttpClient(url, _options);
            _logger.Debug($"Tracer is reporting to {url}.");
            _reportLoop        = new Timer(e => Flush(), null, TimeSpan.Zero, _options.ReportPeriod);
            _firstReportHasRun = false;
        }
Beispiel #21
0
    public void Process(StateChange newState, StateChangeOptions options, IPropagator sender)
    {
        System.Console.WriteLine(options);
        if ((options & StateChangeOptions.Update) != 0)
        {
            Process(newState);
        }

        if ((options & StateChangeOptions.Notify) != 0)
        {
            _dependencyList.ForEach(x =>
            {
                if (x != sender)
                {
                    x.Process(newState, options, this);
                }
            });
        }
    }
        public IEnumerable <OptimalSelection> GetOptimalSelections(HashSet <Goal> goals, IPropagator propagator)
        {
            var countermeasure_goals = _model.Resolutions().Select(x => x.ResolvingGoalIdentifier).Distinct();

            // Initialize vector
            var mapping = Enumerable.Zip(Enumerable.Range(0, countermeasure_goals.Count()), countermeasure_goals, (arg1, arg2) => new { arg1, arg2 })
                          .ToDictionary(item => item.arg1, item => item.arg2);

            double[] sampling = GetInitialSampling(countermeasure_goals, mapping);

            var random = new Random();

            int i           = 0;
            var paretoFront = new HashSet <Candidate>();

            Iterations = 0;
            while (Iterations < StoppingCriterion & i < MaxIterations)
            {
                Console.WriteLine("iterate");
                var paretoFrontIteration = Iterate(goals, propagator, sampling, mapping, random, rho);

                var spf = paretoFront.Count;

                // Add all new non-dominated solutions
                foreach (var item in paretoFrontIteration)
                {
                    paretoFront.Add(item);
                }

                //Console.WriteLine("Before");
                //Console.WriteLine(string.Join("\n", paretoFront.Select(x => x.score + " " + x.cost + " | " + string.Join(",", x.cm))));

                // Remove all dominated solutions
                paretoFront = paretoFront.Where(x => !paretoFront.Any(y => y.Dominate(x))).ToHashSet();

                //Console.WriteLine("After");
                //Console.WriteLine(string.Join("\n", paretoFront.Select(x => x.score + " " + x.cost + " | " + string.Join(",", x.cm))));


                if (spf == paretoFront.Count)
                {
                    Iterations++;
                }
                else
                {
                    Iterations = 0;
                }

                //Console.WriteLine($"{paretoFront.Count,-4} | " + string.Join(" ", sampling.Select(x => $"{x:0.00}")));
                i++;
            }

            Console.WriteLine("Pareto Front:");
            Console.WriteLine(string.Join("\n", paretoFront.Select(x => x.score + " " + x.nb_root_sat + " " + x.cost + " | " + string.Join(",", x.cm))));


            var solution = new List <OptimalSelection>();

            foreach (var candidate in paretoFront)
            {
                var activeResolutions = _model.Resolutions().Where(x => candidate.cm.Contains(x.ResolvingGoalIdentifier));
                solution.Add(new OptimalSelection(activeResolutions, candidate.cost, candidate.score, candidate.sat_root));
            }
            return(solution);
        }
 public void RegisterPropagator(IPropagator p)
 {
     _influenceMap.RegisterPropagator(p);
 }
 public IEnumerable <OptimalSelection> GetOptimalSelections(Goal goal, IPropagator propagator)
 {
     return(GetOptimalSelections(new HashSet <Goal>(new[] { goal }), propagator));
 }
Beispiel #25
0
 public void DeletePropagator(IPropagator p)
 {
     _influenceMap.DeletePropagator(p);
     PropagationUpdate();
 }
Beispiel #26
0
 public void RegisterPropagator(IPropagator p)
 {
     _influenceMap.RegisterPropagator(p);
 }
 public static SpanContext Extract(this IPropagator propagator, IHeadersCollection headers)
 {
     return(propagator.Extract(headers, ExtractFromHeadersCollection));
 }
 public static void Inject(this IPropagator propagator, SpanContext context, IHeadersCollection headers)
 {
     propagator.Inject(context, headers, InjectToHeadersCollection);
 }
 public TrackingExteriorCrackLSM(IPropagator propagator, double tipEnrichmentAreaRadius = 0.0) :
     this(propagator, tipEnrichmentAreaRadius, null)
 {
     this.SingularityResolver = new RelativeAreaResolver(1E-4);
 }
 /// <summary>
 ///     Registers the given propagator for the given carrier format.
 /// </summary>
 /// <param name="format">The format for the given carrier type.</param>
 /// <param name="propagator">The propagator to register.</param>
 /// <typeparam name="TCarrier">The type of the carrier.</typeparam>
 public void Register <TCarrier>(IFormat <TCarrier> format, IPropagator propagator)
 {
     propagators[format] = propagator;
 }
 /// <summary>
 ///     Register custom propagator to support various formats.
 /// </summary>
 /// <typeparam name="TCarrier">The carrier type.</typeparam>
 /// <param name="format">The format for the given carrier type.</param>
 /// <param name="propagator">The propagator to register.</param>
 /// <returns><see cref="this"/></returns>
 public Builder RegisterPropagator <TCarrier>(IFormat <TCarrier> format,
                                              IPropagator propagator)
 {
     registry.Register(format, propagator);
     return(this);
 }
 public void RegisterPropagator(IPropagator p)
 {
     _propagators.Add(p);
 }