private void AddToParent(TaskSpec task, Stack <TaskSpec> stack) { if (stack.Count == 0) { throw new InvalidOperationException(string.Format("Cannot add the task {0} to its parent as the task stack is empty and no parent can be found", task)); } var parent = stack.Peek(); parent.Children.Add(task); }
private ITask BuildSubtree(TaskSpec currentSpec) { var task = taskMap[currentSpec.Name]; foreach (var childSpec in currentSpec.Children) { var childTask = BuildSubtree(childSpec); task.Children.Add(childTask); } return(task); }
public void ShouldParseCorrectlyTypicalTaskSpecs_With_TwoObsIntegerDimensions_And_TwoActionDoubleDimensions(string input) { TaskSpecParser parser = new TaskSpecParser(); TaskSpec <int, double> result = parser.Parse(input) as TaskSpec <int, double>; Assert.That(result, Is.Not.Null); Assert.That(result.ObservationMinimumValues, Is.EqualTo(new[] { 0, -10 })); Assert.That(result.ObservationMaximumValues, Is.EqualTo(new[] { 2, 100 })); Assert.That(result.ActionMinimumValues, Is.EqualTo(new[] { -0.1, 456 })); Assert.That(result.ActionMaximumValues, Is.EqualTo(new[] { 3.4, 9999.9999 })); Assert.That(result.ReinforcementMinimumValue, Is.EqualTo(0)); Assert.That(result.ReinforcementMaximumValue, Is.EqualTo(10)); Assert.That(result.AdditionalInformation, Is.EqualTo(string.Empty)); }
public void ShouldParseCorrectlyTypicalTaskSpecs_With_TwoObsDoubleDimensions_And_OneActionIntegerDimension(string input) { TaskSpecParser parser = new TaskSpecParser(); TaskSpec <double, int> result = parser.Parse(input) as TaskSpec <double, int>; Assert.That(result, Is.Not.Null); Assert.That(result.ObservationMinimumValues, Is.EqualTo(new[] { 0.0, -10.0 })); Assert.That(result.ObservationMaximumValues, Is.EqualTo(new[] { 2.0, 100.0 })); Assert.That(result.ActionMinimumValues, Is.EqualTo(new[] { 0 })); Assert.That(result.ActionMaximumValues, Is.EqualTo(new[] { 3 })); Assert.That(result.ReinforcementMinimumValue, Is.EqualTo(0)); Assert.That(result.ReinforcementMaximumValue, Is.EqualTo(10)); Assert.That(result.AdditionalInformation, Is.EqualTo(string.Empty)); }
public void ShouldProperlyEncodeTypicalIntIntTaskSpec() { TaskSpec <int, int> taskSpec = new TaskSpec <int, int>( observationMinimumValues: new[] { 0, 0 }, observationMaximumValues: new[] { 10, 10 }, actionMinimumValues: new[] { 0 }, actionMaximumValues: new[] { 4 }, reinforcementMinimumValue: -4, reinforcementMaximumValue: 10.5, discountFactor: 0.9, additionalInformation: "test"); string result = (new TaskSpecStringEncoder()).Encode(taskSpec); Assert.That(result, Is.EqualTo("VERSION RL-Glue-3.0 PROBLEMTYPE episodic DISCOUNTFACTOR 0.9 OBSERVATIONS INTS (0 10) (0 10) ACTIONS INTS (0 4) REWARDS (-4 10.5) EXTRA test")); }
public void ShouldProperlyEncodeTypicalDoubleDoubleTaskSpec() { TaskSpec <double, double> taskSpec = new TaskSpec <double, double>( observationMinimumValues: new[] { 0.0 }, observationMaximumValues: new[] { 10.5 }, actionMinimumValues: new[] { 0.0, 1.5, 1.3 }, actionMaximumValues: new[] { 4, 15, 100.5 }, reinforcementMinimumValue: 100, reinforcementMaximumValue: 222, discountFactor: 0.9, additionalInformation: string.Empty); string result = (new TaskSpecStringEncoder()).Encode(taskSpec); Assert.That(result, Is.EqualTo("VERSION RL-Glue-3.0 PROBLEMTYPE episodic DISCOUNTFACTOR 0.9 OBSERVATIONS DOUBLES (0 10.5) ACTIONS DOUBLES (0 4) (1.5 15) (1.3 100.5) REWARDS (100 222)")); }
public void ShouldParseCorrectlyTypicalTaskSpecs_With_OneObsIntegerDimension_And_ThreeActionIntegerDimensions(string input) { TaskSpecParser parser = new TaskSpecParser(); TaskSpec <int, int> result = parser.Parse(input) as TaskSpec <int, int>; Assert.That(result, Is.Not.Null); Assert.That(result.ObservationMinimumValues, Is.EqualTo(new[] { 0 })); Assert.That(result.ObservationMaximumValues, Is.EqualTo(new[] { 2 })); Assert.That(result.ActionMinimumValues, Is.EqualTo(new[] { 0, 0, 0 })); Assert.That(result.ActionMaximumValues, Is.EqualTo(new[] { 4, 4, 4 })); Assert.That(result.ReinforcementMinimumValue, Is.EqualTo(-2)); Assert.That(result.ReinforcementMaximumValue, Is.EqualTo(10)); Assert.That(result.AdditionalInformation, Is.EqualTo("extra loooong string with space at the end ")); Assert.That(result.DiscountFactor, Is.EqualTo(0.4)); }
public void ShouldParseCorrectlyTaskSpecs_With_TwoObsIntegerDimensions_And_OneActionIntegerDimension(string input) { TaskSpecParser parser = new TaskSpecParser(); TaskSpec <int, int> result = parser.Parse(input) as TaskSpec <int, int>; Assert.That(result, Is.Not.Null); Assert.That(result.ObservationMinimumValues, Is.EqualTo(new[] { 0, 0 })); Assert.That(result.ObservationMaximumValues, Is.EqualTo(new[] { 2, 2 })); Assert.That(result.ActionMinimumValues, Is.EqualTo(new[] { 0 })); Assert.That(result.ActionMaximumValues, Is.EqualTo(new[] { 4 })); Assert.That(result.ReinforcementMinimumValue, Is.EqualTo(0)); Assert.That(result.ReinforcementMaximumValue, Is.EqualTo(10)); Assert.That(result.AdditionalInformation, Is.EqualTo("extra string")); Assert.That(result.DiscountFactor, Is.EqualTo(0.0001)); }
private TaskSpec BuildTask(string line) { string name; IDictionary <string, string> args; this.parser.Parse(line, out name, out args); var spec = new TaskSpec(name); foreach (var item in args) { spec.Args.Add(item); } return(spec); }
public string EnvironmentInit() { this.currentReward = 0; this.totalReward = 0; this.episodeTotalReward = 0; this.totalSteps = 0; this.episodeSteps = 0; var environmentDescription = this.environment.GetEnvironmentDescription(); TaskSpec <TStateSpaceType, TActionSpaceType> taskSpec = new TaskSpec <TStateSpaceType, TActionSpaceType>( environmentDescription.StateSpaceDescription.MinimumValues.ToArray(), environmentDescription.StateSpaceDescription.MaximumValues.ToArray(), environmentDescription.ActionSpaceDescription.MinimumValues.ToArray(), environmentDescription.ActionSpaceDescription.MaximumValues.ToArray(), environmentDescription.ReinforcementSpaceDescription.MinimumValue.Value, environmentDescription.ReinforcementSpaceDescription.MaximumValue.Value, environmentDescription.DiscountFactor, string.Empty); return((new TaskSpecStringEncoder()).Encode(taskSpec)); }
public void AgentInit(string taskSpecification) { this.currentReward = 0; this.totalReward = 0; this.episodeTotalReward = 0; this.totalSteps = 0; this.episodeSteps = 0; TaskSpec <TStateSpaceType, TActionSpaceType> taskSpec = (new TaskSpecParser()).Parse(taskSpecification) as TaskSpec <TStateSpaceType, TActionSpaceType>; // TODO: handle data exceptions higher if (taskSpec == null) { throw new InvalidDataException("Incompatible task spec received"); } this.agent.ExperimentStarted(new EnvironmentDescription <TStateSpaceType, TActionSpaceType>( new SpaceDescription <TStateSpaceType>(taskSpec.ObservationMinimumValues.ToArray(), taskSpec.ObservationMaximumValues.ToArray()), new SpaceDescription <TActionSpaceType>(taskSpec.ActionMinimumValues.ToArray(), taskSpec.ActionMaximumValues.ToArray()), new DimensionDescription <double>(taskSpec.ReinforcementMinimumValue, taskSpec.ReinforcementMaximumValue), taskSpec.DiscountFactor)); }
public ITask Build(TaskSpec rootSpec) { return(BuildSubtree(rootSpec.Children[0])); }
public async Task <bool> Update(string FileBase64) { try { Logger.Log($"updating service id : {Id} with DockerId {DockerServiceId}"); this.FilePath = CombineProgram(Id, UserId, FileBase64); var serviceInfo = await Client.Docker.Swarm.InspectServiceAsync(DockerServiceId); var Image = this.Image(); Logger.Log($"Service info gotten! Name is : {Name}, Version is: {serviceInfo.Version.Index}, Network ID is {Network.ID}, Image Id : {Image.ID}, Port: {Port}, this.FilePath: {this.FilePath}"); NetworkAttachmentConfig networkConfig = new NetworkAttachmentConfig() { Target = Network.ID }; EndpointSpec endpointSpec = new EndpointSpec() { Ports = new List <PortConfig>() { new PortConfig() { Protocol = "tcp", PublishedPort = uint.Parse(Port), TargetPort = uint.Parse(Port) } } }; Logger.Log("Endpoint created"); IList <Mount> mounts = new List <Mount> { new Mount() { Target = "/home/node/", Source = this.FilePath, } }; Logger.Log("Mounts created"); TaskSpec taskSpec = new TaskSpec() { ForceUpdate = 1, RestartPolicy = new SwarmRestartPolicy() { Condition = "any", MaxAttempts = 0 }, ContainerSpec = new ContainerSpec() { Image = Image.ID, Env = new List <string>() { $"PORT={Port}" }, Hosts = new List <string>() { $"{Port}:{Port}" }, Mounts = mounts, Dir = "/home/node/", Command = new List <string>() { "/bin/bash", "build.sh" }, }, }; Logger.Log("Task spec created!"); ServiceSpec serviceSpec = new ServiceSpec() { Name = Name, Networks = new List <NetworkAttachmentConfig>() { networkConfig }, EndpointSpec = endpointSpec, TaskTemplate = taskSpec, }; Logger.Log("Service spec created!"); var serviceParams = new ServiceUpdateParameters() { Version = Convert.ToInt64(serviceInfo.Version.Index), Service = serviceSpec }; Logger.Log("Configuration is ready, updating..."); await Client.Docker.Swarm.UpdateServiceAsync(DockerServiceId, serviceParams); Logger.Success($"Updated successful!"); return(true); } catch (Exception e) { Logger.Fail($"Cant update service {DockerServiceId} : {e.Message}"); return(false); } }