Skip to content

Commit

Permalink
Add file test_rwa.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed Jul 3, 2023
1 parent 194eeb8 commit fb136df
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 3 deletions.
10 changes: 7 additions & 3 deletions jmetal/problem/multiobjective/rwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Chen2015(FloatProblem):

def __init__(self):
super(Chen2015, self).__init__()
self.name = 'Chen2015'

self.obj_directions = [self.MINIMIZE, self.MAXIMIZE, self.MAXIMIZE, self.MAXIMIZE, self.MINIMIZE]
self.obj_labels = ['F1', 'F2', 'F3', 'F4', 'F5']
Expand Down Expand Up @@ -413,7 +412,7 @@ def __init__(self):
super(Subasi2016, self).__init__()

self.lower_bound = [20.0, 6.0, 20.0, 0.0, 8000.0]
self.upper_bound = [60.0, 15.0, 40.0, 3.0, 25000.0]
self.upper_bound = [60.0, 15.0, 40.0, 30.0, 25000.0]

self.obj_labels = ['Nu', 'f']
self.obj_directions = [self.MINIMIZE, self.MINIMIZE]
Expand Down Expand Up @@ -518,7 +517,6 @@ class Xu2020(FloatProblem):
""" Problem Xu2020 (RWA6) described in the paper "Engineering applications of multi-objective evolutionary
algorithms: A test suite of box-constrained real-world problems". DOI: https://doi.org/10.1016/j.engappai.2023.106192
"""

def __init__(self):
super(Xu2020, self).__init__()

Expand All @@ -528,6 +526,12 @@ def __init__(self):
self.obj_labels = ['Ft', 'Ra', 'MRR']
self.obj_directions = [self.MINIMIZE, self.MINIMIZE, self.MAXIMIZE]

def number_of_objectives(self) -> int:
return len(self.obj_directions)

def number_of_constraints(self) -> int:
return 0

def evaluate(self, solution: FloatSolution) -> FloatSolution:
vc = solution.variables[0]
fz = solution.variables[1]
Expand Down
279 changes: 279 additions & 0 deletions jmetal/problem/multiobjective/test/test_rwa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
import unittest

from jmetal.problem.multiobjective.rwa import Ahmad2017, Chen2015, Ganesan2013, Gao2020, Goel2007, Liao2008, Padhi2016, \
Subasi2016, Vaidyanathan2004, Xu2020


class Ahmad2017TestCases(unittest.TestCase):
def setUp(self):
self.problem = Ahmad2017()

