# Path: platypus/core.py
# class Solution(object):
#     """Class representing a solution to a problem.
#     
#     Attributes
#     ----------
#     problem: Problem
#         The problem.
#     variables: FixedLengthArray of objects
#         The values of the variables.
#     objectives: FixedLengthArray of float
#         The values of the objectives.  These values will only be assigned after
#         the solution is evaluated.
#     constraints: FixedLengthArray of float
#         The values of the constraints.  These values will only be assigned
#         after the solution is evaluated.
#     constraint_violation: float
#         The magnitude of the constraint violation.
#     feasible: bool
#         True if the solution does not violate any constraints; False otherwise.
#     evaluated: bool
#         True if the solution is evaluated; False otherwise.
#     """
#     
#     def __init__(self, problem):
#         """Creates a new solution for the given problem."""
#         super(Solution, self).__init__()
#         self.problem = problem
#         self.variables = FixedLengthArray(problem.nvars)
#         self.objectives = FixedLengthArray(problem.nobjs)
#         self.constraints = FixedLengthArray(problem.nconstrs)
#         self.constraint_violation = 0.0
#         self.evaluated = False
#         
#     def evaluate(self):
#         """Evaluates this solution."""
#         self.problem(self)
#         
#     def __repr__(self):
#         return self.__str__()
#         
#     def __str__(self):
#         return "Solution[" + ",".join(list(map(str, self.variables))) + "|" + ",".join(list(map(str, self.objectives))) + "|" + str(self.constraint_violation) + "]"
#     
#     def __deepcopy__(self, memo):
#         """Overridden to avoid cloning the problem definition."""
#         result = Solution(self.problem)
#         memo[id(self)] = result
#         
#         for k, v in self.__dict__.items():
#             if k != "problem":
#                 setattr(result, k, copy.deepcopy(v, memo))
#                 
#         return result
# 
# POSITIVE_INFINITY = float("inf")
# 
# EPSILON = sys.float_info.epsilon
# 
# class PlatypusError(Exception):
#     pass


import sys
import math
import random
import inspect
import operator
import functools
from functools import reduce
from .core import Solution, POSITIVE_INFINITY, EPSILON, PlatypusError
# Copyright 2015-2018 David Hadka
#
# This file is part of Platypus, a Python module for designing and using
# evolutionary algorithms (EAs) and multiobjective evolutionary algorithms
# (MOEAs).
#
# Platypus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Platypus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Platypus.  If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, division, print_function


def point_line_dist(point, line):
    return magnitude(subtract(multiply(float(dot(line, point))/float(dot(line, line)), line), point))
    
def magnitude(x):
    return math.sqrt(dot(x, x))

def add(x, y):
    return [x[i] + y[i] for i in range(len(x))]


# Path: platypus/core.py
# class Solution(object):
#     """Class representing a solution to a problem.
#     
#     Attributes
#     ----------
#     problem: Problem
#         The problem.
#     variables: FixedLengthArray of objects
#         The values of the variables.
#     objectives: FixedLengthArray of float
#         The values of the objectives.  These values will only be assigned after
#         the solution is evaluated.
#     constraints: FixedLengthArray of float
#         The values of the constraints.  These values will only be assigned
#         after the solution is evaluated.
#     constraint_violation: float
#         The magnitude of the constraint violation.
#     feasible: bool
#         True if the solution does not violate any constraints; False otherwise.
#     evaluated: bool
#         True if the solution is evaluated; False otherwise.
#     """
#     
#     def __init__(self, problem):
#         """Creates a new solution for the given problem."""
#         super(Solution, self).__init__()
#         self.problem = problem
#         self.variables = FixedLengthArray(problem.nvars)
#         self.objectives = FixedLengthArray(problem.nobjs)
#         self.constraints = FixedLengthArray(problem.nconstrs)
#         self.constraint_violation = 0.0
#         self.evaluated = False
#         
#     def evaluate(self):
#         """Evaluates this solution."""
#         self.problem(self)
#         
#     def __repr__(self):
#         return self.__str__()
#         
#     def __str__(self):
#         return "Solution[" + ",".join(list(map(str, self.variables))) + "|" + ",".join(list(map(str, self.objectives))) + "|" + str(self.constraint_violation) + "]"
#     
#     def __deepcopy__(self, memo):
#         """Overridden to avoid cloning the problem definition."""
#         result = Solution(self.problem)
#         memo[id(self)] = result
#         
#         for k, v in self.__dict__.items():
#             if k != "problem":
#                 setattr(result, k, copy.deepcopy(v, memo))
#                 
#         return result
# 
# POSITIVE_INFINITY = float("inf")
# 
# EPSILON = sys.float_info.epsilon
# 
# class PlatypusError(Exception):
#     pass


# Path: platypus/tools.py
import sys
import math
import random
import inspect
import operator
import functools
from functools import reduce
from .core import Solution, POSITIVE_INFINITY, EPSILON, PlatypusError

# Copyright 2015-2018 David Hadka
#
# This file is part of Platypus, a Python module for designing and using
# evolutionary algorithms (EAs) and multiobjective evolutionary algorithms
# (MOEAs).
#
# Platypus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Platypus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Platypus.  If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, division, print_function


def point_line_dist(point, line):
    return magnitude(subtract(multiply(float(dot(line, point))/float(dot(line, line)), line), point))
    
def magnitude(x):
    return math.sqrt(dot(x, x))

def add(x, y):
    return [x[i] + y[i] for i in range(len(x))]


def subtract(x, y):