<commit_before>package com.hal9000.solver;

import com.hal9000.data.TSPInstance;
import com.hal9000.env.Arg;

import java.util.*;

/** Greedy solver implementation */
public class HeuristicSolver implements Solver {

    private final TSPInstance problem;
    private final Solution solution;
    private ArrayList<Integer> solutionSequence;
    private double best;

    public HeuristicSolver(TSPInstance problem) {
        this.problem = problem;

        List<Integer> fullSequence = new LinkedList<>();
        for (int i = 0; i < problem.getDim(); i++) {
            fullSequence.add(i);
        }

        List<Integer> sequence = new LinkedList<>();
        for (int i = 0; i < problem.getDim(); i++) {
            sequence.clear();
            sequence.addAll(fullSequence);
            generateSolution(sequence, i);
        }

        this.solution = new Solution(solutionSequence, problem);
    }

    private void generateSolution(List<Integer> sequence, int start) {
        ArrayList<Integer> tmpSolution = new ArrayList<>(problem.getDim());
        double score = 0.0;
        tmpSolution.add(start);
        int last = start;
        for (int i = 1; i < problem.getDim(); i++) {
            double distance;
            int bestIdx = 0;
            double bestDistance = problem.getDistance(last, sequence.get(0));
            for (int j = 1; j < sequence.size(); j++) {
                distance = problem.getDistance(last, sequence.get(j));
                if (distance < bestDistance) {
                    bestDistance = distance;
                    bestIdx = j;
                }
            }
            score += bestDistance;
            last = sequence.get(bestIdx);
            tmpSolution.add(last);
            sequence.remove(last);
        }
        score += problem.getDistance(last, start);

        if (solution == null || score < best) {
            solutionSequence = tmpSolution;
            best = score;
        }
    }

    public Solution solve(Arg argument) {
        return solution;
    }

}<commit_msg>heura fixes<commit_after>package com.hal9000.solver;

import com.hal9000.data.TSPInstance;
import com.hal9000.env.Arg;

import java.util.*;

/** Greedy solver implementation */
public class HeuristicSolver implements Solver {

    private final TSPInstance problem;
    private final Solution solution;
    private ArrayList<Integer> solutionSequence;
    private double best;

    public HeuristicSolver(TSPInstance problem) {
        this.problem = problem;

        List<Integer> fullSequence = new LinkedList<>();
        for (int i = 0; i < problem.getDim(); i++) {
            fullSequence.add(i);
        }

        List<Integer> sequence = new LinkedList<>();
        for (int i = 0; i < problem.getDim(); i++) {
            sequence.clear();
            sequence.addAll(fullSequence);
            generateSolution(sequence, i);
        }

        this.solution = new Solution(solutionSequence, problem);
    }

    private void generateSolution(List<Integer> sequence, int start) {
        ArrayList<Integer> tmpSolution = new ArrayList<>(problem.getDim());
        double score = 0.0;
        tmpSolution.add(start);
        sequence.remove(start);
        int last = start;
        for (int i = 1; i < problem.getDim(); i++) {
            double distance;
            int bestIdx = 0;
            double bestDistance = problem.getDistance(last, sequence.get(0));
            for (int j = 0; j < sequence.size(); j++) {
                distance = problem.getDistance(last, sequence.get(j));
                if (distance < bestDistance) {
                    bestDistance = distance;
                    bestIdx = j;
                }
            }
            score += bestDistance;
            last = sequence.get(bestIdx);
            tmpSolution.add(last);

            sequence.remove(bestIdx);
        }
        score += problem.getDistance(last, start);

        if (solution == null || score < best) {
            solutionSequence = tmpSolution;
            best = score;
        }
    }

    public Solution solve(Arg argument) {
        return solution;
    }

}
{'fraction_non_alphanumeric': 0.11046511627906977, 'fraction_numerical': 0.009689922480620155, 'mean_word_length': 1.9812274368231046, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '825154', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1062, 'n_words': 282}