public void EvaluateCumulativeRewardEstimatorMultipleStates() { const int kStateCount = 10; var states = new NativeList <int>(kStateCount, Allocator.TempJob); var stateInfoLookup = new NativeHashMap <int, StateInfo>(kStateCount, Allocator.TempJob); var binnedStateKeys = new NativeMultiHashMap <int, int>(kStateCount, Allocator.TempJob); for (int i = 0; i < kStateCount; i++) { states.Add(i); } var stateEvaluationJob = new EvaluateNewStatesJob <int, int, TestStateDataContext, StateValueAsCumulativeRewardEstimatorValue, DefaultTerminalStateEvaluator <int> > { StateDataContext = new TestStateDataContext(), StateInfoLookup = stateInfoLookup.AsParallelWriter(), States = states.AsDeferredJobArray(), BinnedStateKeys = binnedStateKeys.AsParallelWriter(), }; stateEvaluationJob.Schedule(states, default).Complete(); for (int i = 0; i < states.Length; i++) { stateInfoLookup.TryGetValue(i, out var stateInfo); Assert.AreEqual(new BoundedValue(i, i, i), stateInfo.CumulativeRewardEstimate); } states.Dispose(); stateInfoLookup.Dispose(); binnedStateKeys.Dispose(); }
public void DoesNotExecuteWithoutStates() { var states = new NativeList <int>(0, Allocator.TempJob); var stateInfoLookup = new NativeHashMap <int, StateInfo>(0, Allocator.TempJob); var binnedStateKeys = new NativeMultiHashMap <int, int>(1, Allocator.TempJob); var stateEvaluationJob = new EvaluateNewStatesJob <int, int, TestStateDataContext, ExceptionCumulativeRewardEstimator, ExceptionTerminationEvaluator>() { StateDataContext = new TestStateDataContext(), StateInfoLookup = stateInfoLookup.AsParallelWriter(), States = states.AsDeferredJobArray(), BinnedStateKeys = binnedStateKeys.AsParallelWriter(), }; Assert.DoesNotThrow(() => stateEvaluationJob.Schedule(states, default).Complete()); states.Dispose(); stateInfoLookup.Dispose(); binnedStateKeys.Dispose(); }
public void TestEvaluateMultipleStates() { const int kStateCount = 1000; NativeList <int> states = default; NativeHashMap <int, StateInfo> stateInfoLookup = default; NativeMultiHashMap <int, int> binnedStateKeys = default; Measure.Method(() => { var stateEvaluationJob = new EvaluateNewStatesJob <int, int, TestStateDataContext, NewStateEvaluationJobTests.StateValueAsCumulativeRewardEstimatorValue, DefaultTerminalStateEvaluator <int> > { StateDataContext = new TestStateDataContext(), States = states.AsDeferredJobArray(), StateInfoLookup = stateInfoLookup.AsParallelWriter(), BinnedStateKeys = binnedStateKeys.AsParallelWriter(), }; stateEvaluationJob.Schedule(states, default).Complete(); }).SetUp(() => { states = new NativeList <int>(kStateCount, Allocator.TempJob); stateInfoLookup = new NativeHashMap <int, StateInfo>(kStateCount, Allocator.TempJob); binnedStateKeys = new NativeMultiHashMap <int, int>(kStateCount, Allocator.TempJob); for (int i = 0; i < kStateCount; i++) { states.Add(i); } }).CleanUp(() => { states.Dispose(); stateInfoLookup.Dispose(); binnedStateKeys.Dispose(); }).WarmupCount(1).MeasurementCount(30).IterationsPerMeasurement(1).Run(); }