Beispiel #1
0
    def _evaluate(self,
                  x,  #
                  out,
                  *args,
                  **kwargs):
        """
        This method iterate over an Individual, execute the refactoring operation sequentially,
        and compute quality attributes for the refactored version of the program, as objectives of the search

        params:
        x (Individual): x is an instance of Individual (i.e., a list of refactoring operations)

        """
        # Stage 0: Git restore
        logger.debug("Executing git restore.")
        git_restore(config.PROJECT_PATH)
        update_understand_database(config.UDB_PATH)
        # Stage 1: Execute all refactoring operations in the sequence x
        logger.debug(f"Reached Individual with Size {len(x[0])}")
        for refactoring_operation in x[0]:
            refactoring_operation.do_refactoring()
            # Update Understand DB
            update_understand_database(config.UDB_PATH)

        # Stage 2: Computing quality attributes
        obj = Objectives(udb_path=config.UDB_PATH)
        o1 = obj.average
        del obj
        o2 = testability_main(config.UDB_PATH)
        o3 = modularity_main(config.UDB_PATH)
        logger.info(f"QMOOD AVG Score: {o1}")
        logger.info(f"Testability Score: {o2}")
        logger.info(f"Modularity Score: {o3}")
        # Stage 3: Marshal objectives into vector
        out["F"] = np.array([-1 * o1, -1 * o2, -1 * o3], dtype=float)
    def _evaluate(
            self,
            x,  #
            out,
            *args,
            **kwargs):
        """
        This method iterate over an Individual, execute the refactoring operation sequentially,
        and compute quality attributes for the refactored version of the program, as objectives of the search

        params:
        x (Individual): x is an instance of Individual (i.e., a list of refactoring operations)

        """
        # Git restore`
        logger.debug("Executing git restore.")
        git_restore(config.PROJECT_PATH)
        update_understand_database(config.UDB_PATH)
        # Stage 1: Execute all refactoring operations in the sequence x
        logger.debug(f"Reached Individual with Size {len(x[0])}")
        for refactoring_operation in x[0]:
            refactoring_operation.do_refactoring()
            # Update Understand DB
            update_understand_database(config.UDB_PATH)

        # Stage 2: Computing quality attributes
        qmood = DesignQualityAttributes(udb_path=config.UDB_PATH)
        o1 = qmood.reusability
        o2 = qmood.understandability
        o3 = qmood.flexibility
        o4 = qmood.functionality
        o5 = qmood.effectiveness
        o6 = qmood.extendability
        del qmood
        o7 = testability_main(config.UDB_PATH)
        o8 = modularity_main(config.UDB_PATH)

        logger.info(f"Reusability Score: {o1}")
        logger.info(f"Understandability Score: {o2}")
        logger.info(f"Flexibility Score: {o3}")
        logger.info(f"Functionality Score: {o4}")
        logger.info(f"Effectiveness Score: {o5}")
        logger.info(f"Extendability Score: {o6}")
        logger.info(f"Testability Score: {o7}")
        logger.info(f"Modularity Score: {o8}")

        # Stage 3: Marshal objectives into vector
        out["F"] = np.array([
            -1 * o1,
            -1 * o2,
            -1 * o3,
            -1 * o4,
            -1 * o5,
            -1 * o6,
            -1 * o7,
            -1 * o8,
        ],
                            dtype=float)
