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 bc005c76 authored by EXT José Ignacio Requeno Jarabo's avatar EXT José Ignacio Requeno Jarabo
Browse files

Cleaning code

parent 91e0d004
Pipeline #29231 failed with stages
in 5 minutes and 28 seconds
......@@ -47,7 +47,6 @@ def r(i):
>>> r(i)
>>> 0.5
"""
return round(i, ParetoLib.Geometry.__numdigits__)
......@@ -329,7 +328,6 @@ def incomparables(x, xprime):
>>> incomparables(x, xprime)
>>> True
"""
return (not greater_equal(x, xprime)) and (not greater_equal(xprime, x))
......@@ -456,7 +454,6 @@ def int_to_bin_list(x, pad=0):
>>> int_to_bin_list(x, 4)
>>> [0, 1, 0, 0]
"""
temp1 = [int(i) for i in bin(x)[2:]]
pad_temp = pad if pad > 0 else len(temp1)
temp2 = [0] * (pad_temp - len(temp1)) + temp1
......
......@@ -43,7 +43,6 @@ def r(i):
>>> r(i)
>>> 0.5
"""
return round(i, ParetoLib.Geometry.__numdigits__)
......
......@@ -293,47 +293,6 @@ class Rectangle(object):
"""
return dim(self.min_corner)
def diag_length(self):
# type: (Rectangle) -> tuple
"""
Maximal distance between corners of the Rectangle.
Args:
self (Rectangle): The Rectangle.
Returns:
tuple: Maximal distance between corners of the Rectangle.
Example:
>>> x = (0,0,0)
>>> y = (2,2,2)
>>> r = Rectangle(x,y)
>>> r.diag_length()
>>> (2.0,2.0,2.0)
"""
return subtract(self.max_corner, self.min_corner)
def norm(self):
# type: (Rectangle) -> float
"""
Norm of the diagonal.
Args:
self (Rectangle): The Rectangle.
Returns:
float: Norm of the diagonal.
Example:
>>> x = (0,0,0)
>>> y = (2,2,2)
>>> r = Rectangle(x,y)
>>> r.norm()
>>> 3.464
"""
diagonal = self.diag()
return diagonal.norm()
def _volume(self):
# type: (Rectangle) -> float
diagonal_length = self.diag_length()
......@@ -440,6 +399,47 @@ class Rectangle(object):
"""
return Segment(self.min_corner, self.max_corner)
def diag_vector(self):
# type: (Rectangle) -> tuple
"""
Maximal distance between corners of the Rectangle.
Args:
self (Rectangle): The Rectangle.
Returns:
tuple: Maximal distance between corners of the Rectangle.
Example:
>>> x = (0,0,0)
>>> y = (2,2,2)
>>> r = Rectangle(x,y)
>>> r.diag_vector()
>>> (2.0,2.0,2.0)
"""
return subtract(self.max_corner, self.min_corner)
def norm(self):
# type: (Rectangle) -> float
"""
Norm of the diagonal.
Args:
self (Rectangle): The Rectangle.
Returns:
float: Norm of the diagonal.
Example:
>>> x = (0,0,0)
>>> y = (2,2,2)
>>> r = Rectangle(x,y)
>>> r.norm()
>>> 3.464
"""
diagonal = self.diag()
return diagonal.norm()
def center(self):
# type: (Rectangle) -> tuple
"""
......
......@@ -18,7 +18,7 @@ Pareto point is located.
import math
from ParetoLib.Geometry.Point import maximum, minimum, greater_equal, less_equal, r
from ParetoLib.Geometry.Point import maximum, minimum, greater_equal, less_equal, div, add, r
import ParetoLib.Geometry.Point as Point
......@@ -196,7 +196,6 @@ class Segment (object):
>>> s.diag()
>>> (3.0, 3.0, 3.0)
"""
return Point.subtract(self.high, self.low)
def norm(self):
......@@ -217,6 +216,26 @@ class Segment (object):
>>> s.norm()
>>> 5.196
"""
diagonal = self.diag()
return Point.norm(diagonal)
def center(self):
# type: (Segment) -> tuple
"""
Center of the Segment.
Args:
self (Segment): The Segment.
Returns:
tuple: Center of the Segment.
Example:
>>> x = (0,0)
>>> y = (1,1)
>>> s = Segment(x,y)
>>> s.center()
>>> (0.5,0.5)
"""
offset = div(self.diag(), 2.0)
return add(self.low, offset)
......@@ -14,11 +14,10 @@ decimal digits is indicated by __numdigits__
"""
import sys
from math import log, floor
__name__ = 'Geometry'
__all__ = ['Lattice', 'Segment', 'Rectangle', 'ParRectangle', 'Point', 'PPoint']
# Maximum number of decimal digits that should be used in computations.
# This value depends on the accurary (i.e., number of bits) used for float representations.
__numdigits__ = int(floor(abs(log(sys.float_info.epsilon, 10))))
__numdigits__ = sys.float_info.dig
......@@ -32,6 +32,7 @@ EPS = 1e-5
DELTA = 1e-5
STEPS = float('inf')
def binary_search(x,
member,
error):
......@@ -49,16 +50,18 @@ def binary_search(x,
y.high = x.high
else:
# We don't know. We search for a point in the diagonal
dist = subtract(y.high, y.low)
# while greater_equal(dist, error):
# while any(dist_i > error[0] for dist_i in dist):
while not less_equal(dist, error):
# dist = subtract(y.high, y.low)
dist = y.norm()
# while not less_equal(dist, error):
while dist > error[0]:
i += 1
yval = div(add(y.low, y.high), 2.0)
# yval = div(add(y.low, y.high), 2.0)
yval = y.center()
# We need a oracle() for guiding the search
if member(yval):
y.high = yval
else:
y.low = yval
dist = subtract(y.high, y.low)
# dist = subtract(y.high, y.low)
dist = y.norm()
return y, i
......@@ -197,8 +197,8 @@ class ResultSet(object):
# rect.min_corner == rect.max_corner
# These kind of rectangles appear when the dicothomic search cannot find an intersection of the diagonal
# with the Pareto front
self.ylow = [li for li in self.ylow if li.diag_length() != 0.0]
self.yup = [li for li in self.yup if li.diag_length() != 0.0]
self.ylow = [li for li in self.ylow if li.diag_vector() != 0.0]
self.yup = [li for li in self.yup if li.diag_vector() != 0.0]
# Single points may appear in the boundary, so we don't remove them
# self.border = [li for li in self.border if li.diag_length() != 0]
......
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