private static SimulationConfiguration ToGrpcOptions(PlantSimulationOptions options) { return(new SimulationConfiguration { Id = options.Id, Simulation = new SimulationOptions { TickTime = options.Simulation.TickTime, TickEventTime = options.Simulation.TickEventTime, RandomSeed = options.Simulation.RandomSeed }, Environment = new SimulationEnvironmentOptions { LightSource = VectorToCoordinate(options.Environment.LightSource), Temperature = options.Environment.Temperature }, Plant = new SimulationPlantOptions { Branches = RangeToIntRange(options.Plant.Branches), SubBranches = RangeToIntRange(options.Plant.SubBranches), InternodeLength = RangeToIntRange(options.Plant.InternodeLength), PetioleLength = RangeToIntRange(options.Plant.PetioleLength), Axil = options.Plant.Axil, } }); }
public Task StartSimulationAsync(PlantSimulationOptions options, CancellationToken cancellationToken) { logger.LogInformation("Starting simulator from runtime broker"); options = (PlantSimulationOptions)FluidsPlantOptions.CreateOptions(); // Set the random seed from the options RangeExtensions.Random = new Random(options.Simulation.RandomSeed); // Set the options service options to the received options optionsService.Options = options; // Linked cancellation token source so that the simulation can be cancelled cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); // Instantiate the simulation instance with the dependency injection service container Simulation = provider.ResolvePlantSimulatorConstructor(); // Add event subscribers to the OnTick event Simulation.OnTick += eventHandler.OnSimulationTick; // Start the simulation if it was instantiated correctly through dependency injection try { runningSimulation = Simulation.StartAsync(cancellationTokenSource.Token); } catch (NullReferenceException e) { throw new NullReferenceException("The simulation could not be constructed by the service provider", e); } return(Task.CompletedTask); }
public async Task <IActionResult> StartSimulation(PlantSimulationOptions options) { try { await clientHandler.StartAvailableClientAsync(options); } catch (NoAvailableClientsException e) { return(new BadRequestObjectResult(e.Message)); } return(new OkResult()); }
public async Task StartAsync(PlantSimulationOptions options) { try { await Client.StartSimulationAsync(new SimulationConfiguration() /*ToGrpcOptions(options)*/); Available = false; } catch (RpcException) { Available = true; } }
/// <summary> /// Send the simulation task to an available client /// </summary> /// <param name="options">Simulation options to start the simulation with</param> /// <exception cref="NoAvailableClientsException">Thrown if there is no client available to take the task</exception> public async Task StartAvailableClientAsync(PlantSimulationOptions options) { foreach (ISimulationClient client in clients) { if (!client.Available) { continue; } await client.StartAsync(options); return; } throw new NoAvailableClientsException("No clients are available to take the task"); }
public static IPlantSimulatorOptionsService CreateOptionsService() { var options = new PlantSimulationOptions { Id = Guid.NewGuid().ToString(), Simulation = new SimulationOptions { TickTime = 0, RandomSeed = 3, TickEventTime = 1 }, Environment = new SimulationEnvironmentOptions { LightSource = new Vertex(0, 1000, 0), Temperature = 21f }, Plant = new SimulationPlantOptions { PetioleLength = new Range <int>(5, 5), NewStemWidth = new Range <int>(21, 21), Branches = new Range <int>(0, 0), PetiolesPerNode = new Range <int>(1, 2), StemsPerNode = new Range <int>(0, 0), NewPetioleWidth = new Range <int>(5, 5), InitialStemWidth = 21, SubBranches = new Range <int>(0, 0), MaxInternodeLength = new Range <float>(50, 60), LeafsPerNode = new Range <int>(0, 0), NewNodeTickCount = new Range <int>(50, 50), GrowthRange = new Range <float>(.5f, .5f), NewNodeInternodeLength = new Range <float>(0, 0), TerminalHeight = new Range <float>(50f, 50f) }, Cell = new SimulationCellOptions { ParenchymaCellSize = 10, CollenchymaCellSize = 10, PhloemCellSize = 10, SclerenchymaCellSize = 10, XylemCellSize = 10 }, }; return(new PlantSimulatorOptionsService { Options = options }); }
public async Task <IActionResult> StartSimulation([FromBody] PlantSimulationOptions options) { return(await context.StartSimulation(options)); }