/*
* Copyright (C) 2016 Daniel Dietsch (dietsch@informatik.uni-freiburg.de)
* Copyright (C) 2016 University of Freiburg
*
* This file is part of the Ultimate Delta Debugger plug-in.
*
* The Ultimate Delta Debugger plug-in is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Ultimate Delta Debugger plug-in is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the Ultimate Delta Debugger plug-in. If not, see .
*
* Additional permission under GNU GPL version 3 section 7:
* If you modify the Ultimate Delta Debugger plug-in, or any covered work, by linking
* or combining it with Eclipse RCP (or a modified version of Eclipse RCP),
* containing parts covered by the terms of the Eclipse Public License, the
* licensors of the Ultimate Delta Debugger plug-in grant you additional permission
* to convey the resulting work.
*/
package de.uni_freiburg.informatik.ultimate.deltadebugger;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import org.apache.commons.cli.ParseException;
import de.uni_freiburg.informatik.ultimate.cli.CommandLineController;
import de.uni_freiburg.informatik.ultimate.cli.ParsedParameter;
import de.uni_freiburg.informatik.ultimate.cli.exceptions.InvalidFileArgumentException;
import de.uni_freiburg.informatik.ultimate.core.lib.results.ResultUtil;
import de.uni_freiburg.informatik.ultimate.core.lib.toolchain.RunDefinition;
import de.uni_freiburg.informatik.ultimate.core.model.ICore;
import de.uni_freiburg.informatik.ultimate.core.model.IToolchain;
import de.uni_freiburg.informatik.ultimate.core.model.IToolchainData;
import de.uni_freiburg.informatik.ultimate.core.model.preferences.IPreferenceInitializer;
import de.uni_freiburg.informatik.ultimate.core.model.preferences.IPreferenceProvider;
import de.uni_freiburg.informatik.ultimate.core.model.results.IResult;
import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger;
import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider;
import de.uni_freiburg.informatik.ultimate.deltadebugger.core.PassRunner;
import de.uni_freiburg.informatik.ultimate.deltadebugger.core.exceptions.UncheckedInterruptedException;
import de.uni_freiburg.informatik.ultimate.deltadebugger.core.parser.util.RewriteUtils;
import de.uni_freiburg.informatik.ultimate.deltadebugger.core.passes.HddPass;
import de.uni_freiburg.informatik.ultimate.deltadebugger.core.passes.RemoveUnreferencedPass;
import de.uni_freiburg.informatik.ultimate.deltadebugger.core.passes.ReplaceFunctionDefByDeclPass;
import de.uni_freiburg.informatik.ultimate.deltadebugger.core.search.minimizers.algorithms.BinarySearchMinimizer;
import de.uni_freiburg.informatik.ultimate.deltadebugger.externaltools.ExternalTool;
import de.uni_freiburg.informatik.ultimate.deltadebugger.externaltools.ExternalToolCPAChecker;
import de.uni_freiburg.informatik.ultimate.deltadebugger.externaltools.IExternalTool.ExternalToolResult;
import de.uni_freiburg.informatik.ultimate.deltadebugger.preferences.DeltaDebuggerPreferences;
import de.uni_freiburg.informatik.ultimate.deltadebugger.preferences.DeltaDebuggerPreferences.ExternalComparison;
/**
* The delta debugger controller can repeat a defined toolchain until the specified input cannot be reduced any further.
* This is a quick and dirty implementation with some unfortunate limitations: Parallel testing is not possible, because
* a global state has to be used to associate the results/exception of a toolchain execution. The test function which
* defines the behavior that has to be kept by the reduced variants is implemented right here in this class (
* {@link #isToolchainResultInteresting(ILogger)}). No user interaction is possible, final and intermediate output is
* written to the log.
*/
public class DeltaDebuggerController extends CommandLineController {
private Optional mException;
private Optional