-
Notifications
You must be signed in to change notification settings - Fork 2
/
simple_experiment.py
61 lines (51 loc) · 2.21 KB
/
simple_experiment.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
from gomors_sync_strategies import MoSyncStrategyNoConstraints
from gomors_adaptive_sampling import EvolutionaryAlgorithm
from test_problems import *
from pySOT import SymmetricLatinHypercube, RBFInterpolant, CubicKernel, LinearTail
from poap.controller import SerialController, ThreadController, BasicWorkerThread
from archiving_strategies import NonDominatedArchive, EpsilonArchive
import numpy as np
import os.path
import logging
#from Townbrook import *
def main():
if not os.path.exists("./logfiles"):
os.makedirs("logfiles")
if os.path.exists("./logfiles/test_simple.log"):
os.remove("./logfiles/test_simple.log")
logging.basicConfig(filename="./logfiles/test_simple.log",
level=logging.INFO)
nthreads = 4
maxeval = 100
nsamples = nthreads
print("\nNumber of threads: " + str(nthreads))
print("Maximum number of evaluations: " + str(maxeval))
print("Sampling method: Mixed")
print("Experimental design: Symmetric Latin Hypercube")
print("Surrogate: Cubic RBF")
#data = LZF3()
data = DTLZ4(nobj=2)
num = 1
epsilons = [0.05, 0.05]
# Create a strategy and a controller
controller = ThreadController()
#controller = SerialController(data.objfunction)
controller.strategy = \
MoSyncStrategyNoConstraints(
worker_id=0, data=data,
maxeval=maxeval, nsamples=nsamples,
exp_design=SymmetricLatinHypercube(dim=data.dim, npts=2*(data.dim+1)),
response_surface=RBFInterpolant(kernel=CubicKernel, tail=LinearTail,
maxp=maxeval),
sampling_method=EvolutionaryAlgorithm(data,epsilons=epsilons, cand_flag=1), archiving_method=EpsilonArchive(size_max=200,epsilon=epsilons))
# Launch the threads and give them access to the objective function
for _ in range(nthreads):
worker = BasicWorkerThread(controller, data.objfunction)
controller.launch_worker(worker)
# Run the optimization strategy
def merit(r):
return r.value[0]
result = controller.run(merit=merit)
controller.strategy.save_plot(num)
if __name__ == '__main__':
main()