-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_jmetal.py
61 lines (49 loc) · 2.34 KB
/
main_jmetal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import scenarios
from evaluation import NAPFDMetric
from jmetal.algorithm.singleobjective.genetic_algorithm import GeneticAlgorithm
from jmetal.operator import BinaryTournamentSelection
from jmetal.operator.crossover import PMXCrossover
from jmetal.operator.mutation import PermutationSwapMutation
from jmetal.util.observer import PrintObjectivesObserver
from jmetal.util.density_estimator import CrowdingDistance
from jmetal.util.observer import PrintObjectivesObserver
from jmetal.util.ranking import FastNonDominatedRanking
from jmetal.util.solutions.comparator import MultiComparator
from jmetal.util.termination_criterion import StoppingByEvaluations
from problem import TCPCI
if __name__ == "__main__":
metric = NAPFDMetric()
repo_path = "data"
dataset = 'deeplearning4j@deeplearning4j'
scenario_provider = scenarios.IndustrialDatasetScenarioProvider(f"{repo_path}/{dataset}/features-engineered.csv")
for (t, vsc) in enumerate(scenario_provider, start=1):
if(t > 1):
break
available_time = vsc.get_available_time()
metric.update_available_time(available_time)
test_cases = vsc.get_testcases()
IND_SIZE = len(test_cases)
if (IND_SIZE > 1):
# Run GA to find the best NAPFD in current commit
problem = TCPCI(metric=metric, test_cases=test_cases,
number_of_variables=IND_SIZE)
algorithm = GeneticAlgorithm(
problem=problem,
population_size=300,
offspring_population_size=300,
mutation=PermutationSwapMutation(0.01),
crossover=PMXCrossover(0.9),
selection=BinaryTournamentSelection(),
termination_criterion=StoppingByEvaluations(max=60000)
)
# algorithm.observable.register(observer=PrintObjectivesObserver(1000))
algorithm.run()
result = algorithm.get_result()
print(f"Commit: {t} - Fitness: {result.objectives[0]*-1} - Computing time: {algorithm.total_computing_time}")
else:
print(f"Commit: {t} - Fitness: {1}")
# print('Algorithm: ' + algorithm.get_name())
# print('Problem: ' + problem.get_name())
# print('Solution: ' + str(result.variables[0]))
# print('Fitness: ' + str(result.objectives[0]))
print()