Skip to content

Commit

Permalink
Fixed a bug in the reference point method when comparing the type of …
Browse files Browse the repository at this point in the history
…request that resulted in erraneous comparisons for pickled request objects. Added test for the reference point method.
  • Loading branch information
Giovanni Misitano committed Aug 16, 2023
1 parent f0a98c2 commit 1f98371
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion desdeo_mcdm/interactive/ReferencePointMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def iterate(

if type(request).__name__ == RPMInitialRequest.__name__:
return self.handle_initial_request(request)
elif type(request).__name__ is RPMRequest.__name__:
elif type(request).__name__ == RPMRequest.__name__:
return self.handle_request(request)
else:
# if stop request, do nothing
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "desdeo-mcdm"
version = "1.3.1"
version = "1.3.2"
description = "Contains traditional optimization techniques from the field of Multiple-criteria decision-making. Methods belonging to the NIMBUS and NAUTILUS families can be found here. Part of the DESDEO framework."
authors = ["Giovanni Misitano", "Antti Luopajärvi"]
license = "MIT"
Expand Down
38 changes: 38 additions & 0 deletions tests/test_rpm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
import numpy as np
import numpy.testing as npt
from desdeo_problem.testproblems import river_pollution_problem
from desdeo_mcdm.interactive import ReferencePointMethod

def test_solve():
problem = river_pollution_problem()
problem.ideal = np.array([-6.34, -3.44, -7.5, 0, 0])
problem.nadir = np.array([-4.75, -2.85, -0.32, 9.70, 0.35])

method = ReferencePointMethod(problem, problem.ideal, problem.nadir)

request = method.start()

request.response = {"reference_point": np.array([-6.34, -3.44, -7.5, 0, 0])}
request = method.iterate(request)

solution_1 = request.content["current_solution"]
additionals_1 = request.content["additional_solutions"]

request.response = {"reference_point": np.array([-4.75, -2.85, -0.32, 9.70, 0.35]), "satisfied": False}
request = method.iterate(request)

solution_2 = request.content["current_solution"]
additionals_2 = request.content["additional_solutions"]

# make sure we get different solution for the different reference points
with npt.assert_raises(AssertionError):
npt.assert_almost_equal(solution_1, solution_2)

with npt.assert_raises(AssertionError):
npt.assert_almost_equal(additionals_1, additionals_2)

request.response = {"satisfied": True, "solution_index": 3}
request = method.iterate(request)

npt.assert_almost_equal(request.content["objective_vector"], additionals_2[2])

0 comments on commit 1f98371

Please sign in to comment.