biosustain/optlang

View on GitHub
src/optlang/cplex_interface.py

Summary

Maintainability
F
4 days
Test Coverage

File cplex_interface.py has 793 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2013 Novo Nordisk Foundation Center for Biosustainability,
# Technical University of Denmark.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Severity: Major
Found in src/optlang/cplex_interface.py - About 1 day to fix

    Function _initialize_model_from_problem has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        def _initialize_model_from_problem(self, problem):
            if isinstance(problem, cplex.Cplex):
                self.problem = problem
                zipped_var_args = zip(self.problem.variables.get_names(),
                                      self.problem.variables.get_lower_bounds(),
    Severity: Minor
    Found in src/optlang/cplex_interface.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Model has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Model(interface.Model, metaclass=inheritdocstring):
        def _initialize_problem(self):
            self.problem = cplex.Cplex()
    
        def _initialize_model_from_problem(self, problem):
    Severity: Minor
    Found in src/optlang/cplex_interface.py - About 2 hrs to fix

      Function _add_constraints has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def _add_constraints(self, constraints, sloppy=False):
              super(Model, self)._add_constraints(constraints, sloppy=sloppy)
      
              linear_constraints = dict(lin_expr=[], senses=[], rhs=[], range_values=[], names=[])
              for constraint in constraints:
      Severity: Minor
      Found in src/optlang/cplex_interface.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _get_quadratic_expression has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_quadratic_expression(self, quadratic=None):
              if quadratic is None:
                  try:
                      quadratic = self.problem.objective.get_quadratic()
                  except IndexError:
      Severity: Minor
      Found in src/optlang/cplex_interface.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function objective has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def objective(self, value):
              value.problem = None
              if self._objective is not None:  # Reset previous objective
                  variables = self.objective.variables
                  if len(variables) > 0:
      Severity: Minor
      Found in src/optlang/cplex_interface.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, lp_method='primal', presolve="auto", verbosity=0, timeout=None,
      Severity: Major
      Found in src/optlang/cplex_interface.py - About 1 hr to fix

        Function solution_target has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def solution_target(self, value):
                if self.problem is not None:
                    params = self.problem.problem.parameters
                    try:
                        solution_target = params.optimalitytarget
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function _add_variables has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def _add_variables(self, variables):
                super(Model, self)._add_variables(variables)
                lb, ub, vtype, names, coeff = list(), list(), list(), list(), list()
                for variable in variables:
                    if variable.lb is None:
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function type has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def type(self, value):
                if self.problem is not None:
                    try:
                        cplex_kind = _VTYPE_TO_CPLEX_VTYPE[value]
                    except KeyError:
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function _get_expression has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def _get_expression(self):
                if self.problem is not None:
                    cplex_problem = self.problem.problem
                    try:
                        cplex_row = cplex_problem.linear_constraints.get_rows(self.name)
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function verbosity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def verbosity(self, value):
        
                class StreamHandler(StringIO):
        
                    def __init__(self, logger, *args, **kwargs):
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function _constraint_lb_and_ub_to_cplex_sense_rhs_and_range_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def _constraint_lb_and_ub_to_cplex_sense_rhs_and_range_value(lb, ub):
            """Helper function used by Constraint and Model"""
            if lb is None and ub is None:
                raise Exception("Free constraint ...")
            elif lb is None:
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function _set_presolve has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def _set_presolve(self, value):
                if getattr(self, 'problem', None) is not None:
                    presolve = self.problem.problem.parameters.preprocessing.presolve
                    if value is True:
                        presolve.set(presolve.values.on)
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, lp_method='primal', presolve="auto", verbosity=0, timeout=None,
                         solution_target="auto", qp_method="primal", *args, **kwargs):
                super(Configuration, self).__init__(*args, **kwargs)
                self.lp_method = lp_method
                self.presolve = presolve
        Severity: Minor
        Found in src/optlang/cplex_interface.py - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        There are no issues that match your filters.

        Category
        Status