-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
test/component/particleSwarmOptimization/positionUpdateTest.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Unit tests for DefaultPositionUpdate | ||
|
||
function defaultPositionUpdateConstructorIsCorrectlyInitialized() | ||
velocityChangeWhenLowerLimitIsReached = -1.0 | ||
velocityChangeWhenUpperLimitIsReached = 0.25 | ||
positionBounds = [Bounds{Float64}(1.0, 10.0)] | ||
|
||
positionUpdate = DefaultPositionUpdate(velocityChangeWhenLowerLimitIsReached, velocityChangeWhenUpperLimitIsReached, positionBounds) | ||
|
||
return velocityChangeWhenLowerLimitIsReached == positionUpdate.velocityChangeWhenLowerLimitIsReached && velocityChangeWhenUpperLimitIsReached == positionUpdate.velocityChangeWhenUpperLimitIsReached && positionBounds == positionUpdate.positionBounds | ||
end | ||
|
||
|
||
function positionUpdateWorksProperlyWithASingleParticle() | ||
velocityChangeWhenLowerLimitIsReached = -1.0 | ||
velocityChangeWhenUpperLimitIsReached = 0.25 | ||
positionBounds = [Bounds{Float64}(-10.0, 10.0), Bounds{Float64}(-15.0, 15.0)] | ||
speed = [[0.5, -0.5]] | ||
variables = [2.0, 4.0] | ||
|
||
particle = ContinuousSolution{Float64}(copy(variables), [1.5, 2.5], [], Dict(), positionBounds) | ||
swarm = [particle] | ||
|
||
positionUpdate = DefaultPositionUpdate(velocityChangeWhenLowerLimitIsReached, velocityChangeWhenUpperLimitIsReached, positionBounds) | ||
|
||
update(positionUpdate, swarm, speed) | ||
|
||
return speed[1] .+ variables == particle.variables | ||
end | ||
|
||
function positionUpdateWorksProperlyWithASingleParticleWithPositionsOutOfBounds() | ||
velocityChangeWhenLowerLimitIsReached = -1.0 | ||
velocityChangeWhenUpperLimitIsReached = 1 | ||
positionBounds = [Bounds{Float64}(-10.0, 10.0), Bounds{Float64}(-15.0, 15.0)] | ||
speed = [[-1.0, 1.0]] | ||
variables = [-9.5, 14.5] | ||
|
||
particle = ContinuousSolution{Float64}(copy(variables), [1.5, 2.5], [], Dict(), positionBounds) | ||
swarm = [particle] | ||
|
||
positionUpdate = DefaultPositionUpdate(velocityChangeWhenLowerLimitIsReached, velocityChangeWhenUpperLimitIsReached, positionBounds) | ||
|
||
update(positionUpdate, swarm, speed) | ||
|
||
return [-10.0, 15.0] == particle.variables | ||
end | ||
|
||
|
||
@testset "Default position update tests" begin | ||
@test defaultPositionUpdateConstructorIsCorrectlyInitialized() | ||
@test positionUpdateWorksProperlyWithASingleParticle() | ||
@test positionUpdateWorksProperlyWithASingleParticleWithPositionsOutOfBounds() | ||
end |
40 changes: 40 additions & 0 deletions
40
test/component/particleSwarmOptimization/velocityUpdateTest.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Unit tests for DefaultVelocityUpdate | ||
|
||
function defaultVelocityUpdateIsCorrectlyInitialized() | ||
c1Min = 0.1 | ||
c1Max = 0.5 | ||
c2Min = 0.2 | ||
c2Max = 0.6 | ||
|
||
velocityUpdate = DefaultVelocityUpdate(c1Min, c1Max, c2Min, c2Max) | ||
|
||
return c1Min == velocityUpdate.c1Min && c1Max == velocityUpdate.c1Max && c2Min == velocityUpdate.c2Min && c2Max == velocityUpdate.c2Max | ||
end | ||
|
||
|
||
@testset "DefaultVelocityUpdate tests" begin | ||
@test defaultVelocityUpdateIsCorrectlyInitialized() | ||
end | ||
|
||
# Unit tests for ConstrainedVelocityUpdate | ||
|
||
function constrainedVelocityUpdateIsCorrectlyInitialized() | ||
c1Min = 0.1 | ||
c1Max = 0.5 | ||
c2Min = 0.2 | ||
c2Max = 0.6 | ||
problem = fonseca() | ||
|
||
velocityUpdate = ConstrainedVelocityUpdate(c1Min, c1Max, c2Min, c2Max, problem) | ||
|
||
# Bounds for the tree variables of problen Fonseca: [-4.0, 4.0] | ||
deltaMax = [(4.0 - -4.0)/2.0 for _ in 1:3] | ||
deltaMin = -deltaMax | ||
|
||
|
||
return c1Min == velocityUpdate.c1Min && c1Max == velocityUpdate.c1Max && c2Min == velocityUpdate.c2Min && c2Max == velocityUpdate.c2Max && deltaMax == velocityUpdate.deltaMax && deltaMin == velocityUpdate.deltaMin | ||
end | ||
|
||
@testset "ConstrainedVelocityUpdate tests" begin | ||
@test constrainedVelocityUpdateIsCorrectlyInitialized() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters