<commit_before>package at.ngmpps.fjsstt.factory;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.ngmpps.fjsstt.model.problem.FJSSTTproblem;
import at.ngmpps.fjsstt.model.problem.FJSSTTproblem.Objective;

public class ProblemParser {
	static final Logger logger = LoggerFactory.getLogger(ProblemParser.class);

	static Pattern firstlinePattern = Pattern.compile("(\\d+)\\W(\\d+)");
	static Pattern operationsLinePattern = Pattern.compile("(\\d+)\\W(.+)(\\d+)\\W(\\d+)\\W(\\d+)");
	static Pattern operationsProcessesPattern = Pattern.compile("(\\d+)");
	static Pattern transportTimesLinePatter = Pattern.compile("(\\d+)");

	public static String PROBLEM_FILE_EXTENSION = "fjs";
	public static String TRANSPORT_FILE_EXTENSION = "transport";
	public static String CONFIG_FILE_EXTENSION = "properties";

	public static final String SEARCH_TYPE_KEY = "SubgradientSearch.SearchType";
	public static final String SEARCH_NR_TIME_SLOTS_KEY = "SubgradientSearch.NrTimeSlots";
	public static final String TRANSPORT_FILE_KEY = "SubgradientSearch.TransportFile";

	// fjs file to pares
	File problemFile;

	Properties configuration = new Properties();
	// File file;

	// Objective is to fill to be able to create a FJSSTT_problem
	int jobs;

	int machines;

	// perJob
	int[] operations;

	int maxOperations;

	// make timeslots in the problem the maxDueDate found in the files
	int timeslotsMaxDueDate;

	// The sets of alternative machines per operation. A key is an
	// integer tuple (job,operation), the corresponding value is the set
	// of alternative machines.
	HashMap<String, List<Integer>> altMachines;

	// The first index is the job, the second index is the operation,
	// and the third index is the machine.
	int[][][] processTimes;

	int[][] travelTimes;

	// per job
	int[] dueDates;

	// job priorities
	int[] jobWeights;

	// default objective function for parsed files
	Objective objective = Objective.TARDINESS;

	public ProblemParser() {
	}

	/**
	 * Based on the fjs File find also a .properties file with the same name and
	 * the transport file configured there.
	 * 
	 * @param file
	 * @return
	 * @throws URISyntaxException
	 * @throws IOException
	 */
	public static FJSSTTproblem parseProblemWithProblemFile(final File file) throws URISyntaxException, IOException {
		final ProblemParser parse = new ProblemParser();
		return parse.parseProblemConfig(file);
	}

	/**
	 * Based on the fjs File find also a .properties file with the same name and
	 * the transport file configured there.
	 * <commit_msg>new problemOnlyParse Method<commit_after>package at.ngmpps.fjsstt.factory;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.ngmpps.fjsstt.model.problem.FJSSTTproblem;
import at.ngmpps.fjsstt.model.problem.FJSSTTproblem.Objective;

public class ProblemParser {
	static final Logger logger = LoggerFactory.getLogger(ProblemParser.class);

	static Pattern firstlinePattern = Pattern.compile("(\\d+)\\W(\\d+)");
	static Pattern operationsLinePattern = Pattern.compile("(\\d+)\\W(.+)(\\d+)\\W(\\d+)\\W(\\d+)");
	static Pattern operationsProcessesPattern = Pattern.compile("(\\d+)");
	static Pattern transportTimesLinePatter = Pattern.compile("(\\d+)");

	public static String PROBLEM_FILE_EXTENSION = "fjs";
	public static String TRANSPORT_FILE_EXTENSION = "transport";
	public static String CONFIG_FILE_EXTENSION = "properties";

	public static final String SEARCH_TYPE_KEY = "SubgradientSearch.SearchType";
	public static final String SEARCH_NR_TIME_SLOTS_KEY = "SubgradientSearch.NrTimeSlots";
	public static final String TRANSPORT_FILE_KEY = "SubgradientSearch.TransportFile";

	// fjs file to pares
	File problemFile;

	Properties configuration = new Properties();
	// File file;

	// Objective is to fill to be able to create a FJSSTT_problem
	int jobs;

	int machines;

	// perJob
	int[] operations;

	int maxOperations;

	// make timeslots in the problem the maxDueDate found in the files
	int timeslotsMaxDueDate;

	// The sets of alternative machines per operation. A key is an
	// integer tuple (job,operation), the corresponding value is the set
	// of alternative machines.
	HashMap<String, List<Integer>> altMachines;

	// The first index is the job, the second index is the operation,
	// and the third index is the machine.
	int[][][] processTimes;

	int[][] travelTimes;

	// per job
	int[] dueDates;

	// job priorities
	int[] jobWeights;

	// default objective function for parsed files
	Objective objective = Objective.TARDINESS;

	public ProblemParser() {
	}

	/**
	 * Based on the fjs File find also a .properties file with the same name and
	 * the transport file configured there.
	 * 
	 * @param file
	 * @return
	 * @throws URISyntaxException
	 * @throws IOException
	 */
	public static FJSSTTproblem parseProblemWithProblemFile(final File file) throws URISyntaxException, IOException {
		final ProblemParser parse = new ProblemParser();
		return parse.parseProblemConfig(file);
	}

	/**
	 * Based on the fjs File find also a .properties file with the same name and
	 * the transport file configured there.
	 * 
	 * @param file
	 * @return
	 * @throws URISyntaxException
	 * @throws IOException
	 */
	public static FJSSTTproblem parseProblemFileOnly(final File file) throws URISyntaxException, IOException {
		final ProblemParser parse = new ProblemParser();
		List<File> files = checkOrFindFile(file, PROBLEM_FILE_EXTENSION);
		if (files.size() > 0) {
			parse.problemFile = files.get(0);
			parse.parseProblemFile();
			return parse.getProblem();
		}
		return null;
	}

	
	/**
	 * Based on the fjs File find also a .properties file with the same name and
	 * the transport file configured there.
	 * 
{'fraction_non_alphanumeric': 0.1021886317115415, 'fraction_numerical': 0.000944733112895607, 'mean_word_length': 4.438356164383562, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, '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': '1214889', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1889, 'n_words': 591}