def test_number_of_variables(self):
self.assertEqual(3, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(7, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual(10.0, self.problem.lower_bound[0])
self.assertEqual(10.0, self.problem.lower_bound[1])
self.assertEqual(150.0, self.problem.lower_bound[2])

self.assertEqual(50.0, self.problem.upper_bound[0])
self.assertEqual(50.0, self.problem.upper_bound[1])
self.assertEqual(170.0, self.problem.upper_bound[2])

def test_name(self):
self.assertEqual("Ahmad2017", self.problem.name())


class Chen2015TestCases(unittest.TestCase):
def setUp(self):
self.problem = Chen2015()

def test_number_of_variables(self):
self.assertEqual(6, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(5, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual(17.5, self.problem.lower_bound[0])
self.assertEqual(17.5, self.problem.lower_bound[1])
self.assertEqual(2.0, self.problem.lower_bound[2])
self.assertEqual(2.0, self.problem.lower_bound[3])
self.assertEqual(5.0, self.problem.lower_bound[4])
self.assertEqual(5.0, self.problem.lower_bound[5])

self.assertEqual(22.5, self.problem.upper_bound[0])
self.assertEqual(22.5, self.problem.upper_bound[1])
self.assertEqual(3.0, self.problem.upper_bound[2])
self.assertEqual(3.0, self.problem.upper_bound[3])
self.assertEqual(7.0, self.problem.upper_bound[4])
self.assertEqual(6.0, self.problem.upper_bound[5])

def test_name(self):
self.assertEqual("Chen2015", self.problem.name())

class Ganesan2013TestCases(unittest.TestCase):
def setUp(self):
self.problem = Ganesan2013()

def test_number_of_variables(self):
self.assertEqual(3, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(3, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual(0.25, self.problem.lower_bound[0])
self.assertEqual(10000.0, self.problem.lower_bound[1])
self.assertEqual(600.0, self.problem.lower_bound[2])

self.assertEqual(0.55, self.problem.upper_bound[0])
self.assertEqual(20000.0, self.problem.upper_bound[1])
self.assertEqual(1100.0, self.problem.upper_bound[2])

def test_name(self):
self.assertEqual("Ganesan2013", self.problem.name())


class Gao2020TestCases(unittest.TestCase):
def setUp(self):
self.problem = Gao2020()

def test_number_of_variables(self):
self.assertEqual(9, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(3, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual(40.0, self.problem.lower_bound[0])
self.assertEqual(0.35, self.problem.lower_bound[1])
self.assertEqual(333.0, self.problem.lower_bound[2])
self.assertEqual(20.0, self.problem.lower_bound[3])
self.assertEqual(3000., self.problem.lower_bound[4])
self.assertEqual(0.1, self.problem.lower_bound[5])
self.assertEqual(308.0, self.problem.lower_bound[6])
self.assertEqual(150.0, self.problem.lower_bound[7])
self.assertEqual(0.1, self.problem.lower_bound[8])

self.assertEqual(100.0, self.problem.upper_bound[0])
self.assertEqual(0.5, self.problem.upper_bound[1])
self.assertEqual(363.0, self.problem.upper_bound[2])
self.assertEqual(40.0, self.problem.upper_bound[3])
self.assertEqual(4000.0, self.problem.upper_bound[4])
self.assertEqual(3.0, self.problem.upper_bound[5])
self.assertEqual(328.0, self.problem.upper_bound[6])
self.assertEqual(200, self.problem.upper_bound[7])
self.assertEqual(2.0, self.problem.upper_bound[8])

def test_name(self):
self.assertEqual("Gao2020", self.problem.name())


class Goel2007TestCases(unittest.TestCase):
def setUp(self):
self.problem = Goel2007()

def test_number_of_variables(self):
self.assertEqual(4, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(3, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual([0.0]*4, self.problem.lower_bound)
self.assertEqual([1.0]*4, self.problem.upper_bound)

def test_name(self):
self.assertEqual("Goel2007", self.problem.name())

class Liao2008TestCases(unittest.TestCase):
def setUp(self):
self.problem = Liao2008()

def test_number_of_variables(self):
self.assertEqual(5, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(3, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual([1.0]*5, self.problem.lower_bound)
self.assertEqual([3.0]*5, self.problem.upper_bound)

def test_name(self):
self.assertEqual("Liao2008", self.problem.name())


class Padhi2016TestCases(unittest.TestCase):
def setUp(self):
self.problem = Padhi2016()

def test_number_of_variables(self):
self.assertEqual(5, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(3, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual(1.0, self.problem.lower_bound[0])
self.assertEqual(10.0, self.problem.lower_bound[1])
self.assertEqual(850.0, self.problem.lower_bound[2])
self.assertEqual(20.0, self.problem.lower_bound[3])
self.assertEqual(4.0, self.problem.lower_bound[4])

self.assertEqual(1.4, self.problem.upper_bound[0])
self.assertEqual(26.0, self.problem.upper_bound[1])
self.assertEqual(1650.0, self.problem.upper_bound[2])
self.assertEqual(40.0, self.problem.upper_bound[3])
self.assertEqual(8.0, self.problem.upper_bound[4])

def test_name(self):
self.assertEqual("Padhi2016", self.problem.name())


class Subasi2016TestCases(unittest.TestCase):
def setUp(self):
self.problem = Subasi2016()

def test_number_of_variables(self):
self.assertEqual(5, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(2, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual(20.0, self.problem.lower_bound[0])
self.assertEqual(6.0, self.problem.lower_bound[1])
self.assertEqual(20.0, self.problem.lower_bound[2])
self.assertEqual(0.0, self.problem.lower_bound[3])
self.assertEqual(8000.0, self.problem.lower_bound[4])

self.assertEqual(60.0, self.problem.upper_bound[0])
self.assertEqual(15.0, self.problem.upper_bound[1])
self.assertEqual(40.0, self.problem.upper_bound[2])
self.assertEqual(30.0, self.problem.upper_bound[3])
self.assertEqual(25000.0, self.problem.upper_bound[4])

def test_name(self):
self.assertEqual("Subasi2016", self.problem.name())


class Vaidyanathan2004TestCases(unittest.TestCase):
def setUp(self):
self.problem = Vaidyanathan2004()

def test_number_of_variables(self):
self.assertEqual(4, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(4, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual([0.0]*4, self.problem.lower_bound)
self.assertEqual([1.0]*4, self.problem.upper_bound)

def test_name(self):
self.assertEqual("Vaidyanathan2004", self.problem.name())


class Xu2020TestCases(unittest.TestCase):
def setUp(self):
self.problem = Xu2020()

def test_number_of_variables(self):
self.assertEqual(4, self.problem.number_of_variables())

def test_number_of_objectives(self):
self.assertEqual(3, self.problem.number_of_objectives())

def test_number_of_constraints(self):
self.assertEqual(0, self.problem.number_of_constraints())

def test_variable_bounds(self):
self.assertEqual(12.56, self.problem.lower_bound[0])
self.assertEqual(0.02, self.problem.lower_bound[1])
self.assertEqual(1.0, self.problem.lower_bound[2])
self.assertEqual(0.5, self.problem.lower_bound[3])

self.assertEqual(25.12, self.problem.upper_bound[0])
self.assertEqual(0.06, self.problem.upper_bound[1])
self.assertEqual(5.0, self.problem.upper_bound[2])
self.assertEqual(2.0, self.problem.upper_bound[3])

def test_name(self):
self.assertEqual("Xu2020", self.problem.name())


if __name__ == "__main__":
unittest.main()

0 comments on commit fb136df

Please sign in to comment.