public void TestAllowMixedActions() { // Make sure discrete + continuous actuators are allowed. var manager = new ActuatorManager(); var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3, 4 }), "actuator1"); var actuator2 = new TestActuator(ActionSpec.MakeContinuous(3), "actuator2"); manager.Add(actuator1); manager.Add(actuator2); manager.ReadyActuatorsForExecution(new[] { actuator1, actuator2 }, 3, 10, 4); }
public void CanOverwriteMask() { var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 4, 5, 6 }), "actuator1"); var masker = new ActuatorDiscreteActionMask(new IActuator[] { actuator1 }, 15, 3); masker.SetActionEnabled(0, 1, false); var mask = masker.GetMask(); Assert.IsTrue(mask[1]); masker.SetActionEnabled(0, 1, true); Assert.IsFalse(mask[1]); }
public void TestIndexSet() { var manager = new ActuatorManager(); var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3, 4 }), "actuator1"); var actuator2 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3 }), "actuator2"); manager.Add(actuator1); Assert.IsTrue(manager.NumDiscreteActions == 4); Assert.IsTrue(manager.SumOfDiscreteBranchSizes == 10); manager[0] = actuator2; Assert.IsTrue(manager.NumDiscreteActions == 3); Assert.IsTrue(manager.SumOfDiscreteBranchSizes == 6); }
public void MaskReset() { var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 4, 5, 6 }), "actuator1"); var masker = new ActuatorDiscreteActionMask(new IActuator[] { actuator1 }, 15, 3); masker.WriteMask(1, new[] { 1, 2, 3 }); masker.ResetMask(); var mask = masker.GetMask(); for (var i = 0; i < 15; i++) { Assert.IsFalse(mask[i]); } }
public void TestUpdateActionsContinuous() { var manager = new ActuatorManager(); var actuator1 = new TestActuator(ActionSpec.MakeContinuous(3), "actuator1"); var actuator2 = new TestActuator(ActionSpec.MakeContinuous(3), "actuator2"); manager.Add(actuator1); manager.Add(actuator2); var continuousActionBuffer = new[] { 0f, 1f, 2f, 3f, 4f, 5f }; manager.UpdateActions(new ActionBuffers(continuousActionBuffer, Array.Empty <int>())); Assert.IsTrue(manager.StoredActions.ContinuousActions.SequenceEqual(continuousActionBuffer)); }
public void SecondBranchMask() { var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 4, 5, 6 }), "actuator1"); var masker = new ActuatorDiscreteActionMask(new[] { actuator1 }, 15, 3); masker.WriteMask(1, new[] { 1, 2, 3 }); var mask = masker.GetMask(); Assert.IsFalse(mask[0]); Assert.IsFalse(mask[4]); Assert.IsTrue(mask[5]); Assert.IsTrue(mask[6]); Assert.IsTrue(mask[7]); Assert.IsFalse(mask[8]); Assert.IsFalse(mask[9]); }
public void FirstBranchMask() { var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 4, 5, 6 }), "actuator1"); var masker = new ActuatorDiscreteActionMask(new IActuator[] { actuator1 }, 15, 3); var mask = masker.GetMask(); Assert.IsNull(mask); masker.WriteMask(0, new[] { 1, 2, 3 }); mask = masker.GetMask(); Assert.IsFalse(mask[0]); Assert.IsTrue(mask[1]); Assert.IsTrue(mask[2]); Assert.IsTrue(mask[3]); Assert.IsFalse(mask[4]); Assert.AreEqual(mask.Length, 15); }
public void TestSortActuators(string culture) { List <IActuator> actuators = new List <IActuator>(); var actuator0 = new TestActuator(ActionSpec.MakeContinuous(2), "Apple"); var actuator1 = new TestActuator(ActionSpec.MakeContinuous(2), "Æble"); actuators.Add(actuator0); actuators.Add(actuator1); var originalCulture = CultureInfo.CurrentCulture; CultureInfo.CurrentCulture = new CultureInfo(culture); ActuatorManager.SortActuators(actuators); CultureInfo.CurrentCulture = originalCulture; Assert.AreEqual(actuator1, actuators[0]); Assert.AreEqual(actuator0, actuators[1]); }
public void TestHeuristic() { var manager = new ActuatorManager(2); var va1 = new TestActuator(ActionSpec.MakeDiscrete(1, 2, 3), "name"); var va2 = new TestActuator(ActionSpec.MakeDiscrete(3, 2, 1, 8), "name1"); manager.Add(va1); manager.Add(va2); var actionBuf = new ActionBuffers(Array.Empty <float>(), new[] { 0, 0, 0, 0, 0, 0, 0 }); manager.ApplyHeuristic(actionBuf); Assert.IsTrue(va1.m_HeuristicCalled); Assert.AreEqual(va1.m_DiscreteBufferSize, 3); Assert.IsTrue(va2.m_HeuristicCalled); Assert.AreEqual(va2.m_DiscreteBufferSize, 4); }
public void TestClear() { var manager = new ActuatorManager(); var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3 }), "actuator1"); var actuator2 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3 }), "actuator2"); manager.Add(actuator1); manager.Add(actuator2); Assert.IsTrue(manager.NumDiscreteActions == 6); Assert.IsTrue(manager.SumOfDiscreteBranchSizes == 12); manager.Clear(); Assert.IsTrue(manager.NumDiscreteActions == 0); Assert.IsTrue(manager.SumOfDiscreteBranchSizes == 0); }
public void TestUpdateActionsDiscrete() { var manager = new ActuatorManager(); var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3 }), "actuator1"); var actuator2 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3 }), "actuator2"); manager.Add(actuator1); manager.Add(actuator2); var discreteActionBuffer = new[] { 0, 1, 2, 3, 4, 5 }; manager.UpdateActions(new ActionBuffers(Array.Empty <float>(), discreteActionBuffer)); Debug.Log(manager.StoredActions.DiscreteActions); Debug.Log(discreteActionBuffer); Assert.IsTrue(manager.StoredActions.DiscreteActions.SequenceEqual(discreteActionBuffer)); }
public void ThrowsError() { var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 4, 5, 6 }), "actuator1"); var masker = new ActuatorDiscreteActionMask(new IActuator[] { actuator1 }, 15, 3); Assert.Catch <UnityAgentsException>( () => masker.WriteMask(0, new[] { 5 })); Assert.Catch <UnityAgentsException>( () => masker.WriteMask(1, new[] { 5 })); masker.WriteMask(2, new[] { 5 }); Assert.Catch <UnityAgentsException>( () => masker.WriteMask(3, new[] { 1 })); masker.GetMask(); masker.ResetMask(); masker.WriteMask(0, new[] { 0, 1, 2, 3 }); Assert.Catch <UnityAgentsException>( () => masker.GetMask()); }
public void TestExecuteActionsDiscrete() { var manager = new ActuatorManager(); var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3, 4 }), "actuator1"); var actuator2 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 1, 1 }), "actuator2"); manager.Add(actuator1); manager.Add(actuator2); var discreteActionBuffer = new[] { 0, 1, 2, 3, 4, 5, 6 }; manager.UpdateActions(new ActionBuffers(Array.Empty <float>(), discreteActionBuffer)); manager.ExecuteActions(); var actuator1Actions = actuator1.LastActionBuffer.DiscreteActions; var actuator2Actions = actuator2.LastActionBuffer.DiscreteActions; TestSegmentEquality(actuator1Actions, discreteActionBuffer); TestSegmentEquality(actuator2Actions, discreteActionBuffer); }
public void ThrowsError() { var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 4, 5, 6 }), "actuator1"); var masker = new ActuatorDiscreteActionMask(new IActuator[] { actuator1 }, 15, 3); Assert.Catch <UnityAgentsException>( () => masker.SetActionEnabled(0, 5, false)); Assert.Catch <UnityAgentsException>( () => masker.SetActionEnabled(1, 5, false)); masker.SetActionEnabled(2, 5, false); Assert.Catch <UnityAgentsException>( () => masker.SetActionEnabled(3, 1, false)); masker.GetMask(); masker.ResetMask(); masker.SetActionEnabled(0, 0, false); masker.SetActionEnabled(0, 1, false); masker.SetActionEnabled(0, 2, false); masker.SetActionEnabled(0, 3, false); Assert.Catch <UnityAgentsException>( () => masker.GetMask()); }
public void TestExecuteActionsContinuous() { var manager = new ActuatorManager(); var actuator1 = new TestActuator(ActionSpec.MakeContinuous(3), "actuator1"); var actuator2 = new TestActuator(ActionSpec.MakeContinuous(3), "actuator2"); manager.Add(actuator1); manager.Add(actuator2); var continuousActionBuffer = new[] { 0f, 1f, 2f, 3f, 4f, 5f }; manager.UpdateActions(new ActionBuffers(continuousActionBuffer, Array.Empty <int>())); manager.ExecuteActions(); var actuator1Actions = actuator1.LastActionBuffer.ContinuousActions; var actuator2Actions = actuator2.LastActionBuffer.ContinuousActions; TestSegmentEquality(actuator1Actions, continuousActionBuffer); TestSegmentEquality(actuator2Actions, continuousActionBuffer); }
public void MultipleMaskEdit() { var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 4, 5, 6 }), "actuator1"); var masker = new ActuatorDiscreteActionMask(new IActuator[] { actuator1 }, 15, 3); masker.WriteMask(0, new[] { 0, 1 }); masker.WriteMask(0, new[] { 3 }); masker.WriteMask(2, new[] { 1 }); var mask = masker.GetMask(); for (var i = 0; i < 15; i++) { if ((i == 0) || (i == 1) || (i == 3) || (i == 10)) { Assert.IsTrue(mask[i]); } else { Assert.IsFalse(mask[i]); } } }