Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit e33ae1c7 authored by EXT José Ignacio Requeno Jarabo's avatar EXT José Ignacio Requeno Jarabo
Browse files

Minor changes

parent 0f0fbb87
Pipeline #51862 failed with stages
in 62 minutes and 25 seconds
......@@ -1124,8 +1124,8 @@ class Rectangle(object):
self.max_corner = max_c
# Matplot functions
def plot_2D(self, c='red', xaxe=0, yaxe=1, opacity=1.0):
# type: (Rectangle, str, int, int, float) -> patches.Rectangle
def plot_2D(self, c='red', xaxe=0, yaxe=1, opacity=1.0, clipBox=None):
# type: (Rectangle, str, int, int, float, Rectangle) -> patches.Rectangle
"""
Function that creates a graphical representation of the rectangle in 2D.
In case that the rectangle has dimension higher than 2,
......@@ -1142,11 +1142,25 @@ class Rectangle(object):
"""
assert (self.dim() >= 2), 'Dimension required >= 2'
mc = (self.min_corner[xaxe], self.min_corner[yaxe],)
width = self.diag_vector()[xaxe]
height = self.diag_vector()[yaxe]
minc = (self.min_corner[xaxe], self.min_corner[yaxe],)
maxc = (self.max_corner[xaxe], self.max_corner[yaxe],)
if clipBox is not None:
clipminc = (clipBox.min_corner[xaxe], clipBox.min_corner[yaxe],)
clipmaxc = (clipBox.max_corner[xaxe], clipBox.max_corner[yaxe],)
minc = maximum(minc, clipminc)
minc = minimum(minc, clipmaxc)
maxc = minimum(maxc, clipmaxc)
maxc = maximum(maxc, clipminc)
rect = Rectangle(minc, maxc)
width = rect.diag_vector()[xaxe]
height = rect.diag_vector()[yaxe]
return patches.Rectangle(
mc, # (x,y)
minc, # (x,y)
width, # width
height, # height
# color = c, #color
......@@ -1156,7 +1170,7 @@ class Rectangle(object):
)
def plot_3D(self, c='red', xaxe=0, yaxe=1, zaxe=2, opacity=1.0, clipBox=None):
# type: (Rectangle, str, int, int, int, float) -> Poly3DCollection
# type: (Rectangle, str, int, int, int, float, Rectangle) -> Poly3DCollection
"""
Function that creates a graphical representation of the rectangle in 3D.
In case that the rectangle has dimension higher than 3,
......@@ -1176,23 +1190,16 @@ class Rectangle(object):
minc = (self.min_corner[xaxe], self.min_corner[yaxe], self.min_corner[zaxe],)
maxc = (self.max_corner[xaxe], self.max_corner[yaxe], self.max_corner[zaxe],)
if not (clipBox is None):
if clipBox is not None:
clipminc = (clipBox.min_corner[xaxe], clipBox.min_corner[yaxe], clipBox.min_corner[zaxe],)
clipmaxc = (clipBox.max_corner[xaxe], clipBox.max_corner[yaxe], clipBox.max_corner[zaxe],)
a = [self.min_corner[xaxe], self.min_corner[yaxe], self.min_corner[zaxe]]
b = [self.max_corner[xaxe], self.max_corner[yaxe], self.max_corner[zaxe]]
for i in range(len(a)):
if a[i] < clipminc[i]:
a[i] = clipminc[i]
elif a[i] > clipmaxc[i]:
a[i] = clipmaxc[i]
for i in range(len(b)):
if b[i] < clipminc[i]:
b[i] = clipminc[i]
elif b[i] > clipmaxc[i]:
b[i] = clipmaxc[i]
minc = (a[0], a[1], a[2],)
maxc = (b[0], b[1], b[2],)
minc = maximum(minc, clipminc)
minc = minimum(minc, clipmaxc)
maxc = minimum(maxc, clipmaxc)
maxc = maximum(maxc, clipminc)
rect = Rectangle(minc, maxc)
......
......@@ -216,12 +216,13 @@ class Segment (object):
return Point.norm(diagonal)
def center_eps(self, eps):
# type: (Segment) -> tuple
# type: (Segment, float) -> tuple
"""
off by eps from the center of the Segment.
Args:
self (Segment): The Segment, eps: a float value.
self (Segment): The Segment,
eps: a float value.
Returns:
tuple: eps-center of the Segment.
......@@ -276,5 +277,5 @@ class Segment (object):
>>> (1, 1)
"""
offset = div(self.diag(), 2.0)
offset = (math.floor(offset[0]), math.floor(offset[1]))
offset = tuple(math.floor(off_i) for off_i in offset)
return add(self.low, offset)
......@@ -22,7 +22,8 @@ actions on Evolutionary Computation, 2018.
"""
from ParetoLib.Geometry.Segment import Segment
import copy, math
import copy
import math
# EPS = sys.float_info.epsilon
# DELTA = sys.float_info.epsilon
......@@ -112,6 +113,7 @@ def discrete_binary_search(x,
def determine_intersection(y1, y2):
# type: (Segment, Segment) -> Segment
if y2.high <= y1.low:
return Segment(y1.high, y1.low), NO_INTER
elif y1.high <= y2.low:
......@@ -121,6 +123,7 @@ def determine_intersection(y1, y2):
def intersection_empty_constrained(x, member1, member2, list_constraints):
# type: (Segment, callable, callable, list) -> bool
low_allowed = True
high_allowed = True
for constraint in list_constraints:
......@@ -142,6 +145,7 @@ def intersection_empty_constrained(x, member1, member2, list_constraints):
def intersection_empty(x, member1, member2):
# type: (Segment, callable, callable) -> bool
# The cube doesn't contain an intersection.
return (not member1(x.high)) or (not member2(x.low))
......@@ -153,9 +157,40 @@ def intersection_expansion_search(x,
# member1 is the function whose truth value increases with x.
# member2 is the function whose truth value decreases with x.
def expand_lower_side(y, z, membership, error, eps):
# type: (Segment, Segment, callable, tuple, tuple) -> (Segment, Segment, int)
yIn = copy.deepcopy(y)
yCover = copy.deepcopy(y)
zgrek = copy.deepcopy(z)
# Try to expand on the lower side.
zgrek.high = eps
ygrek, i1 = binary_search(zgrek, membership, error)
yCover.low = ygrek.low
yIn.low = ygrek.high
return yIn, yCover, i1
def expand_upper_side(y, z, membership, error, eps):
# type: (Segment, Segment, callable, tuple, tuple) -> (Segment, Segment, int)
yIn = copy.deepcopy(y)
yCover = copy.deepcopy(y)
zgrek = copy.deepcopy(z)
# Try to expand on the upper side.
zgrek.low = eps
ygrek, i1 = binary_search(zgrek, membership, error)
yCover.high = ygrek.high
yIn.high = ygrek.low
return yIn, yCover, i1
# Try to find an intersection or a proof that there doesn't exist an intersection on the given segment.
i = 0
y = x
z = copy.deepcopy(y)
intersect_indicator = DKNOW
if member1(y.low) and member2(y.high):
# All the cube belongs to B1
......@@ -178,15 +213,11 @@ def intersection_expansion_search(x,
result1 = member1(yval)
result2 = member2(yval)
if result1 and result2:
# assign
z = copy.deepcopy(y)
y.low = yval
y.high = yval
intersect_indicator = INTER
break
elif not (result1 or result2):
# assign
z = copy.deepcopy(y)
y.low = yval
y.high = yval
intersect_indicator = NO_INTER
......@@ -202,45 +233,28 @@ def intersection_expansion_search(x,
yCover = copy.deepcopy(y)
# Expansion step here.
eps_minus = z.center_eps(-error[0] / 2)
eps_plus = z.center_eps(error[0] / 2)
if intersect_indicator == NO_INTER and to_expand:
eps_minus = z.center_eps(-error[0] / 2)
eps_plus = z.center_eps(error[0] / 2)
if not member2(eps_minus):
# Try to expand on the lower side.
zgrek1 = copy.deepcopy(z)
zgrek1.high = eps_minus
flip_member2 = lambda point: not member2(point)
ygrek, i1 = binary_search(zgrek1, flip_member2, error)
yIn, yCover, i1 = expand_lower_side(y, z, flip_member2, error, eps_minus)
i += i1
yCover.low = ygrek.low
yIn.low = ygrek.high
if not member1(eps_plus):
# Try to expand on the upper side.
zgrek2 = copy.deepcopy(z)
zgrek2.low = eps_plus
ygrek, i2 = binary_search(zgrek2, member1, error)
i += i2
yCover.high = ygrek.high
yIn.high = ygrek.low
yIn, yCover, i1 = expand_upper_side(y, z, member1, error, eps_plus)
i += i1
elif intersect_indicator == INTER:
eps_minus = z.center_eps(-error[0] / 2)
eps_plus = z.center_eps(error[0] / 2)
if member1(eps_minus):
# Try to expand on the lower side.
zgrek1 = copy.deepcopy(z)
zgrek1.high = eps_minus
ygrek, i1 = binary_search(zgrek1, member1, error)
yIn, yCover, i1 = expand_lower_side(y, z, member1, error, eps_minus)
i += i1
yCover.low = ygrek.low
yIn.low = ygrek.high
if member2(eps_plus):
# Try to expand on the upper side.
zgrek2 = copy.deepcopy(z)
zgrek2.low = eps_plus
flip_member2 = lambda point: not member2(point)
ygrek, i2 = binary_search(zgrek2, flip_member2, error)
i += i2
yCover.high = ygrek.high
yIn.high = ygrek.low
yIn, yCover, i1 = expand_upper_side(y, z, flip_member2, error, eps_plus)
i += i1
return yIn, yCover, intersect_indicator, i
\ No newline at end of file
......@@ -129,7 +129,6 @@ def multidim_search(xspace,
end = time.time()
time0 = end - start
RootSearch.logger.info('Time multidim search: ' + str(time0))
print 'Time multidim search (pareto front): ' + str(time0)
return rs
......
......@@ -566,8 +566,9 @@ class ResultSet(object):
var_names=list(),
blocking=False,
sec=0.0,
opacity=1.0, fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, list, bool, float, float) -> plt
opacity=1.0,
fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, list, bool, float, float, str) -> plt
fig1 = plt.figure()
# ax1 = fig1.add_subplot(111, aspect='equal')
ax1 = fig1.add_subplot(111)
......@@ -620,15 +621,17 @@ class ResultSet(object):
plt.close()
return plt
def plot_2D_figs(self,rs2,
filename='',
xaxe=0,
yaxe=1,
var_names=list(),
blocking=False,
sec=0.0,
opacity=1.0, fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, list, bool, float, float, str) -> plt
def plot_2D_figs(self,
rs2,
filename='',
xaxe=0,
yaxe=1,
var_names=list(),
blocking=False,
sec=0.0,
opacity=1.0,
fig_title='Approximation of the Pareto front'):
# type: (ResultSet, ResultSet, str, int, int, list, bool, float, float, str) -> plt
fig1 = plt.figure()
# ax1 = fig1.add_subplot(111, aspect='equal')
ax1 = fig1.add_subplot(111)
......@@ -690,8 +693,9 @@ class ResultSet(object):
var_names=list(),
blocking=False,
sec=0.0,
opacity=1.0, fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, list, bool, float, float) -> plt
opacity=1.0,
fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, list, bool, float, float, str) -> plt
fig1 = plt.figure()
# ax1 = fig1.add_subplot(111, aspect='equal')
......@@ -751,14 +755,15 @@ class ResultSet(object):
yaxe=1,
var_names=list(),
blocking=False,
sec=0.0):
# type: (ResultSet, str, int, int, list, bool, float) -> plt
sec=0.0,
fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, list, bool, float, str) -> plt
fig1 = plt.figure()
# ax1 = fig1.add_subplot(111, aspect='equal')
ax1 = fig1.add_subplot(111)
# ax1.set_title('Approximation of the Pareto front, Parameters (' + str(xaxe) + ', ' + str(yaxe) + ')')
ax1.set_title('Approximation of the Pareto front')
ax1.set_title(fig_title)
# The name of the inferred parameters using Pareto search are written in the axes of the graphic.
# For instance, axe 0 represents parameter 'P0', axe 1 represents parameter 'P1', etc.
......@@ -840,7 +845,9 @@ class ResultSet(object):
var_names=list(),
blocking=False,
sec=0.0,
opacity=1.0, fig_title='Approximation of the Pareto front', clip=False):
opacity=1.0,
fig_title='Approximation of the Pareto front',
clip=False):
# type: (ResultSet, str, int, int, int, list, bool, float, float, str, bool) -> plt
fig1 = plt.figure()
......@@ -900,6 +907,79 @@ class ResultSet(object):
plt.close()
return plt
def plot_3D_figs(self,
rs2,
filename='',
xaxe=0,
yaxe=1,
zaxe=2,
var_names=list(),
blocking=False,
sec=0.0,
opacity=1.0,
fig_title='Approximation of the Pareto front',
clip=False):
# type: (ResultSet, ResultSet, str, int, int, int, list, bool, float, float, str, bool) -> plt
fig1 = plt.figure()
# ax1 = fig1.add_subplot(111, aspect='equal', projection='3d')
ax1 = fig1.add_subplot(111, projection='3d')
ax1.set_title(fig_title)
# The name of the inferred parameters using Pareto search are written in the axes of the graphic.
# For instance, axe 0 represents parameter 'P0', axe 1 represents parameter 'P1', etc.
# If parameter names are not provided (var_names is empty or smaller than 2D), then we use
# lexicographic characters by default.
var_names = [chr(i) for i in range(ord('a'), ord('z') + 1)] if len(var_names) < 3 else var_names
ax1.set_xlabel(var_names[xaxe % len(var_names)])
ax1.set_ylabel(var_names[yaxe % len(var_names)])
ax1.set_zlabel(var_names[zaxe % len(var_names)])
if clip:
clipB = self.xspace
else:
clipB = None
faces_yup = self._plot_yup_3D(xaxe, yaxe, zaxe, opacity, clipBox=clipB)
faces_ylow = self._plot_ylow_3D(xaxe, yaxe, zaxe, opacity, clipBox=clipB)
faces_border = self._plot_border_3D(xaxe, yaxe, zaxe, opacity, clipBox=clipB)
faces = faces_yup
faces += faces_ylow
faces += faces_border
faces += rs2._plot_yup_3D(xaxe, yaxe, opacity)
faces += rs2._plot_ylow_3D(xaxe, yaxe, opacity)
for faces_i in faces:
ax1.add_collection3d(faces_i)
# Set limits in the axes
ax1.set_xlim(self.xspace.min_corner[xaxe], self.xspace.max_corner[xaxe])
ax1.set_ylim(self.xspace.min_corner[yaxe], self.xspace.max_corner[yaxe])
ax1.set_zlim(self.xspace.min_corner[zaxe], self.xspace.max_corner[zaxe])
#
fig1.tight_layout()
plt.tight_layout()
#
# plt.autoscale()
plt.xscale('linear')
plt.yscale('linear')
# plt.zscale('linear')
if sec > 0.0 and not blocking:
plt.ion()
plt.show()
plt.pause(float(sec))
else:
plt.ioff()
plt.show()
if filename != '':
fig1.savefig(filename, dpi=90, bbox_inches='tight')
plt.close()
return plt
def plot_3D_light(self,
filename='',
xaxe=0,
......@@ -908,7 +988,8 @@ class ResultSet(object):
var_names=list(),
blocking=False,
sec=0.0,
opacity=1.0, fig_title='Approximation of the Pareto front'):
opacity=1.0,
fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, int, list, bool, float, float, str) -> plt
fig1 = plt.figure()
# ax1 = fig1.add_subplot(111, aspect='equal', projection='3d')
......@@ -970,12 +1051,13 @@ class ResultSet(object):
zaxe=2,
var_names=list(),
blocking=False,
sec=0.0):
# type: (ResultSet, str, int, int, int, list, bool, float) -> plt
sec=0.0,
fig_title='Approximation of the Pareto front'):
# type: (ResultSet, str, int, int, int, list, bool, float, str) -> plt
fig1 = plt.figure()
# ax1 = fig1.add_subplot(111, aspect='equal', projection='3d')
ax1 = fig1.add_subplot(111, projection='3d')
ax1.set_title('Approximation of the Pareto front')
ax1.set_title(fig_title)
# The name of the inferred parameters using Pareto search are written in the axes of the graphic.
# For instance, axe 0 represents parameter 'P0', axe 1 represents parameter 'P1', etc.
......
(<=
(On (0 2000000000) (Count
(and
(>= x2 1)
(not
(StlUntil (0 inf)
(and
(and
(>= (On (-p1 p1) (Max x0) ) (- 0 p3))
(>= x0 (- 0 p3))
)
(and
(<= ( On (p1 70) ( - (Max x0) (Min x0) ) ) p2)
(<= ( On (-70 -p1) ( - (Max x0) (Min x0) ) ) p2)
)
)
(not
(>= x2 1)
)
)
)
)
)
)
1
)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment