<commit_before>import java.io.File;
import java.util.Scanner;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.CommandLine;

public class Main {

    public static void main(String[] args) throws Exception {
		// Разбор CLI
		CommandLineParser parser = new GnuParser();
		Options options = new Options();
		options.addOption( OptionBuilder.withLongOpt("input")
										.hasArg()
										.withDescription("input file")
										.create("i") );
		options.addOption( OptionBuilder.withLongOpt("output")
										.hasArg()
										.withDescription("output file")
										.create("o") );

		CommandLine line = parser.parse(options, args);

		String input, output;

		// Имя входного файла
		if (line.hasOption("input"))
            input = line.getOptionValue("input");
		else
			input = null;

        output = perform(input);

	  	// Вывод
		if (line.hasOption("output")) {
			try( PrintWriter out = new PrintWriter(line.getOptionValue("output")) ) {
				out.println(output);
			}
		} else {
			System.out.println(output);
		}
    }

	public static String perform(String inputFileName) {
		try {
            SimplexTable simplexTable = new SimplexTable(createSimplexTable(inputFileName));
	       	return simplexTable.problemString() + "\nSolution:\n\n" + solve(simplexTable);
		} catch (IOException e) {
			return "File not found: " + inputFileName;
		}
	}

    private static String solve(SimplexTable simplexTable) {
        int cols = simplexTable.cols();
        int rows = simplexTable.rows();
        int resCol, resRow;
        int [] rowNames = new int[rows];
        double [] solution = new double[rows];
        boolean solved = false;
		String answer = "";

        for (int j = 0; j < rows; j++)
            rowNames[j] = cols + j + 1;

        while (!solved) {
            resCol = simplexTable.findResCol();
            if (resCol == -1) {
				return "Objective function is unlimited\n";
            } else if (resCol == 0) {
                solved = true;
            } else {
                resRow = simplexTable.findResRow(resCol);
                rowNames[resRow] = resCol;
                simplexTable.step(resRow, resCol);
            }
        }

        for (int i = 1; i <= cols; i++) {
            int j = 0;
            for (; j < rows && rowNames[j] != i; j++);
			answer += "x" + i + " = ";
            if (j == rows) {
				answer += "0\n";
            }
            else {
				answer += simplexTable.getElement(j, 0) + "\n";
            }
        }
		answer += "max{ F(x) } = " + simplexTable.getElement(rows, 0) + '\n';
		return answer;
    }

    private static double[][] createSimplexTable(String fileName) throws IOException {

        Scanner scanner;

        if (fileName == null) {
            scanner = new Scanner(System.in);
        } else {
            scanner = new Scanner(new File(fileName));
        }

        if (fileName == null) System.out.print("Number of variables: ");
        int cols = scanner.nextInt();

        if (fileName == null) System.out.print("Number of limitations: ");
        int rows = scanner.nextInt();

        double [][] simplexTable = new double[rows + 1][cols + 1];

        simplexTable[rows][0] = 0;
        if (fileName == null) System.out.println("\nCOST FUNCTION");
        for (int i = 1; i <= cols; ++i) {
            if (fileName == null) System.out.print("  Multiplier #" + i + ": ");
            simplexTable[rows][i] = -scanner.nextDouble();<commit_msg>Set scanner locale<commit_after>import java.io.File;
import java.util.Scanner;
import java.util.Locale;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.CommandLine;

public class Main {

    public static void main(String[] args) throws Exception {
		// Разбор CLI
		CommandLineParser parser = new GnuParser();
		Options options = new Options();
		options.addOption( OptionBuilder.withLongOpt("input")
										.hasArg()
										.withDescription("input file")
										.create("i") );
		options.addOption( OptionBuilder.withLongOpt("output")
										.hasArg()
										.withDescription("output file")
										.create("o") );

		CommandLine line = parser.parse(options, args);

		String input, output;

		// Имя входного файла
		if (line.hasOption("input"))
            input = line.getOptionValue("input");
		else
			input = null;

        output = perform(input);

	  	// Вывод
		if (line.hasOption("output")) {
			try( PrintWriter out = new PrintWriter(line.getOptionValue("output")) ) {
				out.println(output);
			}
		} else {
			System.out.println(output);
		}
    }

	public static String perform(String inputFileName) {
		try {
            SimplexTable simplexTable = new SimplexTable(createSimplexTable(inputFileName));
	       	return simplexTable.problemString() + "\nSolution:\n\n" + solve(simplexTable);
		} catch (IOException e) {
			return "File not found: " + inputFileName;
		}
	}

    private static String solve(SimplexTable simplexTable) {
        int cols = simplexTable.cols();
        int rows = simplexTable.rows();
        int resCol, resRow;
        int [] rowNames = new int[rows];
        double [] solution = new double[rows];
        boolean solved = false;
		String answer = "";

        for (int j = 0; j < rows; j++)
            rowNames[j] = cols + j + 1;

        while (!solved) {
            resCol = simplexTable.findResCol();
            if (resCol == -1) {
				return "Objective function is unlimited\n";
            } else if (resCol == 0) {
                solved = true;
            } else {
                resRow = simplexTable.findResRow(resCol);
                rowNames[resRow] = resCol;
                simplexTable.step(resRow, resCol);
            }
        }

        for (int i = 1; i <= cols; i++) {
            int j = 0;
            for (; j < rows && rowNames[j] != i; j++);
			answer += "x" + i + " = ";
            if (j == rows) {
				answer += "0\n";
            }
            else {
				answer += simplexTable.getElement(j, 0) + "\n";
            }
        }
		answer += "max{ F(x) } = " + simplexTable.getElement(rows, 0) + '\n';
		return answer;
    }

    private static double[][] createSimplexTable(String fileName) throws IOException {

        Scanner scanner;

        if (fileName == null) {
            scanner = new Scanner(System.in).useLocale(new Locale("US"));
        } else {
            scanner = new Scanner(new File(fileName)).useLocale(new Locale("US"));
        }

        if (fileName == null) System.out.print("Number of variables: ");
        int cols = scanner.nextInt();

        if (fileName == null) System.out.print("Number of limitations: ");
        int rows = scanner.nextInt();

        double [][] simplexTable = new double[rows + 1][cols + 1];

        simplexTable[rows][0] = 0;
        if (fileName == null) System.out.println("\nCOST FUNCTION");
        for (int i = 1; i <= cols; ++i) {
            if (fileName == null) System.out.print("  Multiplier #" + i + ": ");
            simplexTable[rows][i] = -scanner.nextDouble();
{'fraction_non_alphanumeric': 0.1380939524838013, 'fraction_numerical': 0.003779697624190065, 'mean_word_length': 2.2624394539850288, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 3, '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': '2230658', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2190, 'n_words': 541}