Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public void RatioSelectionRejectsRatiosThatDoNotSumToOne()
Assert.Throws<ArgumentException>(() => new RatioEvolutionSelectionPolicy<TestGenome>(options));
Assert.Throws<ArgumentOutOfRangeException>(() => new RatioEvolutionSelectionPolicy<TestGenome>(
new EvolutionSelectionOptions { ExplorationRatio = -1, ExploitationRatio = 1, EliteRatio = 1 }));
Assert.Throws<ArgumentOutOfRangeException>(() => new RatioEvolutionSelectionPolicy<TestGenome>(
new EvolutionSelectionOptions { ExplorationRatio = double.NaN, ExploitationRatio = 1, EliteRatio = 0 }));
Assert.Throws<ArgumentOutOfRangeException>(() => new RatioEvolutionSelectionPolicy<TestGenome>(
new EvolutionSelectionOptions { ExplorationRatio = 2, ExploitationRatio = 0, EliteRatio = 0 }));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,18 @@ public void InvalidCalibrationSettingsAreRefused()
new EvolutionDescriptorCalibrationOptions { BinCount = 0 }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions { Padding = -1 }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions { Padding = double.NaN }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions { Padding = double.PositiveInfinity }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions { Padding = 101 }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions { DegenerateSpan = 0 }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions { DegenerateSpan = double.NaN }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions { DegenerateSpan = double.PositiveInfinity }.Validate());
Assert.Throws<ArgumentOutOfRangeException>(() =>
new EvolutionDescriptorCalibrationOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public void AnInvalidTopologyOrRateIsRejectedByThePolicyAndByTheOptions()
EvolutionEngineOptions badRate = Options(4, 4, islandCount: 2);
badRate.MigrationRate = -0.5;
Assert.Throws<ArgumentOutOfRangeException>(() => Engine(new SyntheticEvolutionTask(), badRate));

EvolutionEngineOptions nonFiniteRate = Options(4, 4, islandCount: 2);
nonFiniteRate.MigrationRate = double.NaN;
Assert.Throws<ArgumentOutOfRangeException>(() => Engine(new SyntheticEvolutionTask(), nonFiniteRate));

EvolutionEngineOptions excessiveRate = Options(4, 4, islandCount: 2);
excessiveRate.MigrationRate = 1.5;
Assert.Throws<ArgumentOutOfRangeException>(() => Engine(new SyntheticEvolutionTask(), excessiveRate));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void TraceRetentionCannotExceedPackageLevelResourceLimits()
{
ParentQualityCacheSize = EvolutionCollectionLimits.MaximumParentQualityCacheEntries + 1
}.SnapshotAndValidate());
Assert.Throws<ArgumentOutOfRangeException>(() => new EvolutionTraceOptions
{
ParentQualityCacheSize = -1
}.SnapshotAndValidate());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace AiDotNet.Evolution.Tests;

public sealed class EvolutionSelectionPolicyTests
{
[Fact]
public void DoubleSelectionReturnsNullForAnEmptyArchive()
{
var archive = new MapElitesArchive<TestGenome>(new[]
{
new EvolutionDescriptorDefinition("x", 0, 4, 4)
});
var policy = new DoubleEvolutionSelectionPolicy<TestGenome>();

Assert.Null(policy.Select(archive, new StableRandom(3), inspirationCount: 3));
}

[Fact]
public void DoubleSelectionUsesDistinctQualityRankedInspirations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,27 @@ public void BoundedEvictionIsIndependentOfInsertionOrder()
}

[Fact]
public void InvalidEvaluationDoesNotEnterArchive()
public void InvalidEvaluationsDoNotEnterArchive()
{
MapElitesArchive<TestGenome> archive = Archive();
(EvolutionCandidate<TestGenome> candidate, EvolutionEvaluation evaluation) = Create(1, "a", 1, 0.2);
var failed = new EvolutionEvaluation(1, "a", EvolutionEvaluationStatus.Failed, null,
EvolutionOptimizationDirection.Maximize, new Dictionary<string, double>(), Array.Empty<double>(),
Array.Empty<double>(), new EvolutionEvaluationCost(TimeSpan.Zero, 1, 0), evaluation.Lineage,
EvolutionCacheStatus.NotChecked, Array.Empty<EvolutionDiagnostic>(), "task", "eval", "config");
EvolutionEvaluation[] invalidEvaluations =
{
Invalid(EvolutionEvaluationStatus.Failed, null, EvolutionOptimizationDirection.Maximize, 1, "a"),
Invalid(EvolutionEvaluationStatus.Completed, 1, EvolutionOptimizationDirection.Minimize, 1, "a"),
Invalid(EvolutionEvaluationStatus.Completed, 1, EvolutionOptimizationDirection.Maximize, 2, "a"),
Invalid(EvolutionEvaluationStatus.Completed, 1, EvolutionOptimizationDirection.Maximize, 1, "other")
};

Assert.Equal(EvolutionArchiveInsertionResult.Rejected, archive.TryAdd(candidate, failed));
foreach (EvolutionEvaluation invalid in invalidEvaluations)
Assert.Equal(EvolutionArchiveInsertionResult.Rejected, archive.TryAdd(candidate, invalid));
Assert.Empty(archive.Entries);

EvolutionEvaluation Invalid(EvolutionEvaluationStatus status, double? quality,
EvolutionOptimizationDirection direction, long evaluationId, string genomeId) => new(
evaluationId, genomeId, status, quality, direction, evaluation.Descriptors, Array.Empty<double>(),
Array.Empty<double>(), evaluation.Cost, evaluation.Lineage, EvolutionCacheStatus.NotChecked,
Array.Empty<EvolutionDiagnostic>(), "task", "eval", "config");
}

internal static MapElitesArchive<TestGenome> Archive(
Expand Down
Loading