File glpk_interface.py
has 727 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.
Model
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class Model(interface.Model, metaclass=inheritdocstring):
def _initialize_problem(self):
self.problem = glp_create_prob()
glp_create_index(self.problem)
if self.name is not None:
Function _initialize_model_from_problem
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def _initialize_model_from_problem(self, problem):
try:
self.problem = problem
glp_create_index(self.problem)
except TypeError:
- 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_variables
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def _remove_variables(self, variables):
if len(variables) > 0:
if len(variables) > 350:
delete_indices = [variable._index - 1 for variable in variables]
keep_indices = [i for i in range(0, len(self._variables)) if i not in delete_indices]
- 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 _get_expression
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _get_expression(self):
if self.problem is not None and self._expression_expired:
variables = self.problem._variables
def term_generator():
- 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 _glpk_set_col_bounds
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def _glpk_set_col_bounds(self, variable):
if variable.lb is None and variable.ub is None:
# 0.'s are ignored
glp_set_col_bnds(self.problem, variable._index, GLP_FR, 0., 0.)
elif variable.lb is None:
- 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 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, presolve="auto", verbosity=0, timeout=None, *args, **kwargs):
Function _glpk_set_row_bounds
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _glpk_set_row_bounds(self, constraint):
if constraint.lb is None and constraint.ub is None:
# 0.'s are ignored
glp_set_row_bnds(self.problem, constraint._index, GLP_FR, 0., 0.)
elif constraint.lb is None:
- 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 objective
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def objective(self, value):
value.problem = None
if self._objective is not None:
variables = self.objective.variables
for variable in variables:
- 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 6 (exceeds 5 allowed). Consider refactoring. Open
def __setstate__(self, state):
self.__init__()
for key, val in state.items():
if key != "tolerances":
setattr(self, key, val)
- 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 _optimize
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _optimize(self):
glp_scale_prob(self.problem, GLP_SF_AUTO)
status = self._run_glp_simplex()
# Sometimes GLPK gets itself stuck with an invalid basis. This will help it get rid of it.
- 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, presolve="auto", verbosity=0, timeout=None, *args, **kwargs):
super(Configuration, self).__init__(*args, **kwargs)
self._smcp = glp_smcp()
self._iocp = glp_iocp()
glp_init_smcp(self._smcp)
- 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"