KarrLab/conv_opt

View on GitHub
conv_opt/core.py

Summary

Maintainability
D
2 days
Test Coverage
B
89%

File core.py has 532 lines of code (exceeds 250 allowed). Consider refactoring.
Open

""" Module for solving linear and quadratic optimization problems using
multiple open-source and commercials solvers.

:Author: Jonathan Karr <jonrkarr@gmail.com>
:Date: 2017-11-14
Severity: Major
Found in conv_opt/core.py - About 1 day to fix

    Function get_type has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_type(self):
            """ Get the type of the model
    
            Returns:
                :obj:`ModelType`: model type
    Severity: Minor
    Found in conv_opt/core.py - About 2 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

    Function export has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def export(self, filename, format=None, solver=None):
            """ Export a model to a file in one of these support formats
    
            * **alp**: model with generic names in lp format, where the variable names are annotated to indicate the type and bounds of each variable
            * **cbf**
    Severity: Minor
    Found in conv_opt/core.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 convert has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def convert(self, options=None):
            """ Generate a data structure for the model for another package
    
            Args:
                options (:obj:`SolveOptions`, optional): options
    Severity: Minor
    Found in conv_opt/core.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

    Consider simplifying this complex logical expression.
    Open

            if Solver.cbc in preferred_solvers and format in ['lp']:
                from .solver import cbc
                simplex = cbc.CbcModel(self).get_model()
                simplex.writeLp(filename)
            elif Solver.cbc in preferred_solvers and format in ['mps']:
    Severity: Critical
    Found in conv_opt/core.py - About 1 hr to fix

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

          def solve(self, options=None):
              """ Solve the model
      
              Args:
                  options (:obj:`SolveOptions`, optional): options
      Severity: Minor
      Found in conv_opt/core.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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, solver=Solver.cplex, tune=False, presolve=Presolve.off, precision=64,
      Severity: Major
      Found in conv_opt/core.py - About 50 mins to fix

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

            def __init__(self, status_code, status_message, value, primals, reduced_costs, duals):
        Severity: Minor
        Found in conv_opt/core.py - About 45 mins to fix

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

              def __init__(self, name='', variables=None, objective_direction=ObjectiveDirection.minimize, objective_terms=None, constraints=None):
          Severity: Minor
          Found in conv_opt/core.py - About 35 mins to fix

            Avoid too many return statements within this function.
            Open

                        return minos.MinosModel(self, options)
            Severity: Major
            Found in conv_opt/core.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return mosek.MosekModel(self, options)
              Severity: Major
              Found in conv_opt/core.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return xpress.XpressModel(self, options)
                Severity: Major
                Found in conv_opt/core.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return scipy.ScipyModel(self, options)
                  Severity: Major
                  Found in conv_opt/core.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return gurobi.GurobiModel(self, options)
                    Severity: Major
                    Found in conv_opt/core.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return quadprog.QuadprogModel(self, options)
                      Severity: Major
                      Found in conv_opt/core.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return soplex.SoplexModel(self, options)
                        Severity: Major
                        Found in conv_opt/core.py - About 30 mins to fix

                          There are no issues that match your filters.

                          Category
                          Status