Skip to content

Commit

Permalink
add SA from old core, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MangaBoba committed Dec 18, 2023
1 parent 6f1dcba commit 374217a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 139 deletions.
2 changes: 1 addition & 1 deletion gefest/core/opt/adapters/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class StructureFactory(RandomGraphFactory):
"""Simple GEFEST sampler wrap for GOLEM RandomGraphFactory compatibility."""
"""GOLEM RandomGraphFactory version of GEFEST sampler."""

def __init__(
self,
Expand Down
7 changes: 6 additions & 1 deletion gefest/core/opt/objective/objective_eval.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from typing import Union

from golem.utilities.data_structures import ensure_wrapped_in_sequence

from gefest.core.geometry.datastructs.structure import Structure
from gefest.core.opt.objective.objective import Objective
from gefest.core.utils import where
Expand All @@ -20,10 +24,11 @@ def __init__(

def __call__(
self,
pop: list[Structure],
pop: Union[list[Structure], Structure],
**kwargs,
) -> list[Structure]:
"""Calls objectives evaluation."""
pop = ensure_wrapped_in_sequence(pop)
return self.set_pop_objectives(pop=pop)

def set_pop_objectives(
Expand Down
16 changes: 9 additions & 7 deletions gefest/core/viz/struct_vizualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class StructVizualizer:
"""

def __init__(self, domain: Domain):
def __init__(self, domain: Domain = None):
self.domain = domain

def plot_structure(self, structs: list[Structure], domain=None, infos=None, linestyles='-'):
def plot_structure(self, structs: list[Structure], infos=None, linestyles='-', legend=False):
"""The method displays the given list[obj:`Structure`].
Args:
Expand Down Expand Up @@ -52,8 +52,8 @@ def plot_structure(self, structs: list[Structure], domain=None, infos=None, line
x = [pt.x for pt in boundary.points]
y = [pt.y for pt in boundary.points]
plt.plot(x, y, 'k')
if domain.prohibited_area:
for poly in domain.prohibited_area:
if self.domain.prohibited_area:
for poly in self.domain.prohibited_area:
self.plot_poly(poly, '-', color='m')

for poly in struct.polygons:
Expand All @@ -62,7 +62,9 @@ def plot_structure(self, structs: list[Structure], domain=None, infos=None, line
lines = [
Line2D([0], [0], color='black', linewidth=3, linestyle=style) for style in linestyles
]
plt.legend(lines, infos, loc=2)
if legend:
plt.legend(lines, infos, loc=2)

return fig

def plot_poly(self, poly, linestyle, **kwargs):
Expand All @@ -88,14 +90,14 @@ def plot_poly(self, poly, linestyle, **kwargs):
class GIFMaker(StructVizualizer):
"""Smple API for saving a series of plots in mp4 with moviepy."""

def __init__(self, domain) -> None:
def __init__(self, domain=None) -> None:
super().__init__(domain=domain)
self.frames = []
self.counter = 0

def create_frame(self, structure, infos):
"""Appends new frame from given structure."""
fig = self.plot_structure(structure, self.domain, infos)
fig = self.plot_structure(structure, infos)
numpy_fig = mplfig_to_npimage(fig)
self.frames.append(numpy_fig)
plt.close()
Expand Down
Loading

0 comments on commit 374217a

Please sign in to comment.