public static async Task RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext context)
        {
            var populationAndSettings = context.GetInput <PopulationAndSettings>();
            var population            = populationAndSettings.Population;

            var tasks = new Task <double> [population.Individuals.Count];

            for (int i = 0; i < population.Individuals.Count; i++)
            {
                tasks[i] = context.CallActivityAsync <double>("EvaluatePopulation", population);
            }
            await Task.WhenAll(tasks);

            var            evaluationResults = tasks.Select(e => e.Result).ToList();
            BestIndividual bestIndividual    = await context.CallActivityAsync <BestIndividual>("GetBestIndividual", population, evaluationResults);

            populationAndSettings.GenerationId = await context.CallActivityAsync <int>("SaveBestResult", bestIndividual,
                                                                                       populationAndSettings.InstanceId, populationAndSettings.GenerationId);

            population = await context.CallActivityAsync <Population>("Selection", population, evaluationResults);

            population = await context.CallActivityAsync <Population>("Crossover", population);

            populationAndSettings.Population = await context.CallActivityAsync <Population>("Mutation", population);

            context.ContinueAsNew(populationAndSettings);
        }
Exemplo n.º 2
0
 public static int SaveBestResult([ActivityTrigger] BestIndividual individual, string instanceId, int generationId, TraceWriter log)
 {
     return(generationId++);
 }