-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Gleb Solovev <[email protected]>
- Loading branch information
Showing
223 changed files
with
21,627 additions
and
5,345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import pickle | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
from breakwaters.breakwaters_utils import parse_arctic_geojson | ||
|
||
from gefest.core.configs.optimization_params import OptimizationParams | ||
from gefest.core.configs.tuner_params import TunerParams | ||
from gefest.core.geometry.datastructs.structure import Structure | ||
from gefest.core.geometry.domain import Domain | ||
from gefest.core.opt.objective.objective import Objective | ||
from gefest.tools.estimators.simulators.swan.swan_interface import Swan | ||
|
||
root_path = Path(__file__).parent.parent.parent.parent | ||
result_path = 'cases/breakwaters/newdata/result_PwiOsA2HE2igZUel.geojson' | ||
border_path = 'cases/breakwaters/newdata/border_PwiOsA2HE2igZUel.geojson' | ||
|
||
|
||
allow_water = parse_arctic_geojson( | ||
result_path=result_path, | ||
border_path=border_path, | ||
root_path=root_path | ||
) | ||
allow_area = [[74.80, 67.92], [74.80, 67.94]] + allow_water + [[74.80, 67.92]] | ||
grid_resolution_x = 17 # Number of points on x-axis | ||
grid_resolution_y = 31 # Number of points on y-axis | ||
coord_y = np.linspace( | ||
min([p[1] for p in allow_area]) * 500, | ||
max([p[1] for p in allow_area]) * 500, | ||
grid_resolution_y + 1, | ||
) # X coordinate for spatial grid | ||
coord_x = np.linspace( | ||
min([p[0] for p in allow_area]) * 500, | ||
max([p[0] for p in allow_area]) * 500, | ||
grid_resolution_x + 1, | ||
) | ||
grid = [grid_resolution_x, grid_resolution_y] # points grid | ||
fixed_area = None | ||
targets = [[10, 15], [12, 14], [14, 14], [16, 14]] | ||
# targets = [[i,11] for i in [10,12,14,16]] | ||
# WINDWIND 19.1 225 | ||
# targets = [[14,10],[16,10],[18,10]] | ||
# # # Metrics # # # | ||
|
||
|
||
def load_file_from_path(path: str): | ||
"""Func to load pickle file. | ||
:param path: | ||
:return: | ||
""" | ||
with open(path, "rb") as f: | ||
_file = pickle.load(f) | ||
f.close() | ||
|
||
return _file | ||
|
||
|
||
# # # Precompute domain arguments # # # | ||
|
||
pass | ||
|
||
# # # | ||
|
||
domain_cfg = Domain( | ||
allowed_area=[ | ||
(min(coord_x), min(coord_y)), | ||
(min(coord_x), max(coord_y)), | ||
(max(coord_x), max(coord_y)), | ||
(max(coord_x), min(coord_y)), | ||
(min(coord_x), min(coord_y)), | ||
], | ||
name="main", | ||
min_poly_num=1, | ||
max_poly_num=4, | ||
min_points_num=3, | ||
max_points_num=4, | ||
polygon_side=0.0001, | ||
min_dist_from_boundary=0.0001, | ||
geometry_is_convex=False, | ||
geometry_is_closed=False, | ||
geometry="2D", | ||
) | ||
|
||
tuner_cfg = TunerParams( | ||
tuner_type="sequential", | ||
n_steps_tune=25, | ||
hyperopt_dist="uniform", | ||
verbose=True, | ||
timeout_minutes=60, | ||
) | ||
# # # Estimator # # # | ||
path_ = f"{root_path}/cases/breakwaters/ob2_upd/" | ||
swan_estimator = Swan( | ||
targets=targets, | ||
domain=domain_cfg, | ||
grid=grid, | ||
path=path_, | ||
hs_file_path="results/HSig_ob_example.dat", | ||
) | ||
# # # # # # | ||
|
||
|
||
class BreakWatersFitness(Objective): | ||
"""Class to init Objective for BreakWater case.""" | ||
def __init__(self, domain, estimator): | ||
super().__init__(domain, estimator) | ||
self.estimator = estimator | ||
|
||
def _evaluate(self, ind: Structure): | ||
fitness = self.estimator(ind) | ||
return fitness | ||
|
||
|
||
estimator = BreakWatersFitness(domain_cfg, swan_estimator) | ||
opt_params = OptimizationParams( | ||
optimizer="gefest_ga", | ||
domain=domain_cfg, | ||
tuner_cfg=tuner_cfg, | ||
n_steps=4, | ||
pop_size=10, | ||
postprocess_attempts=15, | ||
mutation_prob=0.6, | ||
crossover_prob=0.6, | ||
mutations=[ | ||
"rotate_poly", | ||
"resize_poly", | ||
"add_point", | ||
"drop_point", | ||
"add_poly", | ||
"drop_poly", | ||
"pos_change_point", | ||
], | ||
selector="tournament_selection", | ||
mutation_each_prob=[0.125, 0.125, 0.15, 0.35, 0.00, 0.00, 0.25], | ||
crossovers=[ | ||
"polygon_level", | ||
"structure_level", | ||
], | ||
crossover_each_prob=[0.0, 1.0], | ||
postprocess_rules=[ | ||
"not_out_of_bounds", | ||
"valid_polygon_geom", | ||
"not_self_intersects", | ||
"not_too_close_polygons", | ||
# 'not_overlaps_prohibited', | ||
"not_too_close_points", | ||
], | ||
extra=4, | ||
n_jobs=-1, | ||
log_dir="logs", | ||
run_name="run_name", | ||
golem_keep_histoy=False, | ||
golem_genetic_scheme_type="steady_state", | ||
golem_surrogate_each_n_gen=5, | ||
objectives=[ | ||
estimator, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
# import numpy as np | ||
# from shapely.geometry import shape | ||
|
||
|
||
def parse_arctic_geojson(result_path, border_path, root_path): | ||
"""Function for parsing data for breakwaters case. | ||
:param result_path: path to result data | ||
:param border_path: path to border info data | ||
:param root_path: root path | ||
:return: | ||
""" | ||
with open( | ||
f"{root_path}/{result_path}", "r" | ||
) as file: | ||
res_list = json.load(file) | ||
|
||
water = [i for i in res_list["features"] if i["properties"]["type"] == "water"] | ||
water_coord = [p["geometry"]["coordinates"] for p in water] | ||
allow_water = [ | ||
i | ||
for i in water_coord[0][0] | ||
if (i[0] > 74.8) and (i[1] < 67.942) and (i[1] > 67.915) | ||
] | ||
|
||
return allow_water |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[74.81798968,67.93215759],[74.81798995,67.93215759],[74.8194412,67.93211759],[74.81944121,67.93211759],[74.81944121,67.93211759],[74.82586478,67.93194054],[74.82586523,67.93194051],[74.82586967,67.93194005],[74.82587049,67.9319399],[74.82587414,67.93193885],[74.82587474,67.93193859],[74.82587706,67.93193709],[74.82587736,67.93193676],[74.825878,67.93193505],[74.82587802,67.93193488],[74.82581336,67.93149107],[74.82977234,67.93138194],[74.8297728,67.93138191],[74.82977723,67.93138146],[74.82977806,67.9313813],[74.8297817,67.93138025],[74.82978231,67.93137999],[74.82978462,67.9313785],[74.82978493,67.93137817],[74.82978556,67.93137646],[74.82978558,67.93137628],[74.82951015,67.92948781],[74.82951008,67.92948763],[74.8295089,67.92948592],[74.82950849,67.9294856],[74.82950564,67.92948419],[74.82950522,67.92948405],[74.82922587,67.9275387],[74.82922587,67.9275387],[74.82922587,67.92753865],[74.82922587,67.92753865],[74.82921124,67.92745329],[74.82921124,67.92745329],[74.82921123,67.92745324],[74.82921123,67.92745324],[74.82824882,67.92256293],[74.82824874,67.92256275],[74.82824858,67.92256254],[74.82795309,67.92106018],[74.82795301,67.92106001],[74.82795177,67.92105832],[74.82795135,67.92105801],[74.82794849,67.92105663],[74.82794778,67.9210564],[74.82794374,67.92105554],[74.82794286,67.92105543],[74.82793824,67.92105521],[74.82793778,67.92105521],[74.82397911,67.92116436],[74.82397865,67.92116439],[74.82397416,67.92116486],[74.82397333,67.92116502],[74.82397328,67.92116503],[74.82397318,67.92116501],[74.8239723,67.9211649],[74.82396768,67.92116469],[74.82396722,67.92116468],[74.81754797,67.92134168],[74.81754771,67.92134167],[74.81609737,67.92138166],[74.81609737,67.92138166],[74.8173539,67.9277831],[74.81798968,67.93215759]]]},"properties":{"type":"boundary"}}]} |
Oops, something went wrong.