forked from phoopies/DesignOptimizationCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateFloorGeometryDesingProblem.py
78 lines (59 loc) · 3.08 KB
/
createFloorGeometryDesingProblem.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from desdeo_mcdm.utilities.solvers import solve_pareto_front_representation
from desdeo_emo.EAs import NSGAIII
from modules.utils import save
from modules.GeometryDesign.problem import (
create_problem_constant_floor as create_problem,
)
import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings("ignore") # ignore warnings :)
# Creating geometry design problem with constant floor : tent like buildings
# Always optimizing surface area and volume
# ideal and nadir in respective order
# ideal = 0, 1
# nadir = 5, 0
# Set constraint for objectives, [lower, upper]
# If no constraint then set it to None
# Notice that breaking constraints will result in a penalty and therefore we might get results that break the constraints
constraints = np.array(
[
[0.2, None], # Surface area > 0.2
[
0.5,
0.8,
], # .5 < volume < .8. Even though we're not optimizing volume, we can set a constraint on it
[0.4, None], # Min height > 0.4
]
)
# How many 3d points should the hull be formed of
# more points => More complex problem : longer execution times
# Less points => More likely to fail in constructing the hull
variable_count = 15 # Around 15 - 25 seems to be good enough
# To create the problem we can call the gd_create method with the parameters defined earlier
# the pfront argument should be set to True if using the solve_pareto_front_representation method as it doesn't
# take account minimizing/maximizing. For everything else we can set it to False
# The method returns a MOProblem and a scalarmethod instance which can be passed to different Desdeo objects
problem, method = create_problem(variable_count, constraints, pfront=True)
# Two methods to solve the problem are shown below. Do not use them both at the same time!
# Use one, and comment out the other!
# Example on solving the pareto front : This might take some time so feel free to comment this out (lines 57 and 60).
# We will use the solve_pareto_front_representation method but one can change this to something else.
# The method takes the problem instance and a step size array
# The method will create reference points from nadir to ideal with these step sizes
# in this case : ref points = [[5,0], [4.5, 0], [4, 0] ... [5, 0.2], [4.8, 0.2] ... [0, 1]]
# large step sizes => less solutions but faster calculation
step_sizes = np.array([0.5, 0.2])
# The method returns the decision vectors and corresponding objective vectors
var, obj = solve_pareto_front_representation(problem, step_sizes, solver_method=method)
# Example on solving the pareto front using NSGA-III
evolver = NSGAIII(problem)
while evolver.continue_evolution():
evolver.iterate()
var, obj = evolver.end()
# save the solution if you wish, make sure to change the name to not accidentally overwrite an existing solution.
# Saved solutions can be used later to visualize it
# The solution will be saved to modules/DataAndVisualization/'name'
save("gdfExample", obj, var, problem.nadir, problem.ideal)
pd.DataFrame(obj).to_csv("objective_vectors_3.csv")
pd.DataFrame(var).to_csv("decision_vectors_3.csv")