Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A linear constraint with two linear variables still raises an issue if any non-linear variables are present in the system. #117

Closed
ronald-jaepel opened this issue Mar 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ronald-jaepel
Copy link
Collaborator

So

optimization_problem.add_variable('var_0', lb=-2, ub=2, transform="linear")
optimization_problem.add_variable('var_1', lb=-2, ub=2, transform="linear")
optimization_problem.add_variable('var_2', lb=0, ub=2, transform="log")

optimization_problem.add_linear_constraint(['var_0', 'var_1'], [-1, -0.5], 0)

raises

CADETProcessError: Non-linear transform was used in linear constraints.

Is this intended?

The reason is this section in

    @property
    def A_transformed(self):
        """np.ndarray: LHS Matrix of linear inequality constraints in transformed space.

        See Also
        --------
        A
        A_independent_transformed
        A_independent

        """
        A_t = self.A.copy()
        for a in A_t:
            for j, v in enumerate(self.variables):
                t = v.transform
                if isinstance(t, NoTransform):
                    continue

                if not t.is_linear:
                    raise CADETProcessError(
                        "Non-linear transform was used in linear constraints."
                    )

Which raises an error if any variable is not linear as long as there is a inequality constraint.

If this is a bug, my proposed solution would be to change this to

    @property
    def A_transformed(self):
        """np.ndarray: LHS Matrix of linear inequality constraints in transformed space.

        See Also
        --------
        A
        A_independent_transformed
        A_independent

        """
        A_t = self.A.copy()
        for a in A_t:
            for j, v in enumerate(self.variables):
                t = v.transform
                if isinstance(t, NoTransform):
                    continue

                if a[j] != 0 and not t.is_linear:
                    raise CADETProcessError(
                        "Non-linear transform was used in linear constraints."
                    )

So that only variables with a non-zero influence in the inequality constraint are checked.
I've pushed this to PR #116

@ronald-jaepel
Copy link
Collaborator Author

Closed as solved with #116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant