File coinor_cbc_interface.py
has 584 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.
Configuration
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
class Configuration(interface.MathematicalProgrammingConfiguration, metaclass=inheritdocstring):
def __init__(self, verbosity=0, timeout=None, presolve='auto',
max_nodes=None, max_solutions=None, relax=False,
emphasis=0, cuts=-1, threads=0, *args, **kwargs):
super(Configuration, self).__init__(*args, **kwargs)
Model
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class Model(interface.Model, metaclass=inheritdocstring):
def _initialize_problem(self):
self.problem = mip.Model(solver_name=mip.CBC)
Function __init__
has 11 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, verbosity=0, timeout=None, presolve='auto',
Function _initialize_model_from_problem
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def _initialize_model_from_problem(self, problem):
if not isinstance(problem, mip.Model):
raise TypeError('Problem must be an instance of mip.Model, not ' + repr(type(problem)))
# Set problem
- 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 _remove_constraints
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def _remove_constraints(self, constraints):
not_removed = True
if len(constraints) > 350: # Need to figure out a good threshold here
keys = map(lambda c: c.name, constraints)
self._constraints = self._constraints.fromkeys(set(self._constraints.keys()).difference(set(keys)))
- 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 to_lp
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def to_lp(self):
self.update()
lp_form = ('Maximize' if self.problem.sense == mip.MAXIMIZE else 'Minimize') + '\n'
for i, (var, coef) in enumerate(self.problem.objective.expr.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"
Further reading
Function __setstate__
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def __setstate__(self, state):
for key, val in state.items():
if key != 'tolerances':
setattr(self, key, val)
# TODO: remove if check before final merge. Only here for backwards
- 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 type
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def type(self, value):
if not value in _VTYPE_TO_MIP_VTYPE:
raise ValueError(
'COIN-OR CBC cannot handle variables of type %s. ' % value +
'The following variable types are available:\n' +
- 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 primal
has a Cognitive Complexity of 6 (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:
return self.problem._constr_primal(self, True)
- 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 a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def __init__(self, verbosity=0, timeout=None, presolve='auto',
max_nodes=None, max_solutions=None, relax=False,
emphasis=0, cuts=-1, threads=0, *args, **kwargs):
super(Configuration, self).__init__(*args, **kwargs)
- 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"