Beispiel #3
0
    def _evaluate(self, x, out, *args, **kwargs):
        """
        By default, elementwise_evaluation is set to False, which implies the _evaluate retrieves a set of solutions.

        params:
            x (Population): x is a matrix where each row is an individual, and each column a variable.
            We have one variable of type list (Individual) ==> x.shape = (len(Population), 1)

        """

        objective_values = []
        for k, individual_ in enumerate(x):
            # Stage 0: Git restore
            logger.debug("Executing git restore.")
            git_restore(config.PROJECT_PATH)
            logger.debug("Updating understand database after git restore.")
            update_understand_database(config.UDB_PATH)

            # Stage 1: Execute all refactoring operations in the sequence x
            logger.debug(
                f"Reached an Individual with size {len(individual_[0])}")
            for refactoring_operation in individual_[0]:
                refactoring_operation.do_refactoring()
                # Update Understand DB
                logger.debug(
                    f"Updating understand database after {refactoring_operation.name}."
                )
                update_understand_database(config.UDB_PATH)

            # Stage 2:
            arr = Array('d', range(8))
            if self.evaluate_in_parallel:
                # Stage 2 (parallel mood): Computing quality attributes
                p1 = Process(target=calc_qmood_objectives, args=(arr, ))
                p2 = Process(target=calc_testability_objective,
                             args=(
                                 config.UDB_PATH,
                                 arr,
                             ))
                p3 = Process(target=calc_modularity_objective,
                             args=(
                                 config.UDB_PATH,
                                 arr,
                             ))
                p1.start(), p2.start(), p3.start()
                p1.join(), p2.join(), p3.join()
            else:
                # Stage 2 (sequential mood): Computing quality attributes
                qmood = Objectives(udb_path=config.UDB_PATH)
                arr[0] = qmood.reusability
                arr[1] = qmood.understandability
                arr[2] = qmood.flexibility
                arr[3] = qmood.functionality
                arr[4] = qmood.effectiveness
                arr[5] = qmood.extendability
                arr[6] = testability_main(
                    config.UDB_PATH,
                    initial_value=config.CURRENT_METRICS.get("TEST", 1.0))
                arr[7] = modularity_main(
                    config.UDB_PATH,
                    initial_value=config.CURRENT_METRICS.get("MODULE", 1.0))
                del qmood

            # Stage 3: Marshal objectives into vector
            objective_values.append([-1 * i for i in arr])
            logger.info(
                f"Objective values for individual {k}: {[i for i in arr]}")

        # Stage 4: Marshal all objectives into out dictionary
        out['F'] = np.array(objective_values, dtype=float)
Beispiel #4
0
    def _evaluate(
            self,
            x,  #
            out,
            *args,
            **kwargs):
        """
        This method iterate over an Individual, execute the refactoring operation sequentially,
        and compute quality attributes for the refactored version of the program, as objectives of the search

        params:
        x (Population): x is a matrix where each row is an individual, and each column a variable.
            We have one variable of type list (Individual) ==> x.shape = (len(Population), 1)

        """
        objective_values = []
        for k, individual_ in enumerate(x):
            # Stage 0: Git restore
            logger.debug("Executing git restore.")
            git_restore(config.PROJECT_PATH)
            logger.debug("Updating understand database after git restore.")
            update_understand_database(config.UDB_PATH)

            # Stage 1: Execute all refactoring operations in the sequence x
            logger.debug(f"Reached Individual with Size {len(individual_[0])}")
            for refactoring_operation in individual_[0]:
                refactoring_operation.do_refactoring()
                # Update Understand DB
                logger.debug(
                    f"Updating understand database after {refactoring_operation.name}."
                )
                update_understand_database(config.UDB_PATH)

            # Stage 2:
            arr = Array('d', range(8))
            if self.evaluate_in_parallel:
                # Stage 2 (parallel mood): Computing quality attributes
                p1 = Process(target=calc_qmood_objectives, args=(arr, ))
                p2 = Process(target=calc_testability_objective,
                             args=(
                                 config.UDB_PATH,
                                 arr,
                             ))
                p3 = Process(target=calc_modularity_objective,
                             args=(
                                 config.UDB_PATH,
                                 arr,
                             ))
                p1.start(), p2.start(), p3.start()
                p1.join(), p2.join(), p3.join()
                o1 = sum([i for i in arr[:6]]) / 6.
                o2 = arr[7]
                o3 = arr[8]
            else:
                # Stage 2 (sequential mood): Computing quality attributes
                qmoods = Objectives(udb_path=config.UDB_PATH)
                o1 = qmoods.average
                o2 = testability_main(config.UDB_PATH,
                                      initial_value=config.CURRENT_METRICS.get(
                                          "TEST", 1.0))
                o3 = modularity_main(config.UDB_PATH,
                                     initial_value=config.CURRENT_METRICS.get(
                                         "MODULE", 1.0))
                del qmoods

            # Stage 3: Marshal objectives into vector
            objective_values.append([-1 * o1, -1 * o2, -1 * o3])
            logger.info(
                f"Objective values for individual {k}: {[-1 * o1, -1 * o2, -1 * o3]}"
            )

        # Stage 4: Marshal all objectives into out dictionary
        out['F'] = np.array(objective_values, dtype=float)
Beispiel #5
0
def calc_modularity_objective(path_, arr_):
    arr_[7] = modularity_main(path_,
                              initial_value=config.CURRENT_METRICS.get(
                                  "MODULE", 1.0))