Table of Contents
Fetching ...

Multi-objective Integer Linear Programming approach for Automatic Software Cognitive Complexity Reduction

Adriana Novoa-Hurtado, Rubén Saborido, Francisco Chicano, Manuel Giménez-Medina

TL;DR

This paper addresses the problem of reducing software cognitive complexity (CC) by applying extract-method refactoring within a multi-objective optimization framework. It extends prior single-objective ILP formulations to a MO-ILP model that minimizes the number of extractions while balancing CC and LOC across all resulting methods, using Pareto-optimal solutions. The authors implement an ILP CC reducer tool built with Pyomo and solved via CPLEX, and validate it on 121 open-source and 10 industrial Java methods, yielding rich Pareto fronts and hypervolume metrics. They discuss replication materials, practical implications, and future directions, noting licensing costs of CPLEX and proposing enhancements such as LLM-assisted method naming and scalability improvements.

Abstract

Clear and concise code is necessary to ensure maintainability, so it is crucial that the software is as simple as possible to understand, to avoid bugs and, above all, vulnerabilities. There are many ways to enhance software without changing its functionality, considering the extract method refactoring the primary process to reduce the effort required for code comprehension. The cognitive complexity measure employed in this work is the one defined by SonarSource, which is a company that develops well-known applications for static code analysis. This extraction problem can be modeled as a combinatorial optimization problem. The main difficulty arises from the existence of different criteria for evaluating the solutions obtained, requiring the formulation of the code extraction problem as a multi-objective optimization problem using alternative methods. We propose a multi-objective integer linear programming model to obtain a set of solutions that reduce the cognitive complexity of a given piece of code, such as balancing the number of lines of code and its cognitive complexity. In addition, several algorithms have been developed to validate the model. These algorithms have been integrated into a tool that enables the parameterised resolution of the problem of reducing software cognitive complexity.

Multi-objective Integer Linear Programming approach for Automatic Software Cognitive Complexity Reduction

TL;DR

This paper addresses the problem of reducing software cognitive complexity (CC) by applying extract-method refactoring within a multi-objective optimization framework. It extends prior single-objective ILP formulations to a MO-ILP model that minimizes the number of extractions while balancing CC and LOC across all resulting methods, using Pareto-optimal solutions. The authors implement an ILP CC reducer tool built with Pyomo and solved via CPLEX, and validate it on 121 open-source and 10 industrial Java methods, yielding rich Pareto fronts and hypervolume metrics. They discuss replication materials, practical implications, and future directions, noting licensing costs of CPLEX and proposing enhancements such as LLM-assisted method naming and scalability improvements.

Abstract

Clear and concise code is necessary to ensure maintainability, so it is crucial that the software is as simple as possible to understand, to avoid bugs and, above all, vulnerabilities. There are many ways to enhance software without changing its functionality, considering the extract method refactoring the primary process to reduce the effort required for code comprehension. The cognitive complexity measure employed in this work is the one defined by SonarSource, which is a company that develops well-known applications for static code analysis. This extraction problem can be modeled as a combinatorial optimization problem. The main difficulty arises from the existence of different criteria for evaluating the solutions obtained, requiring the formulation of the code extraction problem as a multi-objective optimization problem using alternative methods. We propose a multi-objective integer linear programming model to obtain a set of solutions that reduce the cognitive complexity of a given piece of code, such as balancing the number of lines of code and its cognitive complexity. In addition, several algorithms have been developed to validate the model. These algorithms have been integrated into a tool that enables the parameterised resolution of the problem of reducing software cognitive complexity.
Paper Structure (32 sections, 3 equations, 17 figures, 3 tables, 4 algorithms)

This paper contains 32 sections, 3 equations, 17 figures, 3 tables, 4 algorithms.

Figures (17)

  • Figure 1: Method routeAPacketTo in the Host class of the open-source project cybercaptor-server, used as running example in the project.
  • Figure 2: AST for code in Figure \ref{['fig:initial-running-example']}.
  • Figure 3: Objective space example and types of solutions that may appear in the objective space. Dominated solutions do not belong to the PF.
  • Figure 4: Method routeAPacketTo in the Host class of the open-source project cybercaptor-server, used as running example in the project. Comments show CC metrics of those statements contributing to the cognitive complexity of the method.
  • Figure 5: Overview of the proposed ILP CC reducer tool. *Objectives list is optional.
  • ...and 12 more figures