Skip to content

Commit

Permalink
Merge pull request #55 from jmejia8/develop
Browse files Browse the repository at this point in the history
update tests and export compatible MCDM methods from JMcDM
  • Loading branch information
jmejia8 authored Nov 14, 2022
2 parents 796942d + e7495db commit 94612ba
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
4 changes: 0 additions & 4 deletions docs/src/mcdm.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ more details about the methods.
Performing MCDM using a population.

```julia-repl
julia> using JMcDM
julia> _, _, population = Metaheuristics.TestProblems.ZDT1();
julia> dm = mcdm(population, [0.5, 0.5], TopsisMethod());
Expand All @@ -103,8 +101,6 @@ julia> population[dm.bestIndex]
Performing MCDM using results from metaheuristic.

```julia-repl
julia> using JMcDM
julia> f, bounds, _ = Metaheuristics.TestProblems.ZDT1();
julia> res = optimize(f, bounds, NSGA2());
Expand Down
2 changes: 1 addition & 1 deletion src/DecisionMaking/DecisionMaking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include("ROI.jl")
include("CompromiseProgramming.jl")

export decisionmaking, dm, best_alternative, ROIArchiving, CompromiseProgramming
export WeightedSum, Tchebysheff, AchievementScalarization
export WeightedSum, Tchebysheff, AchievementScalarization, summary

"""
decisionmaking(fs, w, method)
Expand Down
7 changes: 7 additions & 0 deletions src/DecisionMaking/JMcDM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export summary
export best_alternative


export ArasMethod, CocosoMethod, CodasMethod, CoprasMethod
export EdasMethod, ElectreMethod, GreyMethod, MabacMethod, MaircaMethod
export MooraMethod, SawMethod, TopsisMethod, VikorMethod, WPMMethod
export WaspasMethod, MarcosMethod
export DataFrame


"""
mcdm(fs, w, method)
Expand Down
12 changes: 6 additions & 6 deletions src/PerformanceIndicators/hypervolume.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ is a non-dominated set.
If `front::State` and `reference_point::Vector`, then computes `hypervolume(front.population, reference_point)` after
ignoring solutions in `front` that do not dominate `reference_point`.
"""
function hypervolume(front::Array{Vector{T}}, reference_point::Vector) where T <: Real
function hypervolume(front::Array{Vector{T}}, reference_point::Vector; verbose=true) where T <: Real

weaklyDominates(point, other) = begin
for i in 1:length(point)
Expand All @@ -187,16 +187,16 @@ function hypervolume(front::Array{Vector{T}}, reference_point::Vector) where T <
if length(relevantPoints) != length(front)
ign = length(front) - length(relevantPoints)
rel = length(relevantPoints)
@warn "Ignoring $ign points dominated by the reference point ($rel points are used)."
verbose && @warn "Ignoring $ign points dominated by the reference point ($rel points are used)."
end

return HyperVolume.hv(relevantPoints, reference_point)
end

hypervolume(front::Vector{T}, reference_point::Vector{T}) where T <: AbstractMultiObjectiveSolution = hypervolume(fval.(front), fval(reference_point))
hypervolume(front::Vector{T}, reference_point::Vector) where T <: AbstractMultiObjectiveSolution = hypervolume(fval.(front), reference_point)
hypervolume(front::Vector{T}, reference_point::Vector{T}; verbose=true) where T <: AbstractMultiObjectiveSolution = hypervolume(fval.(front), fval(reference_point); verbose)
hypervolume(front::Vector{T}, reference_point::Vector; verbose=true) where T <: AbstractMultiObjectiveSolution = hypervolume(fval.(front), reference_point;verbose)

function hypervolume(front::Matrix, reference_point::Vector)
function hypervolume(front::Matrix, reference_point::Vector; verbose=true)
front_ = [ front[i,:] for i in 1:size(front,1) ]
hypervolume(front_, reference_point)
hypervolume(front_, reference_point; verbose)
end
2 changes: 1 addition & 1 deletion test/common-methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ import Random: seed!
[1.1 ,0. ,0. ]]

referencePoint = [2.0, 2, 2]
hyperVolume = Metaheuristics.PerformanceIndicators.hypervolume(front, referencePoint)
hyperVolume = Metaheuristics.PerformanceIndicators.hypervolume(front, referencePoint, verbose=false)
@test hyperVolume 6.793879034744429

front_ = Array(hcat(front...)')
Expand Down
16 changes: 3 additions & 13 deletions test/decisionmaking.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import Metaheuristics.JMcDM
import Metaheuristics.JMcDM: ArasMethod, CocosoMethod, CodasMethod, CoprasMethod
import Metaheuristics.JMcDM: EdasMethod, ElectreMethod, GreyMethod, MabacMethod, MaircaMethod
import Metaheuristics.JMcDM: MooraMethod, SawMethod, TopsisMethod, VikorMethod, WPMMethod
import Metaheuristics.JMcDM: WaspasMethod, MarcosMethod
import Metaheuristics.JMcDM: DataFrame


@testset "DecisionMaking: Compromise Programming" begin
function test_cp()
_, _, pf = Metaheuristics.TestProblems.ZDT1();
Expand Down Expand Up @@ -52,8 +44,6 @@ end

w = [0.5, 0.5]

# PrometheeMethod
# PSIMethod, MoosraMethod --err
methods = [
ArasMethod, CocosoMethod, CodasMethod, CoprasMethod,
EdasMethod, ElectreMethod, GreyMethod, MabacMethod, MaircaMethod,
Expand All @@ -62,8 +52,8 @@ end
]

for method in methods
res_dm = JMcDM.mcdm(res, w, method())
res_dm2 = JMcDM.mcdm(MCDMSetting(res, w), method())
res_dm = mcdm(res, w, method())
res_dm2 = mcdm(MCDMSetting(res, w), method())
@test res_dm.bestIndex == res_dm2.bestIndex

# bestIndex can be touple and needs to be handled...
Expand All @@ -74,7 +64,7 @@ end
@test Metaheuristics.compare(fval(best_sol), fval(ref_sol)) == 0
end

@test JMcDM.summary(res, w, [:topsis, :electre, :vikor]) isa DataFrame
@test Metaheuristics.summary(res, w, [:topsis, :electre, :vikor]) isa DataFrame

# check default method TopsisMethod
@test mcdm(MCDMSetting(res, w)).bestIndex == mcdm(res, w, TopsisMethod()).bestIndex
Expand Down

8 comments on commit 94612ba

@jmejia8
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72198

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.2.13 -m "<description of version>" 94612babeb53a7bd7868c4e9f28fed155c34ed33
git push origin v3.2.13

@jbytecode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmejia8 - I can't wait to perform a

Pkg> update

to get my favourite package's new version!

@jbytecode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmejia8 - It seems the night build throws some error indeed.

@jbytecode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmejia8 - by the way, we get Your new version pull request met all of the guidelines for auto-merging and is scheduled to be merged in the next round. :) good news

@jbytecode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmejia8 - MERGED! 🎈

@jmejia8
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your valuable contributions to this package.

@jbytecode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmejia8 - Thank you for creating such a beautiful package and making it alive in Julia.

Please sign in to comment.