package ca.pfv.spmf.algorithmmanager.descriptions;

import java.io.IOException;

import ca.pfv.spmf.algorithmmanager.AlgorithmType;
import ca.pfv.spmf.algorithmmanager.DescriptionOfAlgorithm;
import ca.pfv.spmf.algorithmmanager.DescriptionOfParameter;
import ca.pfv.spmf.algorithms.frequentpatterns.hmp.AlgoHMPHC;

/**
 * This class describes the HMPHC algorithm parameters.
 * It is designed to be used by the graphical and command line interface.
 *
 * HMPHC: HMP algorithm using Hill Climbing.
 * 
 * @author Chen Enze, Philippe Fournier-Viger et al.
 * 
 * @see AlgoHMPHC
 */
public class DescriptionAlgoHMPHC extends DescriptionOfAlgorithm {

    /** Default constructor */
    public DescriptionAlgoHMPHC() {
    }

    @Override
    public String getName() {
        return "HMP-HC";
    }

    @Override
    public String getAlgorithmCategory() {
        return "FREQUENT ITEMSET MINING";
    }

    @Override
    public String getURLOfDocumentation() {
        return "http://www.philippe-fournier-viger.com/spmf/HMPHillClimbing.php";
    }

    @Override
    public void runAlgorithm(String[] parameters, String inputFile, String outputFile) throws IOException {

        // Parameters (in order):
        // 0: number of patterns
        // 1: max iterations (optional)

        int maxCodeTableSize = getParamAsInteger(parameters[0]);

        AlgoHMPHC algo = new AlgoHMPHC();
        

        // Set optional max iterations
        if (parameters.length > 1 && !"".equals(parameters[1])) {
            // Set optional max iterations
            int maxIterations = getParamAsInteger(parameters[1]);
            algo.setMaxiterations(maxIterations);
        }

        // Run algorithm
        algo.runAlgorithm(inputFile, outputFile, maxCodeTableSize);

        // Print statistics
        algo.printStats();
    }

    @Override
    public DescriptionOfParameter[] getParametersDescription() {

        DescriptionOfParameter[] parameters = new DescriptionOfParameter[2];

        parameters[0] = new DescriptionOfParameter(
                "Max number of patterns",
                "(e.g. 4)",
                Integer.class,
                false);

        parameters[1] = new DescriptionOfParameter(
                "Max number of iterations",
                "(e.g. 15)",
                Integer.class,
                true);

        return parameters;
    }

    @Override
    public String getImplementationAuthorNames() {
        return "Chen Enze, Philippe Fournier-Viger et al.";
    }

    @Override
    public String[] getInputFileTypes() {
        return new String[]{"Database of instances",
                "Simple transaction database",
                "Transaction database"};
    }

    @Override
    public String[] getOutputFileTypes() {
        return new String[]{
                "Patterns",
                "Frequent patterns",
                "Frequent itemsets"};
    }

    @Override
    public AlgorithmType getAlgorithmType() {
        return AlgorithmType.DATA_MINING;
    }
}
