biosustain/optlang

View on GitHub
src/optlang/gurobi_interface.py

Summary

Maintainability
D
2 days
Test Coverage

File gurobi_interface.py has 686 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/gurobi_interface.py - About 1 day to fix

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

    class Model(interface.Model):
    
        def _initialize_problem(self):
            self.problem = gurobipy.Model()
            self.problem.params.OutputFlag = 0
    Severity: Minor
    Found in src/optlang/gurobi_interface.py - About 2 hrs to fix

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

          def _initialize_model_from_problem(self, problem):
              if isinstance(problem, gurobipy.Model):
                  self.problem = problem
                  variables = []
                  for gurobi_variable in self.problem.getVars():
      Severity: Minor
      Found in src/optlang/gurobi_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 _add_constraints has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _add_constraints(self, constraints, sloppy=False):
              super(Model, self)._add_constraints(constraints, sloppy=sloppy)
              for constraint in constraints:
                  if constraint.lb is None and constraint.ub is None:
                      raise ValueError("optlang does not support free constraints in the gurobi interface.")
      Severity: Minor
      Found in src/optlang/gurobi_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 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, lp_method='primal', qp_method='primal', presolve=False,
      Severity: Major
      Found in src/optlang/gurobi_interface.py - About 50 mins to fix

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

            def _add_variables(self, variables):
                super(Model, self)._add_variables(variables)
                for variable in variables:
                    if variable.lb is None:
                        lb = -gurobipy.GRB.INFINITY
        Severity: Minor
        Found in src/optlang/gurobi_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_gurobi_sense_rhs_and_range_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def _constraint_lb_and_ub_to_gurobi_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/gurobi_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 __setstate__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def __setstate__(self, state):
                for key, val in state.items():
                    if key != "tolerances":
                        setattr(self, key, val)
                for key, val in state["tolerances"].items():
        Severity: Minor
        Found in src/optlang/gurobi_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 _get_expression has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def _get_expression(self):
                if self.problem is not None:
                    gurobi_problem = self.problem.problem
                    gurobi_constraint = self._internal_constraint
                    row = gurobi_problem.getRow(gurobi_constraint)
        Severity: Minor
        Found in src/optlang/gurobi_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 _set_constraint_bounds has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def _set_constraint_bounds(self, sense, rhs, range_value):
                gurobi_constraint = self.problem.problem.getConstrByName(self.name)
                gurobi_constraint.setAttr('Sense', sense)
                gurobi_constraint.setAttr('RHS', rhs)
        
        
        Severity: Minor
        Found in src/optlang/gurobi_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', qp_method='primal', presolve=False,
                         verbosity=0, timeout=None, *args, **kwargs):
                super(Configuration, self).__init__(*args, **kwargs)
                self.verbosity = verbosity
                self.lp_method = lp_method
        Severity: Minor
        Found in src/optlang/gurobi_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