File scipy_interface.py
has 492 lines of code (exceeds 250 allowed). Consider refactoring. Open
# Copyright 2015 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.
Problem
has 29 functions (exceeds 20 allowed). Consider refactoring. Open
class Problem(object):
"""
Scipy linprog problem. This object implements an object-oriented interface to the linprog solver function.
This class is wrapped by the Model object, but can also be used as a stand-alone low-level interface.
"""
Function _add_constraints
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def _add_constraints(self, constraints, sloppy=False):
if sloppy is False:
for c in constraints:
if not c.is_Linear:
raise ValueError("Scipy solver only works with linear constraints. Please use another interface.")
- Read upRead up
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 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, name, lb=None, ub=None, type="continuous", *args, **kwargs):
Function primal
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def primal(self):
if getattr(self, "problem", None) is not None and self.problem.status == interface.OPTIMAL:
if self.lb is not None:
primal = self.lb + self.problem.problem.get_constraint_slack(self.lower_constraint_name)
return primal
- Read upRead up
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 coefficient_dict
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def coefficient_dict(self):
if self.expression.is_Add:
coefficient_dict = {variable: coef for variable, coef in
self.expression.as_coefficients_dict().items() if variable.is_Symbol}
elif self.expression.is_Atom and self.expression.is_Symbol:
- Read upRead up
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 coefficient_dict
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def coefficient_dict(self, names=True):
if self.expression.is_Add:
coefficient_dict = {variable: coef for variable, coef in
self.expression.as_coefficients_dict().items() if variable.is_Symbol}
coefficient_dict = {var: float(coef) for var, coef in coefficient_dict.items()}
- Read upRead up
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"