constrained.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:jMetalPy 作者: jMetal 项目源码 文件源码
def evaluate_constraints(self, solution: FloatSolution) -> None:
        constraints : [float] = [0.0 for x in range(self.number_of_constraints)]

        x1 = solution.variables[0]
        x2 = solution.variables[1]

        constraints[0] = (x1 * x1 + x2 * x2 - 1.0 - 0.1 * cos(16.0 * atan(x1 / x2)))
        constraints[1] = -2.0 * ((x1 - 0.5) * (x1 - 0.5) + (x2 - 0.5) * (x2 - 0.5) - 0.5)

        overall_constraint_violation = 0.0
        number_of_violated_constraints = 0.0

        for constrain in constraints:
            if constrain < 0.0:
                overall_constraint_violation += constrain
                number_of_violated_constraints += 1

        solution.attributes["overall_constraint_violation"] = overall_constraint_violation
        solution.attributes["number_of_violated_constraints"] = number_of_violated_constraints
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号